Reimplement the checkbox for enabling/disabling GLWindow for performance

This commit is contained in:
Sollace 2018-06-10 09:28:48 +02:00
parent 0b4086db05
commit ca62866e95
3 changed files with 62 additions and 17 deletions

View file

@ -44,9 +44,11 @@ public class GLWindow extends DropTarget {
return instance;
}
public static void refresh(boolean fullscreen) {
if (instance != null) {
instance.onRefresh(fullscreen);
public static void create() {
try {
current().open();
} catch (LWJGLException e) {
throw new RuntimeException(e);
}
}
@ -74,12 +76,11 @@ public class GLWindow extends DropTarget {
private boolean isFullscreen;
private boolean ready = false;
private boolean closeRequested = false;
private GLWindow() {
try {
open();
} catch (LWJGLException e) {
throw new RuntimeException(e);
}
}
private void open() throws LWJGLException {
@ -100,8 +101,11 @@ public class GLWindow extends DropTarget {
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosed(WindowEvent windowEvent) {
if (!closeRequested) {
mc.shutdown();
}
closeRequested = false;
}
@Override
public void windowStateChanged(WindowEvent event) {
@ -139,9 +143,13 @@ public class GLWindow extends DropTarget {
Display.setParent(canvas);
Display.setFullscreen(isFullscreen);
ready = true;
}
private void close() {
closeRequested = true;
try {
Display.setParent(null);
} catch (LWJGLException e) {
@ -196,8 +204,8 @@ public class GLWindow extends DropTarget {
canvas.setBounds(0, 0, frame.getContentPane().getWidth(), frame.getContentPane().getHeight());
}
private void onRefresh(boolean fullscreen) {
if (fullscreen != isFullscreen) {
public void refresh(boolean fullscreen) {
if (ready && fullscreen != isFullscreen) {
// Repaint the canvas, not the window.
// The former strips the window of its state. The latter fixes a viewport scaling bug.
canvas.setBounds(0, 0, 0, 0);
@ -207,7 +215,7 @@ public class GLWindow extends DropTarget {
}
public void clearDropTargetListener() {
if (dropListener != null) {
if (ready && dropListener != null) {
removeDropTargetListener(dropListener);
dropListener = null;
frame.setDropTarget(null);
@ -215,6 +223,10 @@ public class GLWindow extends DropTarget {
}
public void setDropTargetListener(DropTargetListener dtl) {
if (!ready) {
return;
}
clearDropTargetListener();
dropListener = dtl;

View file

@ -1,8 +1,12 @@
package com.voxelmodpack.hdskins.gui;
import com.mumfrey.liteloader.client.gui.GuiCheckbox;
import com.mumfrey.liteloader.core.LiteLoader;
import com.mumfrey.liteloader.modconfig.ConfigPanel;
import com.mumfrey.liteloader.modconfig.ConfigPanelHost;
import com.voxelmodpack.hdskins.HDSkinManager;
import com.voxelmodpack.hdskins.mod.LiteModHDSkinsMod;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
@ -10,21 +14,45 @@ public class HDSkinsConfigPanel implements ConfigPanel {
private GuiButton button;
private GuiCheckbox checkbox;
private LiteModHDSkinsMod mod;
@Override
public void onPanelShown(ConfigPanelHost host) {
this.button = new GuiButton(0, 40, 10, 100, 20, "Clear Skin Cache");
this.mod = LiteLoader.getInstance().getMod(LiteModHDSkinsMod.class);
this.button = new GuiButton(0, 40, 70, 100, 20, "Clear Skin Cache");
this.checkbox = new GuiCheckbox(1, 40, 40, "Experimental Skin Drop");
this.checkbox.checked = mod.experimentalSkinDrop;
}
@Override
public void drawPanel(ConfigPanelHost host, int mouseX, int mouseY, float partialTicks) {
this.button.drawButton(Minecraft.getMinecraft(), mouseX, mouseY, partialTicks);
Minecraft mc = Minecraft.getMinecraft();
this.button.drawButton(mc, mouseX, mouseY, partialTicks);
this.checkbox.drawButton(mc, mouseX, mouseY, partialTicks);
}
@Override
public void mousePressed(ConfigPanelHost host, int mouseX, int mouseY, int mouseButton) {
if (button.mousePressed(Minecraft.getMinecraft(), mouseX, mouseY)) {
Minecraft mc = Minecraft.getMinecraft();
if (button.mousePressed(mc, mouseX, mouseY)) {
HDSkinManager.clearSkinCache();
} else if (checkbox.mousePressed(mc, mouseX, mouseY)) {
checkbox.checked = !checkbox.checked;
mod.experimentalSkinDrop = checkbox.checked;
LiteLoader.getInstance().writeConfig(mod);
if (mod.experimentalSkinDrop) {
GLWindow.create();
} else {
GLWindow.dispose();
}
}
}

View file

@ -27,6 +27,9 @@ public class LiteModHDSkinsMod implements HDSkinsMod {
@Expose
public List<String> skin_servers = SkinServer.defaultServers;
@Expose
public boolean experimentalSkinDrop = true;
@Override
public String getName() {
return "HD Skins";
@ -57,7 +60,9 @@ public class LiteModHDSkinsMod implements HDSkinsMod {
IReloadableResourceManager irrm = (IReloadableResourceManager) Minecraft.getMinecraft().getResourceManager();
irrm.registerReloadListener(HDSkinManager.INSTANCE);
GLWindow.current();
if (experimentalSkinDrop) {
GLWindow.create();
}
}
@Override
@ -92,6 +97,6 @@ public class LiteModHDSkinsMod implements HDSkinsMod {
@Override
public void onFullScreenToggled(boolean fullScreen) {
GLWindow.refresh(fullScreen);
GLWindow.current().refresh(fullScreen);
}
}