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")
public class LiteModHDSkins implements InitCompleteListener, ViewportListener, Configurable, AdvancedExposable {
private static LiteModHDSkins instance;
public static LiteModHDSkins instance() {
return instance;
}
@Expose
public List<SkinServer> 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) {

View file

@ -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();

View file

@ -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);