summaryrefslogtreecommitdiff
path: root/NET/worlds/scape/MontyDoor.java
blob: 0c128ad32a40cc5fa37fc523fc83191d80d9d443 (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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
package NET.worlds.scape;

import NET.worlds.console.Console;
import NET.worlds.console.Main;
import NET.worlds.console.MainCallback;
import NET.worlds.network.URL;
import java.io.IOException;
import java.text.MessageFormat;
import java.util.Enumeration;

public class MontyDoor extends Portal implements MouseDownHandler, MainCallback {
   boolean setsAvatar = false;
   URL url;
   String description = "";
   DialogAction action;
   String viewName;
   URL viewURL;
   Persister lastTrigger;
   private static Object classCookie = new Object();

   public MontyDoor() {
      this.flags |= 262144;
   }

   @Override
   public boolean handle(MouseDownEvent e) {
      if ((e.key & 1) == 0) {
         return false;
      } else if (this.action == null && this.url != null) {
         if (this.setsAvatar) {
            SelectAvatarAction a = new SelectAvatarAction();
            a.url = this.viewURL;
            a.description = this.description;
            this.action = a;
         } else {
            SendURLAction a = new SendURLAction();
            a.destination = this.url;
            a.description = this.description;
            this.action = a;
         }

         this.action.cancelOnly = true;
         Main.register(this);
         return true;
      } else {
         return true;
      }
   }

   @Override
   public void mainCallback() {
      if (this.action.cancelOnly) {
         this.lastTrigger = this.action.trigger(null, this.lastTrigger);
         if (this.lastTrigger != null) {
            return;
         }

         if (this.viewURL != null && this.viewName != null && this._farSideRoomName != null) {
            Room r = this.getRoom();
            World w;
            if (r != null && (w = r.getWorld()) != null) {
               r = w.getRoom(this._farSideRoomName);
               if (r == null) {
                  Main.unregister(this);
                  this.action = null;
                  Object[] arguments = new Object[]{new String(this.getName()), new String(this._farSideRoomName)};
                  Console.println(MessageFormat.format(Console.message("MontyDoor"), arguments));
                  return;
               }

               Enumeration list = r.getDeepOwned();
               SetPropertyAction.propHelper(2, this.viewURL, "File", SuperRoot.nameSearch(list, this.viewName));
            }
         }

         this.action.cancelOnly = false;
         this.flags &= -262145;
         this.reset();
      }

      this.lastTrigger = this.action.trigger(null, this.lastTrigger);
      if (this.lastTrigger == null) {
         Main.unregister(this);
         this.action = null;
         this.flags |= 262144;
         this.reset();
      }
   }

   @Override
   public BumpCalc getBumpCalc(BumpEventTemp b) {
      return standardPlaneBumpCalc;
   }

   @Override
   public boolean handle(BumpEventTemp b) {
      return true;
   }

   @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, "Avatar type"), "SendURL", "SelectAvatar");
            } else if (mode == 1) {
               ret = new Boolean(this.setsAvatar);
            } else if (mode == 2) {
               this.setsAvatar = (Boolean)value;
            }
            break;
         case 1:
            if (mode == 0) {
               ret = URLPropertyEditor.make(new Property(this, index, "URL (used only for non-avatar)").allowSetNull(), null);
            } else if (mode == 1) {
               ret = this.url;
            } else if (mode == 2) {
               this.url = (URL)value;
            }
            break;
         case 2:
            if (mode == 0) {
               ret = StringPropertyEditor.make(new Property(this, index, "Description"));
            } else if (mode == 1) {
               ret = this.description;
            } else if (mode == 2) {
               this.description = ((String)value).toString().trim();
            }
            break;
         case 3:
            if (mode == 0) {
               ret = URLPropertyEditor.make(new Property(this, index, "Display URL").allowSetNull(), null);
            } else if (mode == 1) {
               ret = this.viewURL;
            } else if (mode == 2) {
               this.viewURL = (URL)value;
            }
            break;
         case 4:
            if (mode == 0) {
               ret = StringPropertyEditor.make(new Property(this, index, "Display Name"));
            } else if (mode == 1) {
               ret = this.viewName;
            } else if (mode == 2) {
               this.viewName = ((String)value).toString().trim();
            }
            break;
         default:
            ret = super.properties(index, offset + 5, mode, value);
      }

      return ret;
   }

   @Override
   public void saveState(Saver s) throws IOException {
      s.saveVersion(0, classCookie);
      int f = this.flags;
      this.flags |= 262144;
      super.saveState(s);
      this.flags = f;
      s.saveBoolean(this.setsAvatar);
      URL.save(s, this.url);
      s.saveString(this.description);
      URL.save(s, this.viewURL);
      s.saveString(this.viewName);
   }

   @Override
   public void restoreState(Restorer r) throws IOException, TooNewException {
      switch (r.restoreVersion(classCookie)) {
         case 0:
            super.restoreState(r);
            this.setsAvatar = r.restoreBoolean();
            this.url = URL.restore(r);
            this.description = r.restoreString();
            this.viewURL = URL.restore(r);
            this.viewName = r.restoreString();
            return;
         default:
            throw new TooNewException();
      }
   }
}