commit
f3f3b05faf
|
@ -30,21 +30,12 @@ public class FinderWindow extends JFrame {
|
||||||
private static final long serialVersionUID = 196896954675968191L;
|
private static final long serialVersionUID = 196896954675968191L;
|
||||||
private Container pane;
|
private Container pane;
|
||||||
public Project curProject; //TODO
|
public Project curProject; //TODO
|
||||||
public static Preferences pref;
|
|
||||||
public static boolean dataCollect;
|
public static boolean dataCollect;
|
||||||
private final AmidstMenu menuBar;
|
private final AmidstMenu menuBar;
|
||||||
public FinderWindow() throws IOException {
|
public FinderWindow() throws IOException {
|
||||||
//Initialize window
|
//Initialize window
|
||||||
super("Amidst v" + Amidst.version());
|
super("Amidst v" + Amidst.version());
|
||||||
pref = Preferences.userRoot().node(this.getClass().getName());
|
|
||||||
|
|
||||||
boolean first = pref.getBoolean("firstRun", true);
|
|
||||||
if (first) {
|
|
||||||
Google.track("RunFirstTime");
|
|
||||||
} else {
|
|
||||||
Google.track("Run");
|
|
||||||
}
|
|
||||||
pref.putBoolean("firstRun", false);
|
|
||||||
setSize(800,800);
|
setSize(800,800);
|
||||||
//setLookAndFeel();
|
//setLookAndFeel();
|
||||||
pane = getContentPane();
|
pane = getContentPane();
|
||||||
|
@ -113,16 +104,8 @@ public class FinderWindow extends JFrame {
|
||||||
Class<?> mc = null;
|
Class<?> mc = null;
|
||||||
File s = null;
|
File s = null;
|
||||||
|
|
||||||
//Temporary fix -- Should be removed in a few patches.
|
|
||||||
if (pref.getBoolean("osxMistake", true)) {
|
|
||||||
pref.putBoolean("osxMistake", false);
|
|
||||||
pref.remove("jar");
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
s = new File(Util.minecraftDirectory, "bin/minecraft.jar");
|
ClasspathHacker.addFile(Options.instance.jar.get());
|
||||||
String jar = pref.get("jar", null);
|
|
||||||
ClasspathHacker.addFile((jar != null) ? new File(jar) : s);
|
|
||||||
mc = ClassLoader.getSystemClassLoader().loadClass("net.minecraft.client.Minecraft");
|
mc = ClassLoader.getSystemClassLoader().loadClass("net.minecraft.client.Minecraft");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -156,7 +139,8 @@ public class FinderWindow extends JFrame {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
pref.put("jar", s.getCanonicalPath());
|
if (s != null)
|
||||||
|
Options.instance.jar.set(s);
|
||||||
|
|
||||||
String typeDump = "";
|
String typeDump = "";
|
||||||
Field fields[] = mc.getDeclaredFields();
|
Field fields[] = mc.getDeclaredFields();
|
||||||
|
|
|
@ -16,7 +16,6 @@ public class Amidst {
|
||||||
Util.setLookAndFeel();
|
Util.setLookAndFeel();
|
||||||
Google.startTracking();
|
Google.startTracking();
|
||||||
Google.track("Run");
|
Google.track("Run");
|
||||||
//TODO: load options
|
|
||||||
FinderWindow w = new FinderWindow(); //as long as we design it well, we won’t need a reference to it ;)
|
FinderWindow w = new FinderWindow(); //as long as we design it well, we won’t need a reference to it ;)
|
||||||
//TODO: redesign, move to optipns
|
//TODO: redesign, move to optipns
|
||||||
if (args.length > 0) {
|
if (args.length > 0) {
|
||||||
|
|
|
@ -1,29 +1,42 @@
|
||||||
package amidst;
|
package amidst;
|
||||||
|
|
||||||
import javax.swing.JToggleButton.ToggleButtonModel;
|
import amidst.preferences.BooleanPrefModel;
|
||||||
|
import amidst.preferences.FilePrefModel;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.prefs.Preferences;
|
||||||
|
|
||||||
/** Currently selected options that change AMIDST’s behavior
|
/** Currently selected options that change AMIDST’s behavior
|
||||||
* TODO: save and load
|
|
||||||
*/
|
*/
|
||||||
public enum Options {
|
public enum Options {
|
||||||
instance;
|
instance;
|
||||||
|
|
||||||
|
//per-run preferences. TODO: store elsewhere?
|
||||||
public long seed;
|
public long seed;
|
||||||
public String seedText;
|
public String seedText;
|
||||||
public ToggleButtonModel showSlimeChunks;
|
|
||||||
public ToggleButtonModel showGrid;
|
//permanent preferences
|
||||||
public ToggleButtonModel showNetherFortresses;
|
public final FilePrefModel jar;
|
||||||
public ToggleButtonModel showIcons;
|
public final BooleanPrefModel showSlimeChunks;
|
||||||
|
public final BooleanPrefModel showGrid;
|
||||||
|
public final BooleanPrefModel showNetherFortresses;
|
||||||
|
public final BooleanPrefModel showIcons;
|
||||||
|
|
||||||
|
//maybe temporary preferences…?
|
||||||
public boolean saveEnabled;
|
public boolean saveEnabled;
|
||||||
|
|
||||||
private Options() {
|
private Options() {
|
||||||
seed = 0L;
|
seed = 0L;
|
||||||
seedText = null;
|
seedText = null;
|
||||||
showSlimeChunks = new ToggleButtonModel();
|
|
||||||
showGrid = new ToggleButtonModel();
|
Preferences pref = Preferences.userNodeForPackage(Amidst.class);
|
||||||
showNetherFortresses = new ToggleButtonModel();
|
|
||||||
showIcons = new ToggleButtonModel();
|
jar = new FilePrefModel( pref, "jar", new File(Util.minecraftDirectory, "bin/minecraft.jar"));
|
||||||
showIcons.setSelected(true);
|
showSlimeChunks = new BooleanPrefModel(pref, "slimeChunks", false);
|
||||||
|
showGrid = new BooleanPrefModel(pref, "grid", false);
|
||||||
|
showNetherFortresses = new BooleanPrefModel(pref, "netherFortresses", false);
|
||||||
|
showIcons = new BooleanPrefModel(pref, "icons", true);
|
||||||
|
|
||||||
saveEnabled = true;
|
saveEnabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,44 @@
|
||||||
|
package amidst.preferences;
|
||||||
|
|
||||||
|
import javax.swing.JToggleButton.ToggleButtonModel;
|
||||||
|
import java.util.prefs.Preferences;
|
||||||
|
|
||||||
|
/** Autosaving ToggleButtonModel
|
||||||
|
*/
|
||||||
|
public class BooleanPrefModel extends ToggleButtonModel implements PrefModel<Boolean> {
|
||||||
|
private final String key;
|
||||||
|
private final Preferences pref;
|
||||||
|
|
||||||
|
public BooleanPrefModel(Preferences pref, String key, boolean selected) {
|
||||||
|
super();
|
||||||
|
this.pref = pref;
|
||||||
|
this.key = key;
|
||||||
|
//if the preference doesn’t exist, set it,
|
||||||
|
//else sync the ToggleButtonModel’s status
|
||||||
|
set(pref.getBoolean(key, selected));
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getKey() {
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean get() {
|
||||||
|
assert pref.get(key, null) != null && pref.getBoolean(key, false) == super.isSelected();
|
||||||
|
return super.isSelected();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isSelected() {
|
||||||
|
return get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void set(Boolean value) {
|
||||||
|
super.setSelected(value);
|
||||||
|
pref.putBoolean(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setSelected(boolean value) {
|
||||||
|
set(value);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,37 @@
|
||||||
|
package amidst.preferences;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.prefs.Preferences;
|
||||||
|
|
||||||
|
/** Autosaving File model
|
||||||
|
*/
|
||||||
|
public class FilePrefModel implements PrefModel<File> {
|
||||||
|
private final String key;
|
||||||
|
private final Preferences pref;
|
||||||
|
|
||||||
|
public FilePrefModel(Preferences pref, String key, File init) {
|
||||||
|
super();
|
||||||
|
this.pref = pref;
|
||||||
|
this.key = key;
|
||||||
|
if (pref.get(key, null) == null)
|
||||||
|
set(init);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getKey() {
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
|
||||||
|
public File get() {
|
||||||
|
String path = pref.get(key, null);
|
||||||
|
assert path != null;
|
||||||
|
return new File(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void set(File value) {
|
||||||
|
try {
|
||||||
|
pref.put(key, value.getCanonicalPath());
|
||||||
|
} catch (IOException ignored) {
|
||||||
|
pref.put(key, value.getPath());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,13 @@
|
||||||
|
package amidst.preferences;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/** Backed by a Preferences instance, saves and loads its value from and to it.
|
||||||
|
* TODO: test the fuck out of this
|
||||||
|
*/
|
||||||
|
public interface PrefModel<T> {
|
||||||
|
String getKey();
|
||||||
|
|
||||||
|
public T get();
|
||||||
|
public void set(T value) throws IOException;
|
||||||
|
}
|
Loading…
Reference in New Issue