summaryrefslogtreecommitdiff
path: root/NET/worlds/console/ActionDialog.java
blob: 93deea2275496d66bf4ae566e710093262d2d14b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
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);
      }
   }
}