summaryrefslogtreecommitdiff
path: root/NET/worlds/console/AdPart.java
diff options
context:
space:
mode:
authorFuwn <[email protected]>2021-05-03 16:38:41 -0700
committerFuwn <[email protected]>2021-05-03 16:38:41 -0700
commite1e781bb2135ef78592226f1a3eaba4925702f1f (patch)
tree8a5b590463ed413e1c6eabb719130e701b95ca63 /NET/worlds/console/AdPart.java
downloadworlds.jar-e1e781bb2135ef78592226f1a3eaba4925702f1f.tar.xz
worlds.jar-e1e781bb2135ef78592226f1a3eaba4925702f1f.zip
:star:HEADmain
Diffstat (limited to 'NET/worlds/console/AdPart.java')
-rw-r--r--NET/worlds/console/AdPart.java325
1 files changed, 325 insertions, 0 deletions
diff --git a/NET/worlds/console/AdPart.java b/NET/worlds/console/AdPart.java
new file mode 100644
index 0000000..612761d
--- /dev/null
+++ b/NET/worlds/console/AdPart.java
@@ -0,0 +1,325 @@
+/* */ 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
+ */ \ No newline at end of file