summaryrefslogtreecommitdiff
path: root/NET/worlds/console/RightMenu.java
blob: 832f0a4f1206e4fb1ecb03ba471c9967c72ec5bd (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
package NET.worlds.console;

import NET.worlds.scape.Action;
import NET.worlds.scape.RunningActionHandler;
import NET.worlds.scape.WObject;
import java.util.Enumeration;
import java.util.Hashtable;

public class RightMenu implements MainCallback {
   private static RightMenu _current = null;
   private WObject _obj;
   private Enumeration<Action> _acts;
   private Hashtable<Integer, Action> _inttobuttons = new Hashtable<Integer, Action>();
   private int _edit = 0;
   private int _pm = 0;
   private int _lastID = 0;

   public RightMenu(WObject obj, Enumeration<Action> acts) {
      this._obj = obj;
      this._acts = acts;
      Main.register(this);
   }

   private int add(String label) {
      if (this._lastID == 0) {
         this._lastID = 100;
      }

      int id = this._lastID++;

      assert this._lastID < 200;

      nativeAdd(label, id, this._pm);
      return id;
   }

   private static native int create();

   private static native void nativeAdd(String var0, int var1, int var2);

   private static native void addSeparator(int var0);

   private static native void show(int var0, int var1);

   private static native void discard(int var0);

   private static native int checkPressed();

   private void build(Enumeration<Action> acts) {
      if (_current != null) {
         _current.close();
      }

      _current = this;
      int rows = 0;
      Hashtable<String, Action> buttons = new Hashtable<String, Action>();

      while (acts.hasMoreElements()) {
         Action act = acts.nextElement();
         String label = act.rightMenuLabel;
         if (label != null && label != "") {
            buttons.put(label, act);
            rows++;
         }
      }

      if (rows <= 0 && Gamma.getShaper() == null) {
         this.close();
      } else {
         this._pm = create();
         if (Gamma.getShaper() != null) {
            this._edit = this.add("Edit Properties...");
            if (rows > 0) {
               addSeparator(this._pm);
            }
         }

         Enumeration<String> en = buttons.keys();

         while (en.hasMoreElements()) {
            String label = en.nextElement();
            this._inttobuttons.put(new Integer(this.add(label)), buttons.get(label));
         }

         show(Window.getHWnd(), this._pm);
      }
   }

   private void close() {
      discard(this._pm);
      this._pm = 0;
      Main.unregister(this);
      _current = null;
   }

   private void checkButton() {
      int pressed = checkPressed();
      if (pressed != 0) {
         if (pressed == this._edit) {
            Console.getFrame().getEditTile().viewProperties(this._obj);
         } else {
            Action action = this._inttobuttons.get(new Integer(pressed));
            RunningActionHandler.trigger(action, this._obj.getWorld(), null);
         }

         this.close();
      }
   }

   @Override
   public void mainCallback() {
      if (this._acts != null) {
         this.build(this._acts);
         this._acts = null;
      } else {
         this.checkButton();
      }
   }
}