From 8e0383a3674f4d9c57b3a1b5667750a3e963a7bd Mon Sep 17 00:00:00 2001 From: Starla Insigna Date: Fri, 6 Mar 2009 09:36:26 -0500 Subject: Engine: Added configuration to ChoiceWindow Added ability to force a specific width for MenuEMS so menu looks pREETY OMG IM HYPER Refs #15 --- .../fourpuzzle/gamestate/TitleScreenGameState.java | 6 +- .../fourpuzzle/gamestate/menu/MenuEMS.java | 7 +- .../fourisland/fourpuzzle/window/ChoiceWindow.java | 99 +++++++++++++++++++--- .../fourpuzzle/window/InputableChoiceWindow.java | 61 ------------- 4 files changed, 98 insertions(+), 75 deletions(-) delete mode 100644 src/com/fourisland/fourpuzzle/window/InputableChoiceWindow.java (limited to 'src') diff --git a/src/com/fourisland/fourpuzzle/gamestate/TitleScreenGameState.java b/src/com/fourisland/fourpuzzle/gamestate/TitleScreenGameState.java index 6f12d02..db6225e 100755 --- a/src/com/fourisland/fourpuzzle/gamestate/TitleScreenGameState.java +++ b/src/com/fourisland/fourpuzzle/gamestate/TitleScreenGameState.java @@ -32,8 +32,11 @@ public class TitleScreenGameState implements GameState { { Audio.playMusic(Database.getMusic(Music.Title)); - choices = new ChoiceWindow(Arrays.asList(Database.getVocab(Vocabulary.NewGame), Database.getVocab(Vocabulary.LoadGame), Database.getVocab(Vocabulary.EndGame)), true, ChoiceWindow.ChoiceWindowLocation.BottomLeft); + choices = new ChoiceWindow.Builder(Arrays.asList(Database.getVocab(Vocabulary.NewGame), Database.getVocab(Vocabulary.LoadGame), Database.getVocab(Vocabulary.EndGame)), ChoiceWindow.ChoiceWindowLocation.BottomLeft) + .center(true) + .build(); Display.registerRenderable(choices); + KeyboardInput.registerInputable(choices); } public void deinitalize() @@ -41,6 +44,7 @@ public class TitleScreenGameState implements GameState { Audio.stopMusic(); Display.unregisterRenderable(choices); + KeyboardInput.unregisterInputable(choices); } PauseTimer pt = new PauseTimer(0); diff --git a/src/com/fourisland/fourpuzzle/gamestate/menu/MenuEMS.java b/src/com/fourisland/fourpuzzle/gamestate/menu/MenuEMS.java index 4fad509..b6fcd3b 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/menu/MenuEMS.java +++ b/src/com/fourisland/fourpuzzle/gamestate/menu/MenuEMS.java @@ -14,7 +14,6 @@ import com.fourisland.fourpuzzle.database.Transitions; import com.fourisland.fourpuzzle.database.Vocabulary; import com.fourisland.fourpuzzle.gamestate.TitleScreenGameState; import com.fourisland.fourpuzzle.window.ChoiceWindow; -import com.fourisland.fourpuzzle.window.InputableChoiceWindow; import java.awt.Color; import java.awt.Graphics2D; import java.awt.event.KeyEvent; @@ -27,12 +26,14 @@ import java.util.Arrays; public class MenuEMS implements EscapeMenuState { MenuGameState parent; - InputableChoiceWindow cw; + ChoiceWindow cw; public void initalize(MenuGameState mgs) { parent = mgs; - cw = new InputableChoiceWindow(Arrays.asList(Database.getVocab(Vocabulary.EscapeMenuItems), Database.getVocab(Vocabulary.EscapeMenuEquipment), Database.getVocab(Vocabulary.EscapeMenuMagic), Database.getVocab(Vocabulary.EscapeMenuSave), Database.getVocab(Vocabulary.EscapeMenuQuit)), false, ChoiceWindow.ChoiceWindowLocation.AbsoluteTopLeft); + cw = new ChoiceWindow.Builder(Arrays.asList(Database.getVocab(Vocabulary.EscapeMenuItems), Database.getVocab(Vocabulary.EscapeMenuEquipment), Database.getVocab(Vocabulary.EscapeMenuMagic), Database.getVocab(Vocabulary.EscapeMenuSave), Database.getVocab(Vocabulary.EscapeMenuQuit)), ChoiceWindow.ChoiceWindowLocation.AbsoluteTopLeft) + .width(Game.WIDTH/5) + .build(); Display.registerRenderable(cw); KeyboardInput.registerInputable(cw); } diff --git a/src/com/fourisland/fourpuzzle/window/ChoiceWindow.java b/src/com/fourisland/fourpuzzle/window/ChoiceWindow.java index 90f2d96..8dce753 100755 --- a/src/com/fourisland/fourpuzzle/window/ChoiceWindow.java +++ b/src/com/fourisland/fourpuzzle/window/ChoiceWindow.java @@ -8,12 +8,16 @@ package com.fourisland.fourpuzzle.window; import com.fourisland.fourpuzzle.Audio; import com.fourisland.fourpuzzle.Display; import com.fourisland.fourpuzzle.Game; +import com.fourisland.fourpuzzle.KeyInput; import com.fourisland.fourpuzzle.database.Database; import com.fourisland.fourpuzzle.database.Sound; +import com.fourisland.fourpuzzle.util.Inputable; +import com.fourisland.fourpuzzle.util.PauseTimer; import com.fourisland.fourpuzzle.util.Renderable; import java.awt.Graphics2D; import java.awt.Rectangle; import java.awt.TexturePaint; +import java.awt.event.KeyEvent; import java.awt.image.BufferedImage; import java.util.List; @@ -21,9 +25,40 @@ import java.util.List; * * @author hatkirby */ -public class ChoiceWindow implements Renderable { +public class ChoiceWindow implements Renderable, Inputable { private static final int SPACER = 4; + + public static class Builder + { + List choices; + ChoiceWindowLocation location; + boolean center = false; + int width = 0; + + public Builder(List choices, ChoiceWindowLocation location) + { + this.choices = choices; + this.location = location; + } + + public Builder center(boolean center) + { + this.center = center; + return this; + } + + public Builder width(int width) + { + this.width = width; + return this; + } + + public ChoiceWindow build() + { + return new ChoiceWindow(this); + } + } private List choices; int numChoices; @@ -33,27 +68,36 @@ public class ChoiceWindow implements Renderable { BufferedImage cacheBase; int x; int y; - public ChoiceWindow(List choices, boolean center, ChoiceWindowLocation cwl) + String clickSound; + private ChoiceWindow(Builder builder) { - this.choices = choices; + this.choices = builder.choices; numChoices = choices.size(); - this.center = center; + this.center = builder.center; for (String choice : choices) { - int l = Display.getFontMetrics().stringWidth(choice); - if (l > getWidth()) + if (builder.width == 0) { - width = l; + int l = Display.getFontMetrics().stringWidth(choice); + if (l > getWidth()) + { + width = l; + } } - + height += Display.getFontMetrics().getHeight() + SPACER; } + if (builder.width != 0) + { + width = builder.width; + } + cacheBase = Window.Default.getImage(width, height); - x = cwl.getX(width); - y = cwl.getY(height); + x = builder.location.getX(width); + y = builder.location.getY(height); } public void render(Graphics2D g2) @@ -167,4 +211,39 @@ public class ChoiceWindow implements Renderable { } } + Boolean hasInput = false; + PauseTimer pt = new PauseTimer(0); + public void processInput(KeyInput key) + { + if (key.getKey() == KeyEvent.VK_UP) + { + if (pt.isElapsed()) + { + moveUp(); + pt.setTimer(1); + } + } else if (key.getKey() == KeyEvent.VK_DOWN) + { + if (pt.isElapsed()) + { + moveDown(); + pt.setTimer(1); + } + } else if (key.isActionDown()) + { + synchronized (hasInput) + { + hasInput = true; + } + } + } + + public boolean hasInput() + { + synchronized (hasInput) + { + return hasInput; + } + } + } \ No newline at end of file diff --git a/src/com/fourisland/fourpuzzle/window/InputableChoiceWindow.java b/src/com/fourisland/fourpuzzle/window/InputableChoiceWindow.java deleted file mode 100644 index 02bc737..0000000 --- a/src/com/fourisland/fourpuzzle/window/InputableChoiceWindow.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ - -package com.fourisland.fourpuzzle.window; - -import com.fourisland.fourpuzzle.KeyInput; -import java.util.List; -import com.fourisland.fourpuzzle.util.Inputable; -import com.fourisland.fourpuzzle.util.PauseTimer; -import java.awt.event.KeyEvent; - -/** - * - * @author hatkirby - */ -public class InputableChoiceWindow extends ChoiceWindow implements Inputable { - - Boolean hasInput = false; - PauseTimer pt = new PauseTimer(0); - - public InputableChoiceWindow(List choices, boolean center, ChoiceWindowLocation cwl) - { - super(choices, center, cwl); - } - - public void processInput(KeyInput key) - { - if (key.getKey() == KeyEvent.VK_UP) - { - if (pt.isElapsed()) - { - moveUp(); - pt.setTimer(1); - } - } else if (key.getKey() == KeyEvent.VK_DOWN) - { - if (pt.isElapsed()) - { - moveDown(); - pt.setTimer(1); - } - } else if (key.isActionDown()) - { - synchronized (hasInput) - { - hasInput = true; - } - } - } - - public boolean hasInput() - { - synchronized (hasInput) - { - return hasInput; - } - } - -} -- cgit 1.4.1