summaryrefslogtreecommitdiff
path: root/NET/worlds/console/AnimationButton.java
diff options
context:
space:
mode:
Diffstat (limited to 'NET/worlds/console/AnimationButton.java')
-rw-r--r--NET/worlds/console/AnimationButton.java123
1 files changed, 123 insertions, 0 deletions
diff --git a/NET/worlds/console/AnimationButton.java b/NET/worlds/console/AnimationButton.java
new file mode 100644
index 0000000..22b1aa8
--- /dev/null
+++ b/NET/worlds/console/AnimationButton.java
@@ -0,0 +1,123 @@
+package NET.worlds.console;
+
+import NET.worlds.scape.FrameEvent;
+import java.awt.Container;
+import java.awt.Dimension;
+import java.awt.Event;
+import java.awt.Graphics;
+
+public class AnimationButton extends ImageCanvas implements MainCallback, FramePart, DialogDisabled {
+ private static final long serialVersionUID = 5605353426438467905L;
+ private static final int frameInterval = 33;
+ private String movieName;
+ private int frameCount;
+ private int curFrame;
+ private int width;
+ private int height;
+ private boolean playVideoNext;
+ private int videoHandle = -1;
+ private boolean isDialogDisabled;
+
+ public AnimationButton(String imageName, int frameCount, String movieName) {
+ super(imageName);
+ this.frameCount = frameCount;
+ this.movieName = movieName;
+ }
+
+ @Override
+ public void paint(Graphics g) {
+ g.clipRect(0, 0, this.width, this.height);
+ g.drawImage(this.image_, -this.width * this.curFrame, 0, null);
+ }
+
+ @Override
+ public Dimension preferredSize() {
+ Dimension d = super.preferredSize();
+ return new Dimension(this.width = d.width / this.frameCount, this.height = d.height);
+ }
+
+ @Override
+ public Dimension minimumSize() {
+ return this.preferredSize();
+ }
+
+ @Override
+ public void mainCallback() {
+ if (this.videoHandle == -1) {
+ this.videoHandle = Window.playVideoClip(this, this.movieName);
+ if (this.videoHandle == -1) {
+ this.videoHandle = Window.playVideoClip(this, "..\\" + this.movieName);
+ if (this.videoHandle == -1) {
+ Main.unregister(this);
+ }
+ }
+ } else if (!Window.isVideoPlaying(this.videoHandle)) {
+ Main.unregister(this);
+ this.videoHandle = -1;
+ this.repaint();
+ }
+ }
+
+ @Override
+ public boolean mouseDown(Event e, int x, int y) {
+ if (this.isDialogDisabled) {
+ return false;
+ } else {
+ if (this.playVideoNext) {
+ Main.register(this);
+ this.playVideoNext = false;
+ } else if (this.videoHandle == -1) {
+ Graphics g = this.getGraphics();
+ g.clipRect(0, 0, this.width, this.height);
+ int nextFrameIncr = this.curFrame == 0 ? 1 : -1;
+ long startTime = System.currentTimeMillis();
+ long frameTime = 0L;
+
+ for (int i = 1; i < this.frameCount; i++) {
+ this.curFrame += nextFrameIncr;
+ g.drawImage(this.image_, -this.width * this.curFrame, 0, null);
+ long elapsedTime = System.currentTimeMillis() - startTime;
+ frameTime += 33L;
+ long sleepTime = frameTime - elapsedTime;
+ if (sleepTime > 0L) {
+ try {
+ Thread.sleep(sleepTime);
+ } catch (InterruptedException var16) {
+ }
+ }
+ }
+
+ if (this.curFrame == this.frameCount - 1) {
+ this.playVideoNext = true;
+ }
+
+ g.dispose();
+ }
+
+ return true;
+ }
+ }
+
+ @Override
+ public void activate(Console c, Container f, Console prev) {
+ }
+
+ @Override
+ public void deactivate() {
+ }
+
+ @Override
+ public boolean action(Event event, Object what) {
+ return false;
+ }
+
+ @Override
+ public boolean handle(FrameEvent f) {
+ return false;
+ }
+
+ @Override
+ public void dialogDisable(boolean disable) {
+ this.isDialogDisabled = disable;
+ }
+}