summaryrefslogtreecommitdiff
path: root/NET/worlds/console/AdPart.java
diff options
context:
space:
mode:
authorFuwn <[email protected]>2026-02-12 22:33:32 -0800
committerFuwn <[email protected]>2026-02-12 22:33:32 -0800
commitc7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9 (patch)
treedf9f48bf128a6c0186a8e91857d6ff30fe0e9f18 /NET/worlds/console/AdPart.java
downloadworldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.tar.xz
worldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.zip
Initial commit
Diffstat (limited to 'NET/worlds/console/AdPart.java')
-rw-r--r--NET/worlds/console/AdPart.java221
1 files changed, 221 insertions, 0 deletions
diff --git a/NET/worlds/console/AdPart.java b/NET/worlds/console/AdPart.java
new file mode 100644
index 0000000..bf7c02e
--- /dev/null
+++ b/NET/worlds/console/AdPart.java
@@ -0,0 +1,221 @@
+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;
+ private static Material[] faces = new Material[4];
+ private static WObject cube;
+ private static Transform cubeStart;
+ private float angle;
+ private int currentFace = -1;
+ private int lastAd = -1;
+ private boolean lastAdIsRemote = false;
+ private boolean initialized;
+ URL image0;
+ int nextAdNumber;
+ int nextLoadTime;
+ int lastFrame;
+ static boolean cycleAds = IniFile.gamma().getIniInt("CYCLEADS", 1) == 1;
+
+ public AdPart(URL defaultImage) {
+ super(new Dimension(130, 130));
+ this.image0 = defaultImage;
+ }
+
+ private void init() {
+ if (!this.initialized) {
+ if (world == null) {
+ World.load(URL.make("home:ad.world"), this, true);
+ } else {
+ this.initCamera();
+ }
+ }
+ }
+
+ private void initCamera() {
+ this.setCamera(new Camera());
+ room.add(this.getCamera());
+ this.getCamera().moveTo(room.getDefaultPosition()).spin(room.getDefaultOrientationAxis(), room.getDefaultOrientation());
+ }
+
+ @Override
+ public synchronized void loadedURLSelf(URLSelf o, URL url, String err) {
+ if (world != null) {
+ this.initCamera();
+ } else if (o == null) {
+ Object[] arguments = new Object[]{new String("" + url)};
+ Console.println(MessageFormat.format(Console.message("Error-ad"), arguments));
+ } else {
+ world = (World)o;
+ room = world.getRoom(world.getDefaultRoomName());
+ this.initCamera();
+ cube = (WObject)SuperRoot.nameSearch(room.getContents(), "Cube");
+ if (cube != null) {
+ cubeStart = cube.getTransform();
+
+ for (int i = 0; i < 4; i++) {
+ Rect r = (Rect)SuperRoot.nameSearch(cube.getContents(), "Rect" + (i + 1));
+ if (r != null) {
+ faces[i] = r.getMaterial();
+ }
+ }
+ }
+ }
+ }
+
+ private String getAdBaseURL() {
+ World world = Pilot.getActiveWorld();
+ return world == null ? "ads/ad" : world.getAdCubeBaseURL();
+ }
+
+ @Override
+ public boolean action(Event event, Object what) {
+ return false;
+ }
+
+ @Override
+ public boolean mouseDown(Event e, int x, int y) {
+ World w = Pilot.getActiveWorld();
+ if (w == null || !w.getHasClickableAdCube()) {
+ return false;
+ } else if ((e.modifiers & 12) != 0) {
+ return false;
+ } else {
+ if (this.nextAdNumber > 1 && this.getAdBaseURL() != null) {
+ new SendURLAction(this.getAdBaseURL() + (this.nextAdNumber - 1) + ".html").startBrowser();
+ } else {
+ new SendURLAction(w.getDefaultAdCubeURL()).startBrowser();
+ }
+
+ return true;
+ }
+ }
+
+ @Override
+ public Object asyncBackgroundLoad(String localName, URL remoteURL) {
+ return localName;
+ }
+
+ @Override
+ public boolean syncBackgroundLoad(Object obj, URL remoteURL) {
+ String localName = (String)obj;
+ if (remoteURL != null != this.lastAdIsRemote) {
+ this.lastAd = -1;
+ }
+
+ this.lastAdIsRemote = remoteURL != null;
+ if (localName != null && new File(localName).exists()) {
+ remoteURL = URL.make(localName);
+ } else {
+ this.lastAd = this.nextAdNumber;
+ this.nextAdNumber = 0;
+ remoteURL = this.image0;
+ }
+
+ if (++this.currentFace > 3) {
+ this.currentFace = 0;
+ }
+
+ Material m = faces[this.currentFace];
+ if (m != null) {
+ m.loadTexture(remoteURL);
+ }
+
+ if (++this.nextAdNumber == this.lastAd) {
+ this.nextAdNumber = 0;
+ }
+
+ this.nextLoadTime = Std.getFastTime() + 10000;
+ return false;
+ }
+
+ @Override
+ public Room getBackgroundLoadRoom() {
+ return null;
+ }
+
+ @Override
+ public synchronized boolean handle(FrameEvent f) {
+ if (this.getCamera() != null && cube != null) {
+ int now = Std.getRealTime();
+ if (now >= this.nextLoadTime) {
+ if (this.nextAdNumber == 0) {
+ this.syncBackgroundLoad(null, null);
+ } else if (cycleAds) {
+ String extension = ".cmp";
+ World w = Pilot.getActiveWorld();
+ if (w != null && w.getAdCubeFormatIsGif()) {
+ extension = ".gif";
+ }
+
+ String name = this.getAdBaseURL() + this.nextAdNumber + extension;
+ BackgroundLoader.get(this, URL.make(name));
+ this.nextLoadTime = now + 10000;
+ }
+ } else {
+ float targetAngle = (float) (Math.PI / 2) * this.currentFace;
+ if (targetAngle != this.angle) {
+ int duration = now - this.lastFrame;
+ float rot = (float) (Math.PI / 4) * (duration / 1000.0F);
+ if (targetAngle == 0.0F) {
+ targetAngle = (float) (Math.PI * 2);
+ }
+
+ float dist = targetAngle - this.angle;
+ if (rot >= dist) {
+ this.angle = (float) (Math.PI / 2) * this.currentFace;
+ } else {
+ this.angle += rot;
+ }
+
+ cube.setTransform(cubeStart);
+ cube.spin(0.0F, 0.0F, -1.0F, this.angle * 180.0F / (float) Math.PI);
+ }
+ }
+
+ this.lastFrame = now;
+ if (this.checkForWindow(false)) {
+ Point pt = this.getLocationOnScreen();
+ Dimension dim = this.getSize();
+ this.getWindow().reShape(pt.x, pt.y, dim.width, dim.height);
+ this.getCamera().renderToCanvas();
+ }
+
+ return true;
+ } else {
+ return true;
+ }
+ }
+
+ @Override
+ public void activate(Console c, Container f, Console prev) {
+ super.activate(c, f, prev);
+ this.init();
+ }
+}