diff options
Diffstat (limited to 'src/com/fourisland')
7 files changed, 64 insertions, 58 deletions
diff --git a/src/com/fourisland/fourpuzzle/Display.java b/src/com/fourisland/fourpuzzle/Display.java index cf1cb2d..a8c9a37 100755 --- a/src/com/fourisland/fourpuzzle/Display.java +++ b/src/com/fourisland/fourpuzzle/Display.java | |||
@@ -11,6 +11,7 @@ import com.fourisland.fourpuzzle.transition.MultidirectionalTransition; | |||
11 | import com.fourisland.fourpuzzle.transition.OutTransition; | 11 | import com.fourisland.fourpuzzle.transition.OutTransition; |
12 | import com.fourisland.fourpuzzle.transition.Transition; | 12 | import com.fourisland.fourpuzzle.transition.Transition; |
13 | import com.fourisland.fourpuzzle.transition.TransitionDirection; | 13 | import com.fourisland.fourpuzzle.transition.TransitionDirection; |
14 | import com.fourisland.fourpuzzle.transition.TransitionPair; | ||
14 | import com.fourisland.fourpuzzle.transition.TransitionUnsupportedException; | 15 | import com.fourisland.fourpuzzle.transition.TransitionUnsupportedException; |
15 | import com.fourisland.fourpuzzle.util.Renderable; | 16 | import com.fourisland.fourpuzzle.util.Renderable; |
16 | import java.awt.Color; | 17 | import java.awt.Color; |
@@ -208,7 +209,7 @@ public class Display { | |||
208 | } | 209 | } |
209 | 210 | ||
210 | private static Executor transitioner = Executors.newSingleThreadExecutor(); | 211 | private static Executor transitioner = Executors.newSingleThreadExecutor(); |
211 | public static void transition(final Transition out, final GameState gameState, final Transition in, boolean thread) | 212 | public static void transition(final OutTransition out, final GameState gameState, final InTransition in, boolean thread) |
212 | { | 213 | { |
213 | Runnable transitionCall = new Runnable() { | 214 | Runnable transitionCall = new Runnable() { |
214 | public void run() | 215 | public void run() |
@@ -237,6 +238,11 @@ public class Display { | |||
237 | } | 238 | } |
238 | } | 239 | } |
239 | 240 | ||
241 | public static void transition(TransitionPair trans, GameState gameState, boolean thread) | ||
242 | { | ||
243 | transition(trans.getOutTransition(), gameState, trans.getInTransition(), thread); | ||
244 | } | ||
245 | |||
240 | public static boolean isTransitionRunning() | 246 | public static boolean isTransitionRunning() |
241 | { | 247 | { |
242 | return transitionRunning; | 248 | return transitionRunning; |
diff --git a/src/com/fourisland/fourpuzzle/database/Database.java b/src/com/fourisland/fourpuzzle/database/Database.java index 922ab60..03405c8 100755 --- a/src/com/fourisland/fourpuzzle/database/Database.java +++ b/src/com/fourisland/fourpuzzle/database/Database.java | |||
@@ -6,7 +6,7 @@ | |||
6 | package com.fourisland.fourpuzzle.database; | 6 | package com.fourisland.fourpuzzle.database; |
7 | 7 | ||
8 | import com.fourisland.fourpuzzle.gamestate.mapview.Map; | 8 | import com.fourisland.fourpuzzle.gamestate.mapview.Map; |
9 | import com.fourisland.fourpuzzle.transition.Transition; | 9 | import com.fourisland.fourpuzzle.transition.TransitionPair; |
10 | import java.util.HashMap; | 10 | import java.util.HashMap; |
11 | 11 | ||
12 | /** | 12 | /** |
@@ -77,7 +77,7 @@ public class Database { | |||
77 | key.setValue(value); | 77 | key.setValue(value); |
78 | } | 78 | } |
79 | 79 | ||
80 | public static Transition getTransition(Transitions key) | 80 | public static TransitionPair getTransition(Transitions key) |
81 | { | 81 | { |
82 | return key.getValue().copy(); | 82 | return key.getValue().copy(); |
83 | } | 83 | } |
@@ -96,7 +96,7 @@ public class Database { | |||
96 | * @param key The transition to change | 96 | * @param key The transition to change |
97 | * @param value The transition to change it to | 97 | * @param value The transition to change it to |
98 | */ | 98 | */ |
99 | public static void setTransition(Transitions key, Transition value) | 99 | public static void setTransition(Transitions key, TransitionPair value) |
100 | { | 100 | { |
101 | key.setValue(value); | 101 | key.setValue(value); |
102 | } | 102 | } |
diff --git a/src/com/fourisland/fourpuzzle/database/Transitions.java b/src/com/fourisland/fourpuzzle/database/Transitions.java index 98345a9..74c0674 100644 --- a/src/com/fourisland/fourpuzzle/database/Transitions.java +++ b/src/com/fourisland/fourpuzzle/database/Transitions.java | |||
@@ -6,71 +6,33 @@ | |||
6 | package com.fourisland.fourpuzzle.database; | 6 | package com.fourisland.fourpuzzle.database; |
7 | 7 | ||
8 | import com.fourisland.fourpuzzle.transition.FadeTransition; | 8 | import com.fourisland.fourpuzzle.transition.FadeTransition; |
9 | import com.fourisland.fourpuzzle.transition.InTransition; | ||
10 | import com.fourisland.fourpuzzle.transition.MultidirectionalTransition; | ||
11 | import com.fourisland.fourpuzzle.transition.OutTransition; | ||
12 | import com.fourisland.fourpuzzle.transition.SquareTransition; | 9 | import com.fourisland.fourpuzzle.transition.SquareTransition; |
13 | import com.fourisland.fourpuzzle.transition.Transition; | ||
14 | import com.fourisland.fourpuzzle.transition.TransitionDirection; | 10 | import com.fourisland.fourpuzzle.transition.TransitionDirection; |
15 | import com.fourisland.fourpuzzle.transition.TransitionUnsupportedException; | 11 | import com.fourisland.fourpuzzle.transition.TransitionPair; |
16 | 12 | ||
17 | /** | 13 | /** |
18 | * | 14 | * |
19 | * @author hatkirby | 15 | * @author hatkirby |
20 | */ | 16 | */ |
21 | public enum Transitions { | 17 | public enum Transitions { |
22 | TitleExit(TransitionDirection.Out, new FadeTransition(TransitionDirection.Out)), | ||
23 | TitleToMap(TransitionDirection.In, new FadeTransition(TransitionDirection.In)), | ||
24 | MapExit(TransitionDirection.Out, new SquareTransition(TransitionDirection.Out)), | ||
25 | MapEnter(TransitionDirection.In, new SquareTransition(TransitionDirection.In)), | ||
26 | MapToTitle(TransitionDirection.Out, new FadeTransition(TransitionDirection.Out)), | ||
27 | TitleEnter(TransitionDirection.In, new FadeTransition(TransitionDirection.In)), | ||
28 | MapToGameOver(TransitionDirection.Out, new FadeTransition(TransitionDirection.Out)), | ||
29 | GameOverEnter(TransitionDirection.In, new FadeTransition(TransitionDirection.In)), | ||
30 | GameOverToTitle(TransitionDirection.Out, new FadeTransition(TransitionDirection.Out)); | ||
31 | 18 | ||
32 | private final TransitionDirection dir; | 19 | Generic(new TransitionPair(new FadeTransition(TransitionDirection.Out), new FadeTransition(TransitionDirection.In))), |
33 | private Transition trans; | 20 | Map(new TransitionPair(new SquareTransition(TransitionDirection.Out), new SquareTransition(TransitionDirection.In))); |
34 | private Transitions(TransitionDirection dir, Transition trans) | 21 | |
22 | private TransitionPair trans; | ||
23 | private Transitions(TransitionPair trans) | ||
35 | { | 24 | { |
36 | this.dir = dir; | 25 | this.trans = trans; |
37 | |||
38 | if (isTransitionSupported(dir, trans)) | ||
39 | { | ||
40 | this.trans = trans; | ||
41 | } else { | ||
42 | throw new TransitionUnsupportedException(trans.getClass().getName(), dir); | ||
43 | } | ||
44 | } | 26 | } |
45 | 27 | ||
46 | Transition getValue() | 28 | TransitionPair getValue() |
47 | { | 29 | { |
48 | return trans; | 30 | return trans; |
49 | } | 31 | } |
50 | 32 | ||
51 | void setValue(Transition trans) | 33 | void setValue(TransitionPair trans) |
52 | { | 34 | { |
53 | if (isTransitionSupported(dir, trans)) | 35 | this.trans = trans; |
54 | { | ||
55 | this.trans = trans; | ||
56 | } else { | ||
57 | throw new TransitionUnsupportedException(trans.getClass().getName(), dir); | ||
58 | } | ||
59 | } | 36 | } |
60 | 37 | ||
61 | private boolean isTransitionSupported(TransitionDirection dir, Transition trans) | ||
62 | { | ||
63 | if (trans instanceof MultidirectionalTransition) | ||
64 | { | ||
65 | return (((MultidirectionalTransition) trans).getDirection() == dir); | ||
66 | } else if (trans instanceof OutTransition) | ||
67 | { | ||
68 | return (dir == TransitionDirection.Out); | ||
69 | } else if (trans instanceof InTransition) | ||
70 | { | ||
71 | return (dir == TransitionDirection.In); | ||
72 | } | ||
73 | |||
74 | return false; | ||
75 | } | ||
76 | } | 38 | } |
diff --git a/src/com/fourisland/fourpuzzle/gamestate/GameOverGameState.java b/src/com/fourisland/fourpuzzle/gamestate/GameOverGameState.java index 670d900..692554e 100755 --- a/src/com/fourisland/fourpuzzle/gamestate/GameOverGameState.java +++ b/src/com/fourisland/fourpuzzle/gamestate/GameOverGameState.java | |||
@@ -38,7 +38,7 @@ public class GameOverGameState implements GameState { | |||
38 | { | 38 | { |
39 | Game.setSaveFile(new SaveFile()); | 39 | Game.setSaveFile(new SaveFile()); |
40 | 40 | ||
41 | Display.transition(Database.getTransition(Transitions.GameOverToTitle), new TitleScreenGameState(), Database.getTransition(Transitions.TitleEnter), true); | 41 | Display.transition(Database.getTransition(Transitions.Generic), new TitleScreenGameState(), true); |
42 | } | 42 | } |
43 | } | 43 | } |
44 | 44 | ||
diff --git a/src/com/fourisland/fourpuzzle/gamestate/TitleScreenGameState.java b/src/com/fourisland/fourpuzzle/gamestate/TitleScreenGameState.java index a72a22a..cedf5a6 100755 --- a/src/com/fourisland/fourpuzzle/gamestate/TitleScreenGameState.java +++ b/src/com/fourisland/fourpuzzle/gamestate/TitleScreenGameState.java | |||
@@ -56,7 +56,7 @@ public class TitleScreenGameState implements GameState { | |||
56 | { | 56 | { |
57 | Game.setSaveFile(new SaveFile()); | 57 | Game.setSaveFile(new SaveFile()); |
58 | 58 | ||
59 | Display.transition(Database.getTransition(Transitions.TitleExit), new MapViewGameState("TestMap", 1, 2), Database.getTransition(Transitions.TitleToMap), true); | 59 | Display.transition(Database.getTransition(Transitions.Generic), new MapViewGameState("TestMap", 1, 2), true); |
60 | } else if (choices.getSelected().equals(Database.getVocab(Vocabulary.LoadGame))) | 60 | } else if (choices.getSelected().equals(Database.getVocab(Vocabulary.LoadGame))) |
61 | { | 61 | { |
62 | // Do nothing, yet | 62 | // Do nothing, yet |
@@ -65,7 +65,7 @@ public class TitleScreenGameState implements GameState { | |||
65 | new Thread(new Runnable() { | 65 | new Thread(new Runnable() { |
66 | public void run() { | 66 | public void run() { |
67 | try { | 67 | try { |
68 | Display.transition(Database.getTransition(Transitions.TitleExit)); | 68 | Display.transition(Database.getTransition(Transitions.Generic).getOutTransition()); |
69 | } catch (InterruptedException ex) { | 69 | } catch (InterruptedException ex) { |
70 | Thread.currentThread().interrupt(); | 70 | Thread.currentThread().interrupt(); |
71 | } | 71 | } |
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java index ebb0e27..c3bec32 100755 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java | |||
@@ -157,7 +157,7 @@ public class SpecialEvent { | |||
157 | { | 157 | { |
158 | Audio.stopMusic(); | 158 | Audio.stopMusic(); |
159 | 159 | ||
160 | Display.transition(Database.getTransition(Transitions.MapToGameOver), new GameOverGameState(), Database.getTransition(Transitions.GameOverEnter), false); | 160 | Display.transition(Database.getTransition(Transitions.Generic), new GameOverGameState(), false); |
161 | } | 161 | } |
162 | 162 | ||
163 | /** | 163 | /** |
@@ -169,7 +169,7 @@ public class SpecialEvent { | |||
169 | { | 169 | { |
170 | Audio.stopMusic(); | 170 | Audio.stopMusic(); |
171 | 171 | ||
172 | Display.transition(Database.getTransition(Transitions.MapToTitle), new TitleScreenGameState(), Database.getTransition(Transitions.TitleEnter), false); | 172 | Display.transition(Database.getTransition(Transitions.Generic), new TitleScreenGameState(), false); |
173 | } | 173 | } |
174 | 174 | ||
175 | private boolean startedTransition = false; | 175 | private boolean startedTransition = false; |
@@ -211,7 +211,7 @@ public class SpecialEvent { | |||
211 | { | 211 | { |
212 | if (!startedTransition) | 212 | if (!startedTransition) |
213 | { | 213 | { |
214 | Display.transition(Database.getTransition(Transitions.MapExit), new MapViewGameState(map, x, y), Database.getTransition(Transitions.MapEnter), false); | 214 | Display.transition(Database.getTransition(Transitions.Map), new MapViewGameState(map, x, y), false); |
215 | } else { | 215 | } else { |
216 | Game.setGameState(new MapViewGameState(map, x, y)); | 216 | Game.setGameState(new MapViewGameState(map, x, y)); |
217 | } | 217 | } |
diff --git a/src/com/fourisland/fourpuzzle/transition/TransitionPair.java b/src/com/fourisland/fourpuzzle/transition/TransitionPair.java new file mode 100644 index 0000000..a73e671 --- /dev/null +++ b/src/com/fourisland/fourpuzzle/transition/TransitionPair.java | |||
@@ -0,0 +1,38 @@ | |||
1 | /* | ||
2 | * To change this template, choose Tools | Templates | ||
3 | * and open the template in the editor. | ||
4 | */ | ||
5 | |||
6 | package com.fourisland.fourpuzzle.transition; | ||
7 | |||
8 | /** | ||
9 | * | ||
10 | * @author hatkirby | ||
11 | */ | ||
12 | public class TransitionPair { | ||
13 | |||
14 | private OutTransition out; | ||
15 | private InTransition in; | ||
16 | |||
17 | public TransitionPair(OutTransition out, InTransition in) | ||
18 | { | ||
19 | this.out = out; | ||
20 | this.in = in; | ||
21 | } | ||
22 | |||
23 | public OutTransition getOutTransition() | ||
24 | { | ||
25 | return out; | ||
26 | } | ||
27 | |||
28 | public InTransition getInTransition() | ||
29 | { | ||
30 | return in; | ||
31 | } | ||
32 | |||
33 | public TransitionPair copy() | ||
34 | { | ||
35 | return new TransitionPair((OutTransition) out.copy(), (InTransition) in.copy()); | ||
36 | } | ||
37 | |||
38 | } | ||