summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rwxr-xr-xsrc/com/fourisland/fourpuzzle/gamestate/TitleScreenGameState.java6
-rw-r--r--src/com/fourisland/fourpuzzle/gamestate/menu/MenuEMS.java7
-rwxr-xr-xsrc/com/fourisland/fourpuzzle/window/ChoiceWindow.java99
-rw-r--r--src/com/fourisland/fourpuzzle/window/InputableChoiceWindow.java61
4 files changed, 98 insertions, 75 deletions
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 {
32 { 32 {
33 Audio.playMusic(Database.getMusic(Music.Title)); 33 Audio.playMusic(Database.getMusic(Music.Title));
34 34
35 choices = new ChoiceWindow(Arrays.asList(Database.getVocab(Vocabulary.NewGame), Database.getVocab(Vocabulary.LoadGame), Database.getVocab(Vocabulary.EndGame)), true, ChoiceWindow.ChoiceWindowLocation.BottomLeft); 35 choices = new ChoiceWindow.Builder(Arrays.asList(Database.getVocab(Vocabulary.NewGame), Database.getVocab(Vocabulary.LoadGame), Database.getVocab(Vocabulary.EndGame)), ChoiceWindow.ChoiceWindowLocation.BottomLeft)
36 .center(true)
37 .build();
36 Display.registerRenderable(choices); 38 Display.registerRenderable(choices);
39 KeyboardInput.registerInputable(choices);
37 } 40 }
38 41
39 public void deinitalize() 42 public void deinitalize()
@@ -41,6 +44,7 @@ public class TitleScreenGameState implements GameState {
41 Audio.stopMusic(); 44 Audio.stopMusic();
42 45
43 Display.unregisterRenderable(choices); 46 Display.unregisterRenderable(choices);
47 KeyboardInput.unregisterInputable(choices);
44 } 48 }
45 49
46 PauseTimer pt = new PauseTimer(0); 50 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;
14import com.fourisland.fourpuzzle.database.Vocabulary; 14import com.fourisland.fourpuzzle.database.Vocabulary;
15import com.fourisland.fourpuzzle.gamestate.TitleScreenGameState; 15import com.fourisland.fourpuzzle.gamestate.TitleScreenGameState;
16import com.fourisland.fourpuzzle.window.ChoiceWindow; 16import com.fourisland.fourpuzzle.window.ChoiceWindow;
17import com.fourisland.fourpuzzle.window.InputableChoiceWindow;
18import java.awt.Color; 17import java.awt.Color;
19import java.awt.Graphics2D; 18import java.awt.Graphics2D;
20import java.awt.event.KeyEvent; 19import java.awt.event.KeyEvent;
@@ -27,12 +26,14 @@ import java.util.Arrays;
27public class MenuEMS implements EscapeMenuState { 26public class MenuEMS implements EscapeMenuState {
28 27
29 MenuGameState parent; 28 MenuGameState parent;
30 InputableChoiceWindow cw; 29 ChoiceWindow cw;
31 30
32 public void initalize(MenuGameState mgs) 31 public void initalize(MenuGameState mgs)
33 { 32 {
34 parent = mgs; 33 parent = mgs;
35 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); 34 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)
35 .width(Game.WIDTH/5)
36 .build();
36 Display.registerRenderable(cw); 37 Display.registerRenderable(cw);
37 KeyboardInput.registerInputable(cw); 38 KeyboardInput.registerInputable(cw);
38 } 39 }
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;
8import com.fourisland.fourpuzzle.Audio; 8import com.fourisland.fourpuzzle.Audio;
9import com.fourisland.fourpuzzle.Display; 9import com.fourisland.fourpuzzle.Display;
10import com.fourisland.fourpuzzle.Game; 10import com.fourisland.fourpuzzle.Game;
11import com.fourisland.fourpuzzle.KeyInput;
11import com.fourisland.fourpuzzle.database.Database; 12import com.fourisland.fourpuzzle.database.Database;
12import com.fourisland.fourpuzzle.database.Sound; 13import com.fourisland.fourpuzzle.database.Sound;
14import com.fourisland.fourpuzzle.util.Inputable;
15import com.fourisland.fourpuzzle.util.PauseTimer;
13import com.fourisland.fourpuzzle.util.Renderable; 16import com.fourisland.fourpuzzle.util.Renderable;
14import java.awt.Graphics2D; 17import java.awt.Graphics2D;
15import java.awt.Rectangle; 18import java.awt.Rectangle;
16import java.awt.TexturePaint; 19import java.awt.TexturePaint;
20import java.awt.event.KeyEvent;
17import java.awt.image.BufferedImage; 21import java.awt.image.BufferedImage;
18import java.util.List; 22import java.util.List;
19 23
@@ -21,9 +25,40 @@ import java.util.List;
21 * 25 *
22 * @author hatkirby 26 * @author hatkirby
23 */ 27 */
24public class ChoiceWindow implements Renderable { 28public class ChoiceWindow implements Renderable, Inputable {
25 29
26 private static final int SPACER = 4; 30 private static final int SPACER = 4;
31
32 public static class Builder
33 {
34 List<String> choices;
35 ChoiceWindowLocation location;
36 boolean center = false;
37 int width = 0;
38
39 public Builder(List<String> choices, ChoiceWindowLocation location)
40 {
41 this.choices = choices;
42 this.location = location;
43 }
44
45 public Builder center(boolean center)
46 {
47 this.center = center;
48 return this;
49 }
50
51 public Builder width(int width)
52 {
53 this.width = width;
54 return this;
55 }
56
57 public ChoiceWindow build()
58 {
59 return new ChoiceWindow(this);
60 }
61 }
27 62
28 private List<String> choices; 63 private List<String> choices;
29 int numChoices; 64 int numChoices;
@@ -33,27 +68,36 @@ public class ChoiceWindow implements Renderable {
33 BufferedImage cacheBase; 68 BufferedImage cacheBase;
34 int x; 69 int x;
35 int y; 70 int y;
36 public ChoiceWindow(List<String> choices, boolean center, ChoiceWindowLocation cwl) 71 String clickSound;
72 private ChoiceWindow(Builder builder)
37 { 73 {
38 this.choices = choices; 74 this.choices = builder.choices;
39 numChoices = choices.size(); 75 numChoices = choices.size();
40 this.center = center; 76 this.center = builder.center;
41 77
42 for (String choice : choices) 78 for (String choice : choices)
43 { 79 {
44 int l = Display.getFontMetrics().stringWidth(choice); 80 if (builder.width == 0)
45 if (l > getWidth())
46 { 81 {
47 width = l; 82 int l = Display.getFontMetrics().stringWidth(choice);
83 if (l > getWidth())
84 {
85 width = l;
86 }
48 } 87 }
49 88
50 height += Display.getFontMetrics().getHeight() + SPACER; 89 height += Display.getFontMetrics().getHeight() + SPACER;
51 } 90 }
52 91
92 if (builder.width != 0)
93 {
94 width = builder.width;
95 }
96
53 cacheBase = Window.Default.getImage(width, height); 97 cacheBase = Window.Default.getImage(width, height);
54 98
55 x = cwl.getX(width); 99 x = builder.location.getX(width);
56 y = cwl.getY(height); 100 y = builder.location.getY(height);
57 } 101 }
58 102
59 public void render(Graphics2D g2) 103 public void render(Graphics2D g2)
@@ -167,4 +211,39 @@ public class ChoiceWindow implements Renderable {
167 } 211 }
168 } 212 }
169 213
214 Boolean hasInput = false;
215 PauseTimer pt = new PauseTimer(0);
216 public void processInput(KeyInput key)
217 {
218 if (key.getKey() == KeyEvent.VK_UP)
219 {
220 if (pt.isElapsed())
221 {
222 moveUp();
223 pt.setTimer(1);
224 }
225 } else if (key.getKey() == KeyEvent.VK_DOWN)
226 {
227 if (pt.isElapsed())
228 {
229 moveDown();
230 pt.setTimer(1);
231 }
232 } else if (key.isActionDown())
233 {
234 synchronized (hasInput)
235 {
236 hasInput = true;
237 }
238 }
239 }
240
241 public boolean hasInput()
242 {
243 synchronized (hasInput)
244 {
245 return hasInput;
246 }
247 }
248
170} \ No newline at end of file 249} \ 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 @@
1/*
2 * To change this template, choose Tools | Templates
3 * and open the template in the editor.
4 */
5
6package com.fourisland.fourpuzzle.window;
7
8import com.fourisland.fourpuzzle.KeyInput;
9import java.util.List;
10import com.fourisland.fourpuzzle.util.Inputable;
11import com.fourisland.fourpuzzle.util.PauseTimer;
12import java.awt.event.KeyEvent;
13
14/**
15 *
16 * @author hatkirby
17 */
18public class InputableChoiceWindow extends ChoiceWindow implements Inputable {
19
20 Boolean hasInput = false;
21 PauseTimer pt = new PauseTimer(0);
22
23 public InputableChoiceWindow(List<String> choices, boolean center, ChoiceWindowLocation cwl)
24 {
25 super(choices, center, cwl);
26 }
27
28 public void processInput(KeyInput key)
29 {
30 if (key.getKey() == KeyEvent.VK_UP)
31 {
32 if (pt.isElapsed())
33 {
34 moveUp();
35 pt.setTimer(1);
36 }
37 } else if (key.getKey() == KeyEvent.VK_DOWN)
38 {
39 if (pt.isElapsed())
40 {
41 moveDown();
42 pt.setTimer(1);
43 }
44 } else if (key.isActionDown())
45 {
46 synchronized (hasInput)
47 {
48 hasInput = true;
49 }
50 }
51 }
52
53 public boolean hasInput()
54 {
55 synchronized (hasInput)
56 {
57 return hasInput;
58 }
59 }
60
61}