diff options
author | Starla Insigna <hatkirby@fourisland.com> | 2009-02-14 08:55:12 -0500 |
---|---|---|
committer | Starla Insigna <hatkirby@fourisland.com> | 2009-02-14 08:55:12 -0500 |
commit | 165d7e5591b44dce6bf1e090d51e85c4ad5ad2f3 (patch) | |
tree | 5321ec45aa5a447afb94a6df7a8dd41eb08d96e6 /src/com/fourisland/fourpuzzle/window/MessageWindow.java | |
parent | 6b69a3558d5a7a5ea364a3054ca3494639a62961 (diff) | |
download | fourpuzzle-165d7e5591b44dce6bf1e090d51e85c4ad5ad2f3.tar.gz fourpuzzle-165d7e5591b44dce6bf1e090d51e85c4ad5ad2f3.tar.bz2 fourpuzzle-165d7e5591b44dce6bf1e090d51e85c4ad5ad2f3.zip |
Engine: Added basic FaceSet support
Refs #5
Diffstat (limited to 'src/com/fourisland/fourpuzzle/window/MessageWindow.java')
-rw-r--r-- | src/com/fourisland/fourpuzzle/window/MessageWindow.java | 53 |
1 files changed, 46 insertions, 7 deletions
diff --git a/src/com/fourisland/fourpuzzle/window/MessageWindow.java b/src/com/fourisland/fourpuzzle/window/MessageWindow.java index fd9918c..7947730 100644 --- a/src/com/fourisland/fourpuzzle/window/MessageWindow.java +++ b/src/com/fourisland/fourpuzzle/window/MessageWindow.java | |||
@@ -8,6 +8,7 @@ package com.fourisland.fourpuzzle.window; | |||
8 | import com.fourisland.fourpuzzle.Display; | 8 | import com.fourisland.fourpuzzle.Display; |
9 | import com.fourisland.fourpuzzle.Game; | 9 | import com.fourisland.fourpuzzle.Game; |
10 | import com.fourisland.fourpuzzle.PuzzleApplication; | 10 | import com.fourisland.fourpuzzle.PuzzleApplication; |
11 | import com.fourisland.fourpuzzle.gamestate.mapview.FaceSet; | ||
11 | import com.fourisland.fourpuzzle.util.Interval; | 12 | import com.fourisland.fourpuzzle.util.Interval; |
12 | import com.fourisland.fourpuzzle.util.Renderable; | 13 | import com.fourisland.fourpuzzle.util.Renderable; |
13 | import java.awt.Graphics2D; | 14 | import java.awt.Graphics2D; |
@@ -29,6 +30,7 @@ public class MessageWindow implements Renderable { | |||
29 | private static final int SPACER = 4; | 30 | private static final int SPACER = 4; |
30 | private static final int HEIGHT = 4*(Display.createCanvas(1, 1).createGraphics().getFontMetrics().getHeight()+SPACER); | 31 | private static final int HEIGHT = 4*(Display.createCanvas(1, 1).createGraphics().getFontMetrics().getHeight()+SPACER); |
31 | 32 | ||
33 | String message; | ||
32 | private volatile List<String> messages; | 34 | private volatile List<String> messages; |
33 | int width; | 35 | int width; |
34 | BufferedImage cacheBase; | 36 | BufferedImage cacheBase; |
@@ -38,17 +40,24 @@ public class MessageWindow implements Renderable { | |||
38 | Interval in = Interval.createTickInterval(4); | 40 | Interval in = Interval.createTickInterval(4); |
39 | private MessageWindow(String message) | 41 | private MessageWindow(String message) |
40 | { | 42 | { |
43 | this.message = message; | ||
41 | width = Game.WIDTH - Window.Default.getFullWidth(0); | 44 | width = Game.WIDTH - Window.Default.getFullWidth(0); |
42 | messages = new ArrayList<String>(); | 45 | |
43 | |||
44 | initalizeMessages(message, Display.createCanvas(1, 1).createGraphics()); | ||
45 | |||
46 | cacheBase = Window.Default.getImage(width, HEIGHT); | 46 | cacheBase = Window.Default.getImage(width, HEIGHT); |
47 | } | 47 | } |
48 | 48 | ||
49 | public static void displayMessage(String message) throws InterruptedException | 49 | boolean hasFace = false; |
50 | BufferedImage face; | ||
51 | private MessageWindow(String message, String faceSet, int face) | ||
52 | { | ||
53 | this(message); | ||
54 | |||
55 | this.face = FaceSet.getFaceSet(faceSet).getImage(face); | ||
56 | hasFace = true; | ||
57 | } | ||
58 | |||
59 | private static void displayMessage(final MessageWindow mw) throws InterruptedException | ||
50 | { | 60 | { |
51 | final MessageWindow mw = new MessageWindow(message); | ||
52 | final CountDownLatch cdl = new CountDownLatch(1); | 61 | final CountDownLatch cdl = new CountDownLatch(1); |
53 | 62 | ||
54 | Display.registerRenderable(mw); | 63 | Display.registerRenderable(mw); |
@@ -76,15 +85,33 @@ public class MessageWindow implements Renderable { | |||
76 | Display.unregisterRenderable(mw); | 85 | Display.unregisterRenderable(mw); |
77 | } | 86 | } |
78 | 87 | ||
88 | public static void displayMessage(String message) throws InterruptedException | ||
89 | { | ||
90 | displayMessage(new MessageWindow(message)); | ||
91 | } | ||
92 | |||
93 | public static void displayMessage(String message, String faceSet, int face) throws InterruptedException | ||
94 | { | ||
95 | displayMessage(new MessageWindow(message, faceSet, face)); | ||
96 | } | ||
97 | |||
79 | private void initalizeMessages(String message, Graphics2D g) | 98 | private void initalizeMessages(String message, Graphics2D g) |
80 | { | 99 | { |
100 | messages = new ArrayList<String>(); | ||
101 | |||
81 | Display.setFont(g); | 102 | Display.setFont(g); |
82 | 103 | ||
104 | int length = width - SPACER; | ||
105 | if (hasFace) | ||
106 | { | ||
107 | length -= (48 + (SPACER*2)); | ||
108 | } | ||
109 | |||
83 | String temp = message; | 110 | String temp = message; |
84 | int len = 0; | 111 | int len = 0; |
85 | while (!temp.isEmpty()) | 112 | while (!temp.isEmpty()) |
86 | { | 113 | { |
87 | while ((g.getFontMetrics().stringWidth(temp.substring(0, len)) < (width - SPACER)) && (len < temp.length())) | 114 | while ((g.getFontMetrics().stringWidth(temp.substring(0, len)) < length) && (len < temp.length())) |
88 | { | 115 | { |
89 | len++; | 116 | len++; |
90 | } | 117 | } |
@@ -124,6 +151,11 @@ public class MessageWindow implements Renderable { | |||
124 | 151 | ||
125 | public void render(Graphics2D g2) | 152 | public void render(Graphics2D g2) |
126 | { | 153 | { |
154 | if (messages == null) | ||
155 | { | ||
156 | initalizeMessages(message, g2); | ||
157 | } | ||
158 | |||
127 | int y = MessageWindowLocation.Bottom.getY(); | 159 | int y = MessageWindowLocation.Bottom.getY(); |
128 | 160 | ||
129 | Display.setFont(g2); | 161 | Display.setFont(g2); |
@@ -140,6 +172,13 @@ public class MessageWindow implements Renderable { | |||
140 | int fw = g2.getFontMetrics().stringWidth(message); | 172 | int fw = g2.getFontMetrics().stringWidth(message); |
141 | int tx = Window.Default.getLeftX(); | 173 | int tx = Window.Default.getLeftX(); |
142 | 174 | ||
175 | if (hasFace) | ||
176 | { | ||
177 | g2.drawImage(face, tx, y + ((HEIGHT/2)-24), null); | ||
178 | |||
179 | tx += 48 + SPACER; | ||
180 | } | ||
181 | |||
143 | g2.setPaint(new TexturePaint(SystemGraphic.getTextColor(), new Rectangle(tx, ty, fw, fh))); | 182 | g2.setPaint(new TexturePaint(SystemGraphic.getTextColor(), new Rectangle(tx, ty, fw, fh))); |
144 | g2.drawString(message.substring(0, Math.min(toPrint, message.length())), tx, ty); | 183 | g2.drawString(message.substring(0, Math.min(toPrint, message.length())), tx, ty); |
145 | 184 | ||