From 3c3e8ed4432fde2bdd60c49f29244a13e1e12243 Mon Sep 17 00:00:00 2001 From: Starla Insigna Date: Fri, 6 Mar 2009 15:18:53 -0500 Subject: Engine: Refactored MessageWindow MessageWindow is now an Inputable and a Renderable, which allows it to tie in more logically with the rest of the system. --- .../gamestate/mapview/event/SpecialEvent.java | 20 ++++- .../fourpuzzle/window/MessageWindow.java | 85 +++++++--------------- 2 files changed, 42 insertions(+), 63 deletions(-) (limited to 'src') diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java index 1a33158..ca3ba5e 100755 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java @@ -47,21 +47,35 @@ public class SpecialEvent { * MessageDisplaySettings().

* *

This function also automatically splits your message up into blocks that - * will fit onthe screen (breaks at spaces). If there are too many words, + * will fit on the screen (breaks at spaces). If there are too many words, * they will be held and displayed in the message area after the prior * message has been read.

* + *

Message Escapes can be used to preform specific actions during text + * display. For instance, \C[number] changes the text color to + * the color on the System Graphic represented by "number".

+ * * @param message The message to display * @throws InterruptedException */ public void DisplayMessage(String message) throws InterruptedException { + MessageWindow mw; + if (faceSet.equals("")) { - MessageWindow.displayMessage(message); + mw = new MessageWindow(message); } else { - MessageWindow.displayMessage(message, faceSet, face); + mw = new MessageWindow(message, faceSet, face); } + + Display.registerRenderable(mw); + KeyboardInput.registerInputable(mw); + + mw.waitForCompletion(); + + Display.unregisterRenderable(mw); + KeyboardInput.unregisterInputable(mw); } /** diff --git a/src/com/fourisland/fourpuzzle/window/MessageWindow.java b/src/com/fourisland/fourpuzzle/window/MessageWindow.java index 709704a..43b40cf 100644 --- a/src/com/fourisland/fourpuzzle/window/MessageWindow.java +++ b/src/com/fourisland/fourpuzzle/window/MessageWindow.java @@ -7,7 +7,6 @@ package com.fourisland.fourpuzzle.window; import com.fourisland.fourpuzzle.Display; import com.fourisland.fourpuzzle.Game; -import com.fourisland.fourpuzzle.KeyboardInput; import com.fourisland.fourpuzzle.KeyInput; import com.fourisland.fourpuzzle.gamestate.mapview.FaceSet; import com.fourisland.fourpuzzle.util.Inputable; @@ -21,7 +20,7 @@ import java.util.concurrent.CountDownLatch; * * @author hatkirby */ -public class MessageWindow implements Renderable { +public class MessageWindow implements Renderable, Inputable { private static final int SPACER = 4; private static final int HEIGHT = (4*(Display.getFontMetrics().getHeight()+SPACER)); @@ -32,7 +31,7 @@ public class MessageWindow implements Renderable { int upTo = 0; boolean bounceArrow = false; Interval in = Interval.createTickInterval(4); - private MessageWindow(String message) + public MessageWindow(String message) { width = Game.WIDTH - Window.Default.getFullWidth(0); cacheBase = Window.Default.getImage(width, HEIGHT); @@ -44,7 +43,7 @@ public class MessageWindow implements Renderable { boolean hasFace = false; BufferedImage face; - private MessageWindow(String message, String faceSet, int face) + public MessageWindow(String message, String faceSet, int face) { width = Game.WIDTH - Window.Default.getFullWidth(0); cacheBase = Window.Default.getImage(width, HEIGHT); @@ -58,49 +57,6 @@ public class MessageWindow implements Renderable { tr.initalizeText(message); } - private static void displayMessage(final MessageWindow mw) throws InterruptedException - { - final CountDownLatch cdl = new CountDownLatch(1); - Inputable in = new Inputable() { - public void processInput(KeyInput key) - { - if (key.isActionDown()) - { - if (mw.pushEnter()) - { - cdl.countDown(); - } - - key.letGo(); - } - } - }; - - Display.registerRenderable(mw); - KeyboardInput.registerInputable(in); - - try - { - cdl.await(); - } catch (InterruptedException ex) - { - throw ex; - } finally { - Display.unregisterRenderable(mw); - KeyboardInput.unregisterInputable(in); - } - } - - public static void displayMessage(String message) throws InterruptedException - { - displayMessage(new MessageWindow(message)); - } - - public static void displayMessage(String message, String faceSet, int face) throws InterruptedException - { - displayMessage(new MessageWindow(message, faceSet, face)); - } - public void render(Graphics2D g2) { int y = MessageWindowLocation.Bottom.getY(); @@ -128,26 +84,35 @@ public class MessageWindow implements Renderable { } } - private synchronized boolean pushEnter() + CountDownLatch cdl = new CountDownLatch(1); + public void waitForCompletion() throws InterruptedException { - if (tr.isCascadingDone()) + cdl.await(); + } + + public void processInput(KeyInput key) + { + if (key.isActionDown()) { - int msgs = tr.numLines(); - if (upTo >= (msgs-4)) + if (tr.isCascadingDone()) { - return true; - } else { - upTo += 4; - - if (upTo > msgs) + int msgs = tr.numLines(); + if (upTo >= (msgs-4)) { - upTo = msgs; + cdl.countDown(); + } else { + upTo += 4; + + if (upTo > msgs) + { + upTo = msgs; + } } } + + key.letGo(); } - - return false; - } + } public static enum MessageWindowLocation { -- cgit 1.4.1