Store last chosen file in the config

This commit is contained in:
Sollace 2018-07-28 19:00:45 +02:00
parent 9dbd80ca8e
commit 20cec41037
3 changed files with 27 additions and 10 deletions

View file

@ -27,12 +27,25 @@ import java.util.List;
@ExposableOptions(strategy = ConfigStrategy.Unversioned, filename = "hdskins") @ExposableOptions(strategy = ConfigStrategy.Unversioned, filename = "hdskins")
public class LiteModHDSkins implements InitCompleteListener, ViewportListener, Configurable, AdvancedExposable { public class LiteModHDSkins implements InitCompleteListener, ViewportListener, Configurable, AdvancedExposable {
private static LiteModHDSkins instance;
public static LiteModHDSkins instance() {
return instance;
}
@Expose @Expose
public List<SkinServer> skin_servers = SkinServer.defaultServers; public List<SkinServer> skin_servers = SkinServer.defaultServers;
@Expose @Expose
public boolean experimentalSkinDrop = false; public boolean experimentalSkinDrop = false;
@Expose
public String lastChosenFile = "";
public LiteModHDSkins() {
instance = this;
}
@Override @Override
public String getName() { public String getName() {
return "HD Skins"; return "HD Skins";
@ -43,6 +56,10 @@ public class LiteModHDSkins implements InitCompleteListener, ViewportListener, C
return "4.0.0"; return "4.0.0";
} }
public void writeConfig() {
LiteLoader.getInstance().writeConfig(this);
}
@Override @Override
public void init(File configPath) { public void init(File configPath) {

View file

@ -3,14 +3,13 @@ package com.voxelmodpack.hdskins.gui;
import com.minelittlepony.gui.Button; import com.minelittlepony.gui.Button;
import com.minelittlepony.gui.Checkbox; import com.minelittlepony.gui.Checkbox;
import com.minelittlepony.gui.SettingsPanel; import com.minelittlepony.gui.SettingsPanel;
import com.mumfrey.liteloader.core.LiteLoader;
import com.voxelmodpack.hdskins.HDSkinManager; import com.voxelmodpack.hdskins.HDSkinManager;
import com.voxelmodpack.hdskins.LiteModHDSkins; import com.voxelmodpack.hdskins.LiteModHDSkins;
public class HDSkinsConfigPanel extends SettingsPanel { public class HDSkinsConfigPanel extends SettingsPanel {
@Override @Override
public void initGui() { 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(); HDSkinManager.INSTANCE.clearSkinCache();
@ -18,9 +17,9 @@ public class HDSkinsConfigPanel extends SettingsPanel {
addButton(new Checkbox(40, 40, "hdskins.options.skindrops", mod.experimentalSkinDrop, checked -> { addButton(new Checkbox(40, 40, "hdskins.options.skindrops", mod.experimentalSkinDrop, checked -> {
mod.experimentalSkinDrop = checked; mod.experimentalSkinDrop = checked;
LiteLoader.getInstance().writeConfig(mod); mod.writeConfig();
if (mod.experimentalSkinDrop) { if (checked) {
GLWindow.create(); GLWindow.create();
} else { } else {
GLWindow.dispose(); GLWindow.dispose();

View file

@ -8,6 +8,7 @@ import javax.swing.JFileChooser;
import javax.swing.filechooser.FileFilter; import javax.swing.filechooser.FileFilter;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import com.voxelmodpack.hdskins.LiteModHDSkins;
/** /**
* Base class for "open file" dialog threads * Base class for "open file" dialog threads
@ -23,8 +24,6 @@ public abstract class ThreadOpenFile extends Thread {
*/ */
protected final IOpenFileCallback parentScreen; protected final IOpenFileCallback parentScreen;
private static String lastChosenFile = null;
protected ThreadOpenFile(Minecraft minecraft, String dialogTitle, IOpenFileCallback callback) throws IllegalStateException { protected ThreadOpenFile(Minecraft minecraft, String dialogTitle, IOpenFileCallback callback) throws IllegalStateException {
if (minecraft.isFullScreen()) { if (minecraft.isFullScreen()) {
throw new IllegalStateException("Cannot open an awt window whilst minecraft is in full screen mode!"); 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(); JFileChooser fileDialog = new JFileChooser();
fileDialog.setDialogTitle(dialogTitle); fileDialog.setDialogTitle(dialogTitle);
if (!StringUtils.isBlank(lastChosenFile)) { String last = LiteModHDSkins.instance().lastChosenFile;
fileDialog.setSelectedFile(new File(lastChosenFile)); if (!StringUtils.isBlank(last)) {
fileDialog.setSelectedFile(new File(last));
} }
fileDialog.setFileFilter(getFileFilter()); fileDialog.setFileFilter(getFileFilter());
@ -49,7 +49,8 @@ public abstract class ThreadOpenFile extends Thread {
File f = fileDialog.getSelectedFile(); File f = fileDialog.getSelectedFile();
if (f != null) { if (f != null) {
lastChosenFile = f.getAbsolutePath(); LiteModHDSkins.instance().lastChosenFile = f.getAbsolutePath();
LiteModHDSkins.instance().writeConfig();
} }
parentScreen.onFileOpenDialogClosed(fileDialog, dialogResult); parentScreen.onFileOpenDialogClosed(fileDialog, dialogResult);