summary refs log tree commit diff stats
path: root/src/com
diff options
context:
space:
mode:
authorStarla Insigna <hatkirby@fourisland.com>2009-02-03 21:11:23 -0500
committerStarla Insigna <hatkirby@fourisland.com>2009-02-03 21:11:23 -0500
commit029190712a8f38cef760741cf53652e0ccd89172 (patch)
treebf1a01b9103592f4dda7511e9b23913bbbd98870 /src/com
parentce6ae1b56e4f6548dc19974474c8ee2d8cece13a (diff)
downloadfourpuzzle-029190712a8f38cef760741cf53652e0ccd89172.tar.gz
fourpuzzle-029190712a8f38cef760741cf53652e0ccd89172.tar.bz2
fourpuzzle-029190712a8f38cef760741cf53652e0ccd89172.zip
Started working on new Transitions
The old transition implementation was old and patchy. The new one is planned to be extensible and to work properly with all transitions. Currently this is not so, but with work it hopefully will be.
Diffstat (limited to 'src/com')
-rw-r--r--src/com/fourisland/fourpuzzle/Display.java137
-rw-r--r--src/com/fourisland/fourpuzzle/PuzzleApplication.java10
-rw-r--r--src/com/fourisland/fourpuzzle/gamestate/GameOverGameState.java17
-rw-r--r--src/com/fourisland/fourpuzzle/gamestate/TitleScreenGameState.java24
-rw-r--r--src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java44
-rw-r--r--src/com/fourisland/fourpuzzle/transition/DoNotEraseTransition.java21
-rw-r--r--src/com/fourisland/fourpuzzle/transition/InTransition.java18
-rw-r--r--src/com/fourisland/fourpuzzle/transition/MultidirectionalTransition.java16
-rw-r--r--src/com/fourisland/fourpuzzle/transition/OutTransition.java14
-rw-r--r--src/com/fourisland/fourpuzzle/transition/SquareTransition.java34
-rw-r--r--src/com/fourisland/fourpuzzle/transition/Transition.java51
-rw-r--r--src/com/fourisland/fourpuzzle/transition/TransitionCallbackThread.java38
-rw-r--r--src/com/fourisland/fourpuzzle/transition/TransitionDirection.java15
-rw-r--r--src/com/fourisland/fourpuzzle/transition/TransitionUnsupportedException.java14
14 files changed, 299 insertions, 154 deletions
diff --git a/src/com/fourisland/fourpuzzle/Display.java b/src/com/fourisland/fourpuzzle/Display.java index 6fab3ea..4f1e730 100644 --- a/src/com/fourisland/fourpuzzle/Display.java +++ b/src/com/fourisland/fourpuzzle/Display.java
@@ -5,12 +5,18 @@
5 5
6package com.fourisland.fourpuzzle; 6package com.fourisland.fourpuzzle;
7 7
8import com.fourisland.fourpuzzle.transition.InTransition;
9import com.fourisland.fourpuzzle.transition.MultidirectionalTransition;
10import com.fourisland.fourpuzzle.transition.OutTransition;
8import com.fourisland.fourpuzzle.transition.Transition; 11import com.fourisland.fourpuzzle.transition.Transition;
9import com.fourisland.fourpuzzle.transition.TransitionCallbackThread; 12import com.fourisland.fourpuzzle.transition.TransitionDirection;
13import com.fourisland.fourpuzzle.transition.TransitionUnsupportedException;
10import java.awt.Graphics2D; 14import java.awt.Graphics2D;
11import java.awt.Image; 15import java.awt.Image;
12import java.awt.Toolkit; 16import java.awt.Toolkit;
17import java.awt.image.BufferedImage;
13import java.awt.image.VolatileImage; 18import java.awt.image.VolatileImage;
19import java.util.concurrent.CountDownLatch;
14import javax.swing.JDialog; 20import javax.swing.JDialog;
15 21
16/** 22/**
@@ -23,37 +29,34 @@ public class Display {
23 29
24 public static void render(JDialog gameFrame) 30 public static void render(JDialog gameFrame)
25 { 31 {
26 if (enabled) 32 VolatileImage vImg = gameFrame.createVolatileImage(Game.WIDTH, Game.HEIGHT);
27 { 33 render(gameFrame, vImg);
28 VolatileImage vImg = gameFrame.createVolatileImage(Game.WIDTH, Game.HEIGHT);
29 render(gameFrame, vImg);
30 34
31 Image img = null; 35 Image img = null;
32 do 36 do
37 {
38 int returnCode = vImg.validate(gameFrame.getGraphicsConfiguration());
39 if (returnCode == VolatileImage.IMAGE_RESTORED)
33 { 40 {
34 int returnCode = vImg.validate(gameFrame.getGraphicsConfiguration()); 41 render(gameFrame, vImg);
35 if (returnCode == VolatileImage.IMAGE_RESTORED) 42 } else if (returnCode == VolatileImage.IMAGE_INCOMPATIBLE)
36 { 43 {
37 render(gameFrame, vImg); 44 vImg = gameFrame.createVolatileImage(Game.WIDTH, Game.HEIGHT);
38 } else if (returnCode == VolatileImage.IMAGE_INCOMPATIBLE) 45 render(gameFrame, vImg);
39 { 46 }
40 vImg = gameFrame.createVolatileImage(Game.WIDTH, Game.HEIGHT);
41 render(gameFrame, vImg);
42 }
43 47
44 img = vImg; 48 img = vImg;
45 } while (vImg.contentsLost()); 49 } while (vImg.contentsLost());
46 50
47 gameFrame.getContentPane().getGraphics().drawImage(img, 0, 0, gameFrame.getContentPane().getWidth(), gameFrame.getContentPane().getHeight(), gameFrame); 51 gameFrame.getContentPane().getGraphics().drawImage(img, 0, 0, gameFrame.getContentPane().getWidth(), gameFrame.getContentPane().getHeight(), gameFrame);
48 img.flush(); 52 img.flush();
49 Toolkit.getDefaultToolkit().sync(); 53 Toolkit.getDefaultToolkit().sync();
50 54
51 if (tileAnimationFrame == 15) 55 if (tileAnimationFrame == 15)
52 { 56 {
53 tileAnimationFrame = 0; 57 tileAnimationFrame = 0;
54 } else { 58 } else {
55 tileAnimationFrame++; 59 tileAnimationFrame++;
56 }
57 } 60 }
58 } 61 }
59 62
@@ -68,38 +71,78 @@ public class Display {
68 71
69 if (transition != null) 72 if (transition != null)
70 { 73 {
71 transition.render(g); 74 if (transition.render(g))
75 {
76 if (startedTransition)
77 {
78 midTransition = new BufferedImage(Game.WIDTH, Game.HEIGHT, BufferedImage.TYPE_INT_ARGB);
79 midTransition.getGraphics().drawImage(vImg, 0, 0, null);
80 } else {
81 midTransition = null;
82 }
83
84 transitionWait.countDown();
85 }
72 } 86 }
73 87
74 Game.getGameState().render(g); 88 Game.getGameState().render(g);
75 g.dispose(); 89 g.dispose();
76 } 90 }
77 91
78 public static void transition(Transition transition, Runnable callback) 92 private static boolean startedTransition = false;
79 {
80 setTransition(transition);
81
82 new Thread(new TransitionCallbackThread(callback)).start();
83 }
84
85 private static Transition transition; 93 private static Transition transition;
86 public static Transition getTransition() 94 private static CountDownLatch transitionWait;
87 { 95 private static boolean transitionRunning = false;
88 return transition; 96 private static BufferedImage midTransition = null;
89 } 97 public static void transition(Transition transition) throws InterruptedException
90 public static void setTransition(Transition transition)
91 { 98 {
99 if (transition instanceof MultidirectionalTransition)
100 {
101 MultidirectionalTransition temp = (MultidirectionalTransition) transition;
102
103 if (startedTransition && (temp.getDirection() != TransitionDirection.In))
104 {
105 throw new TransitionUnsupportedException(transition.getClass().getName(), TransitionDirection.In);
106 } else if (!startedTransition && (temp.getDirection() != TransitionDirection.Out))
107 {
108 throw new TransitionUnsupportedException(transition.getClass().getName(), TransitionDirection.Out);
109 }
110
111 if (temp.getDirection() == TransitionDirection.In)
112 {
113 temp.setPreTransition(midTransition);
114 }
115 } else {
116 if (startedTransition && !(transition instanceof InTransition))
117 {
118 throw new TransitionUnsupportedException(transition.getClass().getName(), TransitionDirection.In);
119 } else if (!startedTransition && !(transition instanceof OutTransition))
120 {
121 throw new TransitionUnsupportedException(transition.getClass().getName(), TransitionDirection.Out);
122 }
123
124 if (transition instanceof InTransition)
125 {
126 ((InTransition) transition).setPreTransition(midTransition);
127 }
128 }
129
92 Display.transition = transition; 130 Display.transition = transition;
131 startedTransition = !startedTransition;
132 transitionRunning = true;
133
134 transitionWait = new CountDownLatch(1);
135 transitionWait.await();
136
137 if (!startedTransition)
138 {
139 transitionRunning = false;
140 }
93 } 141 }
94 142
95 private static boolean enabled = true; 143 public static boolean isTransitionRunning()
96 public static boolean isEnabled()
97 {
98 return enabled;
99 }
100 public static void setEnabled(boolean aEnabled)
101 { 144 {
102 enabled = aEnabled; 145 return transitionRunning;
103 } 146 }
104 147
105} 148}
diff --git a/src/com/fourisland/fourpuzzle/PuzzleApplication.java b/src/com/fourisland/fourpuzzle/PuzzleApplication.java index 1c1dde2..9225c90 100644 --- a/src/com/fourisland/fourpuzzle/PuzzleApplication.java +++ b/src/com/fourisland/fourpuzzle/PuzzleApplication.java
@@ -117,12 +117,16 @@ public class PuzzleApplication extends Application {
117 117
118 if ((iTickCount > iTickTrigger) && (!gameSleep)) 118 if ((iTickCount > iTickTrigger) && (!gameSleep))
119 { 119 {
120 if (Game.getKey() != null) 120 if (!Display.isTransitionRunning())
121 { 121 {
122 Game.getGameState().processInput(); 122 if (Game.getKey() != null)
123 {
124 Game.getGameState().processInput();
125 }
126
127 Game.getGameState().doGameCycle();
123 } 128 }
124 129
125 Game.getGameState().doGameCycle();
126 Display.render(gameFrame); 130 Display.render(gameFrame);
127 131
128 if (!debugSpeed) 132 if (!debugSpeed)
diff --git a/src/com/fourisland/fourpuzzle/gamestate/GameOverGameState.java b/src/com/fourisland/fourpuzzle/gamestate/GameOverGameState.java index 48706ad..d20691f 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/GameOverGameState.java +++ b/src/com/fourisland/fourpuzzle/gamestate/GameOverGameState.java
@@ -10,11 +10,10 @@ import com.fourisland.fourpuzzle.Display;
10import com.fourisland.fourpuzzle.Game; 10import com.fourisland.fourpuzzle.Game;
11import com.fourisland.fourpuzzle.SaveFile; 11import com.fourisland.fourpuzzle.SaveFile;
12import com.fourisland.fourpuzzle.transition.SquareTransition; 12import com.fourisland.fourpuzzle.transition.SquareTransition;
13import com.fourisland.fourpuzzle.transition.TransitionDirection;
13import com.fourisland.fourpuzzle.util.ObjectLoader; 14import com.fourisland.fourpuzzle.util.ObjectLoader;
14import java.awt.Graphics2D; 15import java.awt.Graphics2D;
15import java.awt.event.KeyEvent; 16import java.awt.event.KeyEvent;
16import java.util.logging.Level;
17import java.util.logging.Logger;
18 17
19/** 18/**
20 * 19 *
@@ -37,16 +36,18 @@ public class GameOverGameState implements GameState {
37 if ((Game.getKey().getKeyCode() == KeyEvent.VK_ENTER) || (Game.getKey().getKeyCode() == KeyEvent.VK_SPACE)) 36 if ((Game.getKey().getKeyCode() == KeyEvent.VK_ENTER) || (Game.getKey().getKeyCode() == KeyEvent.VK_SPACE))
38 { 37 {
39 Game.setSaveFile(new SaveFile()); 38 Game.setSaveFile(new SaveFile());
40 //Display.transition(SquareTransition.class, this, new TitleScreenGameState()); 39
41 Display.transition(new SquareTransition(true), new Runnable() { 40 new Thread(new Runnable() {
42 public void run() { 41 public void run() {
43 try { 42 try {
44 Game.setGameState(new TitleScreenGameState()); 43 Display.transition(new SquareTransition(TransitionDirection.Out));
45 } catch (Exception ex) { 44 } catch (InterruptedException ex) {
46 Logger.getLogger(GameOverGameState.class.getName()).log(Level.SEVERE, null, ex); 45 Thread.currentThread().interrupt();
47 } 46 }
47
48 Game.setGameState(new TitleScreenGameState());
48 } 49 }
49 }); 50 }).start();
50 } 51 }
51 } 52 }
52 53
diff --git a/src/com/fourisland/fourpuzzle/gamestate/TitleScreenGameState.java b/src/com/fourisland/fourpuzzle/gamestate/TitleScreenGameState.java index 683b361..0b032eb 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/TitleScreenGameState.java +++ b/src/com/fourisland/fourpuzzle/gamestate/TitleScreenGameState.java
@@ -7,6 +7,8 @@ package com.fourisland.fourpuzzle.gamestate;
7 7
8import com.fourisland.fourpuzzle.*; 8import com.fourisland.fourpuzzle.*;
9import com.fourisland.fourpuzzle.gamestate.mapview.MapViewGameState; 9import com.fourisland.fourpuzzle.gamestate.mapview.MapViewGameState;
10import com.fourisland.fourpuzzle.transition.SquareTransition;
11import com.fourisland.fourpuzzle.transition.TransitionDirection;
10import com.fourisland.fourpuzzle.util.ObjectLoader; 12import com.fourisland.fourpuzzle.util.ObjectLoader;
11import java.awt.Graphics2D; 13import java.awt.Graphics2D;
12import java.awt.event.KeyEvent; 14import java.awt.event.KeyEvent;
@@ -32,10 +34,24 @@ public class TitleScreenGameState implements GameState {
32 if (Game.getKey().getKeyCode() == KeyEvent.VK_ENTER) 34 if (Game.getKey().getKeyCode() == KeyEvent.VK_ENTER)
33 { 35 {
34 Game.setSaveFile(new SaveFile()); 36 Game.setSaveFile(new SaveFile());
35 Game.setGameState(new MapViewGameState("TestMap", 1, 2)); 37
36 //Game.setGameState(new SquareTransition(this, new MapViewGameState("TestMap", 0, 0))); 38 new Thread(new Runnable() {
37 //Game.setGameState(new TransitionGameState(this, this)); 39 public void run() {
38 //Game.setGameState(new GameOverGameState()); 40 try {
41 Display.transition(new SquareTransition(TransitionDirection.Out));
42 } catch (InterruptedException ex) {
43 Thread.currentThread().interrupt();
44 }
45
46 Game.setGameState(new MapViewGameState("TestMap", 1, 2));
47
48 try {
49 Display.transition(new SquareTransition(TransitionDirection.In));
50 } catch (InterruptedException ex) {
51 Thread.currentThread().interrupt();
52 }
53 }
54 }).start();
39 } 55 }
40 } 56 }
41 57
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java index faa7a48..cf31bf1 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java
@@ -13,6 +13,8 @@ import com.fourisland.fourpuzzle.gamestate.mapview.viewpoint.AutomaticViewpoint;
13import com.fourisland.fourpuzzle.gamestate.mapview.viewpoint.FixedViewpoint; 13import com.fourisland.fourpuzzle.gamestate.mapview.viewpoint.FixedViewpoint;
14import com.fourisland.fourpuzzle.gamestate.mapview.viewpoint.MovingViewpoint; 14import com.fourisland.fourpuzzle.gamestate.mapview.viewpoint.MovingViewpoint;
15import com.fourisland.fourpuzzle.gamestate.mapview.viewpoint.Viewpoint; 15import com.fourisland.fourpuzzle.gamestate.mapview.viewpoint.Viewpoint;
16import com.fourisland.fourpuzzle.transition.InTransition;
17import com.fourisland.fourpuzzle.transition.OutTransition;
16import java.util.concurrent.CountDownLatch; 18import java.util.concurrent.CountDownLatch;
17 19
18/** 20/**
@@ -149,9 +151,33 @@ public class SpecialEvent {
149 throw new UnsupportedOperationException("Not yet implemented"); 151 throw new UnsupportedOperationException("Not yet implemented");
150 } 152 }
151 153
154 private boolean startedTransition = false;
155
156 /**
157 * Displays a transition from the current map to emptiness
158 *
159 * If this method is executed before Teleport(), Teleport() will not use
160 * the database-default out transition and instead immeditatly jump to the
161 * new map. It will also not use the database-default in transition which
162 * requires you to also execute EndTransition().
163 *
164 * @param trans The transition to use
165 * @throws InterruptedException
166 */
167 public void StartTransition(OutTransition trans) throws InterruptedException
168 {
169 startedTransition = true;
170
171 Display.transition(trans);
172 }
173
152 /** 174 /**
153 * Moves the player to a different map 175 * Moves the player to a different map
154 * 176 *
177 * If StartTransition() is executed prior to this method, then this will
178 * not preform the database-default transitions, which requires that
179 * EndTransition() is executed after this method.
180 *
155 * @param map The name of the map to move to 181 * @param map The name of the map to move to
156 * @param x The X position on the map to move to 182 * @param x The X position on the map to move to
157 * @param y The Y position on the map to move to 183 * @param y The Y position on the map to move to
@@ -162,6 +188,24 @@ public class SpecialEvent {
162 } 188 }
163 189
164 /** 190 /**
191 * Displays a transition from the emptiness to the new map
192 *
193 * This method is only required if you called StartTransition() before
194 * Teleport(), in which case it will display the transition. Otherwise,
195 * this action will do nothing.
196 *
197 * @param trans
198 * @throws InterruptedException
199 */
200 public void EndTransition(InTransition trans) throws InterruptedException
201 {
202 if (startedTransition)
203 {
204 Display.transition(trans);
205 }
206 }
207
208 /**
165 * Waits for a specified interval 209 * Waits for a specified interval
166 * 210 *
167 * @param wait The time to wait in milliseconds 211 * @param wait The time to wait in milliseconds
diff --git a/src/com/fourisland/fourpuzzle/transition/DoNotEraseTransition.java b/src/com/fourisland/fourpuzzle/transition/DoNotEraseTransition.java new file mode 100644 index 0000000..63c3ea3 --- /dev/null +++ b/src/com/fourisland/fourpuzzle/transition/DoNotEraseTransition.java
@@ -0,0 +1,21 @@
1/*
2 * To change this template, choose Tools | Templates
3 * and open the template in the editor.
4 */
5
6package com.fourisland.fourpuzzle.transition;
7
8import java.awt.Graphics2D;
9
10/**
11 *
12 * @author hatkirby
13 */
14public class DoNotEraseTransition implements OutTransition {
15
16 public boolean render(Graphics2D g)
17 {
18 return true;
19 }
20
21}
diff --git a/src/com/fourisland/fourpuzzle/transition/InTransition.java b/src/com/fourisland/fourpuzzle/transition/InTransition.java new file mode 100644 index 0000000..a326f52 --- /dev/null +++ b/src/com/fourisland/fourpuzzle/transition/InTransition.java
@@ -0,0 +1,18 @@
1/*
2 * To change this template, choose Tools | Templates
3 * and open the template in the editor.
4 */
5
6package com.fourisland.fourpuzzle.transition;
7
8import java.awt.image.BufferedImage;
9
10/**
11 *
12 * @author hatkirby
13 */
14public interface InTransition extends Transition {
15
16 public void setPreTransition(BufferedImage preTransition);
17
18}
diff --git a/src/com/fourisland/fourpuzzle/transition/MultidirectionalTransition.java b/src/com/fourisland/fourpuzzle/transition/MultidirectionalTransition.java new file mode 100644 index 0000000..7177179 --- /dev/null +++ b/src/com/fourisland/fourpuzzle/transition/MultidirectionalTransition.java
@@ -0,0 +1,16 @@
1/*
2 * To change this template, choose Tools | Templates
3 * and open the template in the editor.
4 */
5
6package com.fourisland.fourpuzzle.transition;
7
8/**
9 *
10 * @author hatkirby
11 */
12public interface MultidirectionalTransition extends OutTransition, InTransition {
13
14 public TransitionDirection getDirection();
15
16}
diff --git a/src/com/fourisland/fourpuzzle/transition/OutTransition.java b/src/com/fourisland/fourpuzzle/transition/OutTransition.java new file mode 100644 index 0000000..37bf5b4 --- /dev/null +++ b/src/com/fourisland/fourpuzzle/transition/OutTransition.java
@@ -0,0 +1,14 @@
1/*
2 * To change this template, choose Tools | Templates
3 * and open the template in the editor.
4 */
5
6package com.fourisland.fourpuzzle.transition;
7
8/**
9 *
10 * @author hatkirby
11 */
12public interface OutTransition extends Transition {
13
14}
diff --git a/src/com/fourisland/fourpuzzle/transition/SquareTransition.java b/src/com/fourisland/fourpuzzle/transition/SquareTransition.java index d60282d..1d8748a 100644 --- a/src/com/fourisland/fourpuzzle/transition/SquareTransition.java +++ b/src/com/fourisland/fourpuzzle/transition/SquareTransition.java
@@ -7,19 +7,21 @@ package com.fourisland.fourpuzzle.transition;
7 7
8import java.awt.Color; 8import java.awt.Color;
9import java.awt.Graphics2D; 9import java.awt.Graphics2D;
10import java.awt.image.BufferedImage;
10 11
11/** 12/**
12 * 13 *
13 * @author hatkirby 14 * @author hatkirby
14 */ 15 */
15public class SquareTransition extends Transition { 16public class SquareTransition implements MultidirectionalTransition {
16 17
17 private int tick; 18 private int tick;
18 public SquareTransition(boolean from) 19 private TransitionDirection direction;
20 public SquareTransition(TransitionDirection direction)
19 { 21 {
20 setDirection(from); 22 this.direction = direction;
21 23
22 if (from) 24 if (direction == TransitionDirection.Out)
23 { 25 {
24 tick = 160; 26 tick = 160;
25 } else { 27 } else {
@@ -27,24 +29,36 @@ public class SquareTransition extends Transition {
27 } 29 }
28 } 30 }
29 31
30 public void render(Graphics2D g) 32 public boolean render(Graphics2D g)
31 { 33 {
32 if (((!getDirection()) && (tick == 0)) || ((getDirection()) && (tick == 160))) 34 if (((direction == TransitionDirection.Out) && (tick == 0)) || ((direction == TransitionDirection.In) && (tick == 160)))
33 { 35 {
34 setRunning(false); 36 return true;
35 return;
36 } 37 }
37 38
38 if (getDirection()) 39 if (direction == TransitionDirection.In)
39 { 40 {
40 tick+=8; 41 tick+=8;
41 } else { 42 } else {
42 tick-=8; 43 tick-=8;
43 } 44 }
44 45
45 g.setBackground(Color.BLACK); 46 g.setBackground(Color.BLACK);
46 g.fillRect(0, 0, 320, 240); 47 g.fillRect(0, 0, 320, 240);
47 g.setClip(160-tick, 140-tick, tick*2, tick*2-40); 48 g.setClip(160-tick, 140-tick, tick*2, tick*2-40);
49
50 return false;
51 }
52
53 public TransitionDirection getDirection()
54 {
55 return direction;
56 }
57
58 private BufferedImage preTransition;
59 public void setPreTransition(BufferedImage preTransition)
60 {
61 this.preTransition = preTransition;
48 } 62 }
49 63
50} 64}
diff --git a/src/com/fourisland/fourpuzzle/transition/Transition.java b/src/com/fourisland/fourpuzzle/transition/Transition.java index e25fbc9..5b4dbe8 100644 --- a/src/com/fourisland/fourpuzzle/transition/Transition.java +++ b/src/com/fourisland/fourpuzzle/transition/Transition.java
@@ -11,47 +11,14 @@ import java.awt.Graphics2D;
11 * 11 *
12 * @author hatkirby 12 * @author hatkirby
13 */ 13 */
14public abstract class Transition { 14public interface Transition {
15
16 private boolean way;
17 protected void setDirection(boolean from)
18 {
19 if ((from) && !(isFromSupported()))
20 {
21 throw new TransitionUnsupportedException(this.getClass().getSimpleName(), "From");
22 } else if ((!from) && !(isToSupported()))
23 {
24 throw new TransitionUnsupportedException(this.getClass().getSimpleName(), "To");
25 } else {
26 way = from;
27 }
28 }
29
30 public boolean getDirection()
31 {
32 return way;
33 }
34 15
35 public boolean isFromSupported() 16 /**
36 { 17 * Render the transition to the display
37 return true; 18 *
38 } 19 * @param g The graphics device to render the transition to
39 20 * @return If the transition has completed, true. Otherwise false.
40 public boolean isToSupported() 21 */
41 { 22 public boolean render(Graphics2D g);
42 return true;
43 }
44
45 public abstract void render(Graphics2D g);
46
47 private boolean running = true;
48 public boolean isRunning()
49 {
50 return running;
51 }
52 public void setRunning(boolean running)
53 {
54 this.running = running;
55 }
56 23
57} 24} \ No newline at end of file
diff --git a/src/com/fourisland/fourpuzzle/transition/TransitionCallbackThread.java b/src/com/fourisland/fourpuzzle/transition/TransitionCallbackThread.java deleted file mode 100644 index 50eacc2..0000000 --- a/src/com/fourisland/fourpuzzle/transition/TransitionCallbackThread.java +++ /dev/null
@@ -1,38 +0,0 @@
1/*
2 * To change this template, choose Tools | Templates
3 * and open the template in the editor.
4 */
5
6package com.fourisland.fourpuzzle.transition;
7
8import com.fourisland.fourpuzzle.Display;
9
10/**
11 *
12 * @author hatkirby
13 */
14public class TransitionCallbackThread implements Runnable {
15
16 private Runnable callback;
17 public TransitionCallbackThread(Runnable callback)
18 {
19 this.callback = callback;
20 }
21
22 public void run()
23 {
24 while (Display.getTransition().isRunning())
25 {
26 try {
27 Thread.sleep(300);
28 } catch (InterruptedException ex) {
29 Thread.currentThread().interrupt();
30 }
31 }
32
33 //Display.setEnabled(false);
34
35 callback.run();
36 }
37
38}
diff --git a/src/com/fourisland/fourpuzzle/transition/TransitionDirection.java b/src/com/fourisland/fourpuzzle/transition/TransitionDirection.java new file mode 100644 index 0000000..305bb5c --- /dev/null +++ b/src/com/fourisland/fourpuzzle/transition/TransitionDirection.java
@@ -0,0 +1,15 @@
1/*
2 * To change this template, choose Tools | Templates
3 * and open the template in the editor.
4 */
5
6package com.fourisland.fourpuzzle.transition;
7
8/**
9 *
10 * @author hatkirby
11 */
12public enum TransitionDirection {
13 In,
14 Out
15}
diff --git a/src/com/fourisland/fourpuzzle/transition/TransitionUnsupportedException.java b/src/com/fourisland/fourpuzzle/transition/TransitionUnsupportedException.java index 40f3db8..dfea7aa 100644 --- a/src/com/fourisland/fourpuzzle/transition/TransitionUnsupportedException.java +++ b/src/com/fourisland/fourpuzzle/transition/TransitionUnsupportedException.java
@@ -11,9 +11,19 @@ package com.fourisland.fourpuzzle.transition;
11 */ 11 */
12public class TransitionUnsupportedException extends RuntimeException { 12public class TransitionUnsupportedException extends RuntimeException {
13 13
14 public TransitionUnsupportedException(String className, String direction) 14 private String className;
15 private TransitionDirection direction;
16
17 public TransitionUnsupportedException(String className, TransitionDirection direction)
18 {
19 this.className = className;
20 this.direction = direction;
21 }
22
23 @Override
24 public String getMessage()
15 { 25 {
16 super("Transition \"" + className + "\" does not support the " + direction + " direction"); 26 return "Transition \"" + className + "\" does not support the " + direction.toString() + " direction";
17 } 27 }
18 28
19} 29}