diff options
| author | Fuwn <[email protected]> | 2026-02-12 22:33:32 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2026-02-12 22:33:32 -0800 |
| commit | c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9 (patch) | |
| tree | df9f48bf128a6c0186a8e91857d6ff30fe0e9f18 /NET/worlds/scape/Billboard.java | |
| download | worldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.tar.xz worldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.zip | |
Initial commit
Diffstat (limited to 'NET/worlds/scape/Billboard.java')
| -rw-r--r-- | NET/worlds/scape/Billboard.java | 428 |
1 files changed, 428 insertions, 0 deletions
diff --git a/NET/worlds/scape/Billboard.java b/NET/worlds/scape/Billboard.java new file mode 100644 index 0000000..7c30a3b --- /dev/null +++ b/NET/worlds/scape/Billboard.java @@ -0,0 +1,428 @@ +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.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; + +public class Billboard extends Attribute implements WebControlListener { + WebControlImp _wci = null; + TextureSurface _surface; + Texture[] _textures; + Material _material = null; + String _textureURL = "$SCRIPTSERVERgetad.pl?u=$USERNAME"; + String _adURL = "http://www.worlds.com/"; + 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(); + + public Billboard(int attrID) { + super(attrID); + } + + public Billboard() { + } + + @Override + public final void noteChange() { + } + + @Override + protected void noteAddingTo(SuperRoot owner) { + Rect s = (Rect)((Sharer)owner).getOwner(); + s._billboardAttribute = this; + this.assignMaterial(s); + } + + private void assignMaterial(Rect s) { + 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); + s.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 var5) { + System.out.println("Could not create MSIE control for billboard."); + this._wci = null; + return; + } + + if (!this._wci.setURL(this._textureURL)) { + this._retryURL = true; + } + + this._wci.addListener(this); + } + + private void setTexture() { + Sharer sh = (Sharer)this.getOwner(); + if (sh != null) { + Rect s = (Rect)sh.getOwner(); + this.assignMaterial(s); + } + } + + @Override + public void detach() { + Rect s = (Rect)((Sharer)this.getOwner()).getOwner(); + s._billboardAttribute = null; + if (this._wci != null) { + this._wci.detach(); + } + + super.detach(); + } + + @Override + public void finalize() { + this.releaseAuxilaryData(); + super.finalize(); + } + + public boolean getIsAdBanner() { + return this._isAdBanner; + } + + public void billboardClicked(Point2 pt) { + 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); + } else { + 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); + } catch (NoWebControlException var6) { + new SendURLAction(this._adURL).doIt(); + } + } + } + } + + public void billboardFrame(FrameEvent f) { + if (this._retryURL && this._wci != null) { + if (!this._wci.setURL(this._textureURL)) { + return; + } + + 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; + } + + this.frameCnt = 0; + this.draw(); + } + } + } + + 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 void generateNetData(DataOutputStream s) throws IOException { + s.writeUTF(this._adURL); + s.writeUTF(this._textureURL); + s.writeInt(this._xPercent); + s.writeInt(this._yPercent); + s.writeInt(this._xSurface); + s.writeInt(this._ySurface); + s.writeInt(this._refresh); + s.writeInt(this._hasToolbar ? 1 : 0); + s.writeInt(this._isFixed ? 1 : 0); + s.writeInt(this._passClicks ? 1 : 0); + s.writeInt(this._isAdBanner ? 1 : 0); + } + + @Override + public void setFromNetData(DataInputStream ds, int len) throws IOException { + this._adURL = ds.readUTF(); + this._textureURL = ds.readUTF(); + this._xPercent = ds.readInt(); + this._yPercent = ds.readInt(); + this._xSurface = ds.readInt(); + this._ySurface = ds.readInt(); + this._refresh = ds.readInt(); + this._hasToolbar = ds.readInt() == 1; + this._isFixed = ds.readInt() == 1; + this._passClicks = ds.readInt() == 1; + this._isAdBanner = ds.readInt() == 1; + this.noteChange(); + this.setTexture(); + } + + @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, "Target URL")); + } else if (mode == 1) { + ret = this._adURL; + } else if (mode == 2) { + this._adURL = (String)value; + } + break; + case 1: + if (mode == 0) { + ret = StringPropertyEditor.make(new Property(this, index, "Texture URL")); + } else if (mode == 1) { + ret = this._textureURL; + } else if (mode == 2) { + this._textureURL = (String)value; + this.setTexture(); + } + break; + case 2: + if (mode == 0) { + ret = IntegerPropertyEditor.make(new Property(this, index, "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 3: + if (mode == 0) { + ret = IntegerPropertyEditor.make(new Property(this, index, "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 4: + if (mode == 0) { + ret = BooleanPropertyEditor.make(new Property(this, index, "Has Toolbar"), "No", "Yes"); + } else if (mode == 1) { + ret = new Boolean(this._hasToolbar); + } else if (mode == 2) { + this._hasToolbar = (Boolean)value; + } + break; + case 5: + if (mode == 0) { + ret = BooleanPropertyEditor.make(new Property(this, index, "Fixed size"), "No - Percentage specified", "Yes - Pixels specified"); + } else if (mode == 1) { + ret = new Boolean(this._isFixed); + } else if (mode == 2) { + this._isFixed = (Boolean)value; + } + break; + case 6: + if (mode == 0) { + ret = IntegerPropertyEditor.make(new Property(this, index, "Texture Width"), 0, 1024); + } else if (mode == 1) { + ret = new Integer(this._xSurface); + } else if (mode == 2) { + this._xSurface = (Integer)value; + this.setTexture(); + } + break; + case 7: + if (mode == 0) { + ret = IntegerPropertyEditor.make(new Property(this, index, "Texture Height"), 0, 1024); + } else if (mode == 1) { + ret = new Integer(this._ySurface); + } else if (mode == 2) { + this._ySurface = (Integer)value; + this.setTexture(); + } + break; + case 8: + if (mode == 0) { + ret = IntegerPropertyEditor.make(new Property(this, index, "Texture Refresh Rate"), -1, 1024); + } else if (mode == 1) { + ret = new Integer(this._refresh); + } else if (mode == 2) { + this._refresh = (Integer)value; + } + break; + case 9: + if (mode == 0) { + ret = BooleanPropertyEditor.make( + new Property(this, index, "Pass clicks"), "No - Click launches specified page", "Yes - Mouse events passed through to texture page" + ); + } else if (mode == 1) { + ret = new Boolean(this._passClicks); + } else if (mode == 2) { + this._passClicks = (Boolean)value; + } + break; + case 10: + if (mode == 0) { + ret = BooleanPropertyEditor.make(new Property(this, index, "Is Ad Banner"), "No", "Yes"); + } else if (mode == 1) { + ret = new Boolean(this._isAdBanner); + } else if (mode == 2) { + this._isAdBanner = (Boolean)value; + } + break; + default: + ret = super.properties(index, offset + 11, mode, value); + } + + if (mode == 2) { + this.noteChange(); + } + + 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); + } + + @Override + public void restoreState(Restorer r) throws IOException, TooNewException { + switch (r.restoreVersion(classCookie)) { + case 0: + super.restoreState(r); + this._adURL = r.restoreString(); + this._textureURL = r.restoreString(); + this._xPercent = r.restoreInt(); + this._yPercent = r.restoreInt(); + this._hasToolbar = r.restoreBoolean(); + this.noteChange(); + break; + 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.noteChange(); + 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.noteChange(); + 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.noteChange(); + break; + default: + throw new TooNewException(); + } + + this.setTexture(); + } + + @Override + public void releaseAuxilaryData() { + if (this._wci != null) { + this._wci.detach(); + this._wci = null; + } + + if (this._surface != null) { + this._surface.finalize(); + this._surface = null; + } + + if (this._material != null) { + this._material.detach(); + this._material.finalize(); + this._material = null; + } + + this._textures = null; + } +} |