diff options
| author | Fuwn <[email protected]> | 2026-02-12 22:33:32 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2026-02-12 22:33:32 -0800 |
| commit | c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9 (patch) | |
| tree | df9f48bf128a6c0186a8e91857d6ff30fe0e9f18 /NET/worlds/console/FileSaver.java | |
| download | worldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.tar.xz worldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.zip | |
Initial commit
Diffstat (limited to 'NET/worlds/console/FileSaver.java')
| -rw-r--r-- | NET/worlds/console/FileSaver.java | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/NET/worlds/console/FileSaver.java b/NET/worlds/console/FileSaver.java new file mode 100644 index 0000000..dce997d --- /dev/null +++ b/NET/worlds/console/FileSaver.java @@ -0,0 +1,77 @@ +package NET.worlds.console; + +import NET.worlds.scape.World; +import java.text.MessageFormat; +import java.util.Enumeration; +import java.util.Vector; + +class FileSaver implements DialogReceiver { + private Vector<World> saveList = new Vector<World>(); + private int state; + public static final int QUIT = 0; + public static final int SAVING = 1; + public static final int CANCEL = 2; + + FileSaver() { + Enumeration<World> e = World.getWorlds(); + + while (e.hasMoreElements()) { + World w = e.nextElement(); + if (w.getEdited()) { + this.saveList.addElement(w); + } + } + + this.saveNext(false); + } + + public int getState() { + return this.state; + } + + private World getWorld() { + return this.saveList.elementAt(0); + } + + private void saveNext(boolean removeFirst) { + if (removeFirst) { + this.saveList.removeElementAt(0); + } + + if (this.saveList.size() != 0) { + this.state = 1; + Object[] arguments = new Object[]{new String(this.getWorld().getName())}; + new YesNoCancelDialog(Console.getFrame(), this, Console.message("Save-Changes2"), MessageFormat.format(Console.message("has-changed"), arguments)); + } else { + this.state = 0; + } + } + + @Override + public void dialogDone(Object who, boolean confirmed) { + if (who instanceof YesNoCancelDialog) { + switch (((YesNoCancelDialog)who).getChoice()) { + case -1: + this.state = 2; + break; + case 0: + this.saveNext(true); + break; + case 1: + new FileSysDialog( + Console.getFrame(), this, Console.message("Save-World"), 1, "World Save Files|*.world", Shaper.getSaveName(this.getWorld()), true + ); + } + } else { + if (confirmed) { + FileSysDialog fileDialog = (FileSysDialog)who; + if (Shaper.doSave(fileDialog.fileName(), this.getWorld(), false)) { + this.saveNext(true); + return; + } + } + + this.state = 2; + } + } +} |