transferred and structured menu. still not happy with its complexity, but there is only so much you can do.
parent
e861bbb51f
commit
aa0fa3abb6
|
@ -3,6 +3,7 @@ package MoF;
|
|||
|
||||
|
||||
import amidst.map.MapMarkers;
|
||||
import amidst.map.Stronghold;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
|
@ -19,7 +20,7 @@ public class ChunkManager extends Thread
|
|||
private Object b;
|
||||
public float[] a;
|
||||
public long seed;
|
||||
public Point[] strongholds;
|
||||
public Stronghold[] strongholds;
|
||||
private Stack<Fragment> queue;
|
||||
private MapGenVillage villageFinder;
|
||||
private MapGenNetherhold netherholdFinder;
|
||||
|
@ -78,7 +79,7 @@ public class ChunkManager extends Thread
|
|||
m = new SkinManager();
|
||||
m.start();
|
||||
this.seed = seed;
|
||||
strongholds = (new MapGenStronghold().a(seed, this));
|
||||
strongholds = new MapGenStronghold().a(seed, this);
|
||||
queue = new Stack<Fragment>();
|
||||
players = new ArrayList<Player>();
|
||||
active = true;
|
||||
|
|
|
@ -3,28 +3,23 @@ package MoF;
|
|||
|
||||
import amidst.Amidst;
|
||||
import amidst.Options;
|
||||
import amidst.Util;
|
||||
import amidst.gui.AmidstMenu;
|
||||
import amidst.resources.ResourceLoader;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Container;
|
||||
import java.awt.Image;
|
||||
import java.awt.Point;
|
||||
import java.awt.event.*;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
import java.util.prefs.Preferences;
|
||||
|
||||
import javax.swing.JCheckBoxMenuItem;
|
||||
import javax.swing.JFileChooser;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JMenuBar;
|
||||
import javax.swing.JMenu;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.KeyStroke;
|
||||
import javax.swing.filechooser.FileFilter;
|
||||
|
||||
public class FinderWindow extends JFrame {
|
||||
|
@ -34,12 +29,10 @@ public class FinderWindow extends JFrame {
|
|||
public static Class<?> biomeFinder;
|
||||
private static final long serialVersionUID = 196896954675968191L;
|
||||
private Container pane;
|
||||
private Project curProject;
|
||||
private JMenu mapMenu;
|
||||
public JCheckBoxMenuItem layerGridMenu, layerSlimeMenu, layerNetherMenu, layerIconMenu;
|
||||
public Project curProject; //TODO
|
||||
public static Preferences pref;
|
||||
public static boolean dataCollect;
|
||||
private JFileChooser fc;
|
||||
private final AmidstMenu menuBar;
|
||||
public FinderWindow() throws IOException {
|
||||
//Initialize window
|
||||
super("Amidst v" + Amidst.version());
|
||||
|
@ -59,7 +52,7 @@ public class FinderWindow extends JFrame {
|
|||
pane.setLayout(new BorderLayout());
|
||||
loadMinecraft();
|
||||
(new UpdateManager(this, true)).start();
|
||||
setJMenuBar(createMainMenu());
|
||||
setJMenuBar(menuBar = new AmidstMenu(this));
|
||||
setVisible(true);
|
||||
Image icon = ResourceLoader.getImage("icon.png");
|
||||
setIconImage(icon);
|
||||
|
@ -67,21 +60,20 @@ public class FinderWindow extends JFrame {
|
|||
/*
|
||||
boolean dcFirst = pref.getBoolean("datacheckfirst", false);
|
||||
if (!dcFirst) {
|
||||
int result = JOptionPane.YES_OPTION;
|
||||
result = JOptionPane.showConfirmDialog(null, "AMIDST would like to collect data about the maps you search, anonymously.\n You will only be prompted for this once:\n Would you like to allow data to be collected?", "Important alert!", JOptionPane.YES_NO_OPTION);
|
||||
pref.putBoolean("datacollect", (result==0));
|
||||
int result = JOptionPane.YES_OPTION;
|
||||
result = JOptionPane.showConfirmDialog(null, "AMIDST would like to collect data about the maps you search, anonymously.\n You will only be prompted for this once:\n Would you like to allow data to be collected?", "Important alert!", JOptionPane.YES_NO_OPTION);
|
||||
pref.putBoolean("datacollect", (result==0));
|
||||
}
|
||||
dataCollect = pref.getBoolean("datacollect", false);
|
||||
*/addWindowListener(new WindowAdapter()
|
||||
{
|
||||
public void windowClosing(WindowEvent e)
|
||||
{
|
||||
dispose();
|
||||
System.exit(0);
|
||||
}
|
||||
});
|
||||
this.addKeyListener(new KeyListener() {
|
||||
|
||||
*/addWindowListener(new WindowAdapter()
|
||||
{
|
||||
public void windowClosing(WindowEvent e)
|
||||
{
|
||||
dispose();
|
||||
System.exit(0);
|
||||
}
|
||||
});
|
||||
this.addKeyListener(new KeyListener() {
|
||||
@Override
|
||||
public void keyPressed(KeyEvent arg0) {
|
||||
if (arg0.getKeyCode() == KeyEvent.VK_EQUALS) {
|
||||
|
@ -92,296 +84,16 @@ public class FinderWindow extends JFrame {
|
|||
curProject.map.scaleBy(0.5);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyReleased(KeyEvent arg0) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyTyped(KeyEvent arg0) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyReleased(KeyEvent arg0) {}
|
||||
|
||||
@Override
|
||||
public void keyTyped(KeyEvent arg0) {}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private JMenuBar createMainMenu() {
|
||||
JMenuBar menu = new JMenuBar();
|
||||
|
||||
JMenu fileMenu = new JMenu("File");
|
||||
fileMenu.setMnemonic(KeyEvent.VK_F);
|
||||
JMenu newMenu = new JMenu("New");
|
||||
newMenu.setMnemonic(KeyEvent.VK_N);
|
||||
JMenuItem fromSeedMenu = new JMenuItem("From Seed"); fromSeedMenu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, InputEvent.CTRL_DOWN_MASK));
|
||||
JMenuItem fromFileMenu = new JMenuItem("From File");
|
||||
JMenuItem fromServerMenu = new JMenuItem("From Server");
|
||||
JMenuItem saveMenu = new JMenuItem("Save Player Locations"); saveMenu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_DOWN_MASK));
|
||||
JMenuItem exitMenu = new JMenuItem("Exit");
|
||||
JMenu scriptMenu = new JMenu("Script");
|
||||
JMenuItem newScriptMenu = new JMenuItem("New");
|
||||
JMenuItem openScriptMenu = new JMenuItem("Open");
|
||||
JMenuItem saveScriptMenu = new JMenuItem("Save");
|
||||
JMenuItem runScriptMenu = new JMenuItem("Run");
|
||||
mapMenu = new JMenu("Map");
|
||||
mapMenu.setMnemonic(KeyEvent.VK_M);
|
||||
JMenu findMenu = new JMenu("Find");
|
||||
JMenuItem findBiomeMenu = new JMenuItem("Biome");
|
||||
JMenuItem findVillageMenu = new JMenuItem("Village");
|
||||
JMenuItem findStrongholdMenu = new JMenuItem("Stronghold");findStrongholdMenu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F, InputEvent.CTRL_DOWN_MASK));
|
||||
JMenu gotoMenu = new JMenu("Go To");
|
||||
JMenuItem gotoCoordMenu = new JMenuItem("Coordinate"); gotoCoordMenu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_G, InputEvent.CTRL_DOWN_MASK));
|
||||
JMenuItem gotoPlayerMenu = new JMenuItem("Player");
|
||||
JMenuItem gotoSpawnMenu = new JMenuItem("Spawn");
|
||||
JMenuItem gotoChunkMenu = new JMenuItem("Chunk");
|
||||
JMenu layersMenu = new JMenu("Layers");
|
||||
layerSlimeMenu = new JCheckBoxMenuItem("Slimes"); layerSlimeMenu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_1, InputEvent.CTRL_DOWN_MASK));
|
||||
layerGridMenu = new JCheckBoxMenuItem("Grid"); layerGridMenu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_2, InputEvent.CTRL_DOWN_MASK));
|
||||
layerNetherMenu = new JCheckBoxMenuItem("Netherholds"); layerNetherMenu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_3, InputEvent.CTRL_DOWN_MASK));
|
||||
layerNetherMenu.setModel(Options.instance.showNetherFortresses);
|
||||
layerIconMenu = new JCheckBoxMenuItem("Icons"); layerIconMenu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_4, InputEvent.CTRL_DOWN_MASK));
|
||||
layerIconMenu.setModel(Options.instance.showIcons);
|
||||
JMenuItem captureMenu = new JMenuItem("Capture"); captureMenu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_T, InputEvent.CTRL_DOWN_MASK));
|
||||
JMenu helpMenu = new JMenu("Help");
|
||||
JMenuItem checkMenu = new JMenuItem("Check for updates");
|
||||
JMenuItem aboutMenu = new JMenuItem("About");
|
||||
|
||||
menu.add(fileMenu);
|
||||
fileMenu.add(newMenu);
|
||||
newMenu.add(fromSeedMenu);
|
||||
newMenu.add(fromFileMenu);
|
||||
//newMenu.add(fromServerMenu);
|
||||
fileMenu.add(saveMenu);
|
||||
fileMenu.add(exitMenu);
|
||||
//menu.add(scriptMenu);
|
||||
scriptMenu.add(newScriptMenu);
|
||||
scriptMenu.add(openScriptMenu);
|
||||
scriptMenu.add(saveScriptMenu);
|
||||
scriptMenu.add(runScriptMenu);
|
||||
menu.add(mapMenu);
|
||||
mapMenu.add(findMenu);
|
||||
//findMenu.add(findBiomeMenu);
|
||||
//findMenu.add(findVillageMenu);
|
||||
findMenu.add(findStrongholdMenu);
|
||||
mapMenu.add(gotoMenu);
|
||||
gotoMenu.add(gotoCoordMenu);
|
||||
gotoMenu.add(gotoPlayerMenu);
|
||||
//gotoMenu.add(gotoSpawnMenu);
|
||||
//gotoMenu.add(gotoChunkMenu);
|
||||
mapMenu.add(layersMenu);
|
||||
layersMenu.add(layerSlimeMenu);
|
||||
layersMenu.add(layerGridMenu);
|
||||
layersMenu.add(layerNetherMenu);
|
||||
layersMenu.add(layerIconMenu);
|
||||
mapMenu.add(captureMenu);
|
||||
menu.add(helpMenu);
|
||||
helpMenu.add(checkMenu);
|
||||
helpMenu.add(aboutMenu);
|
||||
|
||||
|
||||
final FinderWindow window = this;
|
||||
scriptMenu.setEnabled(false);
|
||||
findBiomeMenu.setEnabled(false);
|
||||
mapMenu.setEnabled(false);
|
||||
findVillageMenu.setEnabled(false);
|
||||
fromServerMenu.setEnabled(false);
|
||||
gotoChunkMenu.setEnabled(false);
|
||||
gotoSpawnMenu.setEnabled(false);
|
||||
layerIconMenu.setSelected(true);
|
||||
if (!Options.instance.saveEnabled)
|
||||
saveMenu.setEnabled(false);
|
||||
captureMenu.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
fc = new JFileChooser();
|
||||
fc.addChoosableFileFilter(new FileFilter() {
|
||||
public boolean accept(File f) {
|
||||
|
||||
if (f.isDirectory()) {
|
||||
return true;
|
||||
}
|
||||
String[] st = f.getName().split("/.");
|
||||
return st[st.length - 1].equalsIgnoreCase("png");
|
||||
}
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Portable Network Graphic (*.PNG)";
|
||||
}
|
||||
});
|
||||
fc.setAcceptAllFileFilterUsed(false);
|
||||
int returnVal = fc.showSaveDialog(window);
|
||||
|
||||
if (returnVal == JFileChooser.APPROVE_OPTION) {
|
||||
String s = fc.getSelectedFile().toString();
|
||||
if (!s.toLowerCase().endsWith(".png")) {
|
||||
s += ".png";
|
||||
}
|
||||
curProject.map.saveToFile(new File(s));
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
layerGridMenu.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
curProject.setGridLayer(layerGridMenu.isSelected());
|
||||
}
|
||||
});
|
||||
layerSlimeMenu.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
curProject.setSlimeLayer(layerSlimeMenu.isSelected());
|
||||
}
|
||||
});
|
||||
checkMenu.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
(new UpdateManager(window)).start();
|
||||
}
|
||||
});
|
||||
aboutMenu.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
JOptionPane.showMessageDialog(window, "Advanced Minecraft Interfacing and Data/Structure Tracking (AMIDST)\nBy Skidoodle (amidst.project@gmail.com)");
|
||||
}
|
||||
});
|
||||
|
||||
saveMenu.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
if (curProject.saveLoaded) {
|
||||
for (Player player : curProject.save.getPlayers()) {
|
||||
if (player.needSave) {
|
||||
curProject.save.movePlayer(player.getName(), player.x, player.y);
|
||||
player.needSave = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
gotoPlayerMenu.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
if (curProject.saveLoaded) {
|
||||
List<Player> players = curProject.save.getPlayers();
|
||||
Object[] options = new Object[players.size()];
|
||||
for (int i = 0; i < options.length; i++) {
|
||||
options[i] = "Player \"" + players.get(i).getName() + "\" at (" + players.get(i).x + ", " + players.get(i).y + ")";
|
||||
}
|
||||
String s = (String)JOptionPane.showInputDialog(
|
||||
window,
|
||||
"Select Player:",
|
||||
"Go to...",
|
||||
JOptionPane.PLAIN_MESSAGE,
|
||||
null,
|
||||
options,
|
||||
options[0]);
|
||||
for (int i = 0; i < options.length; i++) {
|
||||
if (s.equals(options[i])) {
|
||||
curProject.moveMapTo(players.get(i).x >> 2, players.get(i).y >> 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
findStrongholdMenu.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
Point[] sholds = curProject.manager.strongholds;
|
||||
Object[] options = {
|
||||
"Stronghold at (" + sholds[0].x + ", " + sholds[0].y + ")",
|
||||
"Stronghold at (" + sholds[1].x + ", " + sholds[1].y + ")",
|
||||
"Stronghold at (" + sholds[2].x + ", " + sholds[2].y + ")"};
|
||||
String s = (String)JOptionPane.showInputDialog(
|
||||
window,
|
||||
"Select Stronghold:",
|
||||
"Go to...",
|
||||
JOptionPane.PLAIN_MESSAGE,
|
||||
null,
|
||||
options,
|
||||
options[0]);
|
||||
if (s!=null) {
|
||||
for (int i = 0; i < 3; i++) {
|
||||
if (s.equals(options[i])) {
|
||||
curProject.moveMapTo(sholds[i].x >> 2, sholds[i].y >> 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
fromFileMenu.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
fc = new JFileChooser();
|
||||
fc.addChoosableFileFilter(SaveLoader.getFilter());
|
||||
fc.setAcceptAllFileFilterUsed(false);
|
||||
fc.setCurrentDirectory(SaveLoader.getPath("saves"));
|
||||
int returnVal = fc.showOpenDialog(window);
|
||||
|
||||
if (returnVal == JFileChooser.APPROVE_OPTION) {
|
||||
File f = fc.getSelectedFile();
|
||||
SaveLoader s = new SaveLoader(f);
|
||||
setProject(new Project(s));
|
||||
}
|
||||
}
|
||||
});
|
||||
fromSeedMenu.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
//Create the JOptionPane.
|
||||
String s = JOptionPane.showInputDialog(null, "Enter seed...", "New Project", JOptionPane.QUESTION_MESSAGE);
|
||||
if (s!=null) {
|
||||
Object[] possibilities = {"default","flat", "largeBiomes"};
|
||||
String worldType = (String)JOptionPane.showInputDialog(
|
||||
null,
|
||||
"Enter world type...\n",
|
||||
"New Project",
|
||||
JOptionPane.PLAIN_MESSAGE,
|
||||
null,
|
||||
possibilities,
|
||||
"default");
|
||||
|
||||
//If a string was returned, say so.
|
||||
if (worldType != null) {
|
||||
setProject(new Project(s, window, worldType));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
gotoCoordMenu.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
String s = JOptionPane.showInputDialog(null, "Enter coordinates: (Ex. 123,456)", "Go To", JOptionPane.QUESTION_MESSAGE);
|
||||
if (s!=null) {
|
||||
String[] c = s.split(",");
|
||||
long x = 0, y = 0;
|
||||
boolean w = true;
|
||||
try {
|
||||
x = Long.parseLong(c[0]) >> 2;
|
||||
y = Long.parseLong(c[1]) >> 2;
|
||||
} catch (Exception e) {
|
||||
w = false;
|
||||
}
|
||||
if (w)
|
||||
curProject.moveMapTo((int)x, (int)y);
|
||||
}
|
||||
}
|
||||
});
|
||||
exitMenu.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
int ret = JOptionPane.showConfirmDialog(window, "Are you sure you want to exit?");
|
||||
if (ret==0) {
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return menu;
|
||||
}
|
||||
|
||||
public void setProject(Project ep) {
|
||||
// FIXME Release resources.
|
||||
if (curProject != null) {
|
||||
|
@ -389,15 +101,15 @@ public class FinderWindow extends JFrame {
|
|||
pane.remove(curProject);
|
||||
System.gc();
|
||||
}
|
||||
mapMenu.setEnabled(true);
|
||||
menuBar.mapMenu.setEnabled(true);
|
||||
curProject = ep;
|
||||
pane.add(curProject, BorderLayout.CENTER);
|
||||
|
||||
this.validate();
|
||||
|
||||
}
|
||||
|
||||
private void loadMinecraft() {
|
||||
fc = new JFileChooser();
|
||||
JFileChooser fc = new JFileChooser();
|
||||
Class<?> mc = null;
|
||||
File s = null;
|
||||
|
||||
|
@ -408,7 +120,7 @@ public class FinderWindow extends JFrame {
|
|||
}
|
||||
|
||||
try {
|
||||
s = SaveLoader.getPath("bin/minecraft.jar");
|
||||
s = new File(Util.minecraftDirectory, "bin/minecraft.jar");
|
||||
String jar = pref.get("jar", null);
|
||||
ClasspathHacker.addFile((jar != null) ? new File(jar) : s);
|
||||
mc = ClassLoader.getSystemClassLoader().loadClass("net.minecraft.client.Minecraft");
|
||||
|
@ -418,7 +130,7 @@ public class FinderWindow extends JFrame {
|
|||
public boolean accept(File f) {
|
||||
return f.isDirectory() || f.getName().toLowerCase().endsWith(".jar");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Java Executable (*.JAR)";
|
||||
|
@ -442,6 +154,7 @@ public class FinderWindow extends JFrame {
|
|||
System.exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
pref.put("jar", s.getCanonicalPath());
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package MoF;
|
||||
|
||||
|
||||
import amidst.Options;
|
||||
import amidst.map.MapMarkers;
|
||||
|
||||
import java.awt.Color;
|
||||
|
@ -68,9 +69,9 @@ public class Fragment extends BufferedImage {
|
|||
|
||||
public void paint(Graphics2D g2d, int x, int y, int width, int height) {
|
||||
g2d.drawImage(this, x, y, width, height, null);
|
||||
if (proj.grid&(layers.size()>0))
|
||||
if (Options.instance.showGrid.isSelected() & (layers.size()>0))
|
||||
g2d.drawImage(layers.get(0), x, y, width, height, null);
|
||||
if (proj.slimes&(layers.size()>1))
|
||||
if (Options.instance.showSlimeChunks.isSelected() & (layers.size()>1))
|
||||
g2d.drawImage(layers.get(1), x, y, width, height, null);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,19 +1,19 @@
|
|||
package MoF;
|
||||
import amidst.map.Stronghold;
|
||||
|
||||
import java.awt.Point;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Random;
|
||||
|
||||
public class MapGenStronghold
|
||||
{
|
||||
public class MapGenStronghold {
|
||||
private Biome[] a = { Biome.d, Biome.f, Biome.e, Biome.h };
|
||||
private Biome[] b = { Biome.d, Biome.f, Biome.e, Biome.h, Biome.g, Biome.n, Biome.o };
|
||||
private Biome[] ab = { Biome.d, Biome.f, Biome.e, Biome.h, Biome.g, Biome.n, Biome.o, Biome.s, Biome.t, Biome.v };
|
||||
private Biome[] ac = { Biome.d, Biome.f, Biome.e, Biome.h, Biome.g, Biome.n, Biome.o, Biome.s, Biome.t, Biome.v, Biome.w, Biome.x };
|
||||
public Point[] coords = new Point[3];
|
||||
public Stronghold[] coords = new Stronghold[3];
|
||||
private Random c = new Random();
|
||||
public static boolean reset0 = false;
|
||||
protected Point[] a(long seed, ChunkManager x)
|
||||
{
|
||||
protected Stronghold[] a(long seed, ChunkManager x) {
|
||||
int j;
|
||||
c = new Random();
|
||||
this.c.setSeed(seed);
|
||||
|
@ -41,13 +41,12 @@ public class MapGenStronghold
|
|||
k = localPoint.x >> 4;
|
||||
m = localPoint.y >> 4;
|
||||
}
|
||||
coords[j] = new Point((k << 4),(m << 4));
|
||||
coords[j] = new Stronghold((k << 4), (m << 4));
|
||||
|
||||
d1 += 6.283185307179586D / this.coords.length;
|
||||
}
|
||||
if (reset0)
|
||||
coords[0] = new Point(0, 0);
|
||||
|
||||
coords[0] = new Stronghold(0, 0);
|
||||
|
||||
return coords;
|
||||
}
|
||||
|
|
|
@ -3,11 +3,12 @@ import amidst.Options;
|
|||
import amidst.map.MapMarkers;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
public class MapObject {
|
||||
public class MapObject extends Point {
|
||||
public MapMarkers type;
|
||||
public int x, y, rx, ry;
|
||||
public int rx, ry;
|
||||
public double localScale = 1.0;
|
||||
public boolean selectable = true;
|
||||
public double tempDist = 0;
|
||||
|
@ -23,12 +24,12 @@ public class MapObject {
|
|||
}
|
||||
public int getWidth() {
|
||||
if (model.isSelected())
|
||||
return (int)(type.image.getWidth()*localScale);
|
||||
return (int)(type.image.getWidth() * localScale);
|
||||
return 0;
|
||||
}
|
||||
public int getHeight() {
|
||||
if (model.isSelected())
|
||||
return (int)(type.image.getHeight()*localScale);
|
||||
return (int)(type.image.getHeight() * localScale);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ public class Player extends MapObject {
|
|||
private String name;
|
||||
public boolean needSave;
|
||||
private BufferedImage marker;
|
||||
|
||||
|
||||
public Player(String name, int x, int y) {
|
||||
super(MapMarkers.PLAYER, x , y);
|
||||
marker = type.image;
|
||||
|
@ -41,4 +41,9 @@ public class Player extends MapObject {
|
|||
public void setMarker(BufferedImage img) {
|
||||
this.marker = img;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Player \"" + name + "\" at (" + x + ", " + y + ")";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,6 @@ public class Project extends JPanel {
|
|||
private MapInfoPanel minfo;
|
||||
public static int FRAGMENT_SIZE = 256;
|
||||
public ChunkManager manager;
|
||||
public boolean slimes, grid;
|
||||
private Timer timer;
|
||||
public MapObject curTarget;
|
||||
|
||||
|
@ -144,12 +143,6 @@ public class Project extends JPanel {
|
|||
|
||||
return frag;
|
||||
}
|
||||
public void setSlimeLayer(boolean b) {
|
||||
slimes = b;
|
||||
}
|
||||
public void setGridLayer(boolean b) {
|
||||
grid = b;
|
||||
}
|
||||
|
||||
public void moveMapTo(int x, int y) {
|
||||
map.centerAndReset(x, y);
|
||||
|
|
|
@ -29,24 +29,6 @@ public class SaveLoader {
|
|||
});
|
||||
}
|
||||
|
||||
public static File getPath(String post) {
|
||||
return new File(getMinecraftDirectory(), post);
|
||||
}
|
||||
|
||||
public static File getMinecraftDirectory() {
|
||||
File homeDirectory = new File(System.getProperty("user.home", "."));
|
||||
String os = System.getProperty("os.name").toLowerCase();
|
||||
|
||||
if (os.contains("win")) {
|
||||
File appData = new File(System.getenv("APPDATA"));
|
||||
if (appData.isDirectory())
|
||||
return new File(appData, ".minecraft");
|
||||
} else if (os.contains("mac"))
|
||||
return new File(homeDirectory, "Library/Application Support/minecraft");
|
||||
|
||||
return new File(homeDirectory, ".minecraft");
|
||||
}
|
||||
|
||||
private File file;
|
||||
private List<Player> players;
|
||||
public long seed;
|
||||
|
|
|
@ -7,14 +7,19 @@ import javax.swing.JToggleButton.ToggleButtonModel;
|
|||
*/
|
||||
public enum Options {
|
||||
instance;
|
||||
|
||||
public ToggleButtonModel showIcons;
|
||||
|
||||
public ToggleButtonModel showSlimeChunks;
|
||||
public ToggleButtonModel showGrid;
|
||||
public ToggleButtonModel showNetherFortresses;
|
||||
public ToggleButtonModel showIcons;
|
||||
public boolean saveEnabled;
|
||||
|
||||
private Options() {
|
||||
showIcons = new ToggleButtonModel();
|
||||
showSlimeChunks = new ToggleButtonModel();
|
||||
showGrid = new ToggleButtonModel();
|
||||
showNetherFortresses = new ToggleButtonModel();
|
||||
showIcons = new ToggleButtonModel();
|
||||
showIcons.setSelected(true);
|
||||
saveEnabled = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package amidst;
|
|||
|
||||
import javax.swing.*;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.PrintStream;
|
||||
|
||||
public class Util {
|
||||
|
@ -29,6 +30,22 @@ public class Util {
|
|||
} catch (Exception ignored) {}
|
||||
}
|
||||
|
||||
public static final File minecraftDirectory;
|
||||
static {
|
||||
File mcDir = null;
|
||||
File homeDirectory = new File(System.getProperty("user.home", "."));
|
||||
String os = System.getProperty("os.name").toLowerCase();
|
||||
|
||||
if (os.contains("win")) {
|
||||
File appData = new File(System.getenv("APPDATA"));
|
||||
if (appData.isDirectory())
|
||||
mcDir = new File(appData, ".minecraft");
|
||||
} else if (os.contains("mac"))
|
||||
mcDir = new File(homeDirectory, "Library/Application Support/minecraft");
|
||||
|
||||
minecraftDirectory = (mcDir != null) ? mcDir : new File(homeDirectory, ".minecraft");
|
||||
}
|
||||
|
||||
// public static void main(String[] args) {
|
||||
// try {
|
||||
// int infinity = 1 / 0;
|
||||
|
|
|
@ -0,0 +1,305 @@
|
|||
package amidst.gui;
|
||||
|
||||
import MoF.*;
|
||||
import amidst.Options;
|
||||
import amidst.Util;
|
||||
import amidst.resources.ResourceLoader;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.InputEvent;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/** Structured menubar-creation to alleviate the huge mess that it would be elsewise
|
||||
*/
|
||||
public class AmidstMenu extends JMenuBar {
|
||||
final JMenu fileMenu;
|
||||
//final JMenu scriptMenu;
|
||||
public final JMenu mapMenu; //TODO: protected
|
||||
final JMenu helpMenu;
|
||||
|
||||
private final FinderWindow window;
|
||||
|
||||
public AmidstMenu(FinderWindow win) {
|
||||
this.window = win;
|
||||
|
||||
add(fileMenu = new FileMenu());
|
||||
// scriptMenu = new JMenu("Script") {{
|
||||
// setEnabled(false);
|
||||
// add(new JMenuItem("New"));
|
||||
// add(new JMenuItem("Open"));
|
||||
// add(new JMenuItem("Save"));
|
||||
// add(new JMenuItem("Run"));
|
||||
// }};
|
||||
add(mapMenu = new MapMenu());
|
||||
add(helpMenu = new HelpMenu());
|
||||
}
|
||||
|
||||
private class FileMenu extends JMenu {
|
||||
private FileMenu() {
|
||||
super("File");
|
||||
setMnemonic(KeyEvent.VK_F);
|
||||
|
||||
add(new JMenu("New") {{
|
||||
setMnemonic(KeyEvent.VK_N);
|
||||
add(new SeedMenuItem());
|
||||
add(new FileMenuItem());
|
||||
//add(new JMenuItem("From Server"));
|
||||
}});
|
||||
|
||||
add(new JMenuItem("Save player locations") {{
|
||||
setEnabled(Options.instance.saveEnabled);
|
||||
setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_DOWN_MASK));
|
||||
addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
if (window.curProject.saveLoaded)
|
||||
for (Player player : window.curProject.save.getPlayers())
|
||||
if (player.needSave) {
|
||||
window.curProject.save.movePlayer(player.getName(), player.x, player.y);
|
||||
player.needSave = false;
|
||||
}
|
||||
}
|
||||
});
|
||||
}});
|
||||
|
||||
add(new JMenuItem("Exit") {{
|
||||
addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
int ret = JOptionPane.showConfirmDialog(window, "Are you sure you want to exit?");
|
||||
if (ret == 0)
|
||||
System.exit(0);
|
||||
}
|
||||
});
|
||||
}});
|
||||
}
|
||||
|
||||
private class SeedMenuItem extends JMenuItem {
|
||||
private SeedMenuItem() {
|
||||
super("From seed");
|
||||
setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, InputEvent.CTRL_DOWN_MASK));
|
||||
addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
//Create the JOptionPane.
|
||||
String s = JOptionPane.showInputDialog(null, "Enter seed...", "New Project", JOptionPane.QUESTION_MESSAGE);
|
||||
if (s != null) {
|
||||
String[] possibilities = { "default", "flat", "largeBiomes" };
|
||||
String worldType = choose("New Project", "Enter world type...\n", possibilities);
|
||||
|
||||
//If a string was returned, say so.
|
||||
if (worldType != null)
|
||||
window.setProject(new Project(s, window, worldType));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private class FileMenuItem extends JMenuItem {
|
||||
private FileMenuItem() {
|
||||
super("From file");
|
||||
addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
JFileChooser fc = new JFileChooser();
|
||||
fc.addChoosableFileFilter(SaveLoader.getFilter());
|
||||
fc.setAcceptAllFileFilterUsed(false);
|
||||
fc.setCurrentDirectory(new File(Util.minecraftDirectory, "saves"));
|
||||
|
||||
if (fc.showOpenDialog(window) == JFileChooser.APPROVE_OPTION) {
|
||||
File f = fc.getSelectedFile();
|
||||
SaveLoader s = new SaveLoader(f);
|
||||
window.setProject(new Project(s));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class MapMenu extends JMenu {
|
||||
private MapMenu() {
|
||||
super("Map");
|
||||
setEnabled(false);
|
||||
setMnemonic(KeyEvent.VK_M);
|
||||
add(new FindMenu());
|
||||
add(new GoToMenu());
|
||||
add(new LayersMenu());
|
||||
add(new CaptureMenuItem());
|
||||
}
|
||||
|
||||
private class FindMenu extends JMenu {
|
||||
private FindMenu() {
|
||||
super("Find");
|
||||
//add(new JMenuItem("Biome"));
|
||||
//add(new JMenuItem("Village"));
|
||||
add(new JMenuItem("Stronghold") {{
|
||||
setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F, InputEvent.CTRL_DOWN_MASK));
|
||||
addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
goToChosenPoint(window.curProject.manager.strongholds, "stronghold");
|
||||
}
|
||||
});
|
||||
}});
|
||||
}
|
||||
}
|
||||
|
||||
private class GoToMenu extends JMenu {
|
||||
private GoToMenu() {
|
||||
super("Go to");
|
||||
add(new JMenuItem("Coordinate") {{
|
||||
setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_G, InputEvent.CTRL_DOWN_MASK));addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
String s = JOptionPane.showInputDialog(null, "Enter coordinates: (Ex. 123,456)", "Go To", JOptionPane.QUESTION_MESSAGE);
|
||||
if (s != null) {
|
||||
String[] c = s.split(",");
|
||||
long x = 0, y = 0;
|
||||
boolean w = true;
|
||||
try {
|
||||
x = Long.parseLong(c[0]) >> 2;
|
||||
y = Long.parseLong(c[1]) >> 2;
|
||||
} catch (Exception e) {
|
||||
w = false;
|
||||
}
|
||||
if (w)
|
||||
window.curProject.moveMapTo((int)x, (int)y);
|
||||
}
|
||||
}
|
||||
});
|
||||
}});
|
||||
|
||||
add(new JMenuItem("Player") {{
|
||||
addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
if (window.curProject.saveLoaded) {
|
||||
List<Player> playerList = window.curProject.save.getPlayers();
|
||||
Player[] players = playerList.toArray(new Player[playerList.size()]);
|
||||
goToChosenPoint(players, "Player");
|
||||
}
|
||||
}
|
||||
});
|
||||
}});
|
||||
//new JMenuItem("Spawn");
|
||||
//new JMenuItem("Chunk");
|
||||
}
|
||||
}
|
||||
|
||||
private class LayersMenu extends JMenu {
|
||||
private LayersMenu() {
|
||||
super("Layers");
|
||||
|
||||
add(new DisplayingCheckbox("Slime chunks",
|
||||
ResourceLoader.getImage("slime.png"),
|
||||
KeyEvent.VK_1,
|
||||
Options.instance.showSlimeChunks));
|
||||
add(new DisplayingCheckbox("Grid",
|
||||
null,
|
||||
KeyEvent.VK_2,
|
||||
Options.instance.showGrid));
|
||||
add(new DisplayingCheckbox("Nether fortresses",
|
||||
ResourceLoader.getImage("nether_fortress.png"),
|
||||
KeyEvent.VK_3,
|
||||
Options.instance.showNetherFortresses));
|
||||
add(new DisplayingCheckbox("Icons",
|
||||
null,
|
||||
KeyEvent.VK_4,
|
||||
Options.instance.showIcons));
|
||||
}
|
||||
|
||||
private class DisplayingCheckbox extends JCheckBoxMenuItem {
|
||||
private DisplayingCheckbox(String text, BufferedImage icon, int key, JToggleButton.ToggleButtonModel model) {
|
||||
super(text, (icon != null) ? new ImageIcon(icon) : null);
|
||||
setAccelerator(KeyStroke.getKeyStroke(key, InputEvent.CTRL_DOWN_MASK));
|
||||
setModel(model);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class CaptureMenuItem extends JMenuItem {
|
||||
private CaptureMenuItem() {
|
||||
super("Capture");
|
||||
|
||||
setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_T, InputEvent.CTRL_DOWN_MASK));
|
||||
|
||||
addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
JFileChooser fc = new JFileChooser();
|
||||
fc.addChoosableFileFilter(new PNGFileFilter());
|
||||
fc.setAcceptAllFileFilterUsed(false);
|
||||
int returnVal = fc.showSaveDialog(window);
|
||||
|
||||
if (returnVal == JFileChooser.APPROVE_OPTION) {
|
||||
String s = fc.getSelectedFile().toString();
|
||||
if (!s.toLowerCase().endsWith(".png"))
|
||||
s += ".png";
|
||||
window.curProject.map.saveToFile(new File(s));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class HelpMenu extends JMenu {
|
||||
private HelpMenu() {
|
||||
super("Help");
|
||||
|
||||
add(new JMenuItem("Check for updates") {{
|
||||
addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
new UpdateManager(window).start();
|
||||
}
|
||||
});
|
||||
}});
|
||||
|
||||
add(new JMenuItem("About") {{
|
||||
addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
JOptionPane.showMessageDialog(window,
|
||||
"Advanced Minecraft Interfacing and Data/Structure Tracking (AMIDST)\n" +
|
||||
"By Skidoodle (amidst.project@gmail.com)");
|
||||
}
|
||||
});
|
||||
}});
|
||||
}
|
||||
}
|
||||
|
||||
/** Allows the user to choose one of several things.
|
||||
*
|
||||
* Convenience wrapper around JOptionPane.showInputDialog
|
||||
*/
|
||||
private <T> T choose(String title, String message, T[] choices) {
|
||||
return (T) JOptionPane.showInputDialog(
|
||||
window,
|
||||
message,
|
||||
title,
|
||||
JOptionPane.PLAIN_MESSAGE,
|
||||
null,
|
||||
choices,
|
||||
choices[0]);
|
||||
}
|
||||
|
||||
/** Lets the user decide one of the given points and go to it
|
||||
* @param points Given points to choose from
|
||||
* @param name name displayed in the choice
|
||||
*/
|
||||
private <T extends Point> void goToChosenPoint(T[] points, String name) {
|
||||
T p = choose("Go to…", "Select " + name + ":", points);
|
||||
if (p != null)
|
||||
window.curProject.moveMapTo(p.x >> 2, p.y >> 2);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package amidst.gui;
|
||||
|
||||
import javax.swing.filechooser.FileFilter;
|
||||
import java.io.File;
|
||||
|
||||
public class PNGFileFilter extends FileFilter {
|
||||
@Override
|
||||
public boolean accept(File file) {
|
||||
if (file.isDirectory())
|
||||
return true;
|
||||
String[] st = file.getName().split("/.");
|
||||
return st[st.length - 1].equalsIgnoreCase("png");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Portable Network Graphic (*.PNG)";
|
||||
}
|
||||
}
|
|
@ -23,10 +23,6 @@ public enum MapMarkers {
|
|||
//we test, therefore this exception isn’t thrown.
|
||||
private MapMarkers() {
|
||||
String fileName = this.toString().toLowerCase() + ".png";
|
||||
try {
|
||||
image = ResourceLoader.getImage(fileName);
|
||||
} catch (IOException e) {
|
||||
throw new ExceptionInInitializerError("Enum creation " + this + " failed.\n" + e.getLocalizedMessage());
|
||||
}
|
||||
image = ResourceLoader.getImage(fileName);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
package amidst.map;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
/** Used mainly to be override its toString method for use in choices
|
||||
*/
|
||||
public class Stronghold extends Point {
|
||||
public Stronghold(int x, int y) {
|
||||
super(x, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Stronghold at (" + x + ", " + y + ")";
|
||||
}
|
||||
}
|
|
@ -15,7 +15,11 @@ public class ResourceLoader {
|
|||
return ResourceLoader.class.getResource(name);
|
||||
}
|
||||
|
||||
public static BufferedImage getImage(String name) throws IOException {
|
||||
return ImageIO.read(getResourceURL(name));
|
||||
public static BufferedImage getImage(String name) {
|
||||
try {
|
||||
return ImageIO.read(getResourceURL(name));
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue