diff --git a/src/hdskins/java/com/voxelmodpack/hdskins/HDSkins.java b/src/hdskins/java/com/voxelmodpack/hdskins/HDSkins.java index b153d714..3fcc7443 100644 --- a/src/hdskins/java/com/voxelmodpack/hdskins/HDSkins.java +++ b/src/hdskins/java/com/voxelmodpack/hdskins/HDSkins.java @@ -9,6 +9,8 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.resources.IReloadableResourceManager; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.client.registry.RenderingRegistry; +import net.minecraftforge.fml.common.FMLCommonHandler; +import net.minecraftforge.fml.common.ICrashCallable; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; @@ -53,7 +55,20 @@ public class HDSkins { } } -// GLWindow.current(); + // Create a bogus crash callable so we can properly close the window in case of a crash. + FMLCommonHandler.instance().registerCrashCallable(new ICrashCallable() { + @Override + public String getLabel() { + return "HDSkins"; + } + + @Override + public String call() { + GLWindow.dispose(); + return ""; + } + }); + } private boolean fullscreen; diff --git a/src/hdskins/java/com/voxelmodpack/hdskins/gui/GLWindow.java b/src/hdskins/java/com/voxelmodpack/hdskins/gui/GLWindow.java index 61cd4003..09aad611 100644 --- a/src/hdskins/java/com/voxelmodpack/hdskins/gui/GLWindow.java +++ b/src/hdskins/java/com/voxelmodpack/hdskins/gui/GLWindow.java @@ -1,7 +1,6 @@ package com.voxelmodpack.hdskins.gui; import com.google.common.collect.Lists; - import net.minecraft.client.Minecraft; import net.minecraft.client.resources.DefaultResourcePack; import net.minecraft.util.ResourceLocation; @@ -24,7 +23,6 @@ import javax.swing.*; /** * Experimental window to control file drop. It kind of sucks. - * */ public class GLWindow extends DropTarget { @@ -60,7 +58,7 @@ public class GLWindow extends DropTarget { } private static int getScaledPixelUnit(int i) { - return (int)Math.floor(i * Display.getPixelScaleFactor()); + return (int) Math.floor(i * Display.getPixelScaleFactor()); } private final Minecraft mc = Minecraft.getMinecraft(); @@ -74,6 +72,8 @@ public class GLWindow extends DropTarget { private boolean isFullscreen; + private boolean open; + private GLWindow() { try { open(); @@ -95,12 +95,16 @@ public class GLWindow extends DropTarget { canvas = new Canvas(); frame = new JFrame(Display.getTitle()); - frame.add(canvas); + frame.getContentPane().add(canvas); frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); frame.addWindowListener(new WindowAdapter() { @Override public void windowClosed(WindowEvent windowEvent) { - mc.shutdown(); + // If we don't check this, exiting the skins menu + // will shutdown minecraft. + if (open) { + mc.shutdown(); + } } @Override @@ -116,7 +120,7 @@ public class GLWindow extends DropTarget { float frameFactorX = frame.getWidth() - frame.getContentPane().getWidth(); float frameFactorY = frame.getHeight() - frame.getContentPane().getHeight(); - frame.setSize((int)Math.floor(w + frameFactorX), (int)Math.floor(h + frameFactorY)); + frame.setSize((int) Math.floor(w + frameFactorX), (int) Math.floor(h + frameFactorY)); } }); frame.addComponentListener(new ComponentAdapter() { @@ -139,9 +143,13 @@ public class GLWindow extends DropTarget { Display.setParent(canvas); Display.setFullscreen(isFullscreen); + + open = true; } private void close() { + open = false; + clearDropTargetListener(); try { Display.setParent(null); } catch (LWJGLException e) { @@ -197,7 +205,9 @@ public class GLWindow extends DropTarget { } private void onRefresh(boolean fullscreen) { - if (fullscreen != isFullscreen) { + if (fullscreen) { + close(); + } else if (open) { // 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); @@ -206,7 +216,7 @@ public class GLWindow extends DropTarget { } } - public void clearDropTargetListener() { + private void clearDropTargetListener() { if (dropListener != null) { removeDropTargetListener(dropListener); dropListener = null; diff --git a/src/hdskins/java/com/voxelmodpack/hdskins/gui/GuiSkins.java b/src/hdskins/java/com/voxelmodpack/hdskins/gui/GuiSkins.java index 43208dcd..9b31dc37 100644 --- a/src/hdskins/java/com/voxelmodpack/hdskins/gui/GuiSkins.java +++ b/src/hdskins/java/com/voxelmodpack/hdskins/gui/GuiSkins.java @@ -194,9 +194,11 @@ public class GuiSkins extends GuiScreen implements FutureCallback { - files.stream().findFirst().ifPresent(instance::loadLocalFile); - }); + if (!mc.isFullScreen()) { + GLWindow.current().setDropTargetListener((FileDropListener) files -> { + files.stream().findFirst().ifPresent(instance::loadLocalFile); + }); + } } private void initPanoramaRenderer() { @@ -210,7 +212,7 @@ public class GuiSkins extends GuiScreen implements FutureCallback