summaryrefslogtreecommitdiff
path: root/NET/worlds/scape/WebPageWall.java
blob: 1dbe84320c8b4d8da98629be2d69ee4bcd5fa37f (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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
package NET.worlds.scape;

import NET.worlds.console.Console;
import NET.worlds.console.DefaultConsole;
import NET.worlds.console.NoWebControlException;
import NET.worlds.console.WebControl;
import NET.worlds.console.WebControlFactory;
import NET.worlds.console.WebControlImp;
import NET.worlds.console.WebControlListener;
import NET.worlds.core.IniFile;
import NET.worlds.network.URL;
import java.io.IOException;

public class WebPageWall extends Rect implements WebControlListener {
   WebControlImp _wci = null;
   TextureSurface _surface;
   Texture[] _textures;
   Material _material = null;
   String _textureURL = "$SCRIPTSERVERgetad.pl?u=$USERNAME";
   String _postTextureData = null;
   String _adURL = "http://www.worlds.com/";
   String _postAdData = null;
   String _defTextureURL = IniFile.override().getIniString("defaultAd", "adworlds.cmp");
   int _xPercent = 100;
   int _yPercent = 100;
   int _xSurface = 468;
   int _ySurface = 60;
   boolean _hasToolbar = true;
   boolean _isFixed = false;
   int _rows = 1;
   int _refresh = 5;
   boolean _passClicks = true;
   boolean _isAdBanner = true;
   boolean _retryURL = false;
   int frameCnt = -1;
   private static Object classCookie = new Object();

   WebPageWall() {
   }

   public boolean getIsAdBanner() {
      return this._isAdBanner;
   }

   public void rebuild() {
      this.unbuild();
      this.assignMaterial();
   }

   public void unbuild() {
      if (this._wci != null) {
         this._wci.detach();
         this._wci = null;
      }
   }

   @Override
   public void detach() {
      this.unbuild();
      super.detach();
   }

   @Override
   public void finalize() {
      this.unbuild();
      super.finalize();
   }

   @Override
   public boolean handle(MouseDownEvent event) {
      if ((event.key & 1) == 1) {
         Point2 pt = this.deproject();
         if (this._passClicks) {
            double realX = (double)pt.x * this._surface.getWidth();
            double realY = (double)pt.y * this._surface.getHeight();
            realY = this._surface.getHeight() - realY;
            this._surface.sendLeftClick((int)realX, (int)realY);
            return false;
         }

         Console c = Console.getActive();
         if (c != null && c instanceof DefaultConsole) {
            DefaultConsole dc = (DefaultConsole)c;

            try {
               WebControl wc = new WebControl(dc.getRender(), this._xPercent, this._yPercent, this._hasToolbar, this._isFixed, false);
               wc.activate();
               wc.setURL(this._adURL, this._postAdData);
            } catch (NoWebControlException var7) {
               new SendURLAction(this._adURL).doIt();
            }
         }
      }

      return false;
   }

   @Override
   public void prerender(Camera cam) {
      Point3Temp p = this.inCamSpace(cam);
      boolean v = p != null && p.z > 1.0F && p.x < p.z && -p.x < p.z;
      if (v) {
         this.visible = true;
      }
   }

   @Override
   public boolean handle(FrameEvent f) {
      if (this.visible) {
         if (this._retryURL && this._wci != null) {
            if (!this._wci.setURL(this._textureURL, this._postTextureData)) {
               return false;
            }

            this._retryURL = false;
         }

         if (this._surface != null) {
            if (this.frameCnt <= this._refresh && this.frameCnt != -1) {
               this.frameCnt++;
            } else {
               if (this.frameCnt != -1 && this._refresh == -1) {
                  return false;
               }

               this.frameCnt = 0;
               this.draw();
            }
         }
      }

      return false;
   }

   public WebControlImp getWebControlImp() {
      return this._wci;
   }

   private void assignMaterial() {
      int xTex = this._xSurface / 128;
      if (xTex < 1) {
         xTex = 1;
      }

      int yTex = this._ySurface / 128;
      if (yTex < 1) {
         yTex = 1;
      }

      this._surface = null;
      if (this._wci != null) {
         this._wci.detach();
      }

      this._wci = null;
      this._rows = yTex;
      this._material = new Material(URL.make(this._defTextureURL), xTex, yTex);
      this.setMaterial(this._material);
      this._textures = this._material.getTextures();
      this._surface = new TextureSurface(this._textures, yTex, this._xSurface, this._ySurface);

      try {
         this._wci = WebControlFactory.createWebControlImp(this._surface.getHwnd(), false, this._isAdBanner);
      } catch (NoWebControlException var4) {
         System.out.println("Could not create MSIE control for billboard.");
         this._wci = null;
         return;
      }

      if (!this._wci.setURL(this._textureURL, this._postTextureData)) {
         this._retryURL = true;
      }

      this._wci.addListener(this);
   }

   public synchronized void draw() {
      if (this._surface != null && this._wci != null) {
         this._surface.setTextures(this._material.getTextures(), this._rows);
         this._surface.draw(this._wci);
      }
   }

   @Override
   public void webControlEvent(int eventID) {
      if (eventID == 1 && this._refresh == -1) {
         this.draw();
      }
   }

   @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 = StringPropertyEditor.make(new Property(this, index, "Wall's URL"));
            } else if (mode == 1) {
               ret = this._textureURL;
            } else if (mode == 2) {
               this._textureURL = (String)value;
               this.rebuild();
            }
            break;
         case 1:
            if (mode == 0) {
               ret = StringPropertyEditor.make(new Property(this, index, "Wall's POST data"));
            } else if (mode == 1) {
               ret = this._postTextureData;
            } else if (mode == 2) {
               this._postTextureData = (String)value;
               this.rebuild();
            }
            break;
         case 2:
            if (mode == 0) {
               ret = IntegerPropertyEditor.make(new Property(this, index, "Wall Page Width (pixels)"), 0, 1024);
            } else if (mode == 1) {
               ret = new Integer(this._xSurface);
            } else if (mode == 2) {
               this._xSurface = (Integer)value;
               this.rebuild();
            }
            break;
         case 3:
            if (mode == 0) {
               ret = IntegerPropertyEditor.make(new Property(this, index, "Wall Page Height (pixels)"), 0, 1024);
            } else if (mode == 1) {
               ret = new Integer(this._ySurface);
            } else if (mode == 2) {
               this._ySurface = (Integer)value;
               this.rebuild();
            }
            break;
         case 4:
            if (mode == 0) {
               ret = IntegerPropertyEditor.make(new Property(this, index, "Wall Refresh Rate (frames)"), -1, 1024);
            } else if (mode == 1) {
               ret = new Integer(this._refresh);
            } else if (mode == 2) {
               this._refresh = (Integer)value;
            }
            break;
         case 5:
            if (mode == 0) {
               ret = BooleanPropertyEditor.make(new Property(this, index, "Use Scrollbars"), "No", "Yes");
            } else if (mode == 1) {
               ret = new Boolean(!this._isAdBanner);
            } else if (mode == 2) {
               this._isAdBanner = !(Boolean)value;
            }
            break;
         case 6:
            if (mode == 0) {
               ret = BooleanPropertyEditor.make(
                  new Property(this, index, "Pass clicks"), "No - Click launches target page", "Yes - Mouse events passed through to wall page"
               );
            } else if (mode == 1) {
               ret = new Boolean(this._passClicks);
            } else if (mode == 2) {
               this._passClicks = (Boolean)value;
            }
            break;
         case 7:
            if (mode == 0) {
               ret = StringPropertyEditor.make(new Property(this, index, "Target URL for click"));
            } else if (mode == 1) {
               ret = this._adURL;
            } else if (mode == 2) {
               this._adURL = (String)value;
            }
            break;
         case 8:
            if (mode == 0) {
               ret = StringPropertyEditor.make(new Property(this, index, "Target's POST data"));
            } else if (mode == 1) {
               ret = this._postAdData;
            } else if (mode == 2) {
               this._postAdData = (String)value;
               this.rebuild();
            }
            break;
         case 9:
            if (mode == 0) {
               ret = BooleanPropertyEditor.make(new Property(this, index, "Target Page Size Units"), "Percentage", "Pixels");
            } else if (mode == 1) {
               ret = new Boolean(this._isFixed);
            } else if (mode == 2) {
               this._isFixed = (Boolean)value;
            }
            break;
         case 10:
            if (mode == 0) {
               ret = IntegerPropertyEditor.make(new Property(this, index, "Target X Overlay % or Width"), 0, 1024);
            } else if (mode == 1) {
               ret = new Integer(this._xPercent);
            } else if (mode == 2) {
               this._xPercent = (Integer)value;
            }
            break;
         case 11:
            if (mode == 0) {
               ret = IntegerPropertyEditor.make(new Property(this, index, "Target Y Overlay % or Height"), 0, 1024);
            } else if (mode == 1) {
               ret = new Integer(this._yPercent);
            } else if (mode == 2) {
               this._yPercent = (Integer)value;
            }
            break;
         case 12:
            if (mode == 0) {
               ret = BooleanPropertyEditor.make(new Property(this, index, "Target Page Has Toolbar"), "No", "Yes");
            } else if (mode == 1) {
               ret = new Boolean(this._hasToolbar);
            } else if (mode == 2) {
               this._hasToolbar = (Boolean)value;
            }
            break;
         default:
            ret = super.properties(index, offset + 13, mode, value);
      }

      if (mode == 2) {
         this.rebuild();
      }

      return ret;
   }

   @Override
   public void saveState(Saver s) throws IOException {
      s.saveVersion(3, classCookie);
      super.saveState(s);
      s.saveString(this._adURL);
      s.saveString(this._textureURL);
      s.saveInt(this._xPercent);
      s.saveInt(this._yPercent);
      s.saveBoolean(this._hasToolbar);
      s.saveBoolean(this._isFixed);
      s.saveInt(this._xSurface);
      s.saveInt(this._ySurface);
      s.saveInt(this._refresh);
      s.saveBoolean(this._passClicks);
      s.saveBoolean(this._isAdBanner);
      s.saveString(this._postTextureData);
      s.saveString(this._postAdData);
   }

   @Override
   public void restoreState(Restorer r) throws IOException, TooNewException {
      switch (r.restoreVersion(classCookie)) {
         case 1:
            super.restoreState(r);
            this._adURL = r.restoreString();
            this._textureURL = r.restoreString();
            this._xPercent = r.restoreInt();
            this._yPercent = r.restoreInt();
            this._hasToolbar = r.restoreBoolean();
            this._isFixed = r.restoreBoolean();
            this._xSurface = r.restoreInt();
            this._ySurface = r.restoreInt();
            this._refresh = r.restoreInt();
            this._passClicks = r.restoreBoolean();
            this._isAdBanner = r.restoreBoolean();
            break;
         case 2:
            super.restoreState(r);
            this._adURL = r.restoreString();
            this._textureURL = r.restoreString();
            this._xPercent = r.restoreInt();
            this._yPercent = r.restoreInt();
            this._hasToolbar = r.restoreBoolean();
            this._isFixed = r.restoreBoolean();
            this._xSurface = r.restoreInt();
            this._ySurface = r.restoreInt();
            this._refresh = r.restoreInt();
            this._passClicks = r.restoreBoolean();
            this._isAdBanner = r.restoreBoolean();
            this._postTextureData = r.restoreString();
            break;
         case 3:
            super.restoreState(r);
            this._adURL = r.restoreString();
            this._textureURL = r.restoreString();
            this._xPercent = r.restoreInt();
            this._yPercent = r.restoreInt();
            this._hasToolbar = r.restoreBoolean();
            this._isFixed = r.restoreBoolean();
            this._xSurface = r.restoreInt();
            this._ySurface = r.restoreInt();
            this._refresh = r.restoreInt();
            this._passClicks = r.restoreBoolean();
            this._isAdBanner = r.restoreBoolean();
            this._postTextureData = r.restoreString();
            this._postAdData = r.restoreString();
            break;
         default:
            throw new TooNewException();
      }

      this.rebuild();
   }

   @Override
   public boolean acceptsLeftClicks() {
      return this.getIsAdBanner() ? true : this.getMouseOver();
   }
}