From 165d7e5591b44dce6bf1e090d51e85c4ad5ad2f3 Mon Sep 17 00:00:00 2001 From: Starla Insigna Date: Sat, 14 Feb 2009 08:55:12 -0500 Subject: Engine: Added basic FaceSet support Refs #5 --- .../fourpuzzle/gamestate/mapview/FaceSet.java | 38 ++++++++++++++++ .../gamestate/mapview/event/SpecialEvent.java | 16 +++++-- .../fourpuzzle/window/MessageWindow.java | 53 +++++++++++++++++++--- 3 files changed, 97 insertions(+), 10 deletions(-) create mode 100644 src/com/fourisland/fourpuzzle/gamestate/mapview/FaceSet.java (limited to 'src/com') 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 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package com.fourisland.fourpuzzle.gamestate.mapview; + +import com.fourisland.fourpuzzle.util.ObjectLoader; +import java.awt.image.BufferedImage; + +/** + * + * @author hatkirby + */ +public class FaceSet { + + private BufferedImage faceSetImage; + + private FaceSet() + { + } + + public BufferedImage getImage(int offset) + { + int sx = (offset % 4) * 48; + int sy = (offset / 4) * 48; + + return faceSetImage.getSubimage(sx, sy, 48, 48); + } + + public static FaceSet getFaceSet(String faceSet) + { + FaceSet temp = new FaceSet(); + temp.faceSetImage = ObjectLoader.getImage("FaceSet", faceSet); + return temp; + } + +} 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 { { SpecialEvent.mapView = mapView; } + + private String faceSet = ""; + private int face = 0; /** * Display a message on the screen. @@ -51,7 +54,12 @@ public class SpecialEvent { */ public void DisplayMessage(String message) throws InterruptedException { - MessageWindow.displayMessage(message); + if (faceSet.equals("")) + { + MessageWindow.displayMessage(message); + } else { + MessageWindow.displayMessage(message, faceSet, face); + } } /** @@ -66,7 +74,8 @@ public class SpecialEvent { */ public void SetFace(String faceSet, int face) { - throw new UnsupportedOperationException("Not yet implemented"); + this.faceSet = faceSet; + this.face = face; } /** @@ -76,7 +85,8 @@ public class SpecialEvent { */ public void EraseFace() { - throw new UnsupportedOperationException("Not yet implemented"); + faceSet = ""; + face = 0; } /** 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; import com.fourisland.fourpuzzle.Display; import com.fourisland.fourpuzzle.Game; import com.fourisland.fourpuzzle.PuzzleApplication; +import com.fourisland.fourpuzzle.gamestate.mapview.FaceSet; import com.fourisland.fourpuzzle.util.Interval; import com.fourisland.fourpuzzle.util.Renderable; import java.awt.Graphics2D; @@ -29,6 +30,7 @@ public class MessageWindow implements Renderable { private static final int SPACER = 4; private static final int HEIGHT = 4*(Display.createCanvas(1, 1).createGraphics().getFontMetrics().getHeight()+SPACER); + String message; private volatile List messages; int width; BufferedImage cacheBase; @@ -38,17 +40,24 @@ public class MessageWindow implements Renderable { Interval in = Interval.createTickInterval(4); private MessageWindow(String message) { + this.message = message; width = Game.WIDTH - Window.Default.getFullWidth(0); - messages = new ArrayList(); - - initalizeMessages(message, Display.createCanvas(1, 1).createGraphics()); - + cacheBase = Window.Default.getImage(width, HEIGHT); } - public static void displayMessage(String message) throws InterruptedException + boolean hasFace = false; + BufferedImage face; + private MessageWindow(String message, String faceSet, int face) + { + this(message); + + this.face = FaceSet.getFaceSet(faceSet).getImage(face); + hasFace = true; + } + + private static void displayMessage(final MessageWindow mw) throws InterruptedException { - final MessageWindow mw = new MessageWindow(message); final CountDownLatch cdl = new CountDownLatch(1); Display.registerRenderable(mw); @@ -76,15 +85,33 @@ public class MessageWindow implements Renderable { Display.unregisterRenderable(mw); } + 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)); + } + private void initalizeMessages(String message, Graphics2D g) { + messages = new ArrayList(); + Display.setFont(g); + int length = width - SPACER; + if (hasFace) + { + length -= (48 + (SPACER*2)); + } + String temp = message; int len = 0; while (!temp.isEmpty()) { - while ((g.getFontMetrics().stringWidth(temp.substring(0, len)) < (width - SPACER)) && (len < temp.length())) + while ((g.getFontMetrics().stringWidth(temp.substring(0, len)) < length) && (len < temp.length())) { len++; } @@ -124,6 +151,11 @@ public class MessageWindow implements Renderable { public void render(Graphics2D g2) { + if (messages == null) + { + initalizeMessages(message, g2); + } + int y = MessageWindowLocation.Bottom.getY(); Display.setFont(g2); @@ -140,6 +172,13 @@ public class MessageWindow implements Renderable { int fw = g2.getFontMetrics().stringWidth(message); int tx = Window.Default.getLeftX(); + if (hasFace) + { + g2.drawImage(face, tx, y + ((HEIGHT/2)-24), null); + + tx += 48 + SPACER; + } + g2.setPaint(new TexturePaint(SystemGraphic.getTextColor(), new Rectangle(tx, ty, fw, fh))); g2.drawString(message.substring(0, Math.min(toPrint, message.length())), tx, ty); -- cgit 1.4.1