summary refs log tree commit diff stats
path: root/src/com/fourisland
diff options
context:
space:
mode:
authorStarla Insigna <hatkirby@fourisland.com>2009-02-14 08:55:12 -0500
committerStarla Insigna <hatkirby@fourisland.com>2009-02-14 08:55:12 -0500
commit165d7e5591b44dce6bf1e090d51e85c4ad5ad2f3 (patch)
tree5321ec45aa5a447afb94a6df7a8dd41eb08d96e6 /src/com/fourisland
parent6b69a3558d5a7a5ea364a3054ca3494639a62961 (diff)
downloadfourpuzzle-165d7e5591b44dce6bf1e090d51e85c4ad5ad2f3.tar.gz
fourpuzzle-165d7e5591b44dce6bf1e090d51e85c4ad5ad2f3.tar.bz2
fourpuzzle-165d7e5591b44dce6bf1e090d51e85c4ad5ad2f3.zip
Engine: Added basic FaceSet support
Refs #5
Diffstat (limited to 'src/com/fourisland')
-rw-r--r--src/com/fourisland/fourpuzzle/gamestate/mapview/FaceSet.java38
-rwxr-xr-xsrc/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java16
-rw-r--r--src/com/fourisland/fourpuzzle/window/MessageWindow.java53
3 files changed, 97 insertions, 10 deletions
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/FaceSet.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/FaceSet.java new file mode 100644 index 0000000..0a2b2d1 --- /dev/null +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/FaceSet.java
@@ -0,0 +1,38 @@
1/*
2 * To change this template, choose Tools | Templates
3 * and open the template in the editor.
4 */
5
6package com.fourisland.fourpuzzle.gamestate.mapview;
7
8import com.fourisland.fourpuzzle.util.ObjectLoader;
9import java.awt.image.BufferedImage;
10
11/**
12 *
13 * @author hatkirby
14 */
15public class FaceSet {
16
17 private BufferedImage faceSetImage;
18
19 private FaceSet()
20 {
21 }
22
23 public BufferedImage getImage(int offset)
24 {
25 int sx = (offset % 4) * 48;
26 int sy = (offset / 4) * 48;
27
28 return faceSetImage.getSubimage(sx, sy, 48, 48);
29 }
30
31 public static FaceSet getFaceSet(String faceSet)
32 {
33 FaceSet temp = new FaceSet();
34 temp.faceSetImage = ObjectLoader.getImage("FaceSet", faceSet);
35 return temp;
36 }
37
38}
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java index 40e1536..94d2b16 100755 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java
@@ -31,6 +31,9 @@ public class SpecialEvent {
31 { 31 {
32 SpecialEvent.mapView = mapView; 32 SpecialEvent.mapView = mapView;
33 } 33 }
34
35 private String faceSet = "";
36 private int face = 0;
34 37
35 /** 38 /**
36 * Display a message on the screen. 39 * Display a message on the screen.
@@ -51,7 +54,12 @@ public class SpecialEvent {
51 */ 54 */
52 public void DisplayMessage(String message) throws InterruptedException 55 public void DisplayMessage(String message) throws InterruptedException
53 { 56 {
54 MessageWindow.displayMessage(message); 57 if (faceSet.equals(""))
58 {
59 MessageWindow.displayMessage(message);
60 } else {
61 MessageWindow.displayMessage(message, faceSet, face);
62 }
55 } 63 }
56 64
57 /** 65 /**
@@ -66,7 +74,8 @@ public class SpecialEvent {
66 */ 74 */
67 public void SetFace(String faceSet, int face) 75 public void SetFace(String faceSet, int face)
68 { 76 {
69 throw new UnsupportedOperationException("Not yet implemented"); 77 this.faceSet = faceSet;
78 this.face = face;
70 } 79 }
71 80
72 /** 81 /**
@@ -76,7 +85,8 @@ public class SpecialEvent {
76 */ 85 */
77 public void EraseFace() 86 public void EraseFace()
78 { 87 {
79 throw new UnsupportedOperationException("Not yet implemented"); 88 faceSet = "";
89 face = 0;
80 } 90 }
81 91
82 /** 92 /**
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;
8import com.fourisland.fourpuzzle.Display; 8import com.fourisland.fourpuzzle.Display;
9import com.fourisland.fourpuzzle.Game; 9import com.fourisland.fourpuzzle.Game;
10import com.fourisland.fourpuzzle.PuzzleApplication; 10import com.fourisland.fourpuzzle.PuzzleApplication;
11import com.fourisland.fourpuzzle.gamestate.mapview.FaceSet;
11import com.fourisland.fourpuzzle.util.Interval; 12import com.fourisland.fourpuzzle.util.Interval;
12import com.fourisland.fourpuzzle.util.Renderable; 13import com.fourisland.fourpuzzle.util.Renderable;
13import java.awt.Graphics2D; 14import 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