/* */ package NET.worlds.console; /* */ /* */ import NET.worlds.core.IniFile; /* */ import NET.worlds.core.Std; /* */ import NET.worlds.network.URL; /* */ import NET.worlds.scape.BGLoaded; /* */ import NET.worlds.scape.BackgroundLoader; /* */ import NET.worlds.scape.Camera; /* */ import NET.worlds.scape.FrameEvent; /* */ import NET.worlds.scape.LoadedURLSelf; /* */ import NET.worlds.scape.Material; /* */ import NET.worlds.scape.Pilot; /* */ import NET.worlds.scape.Rect; /* */ import NET.worlds.scape.Room; /* */ import NET.worlds.scape.SendURLAction; /* */ import NET.worlds.scape.SuperRoot; /* */ import NET.worlds.scape.Transform; /* */ import NET.worlds.scape.URLSelf; /* */ import NET.worlds.scape.WObject; /* */ import NET.worlds.scape.World; /* */ import java.awt.Container; /* */ import java.awt.Dimension; /* */ import java.awt.Event; /* */ import java.awt.Point; /* */ import java.io.File; /* */ import java.text.MessageFormat; /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ public class AdPart /* */ extends RenderCanvas /* */ implements LoadedURLSelf, BGLoaded /* */ { /* */ private static final long serialVersionUID = 4290496811864911807L; /* */ private static World world; /* */ private static Room room; /* 64 */ private static Material[] faces = new Material[4]; /* */ /* */ private static WObject cube; /* */ /* */ private static Transform cubeStart; /* */ private float angle; /* 70 */ private int currentFace = -1; /* 71 */ private int lastAd = -1; /* 72 */ private boolean lastAdIsRemote = false; /* */ private boolean initialized; /* */ URL image0; /* */ /* 76 */ public AdPart(URL defaultImage) { super(new Dimension(130, 130)); /* 77 */ this.image0 = defaultImage; /* */ } /* */ /* */ /* */ /* */ /* */ private void init() /* */ { /* 85 */ if (!this.initialized) { /* 86 */ if (world == null) { /* 87 */ World.load(URL.make("home:ad.world"), this, true); /* */ } else /* 89 */ initCamera(); /* */ } /* */ } /* */ /* */ private void initCamera() { /* 94 */ setCamera(new Camera()); /* 95 */ room.add(getCamera()); /* 96 */ getCamera().moveTo(room.getDefaultPosition()).spin( /* 97 */ room.getDefaultOrientationAxis(), room.getDefaultOrientation()); /* */ } /* */ /* */ /* */ public synchronized void loadedURLSelf(URLSelf o, URL url, String err) /* */ { /* 103 */ if (world != null) { /* 104 */ initCamera(); /* 105 */ return; /* */ } /* */ /* 108 */ if (o == null) { /* 109 */ Object[] arguments = { new String(url) }; /* 110 */ Console.println(MessageFormat.format(Console.message("Error-ad"), /* 111 */ arguments)); /* 112 */ return; /* */ } /* */ /* 115 */ world = (World)o; /* */ /* */ /* 118 */ room = world.getRoom(world.getDefaultRoomName()); /* */ /* 120 */ initCamera(); /* */ /* 122 */ cube = (WObject)SuperRoot.nameSearch(room.getContents(), "Cube"); /* 123 */ if (cube == null) { /* 124 */ return; /* */ } /* 126 */ cubeStart = cube.getTransform(); /* */ /* 128 */ for (int i = 0; i < 4; i++) { /* 129 */ Rect r = (Rect)SuperRoot.nameSearch(cube.getContents(), "Rect" + ( /* 130 */ i + 1)); /* 131 */ if (r != null) { /* 132 */ faces[i] = r.getMaterial(); /* */ } /* */ } /* */ } /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ private String getAdBaseURL() /* */ { /* 145 */ World world = Pilot.getActiveWorld(); /* 146 */ if (world == null) { /* 147 */ return "ads/ad"; /* */ } /* */ /* */ /* 151 */ return world.getAdCubeBaseURL(); /* */ } /* */ /* */ public boolean action(Event event, Object what) /* */ { /* 156 */ return false; /* */ } /* */ /* */ public boolean mouseDown(Event e, int x, int y) /* */ { /* 161 */ World w = Pilot.getActiveWorld(); /* */ /* 163 */ if ((w != null) && (w.getHasClickableAdCube())) /* */ { /* */ /* 166 */ if ((e.modifiers & 0xC) != 0) { /* 167 */ return false; /* */ } /* 169 */ if ((this.nextAdNumber > 1) && (getAdBaseURL() != null)) /* */ { /* 171 */ new SendURLAction(getAdBaseURL() + (this.nextAdNumber - 1) + ".html").startBrowser(); /* */ } /* */ else { /* 174 */ new SendURLAction(w.getDefaultAdCubeURL()).startBrowser(); /* */ } /* 176 */ return true; /* */ } /* */ /* 179 */ return false; /* */ } /* */ /* */ /* */ /* */ int nextAdNumber; /* */ /* */ int nextLoadTime; /* */ /* */ int lastFrame; /* */ /* */ public Object asyncBackgroundLoad(String localName, URL remoteURL) /* */ { /* 192 */ return localName; /* */ } /* */ /* */ public boolean syncBackgroundLoad(Object obj, URL remoteURL) { /* 196 */ String localName = (String)obj; /* */ /* 198 */ if ((remoteURL != null) != this.lastAdIsRemote) /* 199 */ this.lastAd = -1; /* 200 */ this.lastAdIsRemote = (remoteURL != null); /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* 218 */ if ((localName == null) || (!new File(localName).exists())) { /* 219 */ this.lastAd = this.nextAdNumber; /* 220 */ this.nextAdNumber = 0; /* 221 */ remoteURL = this.image0; /* */ } else { /* 223 */ remoteURL = URL.make(localName); /* */ } /* 225 */ if (++this.currentFace > 3) { /* 226 */ this.currentFace = 0; /* */ } /* */ /* */ /* 230 */ Material m = faces[this.currentFace]; /* */ /* 232 */ if (m != null) { /* 233 */ m.loadTexture(remoteURL); /* */ } /* 235 */ if (++this.nextAdNumber == this.lastAd) { /* 236 */ this.nextAdNumber = 0; /* */ } /* 238 */ this.nextLoadTime = (Std.getFastTime() + 10000); /* */ /* 240 */ return false; /* */ } /* */ /* */ public Room getBackgroundLoadRoom() { /* 244 */ return null; /* */ } /* */ /* 247 */ static boolean cycleAds = IniFile.gamma().getIniInt("CYCLEADS", 1) == 1; /* */ /* */ public synchronized boolean handle(FrameEvent f) /* */ { /* 251 */ if ((getCamera() == null) || (cube == null)) { /* 252 */ return true; /* */ } /* */ /* */ /* 256 */ int now = Std.getRealTime(); /* */ /* 258 */ if (now >= this.nextLoadTime) /* */ { /* 260 */ if (this.nextAdNumber == 0) { /* 261 */ syncBackgroundLoad(null, null); /* 262 */ } else if (cycleAds) /* */ { /* 264 */ String extension = ".cmp"; /* 265 */ World w = Pilot.getActiveWorld(); /* 266 */ if ((w != null) && /* 267 */ (w.getAdCubeFormatIsGif())) { /* 268 */ extension = ".gif"; /* */ } /* */ /* 271 */ String name = getAdBaseURL() + this.nextAdNumber + extension; /* */ /* */ /* */ /* 275 */ BackgroundLoader.get(this, URL.make(name)); /* 276 */ this.nextLoadTime = (now + 10000); /* */ } /* */ } /* */ else { /* 280 */ float targetAngle = 1.5707964F * this.currentFace; /* 281 */ if (targetAngle != this.angle) { /* 282 */ int duration = now - this.lastFrame; /* */ /* */ /* 285 */ float rot = 0.7853982F * (duration / 1000.0F); /* */ /* */ /* 288 */ if (targetAngle == 0.0F) /* 289 */ targetAngle = 6.2831855F; /* 290 */ float dist = targetAngle - this.angle; /* 291 */ if (rot >= dist) { /* 292 */ this.angle = (1.5707964F * this.currentFace); /* */ } else { /* 294 */ this.angle += rot; /* */ } /* */ /* 297 */ cube.setTransform(cubeStart); /* 298 */ cube.spin(0.0F, 0.0F, -1.0F, this.angle * 180.0F / 3.1415927F); /* */ } /* */ } /* 301 */ this.lastFrame = now; /* */ /* 303 */ if (checkForWindow(false)) { /* 304 */ Point pt = getLocationOnScreen(); /* 305 */ Dimension dim = getSize(); /* */ /* 307 */ getWindow().reShape(pt.x, pt.y, dim.width, dim.height); /* 308 */ getCamera().renderToCanvas(); /* */ } /* */ /* 311 */ return true; /* */ } /* */ /* */ public void activate(Console c, Container f, Console prev) /* */ { /* 316 */ super.activate(c, f, prev); /* 317 */ init(); /* */ } /* */ } /* Location: C:\Program Files (x86)\Worlds Inc\WorldsPlayer - Win7\lib\worlds.jar!\NET\worlds\console\AdPart.class * Java compiler version: 6 (50.0) * JD-Core Version: 0.7.1 */