From b5dfd57727fb0d0d8374742c0084bdfb9b6caf07 Mon Sep 17 00:00:00 2001 From: Sollace Date: Sat, 28 Jul 2018 19:00:45 +0200 Subject: [PATCH] I finally got tired of this --- .../voxelmodpack/hdskins/LiteModHDSkins.java | 17 +++++++++++++++++ .../hdskins/gui/HDSkinsConfigPanel.java | 9 ++++----- .../hdskins/upload/awt/ThreadOpenFile.java | 14 +++++++++----- 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/src/hdskins/java/com/voxelmodpack/hdskins/LiteModHDSkins.java b/src/hdskins/java/com/voxelmodpack/hdskins/LiteModHDSkins.java index 9fe6d085..d0732b50 100644 --- a/src/hdskins/java/com/voxelmodpack/hdskins/LiteModHDSkins.java +++ b/src/hdskins/java/com/voxelmodpack/hdskins/LiteModHDSkins.java @@ -27,12 +27,25 @@ import java.util.List; @ExposableOptions(strategy = ConfigStrategy.Unversioned, filename = "hdskins") public class LiteModHDSkins implements InitCompleteListener, ViewportListener, Configurable, AdvancedExposable { + private static LiteModHDSkins instance; + + public static LiteModHDSkins instance() { + return instance; + } + @Expose public List skin_servers = SkinServer.defaultServers; @Expose public boolean experimentalSkinDrop = false; + @Expose + public String lastChosenFile = ""; + + public LiteModHDSkins() { + instance = this; + } + @Override public String getName() { return "HD Skins"; @@ -43,6 +56,10 @@ public class LiteModHDSkins implements InitCompleteListener, ViewportListener, C return "4.0.0"; } + public void writeConfig() { + LiteLoader.getInstance().writeConfig(this); + } + @Override public void init(File configPath) { diff --git a/src/hdskins/java/com/voxelmodpack/hdskins/gui/HDSkinsConfigPanel.java b/src/hdskins/java/com/voxelmodpack/hdskins/gui/HDSkinsConfigPanel.java index 707e36c8..67e6eaa5 100644 --- a/src/hdskins/java/com/voxelmodpack/hdskins/gui/HDSkinsConfigPanel.java +++ b/src/hdskins/java/com/voxelmodpack/hdskins/gui/HDSkinsConfigPanel.java @@ -3,24 +3,23 @@ package com.voxelmodpack.hdskins.gui; import com.minelittlepony.gui.Button; import com.minelittlepony.gui.Checkbox; import com.minelittlepony.gui.SettingsPanel; -import com.mumfrey.liteloader.core.LiteLoader; import com.voxelmodpack.hdskins.HDSkinManager; import com.voxelmodpack.hdskins.LiteModHDSkins; public class HDSkinsConfigPanel extends SettingsPanel { @Override public void initGui() { - final LiteModHDSkins mod = LiteLoader.getInstance().getMod(LiteModHDSkins.class); + final LiteModHDSkins mod = LiteModHDSkins.instance(); - addButton(new Button(40, 70, 100, 20, "hdskins.options.cache", sender ->{ + addButton(new Button(40, 70, 100, 20, "hdskins.options.cache", sender -> { HDSkinManager.INSTANCE.clearSkinCache(); })); addButton(new Checkbox(40, 40, "hdskins.options.skindrops", mod.experimentalSkinDrop, checked -> { mod.experimentalSkinDrop = checked; - LiteLoader.getInstance().writeConfig(mod); + mod.writeConfig(); - if (mod.experimentalSkinDrop) { + if (checked) { GLWindow.create(); } else { GLWindow.dispose(); diff --git a/src/hdskins/java/com/voxelmodpack/hdskins/upload/awt/ThreadOpenFile.java b/src/hdskins/java/com/voxelmodpack/hdskins/upload/awt/ThreadOpenFile.java index 86b27cef..bb2d7492 100644 --- a/src/hdskins/java/com/voxelmodpack/hdskins/upload/awt/ThreadOpenFile.java +++ b/src/hdskins/java/com/voxelmodpack/hdskins/upload/awt/ThreadOpenFile.java @@ -7,6 +7,10 @@ import java.io.File; import javax.swing.JFileChooser; import javax.swing.filechooser.FileFilter; +import org.apache.logging.log4j.util.Strings; + +import com.voxelmodpack.hdskins.LiteModHDSkins; + /** * Base class for "open file" dialog threads * @@ -21,8 +25,6 @@ public abstract class ThreadOpenFile extends Thread { */ protected final IOpenFileCallback parentScreen; - private static String lastChosenFile = null; - protected ThreadOpenFile(Minecraft minecraft, String dialogTitle, IOpenFileCallback callback) throws IllegalStateException { if (minecraft.isFullScreen()) { throw new IllegalStateException("Cannot open an awt window whilst minecraft is in full screen mode!"); @@ -37,8 +39,9 @@ public abstract class ThreadOpenFile extends Thread { JFileChooser fileDialog = new JFileChooser(); fileDialog.setDialogTitle(dialogTitle); - if (lastChosenFile != null) { - fileDialog.setSelectedFile(new File(lastChosenFile)); + String last = LiteModHDSkins.instance().lastChosenFile; + if (!Strings.isBlank(last)) { + fileDialog.setSelectedFile(new File(last)); } fileDialog.setFileFilter(getFileFilter()); @@ -47,7 +50,8 @@ public abstract class ThreadOpenFile extends Thread { File f = fileDialog.getSelectedFile(); if (f != null) { - lastChosenFile = f.getAbsolutePath(); + LiteModHDSkins.instance().lastChosenFile = f.getAbsolutePath(); + LiteModHDSkins.instance().writeConfig(); } parentScreen.onFileOpenDialogClosed(fileDialog, dialogResult);