summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorStarla Insigna <hatkirby@fourisland.com>2009-03-06 15:18:53 -0500
committerStarla Insigna <hatkirby@fourisland.com>2009-03-06 15:18:53 -0500
commit3c3e8ed4432fde2bdd60c49f29244a13e1e12243 (patch)
tree9f6b1dfa53bd3d12673732adbed411f537ad31bb /src
parent8e0383a3674f4d9c57b3a1b5667750a3e963a7bd (diff)
downloadfourpuzzle-3c3e8ed4432fde2bdd60c49f29244a13e1e12243.tar.gz
fourpuzzle-3c3e8ed4432fde2bdd60c49f29244a13e1e12243.tar.bz2
fourpuzzle-3c3e8ed4432fde2bdd60c49f29244a13e1e12243.zip
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.
Diffstat (limited to 'src')
-rwxr-xr-xsrc/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java20
-rw-r--r--src/com/fourisland/fourpuzzle/window/MessageWindow.java85
2 files changed, 42 insertions, 63 deletions
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 {
47 * MessageDisplaySettings().</p> 47 * MessageDisplaySettings().</p>
48 * 48 *
49 * <p>This function also automatically splits your message up into blocks that 49 * <p>This function also automatically splits your message up into blocks that
50 * will fit onthe screen (breaks at spaces). If there are too many words, 50 * will fit on the screen (breaks at spaces). If there are too many words,
51 * they will be held and displayed in the message area after the prior 51 * they will be held and displayed in the message area after the prior
52 * message has been read.</p> 52 * message has been read.</p>
53 * 53 *
54 * <p>Message Escapes can be used to preform specific actions during text
55 * display. For instance, <code>\C[number]</code> changes the text color to
56 * the color on the System Graphic represented by "number".</p>
57 *
54 * @param message The message to display 58 * @param message The message to display
55 * @throws InterruptedException 59 * @throws InterruptedException
56 */ 60 */
57 public void DisplayMessage(String message) throws InterruptedException 61 public void DisplayMessage(String message) throws InterruptedException
58 { 62 {
63 MessageWindow mw;
64
59 if (faceSet.equals("")) 65 if (faceSet.equals(""))
60 { 66 {
61 MessageWindow.displayMessage(message); 67 mw = new MessageWindow(message);
62 } else { 68 } else {
63 MessageWindow.displayMessage(message, faceSet, face); 69 mw = new MessageWindow(message, faceSet, face);
64 } 70 }
71
72 Display.registerRenderable(mw);
73 KeyboardInput.registerInputable(mw);
74
75 mw.waitForCompletion();
76
77 Display.unregisterRenderable(mw);
78 KeyboardInput.unregisterInputable(mw);
65 } 79 }
66 80
67 /** 81 /**
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;
7 7
8import com.fourisland.fourpuzzle.Display; 8import com.fourisland.fourpuzzle.Display;
9import com.fourisland.fourpuzzle.Game; 9import com.fourisland.fourpuzzle.Game;
10import com.fourisland.fourpuzzle.KeyboardInput;
11import com.fourisland.fourpuzzle.KeyInput; 10import com.fourisland.fourpuzzle.KeyInput;
12import com.fourisland.fourpuzzle.gamestate.mapview.FaceSet; 11import com.fourisland.fourpuzzle.gamestate.mapview.FaceSet;
13import com.fourisland.fourpuzzle.util.Inputable; 12import com.fourisland.fourpuzzle.util.Inputable;
@@ -21,7 +20,7 @@ import java.util.concurrent.CountDownLatch;
21 * 20 *
22 * @author hatkirby 21 * @author hatkirby
23 */ 22 */
24public class MessageWindow implements Renderable { 23public class MessageWindow implements Renderable, Inputable {
25 24
26 private static final int SPACER = 4; 25 private static final int SPACER = 4;
27 private static final int HEIGHT = (4*(Display.getFontMetrics().getHeight()+SPACER)); 26 private static final int HEIGHT = (4*(Display.getFontMetrics().getHeight()+SPACER));
@@ -32,7 +31,7 @@ public class MessageWindow implements Renderable {
32 int upTo = 0; 31 int upTo = 0;
33 boolean bounceArrow = false; 32 boolean bounceArrow = false;
34 Interval in = Interval.createTickInterval(4); 33 Interval in = Interval.createTickInterval(4);
35 private MessageWindow(String message) 34 public MessageWindow(String message)
36 { 35 {
37 width = Game.WIDTH - Window.Default.getFullWidth(0); 36 width = Game.WIDTH - Window.Default.getFullWidth(0);
38 cacheBase = Window.Default.getImage(width, HEIGHT); 37 cacheBase = Window.Default.getImage(width, HEIGHT);
@@ -44,7 +43,7 @@ public class MessageWindow implements Renderable {
44 43
45 boolean hasFace = false; 44 boolean hasFace = false;
46 BufferedImage face; 45 BufferedImage face;
47 private MessageWindow(String message, String faceSet, int face) 46 public MessageWindow(String message, String faceSet, int face)
48 { 47 {
49 width = Game.WIDTH - Window.Default.getFullWidth(0); 48 width = Game.WIDTH - Window.Default.getFullWidth(0);
50 cacheBase = Window.Default.getImage(width, HEIGHT); 49 cacheBase = Window.Default.getImage(width, HEIGHT);
@@ -58,49 +57,6 @@ public class MessageWindow implements Renderable {
58 tr.initalizeText(message); 57 tr.initalizeText(message);
59 } 58 }
60 59
61 private static void displayMessage(final MessageWindow mw) throws InterruptedException
62 {
63 final CountDownLatch cdl = new CountDownLatch(1);
64 Inputable in = new Inputable() {
65 public void processInput(KeyInput key)
66 {
67 if (key.isActionDown())
68 {
69 if (mw.pushEnter())
70 {
71 cdl.countDown();
72 }
73
74 key.letGo();
75 }
76 }
77 };
78
79 Display.registerRenderable(mw);
80 KeyboardInput.registerInputable(in);
81
82 try
83 {
84 cdl.await();
85 } catch (InterruptedException ex)
86 {
87 throw ex;
88 } finally {
89 Display.unregisterRenderable(mw);
90 KeyboardInput.unregisterInputable(in);
91 }
92 }
93
94 public static void displayMessage(String message) throws InterruptedException
95 {
96 displayMessage(new MessageWindow(message));
97 }
98
99 public static void displayMessage(String message, String faceSet, int face) throws InterruptedException
100 {
101 displayMessage(new MessageWindow(message, faceSet, face));
102 }
103
104 public void render(Graphics2D g2) 60 public void render(Graphics2D g2)
105 { 61 {
106 int y = MessageWindowLocation.Bottom.getY(); 62 int y = MessageWindowLocation.Bottom.getY();
@@ -128,26 +84,35 @@ public class MessageWindow implements Renderable {
128 } 84 }
129 } 85 }
130 86
131 private synchronized boolean pushEnter() 87 CountDownLatch cdl = new CountDownLatch(1);
88 public void waitForCompletion() throws InterruptedException
132 { 89 {
133 if (tr.isCascadingDone()) 90 cdl.await();
91 }
92
93 public void processInput(KeyInput key)
94 {
95 if (key.isActionDown())
134 { 96 {
135 int msgs = tr.numLines(); 97 if (tr.isCascadingDone())
136 if (upTo >= (msgs-4))
137 { 98 {
138 return true; 99 int msgs = tr.numLines();
139 } else { 100 if (upTo >= (msgs-4))
140 upTo += 4;
141
142 if (upTo > msgs)
143 { 101 {
144 upTo = msgs; 102 cdl.countDown();
103 } else {
104 upTo += 4;
105
106 if (upTo > msgs)
107 {
108 upTo = msgs;
109 }
145 } 110 }
146 } 111 }
112
113 key.letGo();
147 } 114 }
148 115 }
149 return false;
150 }
151 116
152 public static enum MessageWindowLocation 117 public static enum MessageWindowLocation
153 { 118 {