From 20cec41037c6a55ea5d879378feb7ccc88eb0e22 Mon Sep 17 00:00:00 2001 From: Sollace Date: Sat, 28 Jul 2018 19:00:45 +0200 Subject: [PATCH] Store last chosen file in the config --- .../voxelmodpack/hdskins/LiteModHDSkins.java | 17 +++++++++++++++++ .../hdskins/gui/HDSkinsConfigPanel.java | 9 ++++----- .../hdskins/upload/awt/ThreadOpenFile.java | 11 ++++++----- 3 files changed, 27 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 df2edaab..e7aa5105 100644 --- a/src/hdskins/java/com/voxelmodpack/hdskins/upload/awt/ThreadOpenFile.java +++ b/src/hdskins/java/com/voxelmodpack/hdskins/upload/awt/ThreadOpenFile.java @@ -8,6 +8,7 @@ import javax.swing.JFileChooser; import javax.swing.filechooser.FileFilter; import org.apache.commons.lang3.StringUtils; +import com.voxelmodpack.hdskins.LiteModHDSkins; /** * Base class for "open file" dialog threads @@ -23,8 +24,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!"); @@ -39,8 +38,9 @@ public abstract class ThreadOpenFile extends Thread { JFileChooser fileDialog = new JFileChooser(); fileDialog.setDialogTitle(dialogTitle); - if (!StringUtils.isBlank(lastChosenFile)) { - fileDialog.setSelectedFile(new File(lastChosenFile)); + String last = LiteModHDSkins.instance().lastChosenFile; + if (!StringUtils.isBlank(last)) { + fileDialog.setSelectedFile(new File(last)); } fileDialog.setFileFilter(getFileFilter()); @@ -49,7 +49,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);