diff options
Diffstat (limited to 'src/com/fourisland')
4 files changed, 153 insertions, 2 deletions
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java index 3acfff4..9924c9e 100755 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java | |||
@@ -22,6 +22,7 @@ import com.fourisland.fourpuzzle.gamestate.mapview.viewpoint.AutomaticViewpoint; | |||
22 | import com.fourisland.fourpuzzle.gamestate.mapview.viewpoint.Viewpoint; | 22 | import com.fourisland.fourpuzzle.gamestate.mapview.viewpoint.Viewpoint; |
23 | import com.fourisland.fourpuzzle.util.Functions; | 23 | import com.fourisland.fourpuzzle.util.Functions; |
24 | import com.fourisland.fourpuzzle.util.ResourceNotFoundException; | 24 | import com.fourisland.fourpuzzle.util.ResourceNotFoundException; |
25 | import com.fourisland.fourpuzzle.window.MessageWindow; | ||
25 | import java.awt.Graphics2D; | 26 | import java.awt.Graphics2D; |
26 | import java.awt.event.KeyEvent; | 27 | import java.awt.event.KeyEvent; |
27 | import java.awt.image.BufferedImage; | 28 | import java.awt.image.BufferedImage; |
@@ -230,6 +231,11 @@ public class MapViewGameState implements GameState { | |||
230 | 231 | ||
231 | g.drawImage(eventLayer, 0, 0, Game.WIDTH, Game.HEIGHT, x, y, x+Game.WIDTH, y+Game.HEIGHT, null); | 232 | g.drawImage(eventLayer, 0, 0, Game.WIDTH, Game.HEIGHT, x, y, x+Game.WIDTH, y+Game.HEIGHT, null); |
232 | g.drawImage(currentMap.renderUpper(), 0, 0, Game.WIDTH, Game.HEIGHT, x, y, x+Game.WIDTH, y+Game.HEIGHT, null); | 233 | g.drawImage(currentMap.renderUpper(), 0, 0, Game.WIDTH, Game.HEIGHT, x, y, x+Game.WIDTH, y+Game.HEIGHT, null); |
234 | |||
235 | if (mw != null) | ||
236 | { | ||
237 | mw.render(g); | ||
238 | } | ||
233 | } | 239 | } |
234 | 240 | ||
235 | public void initCurrentMap(String mapName) | 241 | public void initCurrentMap(String mapName) |
@@ -268,5 +274,11 @@ public class MapViewGameState implements GameState { | |||
268 | { | 274 | { |
269 | currentViewpoint = viewpoint; | 275 | currentViewpoint = viewpoint; |
270 | } | 276 | } |
277 | |||
278 | volatile MessageWindow mw = null; | ||
279 | public void displayMessage(String message) | ||
280 | { | ||
281 | mw = new MessageWindow(message); | ||
282 | } | ||
271 | 283 | ||
272 | } | 284 | } |
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java index c48b312..5bd312a 100755 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java | |||
@@ -51,7 +51,7 @@ public class SpecialEvent { | |||
51 | */ | 51 | */ |
52 | public void DisplayMessage(String message) | 52 | public void DisplayMessage(String message) |
53 | { | 53 | { |
54 | throw new UnsupportedOperationException("Not yet implemented"); | 54 | mapView.displayMessage(message); |
55 | } | 55 | } |
56 | 56 | ||
57 | /** | 57 | /** |
diff --git a/src/com/fourisland/fourpuzzle/window/ChoiceWindow.java b/src/com/fourisland/fourpuzzle/window/ChoiceWindow.java index 19d53ac..e466e63 100755 --- a/src/com/fourisland/fourpuzzle/window/ChoiceWindow.java +++ b/src/com/fourisland/fourpuzzle/window/ChoiceWindow.java | |||
@@ -19,7 +19,7 @@ import java.util.List; | |||
19 | */ | 19 | */ |
20 | public class ChoiceWindow { | 20 | public class ChoiceWindow { |
21 | 21 | ||
22 | private final int SPACER = 4; | 22 | private static final int SPACER = 4; |
23 | 23 | ||
24 | private List<String> choices; | 24 | private List<String> choices; |
25 | int numChoices; | 25 | int numChoices; |
diff --git a/src/com/fourisland/fourpuzzle/window/MessageWindow.java b/src/com/fourisland/fourpuzzle/window/MessageWindow.java new file mode 100644 index 0000000..9e482ba --- /dev/null +++ b/src/com/fourisland/fourpuzzle/window/MessageWindow.java | |||
@@ -0,0 +1,139 @@ | |||
1 | /* | ||
2 | * To change this template, choose Tools | Templates | ||
3 | * and open the template in the editor. | ||
4 | */ | ||
5 | |||
6 | package com.fourisland.fourpuzzle.window; | ||
7 | |||
8 | import com.fourisland.fourpuzzle.Game; | ||
9 | import java.awt.Font; | ||
10 | import java.awt.FontFormatException; | ||
11 | import java.awt.Graphics2D; | ||
12 | import java.awt.Rectangle; | ||
13 | import java.awt.TexturePaint; | ||
14 | import java.awt.image.BufferedImage; | ||
15 | import java.io.File; | ||
16 | import java.io.IOException; | ||
17 | import java.util.ArrayList; | ||
18 | import java.util.List; | ||
19 | import java.util.logging.Level; | ||
20 | import java.util.logging.Logger; | ||
21 | |||
22 | /** | ||
23 | * | ||
24 | * @author hatkirby | ||
25 | */ | ||
26 | public class MessageWindow { | ||
27 | |||
28 | private static final int SPACER = 4; | ||
29 | private static final int HEIGHT = 4*(new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB).createGraphics().getFontMetrics().getHeight()+SPACER); | ||
30 | |||
31 | private List<String> messages; | ||
32 | int width; | ||
33 | BufferedImage cacheBase; | ||
34 | public MessageWindow(String message) | ||
35 | { | ||
36 | width = Game.WIDTH - Window.Default.getFullWidth(0); | ||
37 | messages = new ArrayList<String>(); | ||
38 | |||
39 | initalizeMessages(message, new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB).createGraphics()); | ||
40 | |||
41 | cacheBase = new BufferedImage(Game.WIDTH, Window.Default.getFullHeight(HEIGHT), BufferedImage.TYPE_INT_ARGB); | ||
42 | Graphics2D g2 = cacheBase.createGraphics(); | ||
43 | |||
44 | g2.drawImage(SystemGraphic.getMessageBackground(), 1, 1, Game.WIDTH-2, Window.Default.getFullHeight(HEIGHT)-2, null); | ||
45 | g2.drawImage(Window.Default.getImage(width, HEIGHT), 0, 0, null); | ||
46 | } | ||
47 | |||
48 | private void initalizeMessages(String message, Graphics2D g) | ||
49 | { | ||
50 | setFont(g); | ||
51 | |||
52 | String temp = message; | ||
53 | int len = 0; | ||
54 | while (!temp.isEmpty()) | ||
55 | { | ||
56 | while ((g.getFontMetrics().stringWidth(temp.substring(0, len)) < (width - SPACER)) && (len < temp.length())) | ||
57 | { | ||
58 | len++; | ||
59 | } | ||
60 | |||
61 | if (len != temp.length()) | ||
62 | { | ||
63 | while ((!temp.substring(len, len+1).equals(" ")) && (len > 0)) | ||
64 | { | ||
65 | len--; | ||
66 | } | ||
67 | } | ||
68 | |||
69 | messages.add(temp.substring(0, len)); | ||
70 | |||
71 | if (len != temp.length()) | ||
72 | { | ||
73 | temp = temp.substring(len+1); | ||
74 | } else { | ||
75 | temp = ""; | ||
76 | } | ||
77 | |||
78 | len = 0; | ||
79 | } | ||
80 | } | ||
81 | |||
82 | public void render(Graphics2D g2) | ||
83 | { | ||
84 | int y = MessageWindowLocation.Bottom.getY(); | ||
85 | |||
86 | g2.drawImage(cacheBase, 0, y, null); | ||
87 | |||
88 | setFont(g2); | ||
89 | |||
90 | int fh = g2.getFontMetrics().getHeight(); | ||
91 | int ty = Window.Default.getTopY()+fh-(SPACER/2)+y; | ||
92 | int msgs = Math.min(messages.size(), 4); | ||
93 | for (int i=0;i<msgs;i++) | ||
94 | { | ||
95 | String message = messages.get(i); | ||
96 | int fw = g2.getFontMetrics().stringWidth(message); | ||
97 | int tx = Window.Default.getLeftX(); | ||
98 | |||
99 | g2.setPaint(new TexturePaint(SystemGraphic.getTextColor(), new Rectangle(tx, ty, fw, fh))); | ||
100 | g2.drawString(message, tx, ty); | ||
101 | |||
102 | ty+=(SPACER+g2.getFontMetrics().getHeight()); | ||
103 | } | ||
104 | |||
105 | g2.setFont(g2.getFont().deriveFont(Font.PLAIN)); | ||
106 | } | ||
107 | |||
108 | public static enum MessageWindowLocation | ||
109 | { | ||
110 | Top(0), | ||
111 | Middle((Game.HEIGHT/2)-(Window.Default.getFullHeight(MessageWindow.HEIGHT)/2)), | ||
112 | Bottom(Game.HEIGHT-Window.Default.getFullHeight(MessageWindow.HEIGHT)); | ||
113 | |||
114 | private int y; | ||
115 | private MessageWindowLocation(int y) | ||
116 | { | ||
117 | this.y = y; | ||
118 | } | ||
119 | |||
120 | public int getY() | ||
121 | { | ||
122 | return y; | ||
123 | } | ||
124 | } | ||
125 | |||
126 | public static void setFont(Graphics2D g) | ||
127 | { | ||
128 | try { | ||
129 | g.setFont(Font.createFont(Font.TRUETYPE_FONT, new File("/usr/share/fonts/truetype/ttf-dejavu/DejaVuSansMono.ttf"))); | ||
130 | } catch (FontFormatException ex) { | ||
131 | Logger.getLogger(MessageWindow.class.getName()).log(Level.SEVERE, null, ex); | ||
132 | } catch (IOException ex) { | ||
133 | Logger.getLogger(MessageWindow.class.getName()).log(Level.SEVERE, null, ex); | ||
134 | } | ||
135 | |||
136 | g.setFont(g.getFont().deriveFont(Font.PLAIN, 10)); | ||
137 | } | ||
138 | |||
139 | } | ||