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/ActionDialog.java | |
| download | worldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.tar.xz worldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.zip | |
Initial commit
Diffstat (limited to 'NET/worlds/console/ActionDialog.java')
| -rw-r--r-- | NET/worlds/console/ActionDialog.java | 150 |
1 files changed, 150 insertions, 0 deletions
diff --git a/NET/worlds/console/ActionDialog.java b/NET/worlds/console/ActionDialog.java new file mode 100644 index 0000000..93deea2 --- /dev/null +++ b/NET/worlds/console/ActionDialog.java @@ -0,0 +1,150 @@ +package NET.worlds.console; + +import NET.worlds.core.IniFile; +import NET.worlds.core.ServerTableManager; +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Component; +import java.awt.Event; +import java.awt.GridLayout; +import java.awt.Panel; +import java.awt.Point; +import java.util.Vector; + +class ActionDialog extends PolledDialog implements ImageButtonsCallback { + private static final long serialVersionUID = -1190930869038557992L; + BorderLayout overall = new BorderLayout(); + static Point lastWindowLocation = null; + private Vector<TextImageButtons> hunks = new Vector<TextImageButtons>(); + private Vector<String> names = new Vector<String>(); + private static final int buttonsPerHunk = 1; + private static final int buttonWidth = 72; + private static final int[] buttonHeights = new int[]{16}; + private static final int[] xText = new int[]{22}; + private static final String topImageName = IniFile.override().getIniString("actionsTopGif", Console.message("actt.gif")); + private static final String buttonImageName = IniFile.override().getIniString("actionsButtonGif", "actm.gif"); + private static final String bottomImageName = IniFile.override().getIniString("actionsBottomGif", "actb.gif"); + + ActionDialog(Vector<String> inNames) { + super(Console.getFrame(), null, Console.message("Actions"), false); + String[] hiddenActions = ServerTableManager.instance().getTable("hiddenActions"); + String[] actionAliases = ServerTableManager.instance().getTable("actionAliases"); + if (IniFile.gamma().getIniInt("HideActions", 1) == 0) { + hiddenActions = (String[])null; + } + + this.names = new Vector<String>(); + + for (int i = 0; i < inNames.size(); i++) { + boolean hide = false; + if (hiddenActions != null) { + String inStr = inNames.elementAt(i); + inStr = inStr.toLowerCase(); + + for (int j = 0; j < hiddenActions.length; j++) { + if (inStr.equals(hiddenActions[j])) { + hide = true; + } + } + } + + if (!hide) { + String prettyName = inNames.elementAt(i); + if (actionAliases != null) { + String var11 = prettyName.toLowerCase(); + + for (int jx = 0; jx < actionAliases.length; jx += 2) { + if (var11.equals(actionAliases[jx])) { + prettyName = actionAliases[jx + 1]; + } + } + } + + this.names.addElement(upperFirst(prettyName)); + } + } + + this.setResizable(false); + this.setAlignment(2); + this.setLayout(this.overall); + this.ready(); + } + + @Override + protected boolean done(boolean confirmed) { + ActionsPart.showDialog = false; + lastWindowLocation = this.getLocation(); + return super.done(confirmed); + } + + private static String upperFirst(String text) { + String ret = text.substring(0, 1).toUpperCase(); + if (text.length() > 1) { + ret = ret + text.substring(1); + } + + return ret.replace('_', ' '); + } + + @Override + public synchronized Object imageButtonsCallback(Component who, int which) { + int whichHunk = this.hunks.indexOf(who); + if (whichHunk == -1) { + return null; + } else { + Console.wake(); + ActionsPart.actionToPerform = whichHunk * 1 + which; + return null; + } + } + + @Override + protected void build() { + int numHunks = (this.names.size() + 1 - 1) / 1; + int numRows = (numHunks + 1) / 2; + numHunks = numRows * 2; + Panel hunky = new Panel(new GridLayout(numRows, 2)); + hunky.setBackground(Color.black); + int nextNameIndex = 0; + + for (int i = 0; i < numHunks; i++) { + String[] strings = new String[1]; + + for (int s = 0; s < 1; nextNameIndex++) { + if (nextNameIndex < this.names.size()) { + strings[s] = this.names.elementAt(nextNameIndex); + } + + s++; + } + + TextImageButtons hunk = new TextImageButtons(buttonImageName, 72, buttonHeights, xText, strings, this); + this.hunks.addElement(hunk); + hunky.add(hunk); + } + + this.add("North", new ImageCanvas(topImageName)); + this.add("Center", hunky); + this.add("South", new ImageCanvas(bottomImageName)); + } + + @Override + protected void initialSize(int width, int height) { + if (lastWindowLocation == null) { + super.initialSize(width, height); + } else { + this.setLocation(lastWindowLocation); + this.setSize(width, height); + } + } + + @Override + public boolean handleEvent(Event event) { + if (event.id == 1004) { + Console.getFrame().requestFocus(); + return true; + } else { + return super.handleEvent(event); + } + } +} |