summary refs log tree commit diff stats
path: root/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java')
-rw-r--r--src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java78
1 files changed, 78 insertions, 0 deletions
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java index 615396b..342b65f 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java
@@ -9,6 +9,11 @@ import com.fourisland.fourpuzzle.*;
9import com.fourisland.fourpuzzle.gamestate.mapview.MapViewGameState; 9import com.fourisland.fourpuzzle.gamestate.mapview.MapViewGameState;
10import com.fourisland.fourpuzzle.gamestate.mapview.event.specialmove.MoveEvent; 10import com.fourisland.fourpuzzle.gamestate.mapview.event.specialmove.MoveEvent;
11import com.fourisland.fourpuzzle.gamestate.mapview.event.specialmove.MoveEventThread; 11import com.fourisland.fourpuzzle.gamestate.mapview.event.specialmove.MoveEventThread;
12import com.fourisland.fourpuzzle.gamestate.mapview.viewpoint.AutomaticViewpoint;
13import com.fourisland.fourpuzzle.gamestate.mapview.viewpoint.FixedViewpoint;
14import com.fourisland.fourpuzzle.gamestate.mapview.viewpoint.MovingViewpoint;
15import com.fourisland.fourpuzzle.gamestate.mapview.viewpoint.Viewpoint;
16import java.util.concurrent.CountDownLatch;
12import java.util.logging.Level; 17import java.util.logging.Level;
13import java.util.logging.Logger; 18import java.util.logging.Logger;
14 19
@@ -17,6 +22,12 @@ import java.util.logging.Logger;
17 * @author hatkirby 22 * @author hatkirby
18 */ 23 */
19public class SpecialEvent { 24public class SpecialEvent {
25
26 protected static MapViewGameState mapView = null;
27 public static void setMapView(MapViewGameState mapView)
28 {
29 SpecialEvent.mapView = mapView;
30 }
20 31
21 /** 32 /**
22 * Display a message on the screen. 33 * Display a message on the screen.
@@ -165,4 +176,71 @@ public class SpecialEvent {
165 } 176 }
166 } 177 }
167 178
179 /**
180 * Fixes the viewpoint in the current position
181 */
182 public void FixViewpoint()
183 {
184 Viewpoint viewpoint = mapView.getViewpoint();
185 mapView.setViewpoint(new FixedViewpoint(viewpoint.getX(),viewpoint.getY()));
186 }
187
188 /**
189 * Pans the viewpoint the the specified tile location
190 *
191 * @param x The x coordinate of the tile to pan to
192 * @param y The y coordinate of the tile to pan to
193 * @param length How long (in milliseconds) it will take to pan
194 * @param block If true, the game will wait for the pan to complete
195 * before executing any more commands
196 */
197 public void PanViewpoint(final int x, final int y, int length, final boolean block)
198 {
199 Viewpoint viewpoint = mapView.getViewpoint();
200 final CountDownLatch blocker;
201
202 if (block)
203 {
204 blocker = new CountDownLatch(1);
205 } else {
206 blocker = null;
207 }
208
209 mapView.setViewpoint(new MovingViewpoint(viewpoint.getX(), viewpoint.getY(), x*16, y*16, new Runnable() {
210 public void run()
211 {
212 mapView.setViewpoint(new FixedViewpoint(x*16,y*16));
213
214 if (block)
215 {
216 blocker.countDown();
217 }
218 }
219 }, length));
220
221 if (block)
222 {
223 try {
224 blocker.await();
225 } catch (InterruptedException ex) {
226 Logger.getLogger(SpecialEvent.class.getName()).log(Level.SEVERE, null, ex);
227 }
228 }
229 }
230
231 /**
232 * Resets the viewpoint from whatever state is is currently in
233 */
234 public void ResetViewpoint()
235 {
236 Viewpoint viewpoint = mapView.getViewpoint();
237 AutomaticViewpoint dest = new AutomaticViewpoint(mapView.getCurrentMap());
238
239 mapView.setViewpoint(new MovingViewpoint(viewpoint.getX(), viewpoint.getY(), dest.getX(), dest.getY(), new Runnable() {
240 public void run() {
241 mapView.setViewpoint(new AutomaticViewpoint(mapView.getCurrentMap()));
242 }
243 }));
244 }
245
168} 246}