mirror of
https://github.com/MineLittlePony/MineLittlePony.git
synced 2024-11-30 07:57:59 +01:00
Reimplement the checkbox for enabling/disabling GLWindow for performance
This commit is contained in:
parent
0b4086db05
commit
ca62866e95
3 changed files with 62 additions and 17 deletions
|
@ -44,9 +44,11 @@ public class GLWindow extends DropTarget {
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void refresh(boolean fullscreen) {
|
public static void create() {
|
||||||
if (instance != null) {
|
try {
|
||||||
instance.onRefresh(fullscreen);
|
current().open();
|
||||||
|
} catch (LWJGLException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,12 +76,11 @@ public class GLWindow extends DropTarget {
|
||||||
|
|
||||||
private boolean isFullscreen;
|
private boolean isFullscreen;
|
||||||
|
|
||||||
|
private boolean ready = false;
|
||||||
|
private boolean closeRequested = false;
|
||||||
|
|
||||||
private GLWindow() {
|
private GLWindow() {
|
||||||
try {
|
|
||||||
open();
|
|
||||||
} catch (LWJGLException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void open() throws LWJGLException {
|
private void open() throws LWJGLException {
|
||||||
|
@ -100,8 +101,11 @@ public class GLWindow extends DropTarget {
|
||||||
frame.addWindowListener(new WindowAdapter() {
|
frame.addWindowListener(new WindowAdapter() {
|
||||||
@Override
|
@Override
|
||||||
public void windowClosed(WindowEvent windowEvent) {
|
public void windowClosed(WindowEvent windowEvent) {
|
||||||
|
if (!closeRequested) {
|
||||||
mc.shutdown();
|
mc.shutdown();
|
||||||
}
|
}
|
||||||
|
closeRequested = false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void windowStateChanged(WindowEvent event) {
|
public void windowStateChanged(WindowEvent event) {
|
||||||
|
@ -139,9 +143,13 @@ public class GLWindow extends DropTarget {
|
||||||
|
|
||||||
Display.setParent(canvas);
|
Display.setParent(canvas);
|
||||||
Display.setFullscreen(isFullscreen);
|
Display.setFullscreen(isFullscreen);
|
||||||
|
|
||||||
|
ready = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void close() {
|
private void close() {
|
||||||
|
closeRequested = true;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Display.setParent(null);
|
Display.setParent(null);
|
||||||
} catch (LWJGLException e) {
|
} catch (LWJGLException e) {
|
||||||
|
@ -196,8 +204,8 @@ public class GLWindow extends DropTarget {
|
||||||
canvas.setBounds(0, 0, frame.getContentPane().getWidth(), frame.getContentPane().getHeight());
|
canvas.setBounds(0, 0, frame.getContentPane().getWidth(), frame.getContentPane().getHeight());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onRefresh(boolean fullscreen) {
|
public void refresh(boolean fullscreen) {
|
||||||
if (fullscreen != isFullscreen) {
|
if (ready && fullscreen != isFullscreen) {
|
||||||
// Repaint the canvas, not the window.
|
// Repaint the canvas, not the window.
|
||||||
// The former strips the window of its state. The latter fixes a viewport scaling bug.
|
// The former strips the window of its state. The latter fixes a viewport scaling bug.
|
||||||
canvas.setBounds(0, 0, 0, 0);
|
canvas.setBounds(0, 0, 0, 0);
|
||||||
|
@ -207,7 +215,7 @@ public class GLWindow extends DropTarget {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clearDropTargetListener() {
|
public void clearDropTargetListener() {
|
||||||
if (dropListener != null) {
|
if (ready && dropListener != null) {
|
||||||
removeDropTargetListener(dropListener);
|
removeDropTargetListener(dropListener);
|
||||||
dropListener = null;
|
dropListener = null;
|
||||||
frame.setDropTarget(null);
|
frame.setDropTarget(null);
|
||||||
|
@ -215,6 +223,10 @@ public class GLWindow extends DropTarget {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDropTargetListener(DropTargetListener dtl) {
|
public void setDropTargetListener(DropTargetListener dtl) {
|
||||||
|
if (!ready) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
clearDropTargetListener();
|
clearDropTargetListener();
|
||||||
dropListener = dtl;
|
dropListener = dtl;
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,12 @@
|
||||||
package com.voxelmodpack.hdskins.gui;
|
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.ConfigPanel;
|
||||||
import com.mumfrey.liteloader.modconfig.ConfigPanelHost;
|
import com.mumfrey.liteloader.modconfig.ConfigPanelHost;
|
||||||
import com.voxelmodpack.hdskins.HDSkinManager;
|
import com.voxelmodpack.hdskins.HDSkinManager;
|
||||||
|
import com.voxelmodpack.hdskins.mod.LiteModHDSkinsMod;
|
||||||
|
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.gui.GuiButton;
|
import net.minecraft.client.gui.GuiButton;
|
||||||
|
|
||||||
|
@ -10,21 +14,45 @@ public class HDSkinsConfigPanel implements ConfigPanel {
|
||||||
|
|
||||||
private GuiButton button;
|
private GuiButton button;
|
||||||
|
|
||||||
|
private GuiCheckbox checkbox;
|
||||||
|
|
||||||
|
private LiteModHDSkinsMod mod;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPanelShown(ConfigPanelHost host) {
|
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
|
@Override
|
||||||
public void drawPanel(ConfigPanelHost host, int mouseX, int mouseY, float partialTicks) {
|
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
|
@Override
|
||||||
public void mousePressed(ConfigPanelHost host, int mouseX, int mouseY, int mouseButton) {
|
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();
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,9 @@ public class LiteModHDSkinsMod implements HDSkinsMod {
|
||||||
@Expose
|
@Expose
|
||||||
public List<String> skin_servers = SkinServer.defaultServers;
|
public List<String> skin_servers = SkinServer.defaultServers;
|
||||||
|
|
||||||
|
@Expose
|
||||||
|
public boolean experimentalSkinDrop = true;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "HD Skins";
|
return "HD Skins";
|
||||||
|
@ -57,7 +60,9 @@ public class LiteModHDSkinsMod implements HDSkinsMod {
|
||||||
IReloadableResourceManager irrm = (IReloadableResourceManager) Minecraft.getMinecraft().getResourceManager();
|
IReloadableResourceManager irrm = (IReloadableResourceManager) Minecraft.getMinecraft().getResourceManager();
|
||||||
irrm.registerReloadListener(HDSkinManager.INSTANCE);
|
irrm.registerReloadListener(HDSkinManager.INSTANCE);
|
||||||
|
|
||||||
GLWindow.current();
|
if (experimentalSkinDrop) {
|
||||||
|
GLWindow.create();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -92,6 +97,6 @@ public class LiteModHDSkinsMod implements HDSkinsMod {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFullScreenToggled(boolean fullScreen) {
|
public void onFullScreenToggled(boolean fullScreen) {
|
||||||
GLWindow.refresh(fullScreen);
|
GLWindow.current().refresh(fullScreen);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue