delete world progress, pointer lock fixes

This commit is contained in:
LAX1DUDE 2022-05-01 21:29:27 -07:00
parent da198ea1c3
commit 7a3989e88e
8 changed files with 8978 additions and 8950 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -99,8 +99,8 @@ public class EaglercraftSaveManager implements ISaveFormat {
}
@Override
public void deleteWorldByDirectory(String s) {
FilesystemUtils.recursiveDeleteDirectory(directory + "/" + s);
public void deleteWorldByDirectory(String s, IProgressUpdate progress) {
FilesystemUtils.recursiveDeleteDirectoryWithProgress(directory + "/" + s, "Deleting World", "%i chunks", progress);
}
@Override

View File

@ -5,27 +5,45 @@ import java.util.function.Consumer;
import net.lax1dude.eaglercraft.EaglerAdapter;
import net.lax1dude.eaglercraft.adapter.EaglerAdapterImpl2.FileEntry;
import net.minecraft.src.IProgressUpdate;
public class FilesystemUtils {
public static void recursiveDeleteDirectory(String dir) {
Collection<FileEntry> lst = EaglerAdapter.listFiles(dir, true, true);
lst.forEach(new Consumer<FileEntry>() {
@Override
public void accept(FileEntry t) {
for(FileEntry t : lst) {
if(!t.isDirectory) {
EaglerAdapter.deleteFile(t.path);
}
}
});
lst.forEach(new Consumer<FileEntry>() {
@Override
public void accept(FileEntry t) {
for(FileEntry t : lst) {
if(t.isDirectory) {
EaglerAdapter.deleteFile(t.path);
}
}
EaglerAdapter.deleteFile(dir);
}
public static void recursiveDeleteDirectoryWithProgress(String dir, String title, String subText, IProgressUpdate progress) {
progress.displayLoadingString(title, "(please wait)");
Collection<FileEntry> lst = EaglerAdapter.listFiles(dir, true, true);
int totalDeleted = 0;
int lastTotalDeleted = 0;
for(FileEntry t : lst) {
if(!t.isDirectory) {
EaglerAdapter.deleteFile(t.path);
++totalDeleted;
if(totalDeleted - lastTotalDeleted >= 10) {
lastTotalDeleted = totalDeleted;
progress.displayLoadingString(title, subText.replace("%i", "" + totalDeleted));
}
}
}
for(FileEntry t : lst) {
if(t.isDirectory) {
EaglerAdapter.deleteFile(t.path);
}
}
});
EaglerAdapter.deleteFile(dir);
}

View File

@ -889,7 +889,10 @@ public abstract class Minecraft implements Runnable {
world.func_651_a(loadingScreen);
}
field_22009_h = thePlayer;
field_6289_L = true;
mouseHelper.func_774_a();
} else {
ungrabMouseCursor();
thePlayer = null;
}
System.gc();

View File

@ -131,7 +131,7 @@ public class GuiSelectWorld extends GuiScreen {
if (flag) {
ISaveFormat isaveformat = mc.func_22004_c();
isaveformat.flushCache();
isaveformat.deleteWorldByDirectory(func_22091_c(i));
isaveformat.deleteWorldByDirectory(func_22091_c(i), mc.loadingScreen);
func_22084_k();
}
mc.displayGuiScreen(this);

View File

@ -18,7 +18,7 @@ public interface ISaveFormat {
public abstract WorldInfo getWorldInfoForWorld(String s);
public abstract void deleteWorldByDirectory(String s);
public abstract void deleteWorldByDirectory(String s, IProgressUpdate progress);
public abstract void renameWorldData(String s, String s1);

View File

@ -235,6 +235,7 @@ public class EaglerAdapterImpl2 {
mouseEvents.add(evt);
evt.preventDefault();
evt.stopPropagation();
forceMouseGrabbed();
}
});
canvas.addEventListener("mouseup", mouseup = new EventListener<MouseEvent>() {
@ -266,6 +267,7 @@ public class EaglerAdapterImpl2 {
keyEvents.add(evt);
evt.preventDefault();
evt.stopPropagation();
forceMouseGrabbed();
}
});
win.addEventListener("keyup", keyup = new EventListener<KeyboardEvent>() {
@ -304,6 +306,7 @@ public class EaglerAdapterImpl2 {
@Override
public void handleEvent(WheelEvent evt) {
isWindowFocused = true;
forceMouseGrabbed();
}
});
onBeforeCloseRegister();
@ -916,7 +919,9 @@ public class EaglerAdapterImpl2 {
}
private static long mouseUngrabTimer = 0l;
private static int mouseUngrabTimeout = 0;
private static boolean needsPointerLock = false;
public static final void mouseSetGrabbed(boolean grabbed) {
needsPointerLock = grabbed;
if(grabbed) {
canvas.requestPointerLock();
long t = System.currentTimeMillis();
@ -935,6 +940,17 @@ public class EaglerAdapterImpl2 {
doc.exitPointerLock();
}
}
private static void forceMouseGrabbed() {
long t = System.currentTimeMillis();
if(t - mouseUngrabTimer > 3000l) {
if(needsPointerLock && !isPointerLocked()) {
canvas.requestPointerLock();
if(isPointerLocked()) {
needsPointerLock = false;
}
}
}
}
public static final int mouseGetDX() {
double dx = mouseDX;
mouseDX = 0.0D;