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 hunks = new Vector(); private Vector names = new Vector(); 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 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(); 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); } } }