summaryrefslogtreecommitdiff
path: root/NET/worlds/scape/DialogAction.java
diff options
context:
space:
mode:
authorFuwn <[email protected]>2026-02-12 22:33:32 -0800
committerFuwn <[email protected]>2026-02-12 22:33:32 -0800
commitc7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9 (patch)
treedf9f48bf128a6c0186a8e91857d6ff30fe0e9f18 /NET/worlds/scape/DialogAction.java
downloadworldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.tar.xz
worldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.zip
Initial commit
Diffstat (limited to 'NET/worlds/scape/DialogAction.java')
-rw-r--r--NET/worlds/scape/DialogAction.java118
1 files changed, 118 insertions, 0 deletions
diff --git a/NET/worlds/scape/DialogAction.java b/NET/worlds/scape/DialogAction.java
new file mode 100644
index 0000000..b0092be
--- /dev/null
+++ b/NET/worlds/scape/DialogAction.java
@@ -0,0 +1,118 @@
+package NET.worlds.scape;
+
+import NET.worlds.console.Console;
+import NET.worlds.console.DialogReceiver;
+import NET.worlds.console.PolledDialog;
+import java.io.IOException;
+
+public abstract class DialogAction extends Action implements DialogReceiver {
+ boolean showDialog = true;
+ boolean cancelOnly = false;
+ private static PolledDialog dialogUp = null;
+ private PolledDialog thisDialog;
+ protected static boolean doCancel = false;
+ private static Object classCookie = new Object();
+
+ @Override
+ public void dialogDone(Object who, boolean confirmed) {
+ if (dialogUp == who) {
+ doCancel = true;
+ if (confirmed) {
+ this.doIt();
+ }
+ }
+ }
+
+ public abstract void doIt();
+
+ public abstract PolledDialog getDialog();
+
+ @Override
+ public Persister trigger(Event e, Persister seqID) {
+ Console console = Console.getActive();
+ if (console == null) {
+ return null;
+ } else if (!this.showDialog && !this.cancelOnly) {
+ if (console != null) {
+ this.doIt();
+ }
+
+ return null;
+ } else if (dialogUp == null) {
+ if (this.cancelOnly) {
+ return null;
+ } else {
+ this.thisDialog = dialogUp = this.getDialog();
+ doCancel = false;
+ return this;
+ }
+ } else {
+ if (this.thisDialog == dialogUp && seqID != null) {
+ if (doCancel) {
+ dialogUp.closeIt(false);
+ dialogUp = null;
+ this.thisDialog = null;
+ return null;
+ }
+ } else {
+ doCancel = true;
+ }
+
+ return this;
+ }
+ }
+
+ @Override
+ public Object properties(int index, int offset, int mode, Object value) throws NoSuchPropertyException {
+ Object ret = null;
+ switch (index - offset) {
+ case 0:
+ if (mode == 0) {
+ ret = BooleanPropertyEditor.make(new Property(this, index, "Display Dialog Box"), "Don't ask", "Ask user to ok choice");
+ } else if (mode == 1) {
+ ret = new Boolean(this.showDialog);
+ } else if (mode == 2) {
+ this.showDialog = (Boolean)value;
+ }
+ break;
+ case 1:
+ if (mode == 0) {
+ ret = BooleanPropertyEditor.make(new Property(this, index, "Cancel only"), "Regular operation", "Cancels dialog, doesn't do action");
+ } else if (mode == 1) {
+ ret = new Boolean(this.cancelOnly);
+ } else if (mode == 2) {
+ this.cancelOnly = (Boolean)value;
+ }
+ break;
+ default:
+ ret = super.properties(index, offset + 2, mode, value);
+ }
+
+ return ret;
+ }
+
+ @Override
+ public void saveState(Saver s) throws IOException {
+ s.saveVersion(0, classCookie);
+ super.saveState(s);
+ s.saveBoolean(this.showDialog);
+ s.saveBoolean(this.cancelOnly);
+ }
+
+ protected void dialogActionSkipRestore(Restorer r) throws IOException, TooNewException {
+ super.restoreState(r);
+ }
+
+ @Override
+ public void restoreState(Restorer r) throws IOException, TooNewException {
+ switch (r.restoreVersion(classCookie)) {
+ case 0:
+ super.restoreState(r);
+ this.showDialog = r.restoreBoolean();
+ this.cancelOnly = r.restoreBoolean();
+ return;
+ default:
+ throw new TooNewException();
+ }
+ }
+}