diff options
author | Starla Insigna <hatkirby@fourisland.com> | 2009-02-12 16:36:07 -0500 |
---|---|---|
committer | Starla Insigna <hatkirby@fourisland.com> | 2009-02-12 16:36:07 -0500 |
commit | bbf294dbf6b552751e5d9f3fb66188bd1bee724b (patch) | |
tree | 1e29d91a6e8a3b9d26ec874169de85928d4ec56f /src/com/fourisland/fourpuzzle/Display.java | |
parent | 3cd96daaf22236e4eb15c6422f772abf08351023 (diff) | |
download | fourpuzzle-bbf294dbf6b552751e5d9f3fb66188bd1bee724b.tar.gz fourpuzzle-bbf294dbf6b552751e5d9f3fb66188bd1bee724b.tar.bz2 fourpuzzle-bbf294dbf6b552751e5d9f3fb66188bd1bee724b.zip |
Engine: Wrote Message System
MessageWindow now has a static method run by SpecialEvent that triggers the message box. This method blocks until the message is complete and renders via Display's new feature. The message box also now features the "next" arrow and the letters gradually appear. Display has also been re-worked to have a list of a new interface called Renderable, which is any object that can be rendered. Such objects (such as MessageWindow) can register to Display, which will render them onto the game frame after the GameState has been rendered. Closes #5.
Diffstat (limited to 'src/com/fourisland/fourpuzzle/Display.java')
-rwxr-xr-x | src/com/fourisland/fourpuzzle/Display.java | 52 |
1 files changed, 38 insertions, 14 deletions
diff --git a/src/com/fourisland/fourpuzzle/Display.java b/src/com/fourisland/fourpuzzle/Display.java index 85acaf4..ec835ab 100755 --- a/src/com/fourisland/fourpuzzle/Display.java +++ b/src/com/fourisland/fourpuzzle/Display.java | |||
@@ -11,6 +11,7 @@ import com.fourisland.fourpuzzle.transition.OutTransition; | |||
11 | import com.fourisland.fourpuzzle.transition.Transition; | 11 | import com.fourisland.fourpuzzle.transition.Transition; |
12 | import com.fourisland.fourpuzzle.transition.TransitionDirection; | 12 | import com.fourisland.fourpuzzle.transition.TransitionDirection; |
13 | import com.fourisland.fourpuzzle.transition.TransitionUnsupportedException; | 13 | import com.fourisland.fourpuzzle.transition.TransitionUnsupportedException; |
14 | import com.fourisland.fourpuzzle.util.Renderable; | ||
14 | import java.awt.Font; | 15 | import java.awt.Font; |
15 | import java.awt.FontFormatException; | 16 | import java.awt.FontFormatException; |
16 | import java.awt.Graphics2D; | 17 | import java.awt.Graphics2D; |
@@ -20,6 +21,8 @@ import java.awt.image.BufferedImage; | |||
20 | import java.awt.image.VolatileImage; | 21 | import java.awt.image.VolatileImage; |
21 | import java.io.IOException; | 22 | import java.io.IOException; |
22 | import java.io.InputStream; | 23 | import java.io.InputStream; |
24 | import java.util.List; | ||
25 | import java.util.concurrent.CopyOnWriteArrayList; | ||
23 | import java.util.concurrent.CountDownLatch; | 26 | import java.util.concurrent.CountDownLatch; |
24 | import java.util.logging.Level; | 27 | import java.util.logging.Level; |
25 | import java.util.logging.Logger; | 28 | import java.util.logging.Logger; |
@@ -33,6 +36,8 @@ import org.jdesktop.application.ResourceMap; | |||
33 | public class Display { | 36 | public class Display { |
34 | 37 | ||
35 | public static int tileAnimationFrame = 0; | 38 | public static int tileAnimationFrame = 0; |
39 | |||
40 | private static List<Renderable> renderables = new CopyOnWriteArrayList<Renderable>(); | ||
36 | 41 | ||
37 | public static void render(JDialog gameFrame) | 42 | public static void render(JDialog gameFrame) |
38 | { | 43 | { |
@@ -95,18 +100,37 @@ public class Display { | |||
95 | g.drawImage(midTransition, 0, 0, null); | 100 | g.drawImage(midTransition, 0, 0, null); |
96 | } | 101 | } |
97 | } else { | 102 | } else { |
98 | Game.getGameState().render(g); | 103 | render(g); |
99 | } | 104 | } |
100 | 105 | ||
101 | g.dispose(); | 106 | g.dispose(); |
102 | } | 107 | } |
103 | 108 | ||
109 | private static void render(Graphics2D g) | ||
110 | { | ||
111 | Game.getGameState().render(g); | ||
112 | |||
113 | for (Renderable r : renderables) | ||
114 | { | ||
115 | r.render(g); | ||
116 | } | ||
117 | } | ||
118 | |||
119 | public static void registerRenderable(Renderable r) | ||
120 | { | ||
121 | renderables.add(r); | ||
122 | } | ||
123 | |||
124 | public static void unregisterRenderable(Renderable r) | ||
125 | { | ||
126 | renderables.remove(r); | ||
127 | } | ||
128 | |||
104 | private static boolean startedTransition = false; | 129 | private static boolean startedTransition = false; |
105 | private static Transition transition; | 130 | private static Transition transition; |
106 | private static CountDownLatch transitionWait; | 131 | private static CountDownLatch transitionWait; |
107 | private static boolean transitionRunning = false; | 132 | private static boolean transitionRunning = false; |
108 | private static BufferedImage midTransition = null; | 133 | private static BufferedImage midTransition = null; |
109 | private static BufferedImage postTransition = null; | ||
110 | public static void transition(Transition transition) throws InterruptedException | 134 | public static void transition(Transition transition) throws InterruptedException |
111 | { | 135 | { |
112 | if (transition instanceof MultidirectionalTransition) | 136 | if (transition instanceof MultidirectionalTransition) |
@@ -125,13 +149,13 @@ public class Display { | |||
125 | { | 149 | { |
126 | temp.setPreTransition(midTransition); | 150 | temp.setPreTransition(midTransition); |
127 | 151 | ||
128 | postTransition = Display.createCanvas(Game.WIDTH, Game.HEIGHT); | 152 | BufferedImage bImg = Display.createCanvas(Game.WIDTH, Game.HEIGHT); |
129 | Game.getGameState().render(postTransition.createGraphics()); | 153 | render(bImg.createGraphics()); |
130 | temp.setPostTransition(postTransition); | 154 | temp.setPostTransition(bImg); |
131 | } else { | 155 | } else { |
132 | BufferedImage preTransition = Display.createCanvas(Game.WIDTH, Game.HEIGHT); | 156 | BufferedImage bImg = Display.createCanvas(Game.WIDTH, Game.HEIGHT); |
133 | Game.getGameState().render(preTransition.createGraphics()); | 157 | render(bImg.createGraphics()); |
134 | temp.setPreTransition(preTransition); | 158 | temp.setPreTransition(bImg); |
135 | } | 159 | } |
136 | } else { | 160 | } else { |
137 | if (startedTransition && !(transition instanceof InTransition)) | 161 | if (startedTransition && !(transition instanceof InTransition)) |
@@ -146,13 +170,13 @@ public class Display { | |||
146 | { | 170 | { |
147 | transition.setPreTransition(midTransition); | 171 | transition.setPreTransition(midTransition); |
148 | 172 | ||
149 | postTransition = Display.createCanvas(Game.WIDTH, Game.HEIGHT); | 173 | BufferedImage bImg = Display.createCanvas(Game.WIDTH, Game.HEIGHT); |
150 | Game.getGameState().render(postTransition.createGraphics()); | 174 | render(bImg.createGraphics()); |
151 | ((InTransition) transition).setPostTransition(postTransition); | 175 | ((InTransition) transition).setPostTransition(bImg); |
152 | } else { | 176 | } else { |
153 | BufferedImage preTransition = Display.createCanvas(Game.WIDTH, Game.HEIGHT); | 177 | BufferedImage bImg = Display.createCanvas(Game.WIDTH, Game.HEIGHT); |
154 | Game.getGameState().render(preTransition.createGraphics()); | 178 | render(bImg.createGraphics()); |
155 | transition.setPreTransition(preTransition); | 179 | transition.setPreTransition(bImg); |
156 | } | 180 | } |
157 | } | 181 | } |
158 | 182 | ||