diff options
Diffstat (limited to 'src/com/fourisland/fourpuzzle/gamestate/menu')
4 files changed, 220 insertions, 0 deletions
diff --git a/src/com/fourisland/fourpuzzle/gamestate/menu/EscapeMenuState.java b/src/com/fourisland/fourpuzzle/gamestate/menu/EscapeMenuState.java new file mode 100644 index 0000000..d316a8d --- /dev/null +++ b/src/com/fourisland/fourpuzzle/gamestate/menu/EscapeMenuState.java | |||
@@ -0,0 +1,21 @@ | |||
1 | /* | ||
2 | * To change this template, choose Tools | Templates | ||
3 | * and open the template in the editor. | ||
4 | */ | ||
5 | |||
6 | package com.fourisland.fourpuzzle.gamestate.menu; | ||
7 | |||
8 | import com.fourisland.fourpuzzle.util.Renderable; | ||
9 | import com.fourisland.fourpuzzle.util.Inputable; | ||
10 | |||
11 | /** | ||
12 | * | ||
13 | * @author hatkirby | ||
14 | */ | ||
15 | public interface EscapeMenuState extends Renderable, Inputable { | ||
16 | |||
17 | public void initalize(MenuGameState mgs); | ||
18 | public void deinitalize(); | ||
19 | public void tick(); | ||
20 | |||
21 | } | ||
diff --git a/src/com/fourisland/fourpuzzle/gamestate/menu/MenuEMS.java b/src/com/fourisland/fourpuzzle/gamestate/menu/MenuEMS.java new file mode 100644 index 0000000..4fad509 --- /dev/null +++ b/src/com/fourisland/fourpuzzle/gamestate/menu/MenuEMS.java | |||
@@ -0,0 +1,83 @@ | |||
1 | /* | ||
2 | * To change this template, choose Tools | Templates | ||
3 | * and open the template in the editor. | ||
4 | */ | ||
5 | |||
6 | package com.fourisland.fourpuzzle.gamestate.menu; | ||
7 | |||
8 | import com.fourisland.fourpuzzle.Display; | ||
9 | import com.fourisland.fourpuzzle.Game; | ||
10 | import com.fourisland.fourpuzzle.KeyInput; | ||
11 | import com.fourisland.fourpuzzle.KeyboardInput; | ||
12 | import com.fourisland.fourpuzzle.database.Database; | ||
13 | import com.fourisland.fourpuzzle.database.Transitions; | ||
14 | import com.fourisland.fourpuzzle.database.Vocabulary; | ||
15 | import com.fourisland.fourpuzzle.gamestate.TitleScreenGameState; | ||
16 | import com.fourisland.fourpuzzle.window.ChoiceWindow; | ||
17 | import com.fourisland.fourpuzzle.window.InputableChoiceWindow; | ||
18 | import java.awt.Color; | ||
19 | import java.awt.Graphics2D; | ||
20 | import java.awt.event.KeyEvent; | ||
21 | import java.util.Arrays; | ||
22 | |||
23 | /** | ||
24 | * | ||
25 | * @author hatkirby | ||
26 | */ | ||
27 | public class MenuEMS implements EscapeMenuState { | ||
28 | |||
29 | MenuGameState parent; | ||
30 | InputableChoiceWindow cw; | ||
31 | |||
32 | public void initalize(MenuGameState mgs) | ||
33 | { | ||
34 | 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); | ||
36 | Display.registerRenderable(cw); | ||
37 | KeyboardInput.registerInputable(cw); | ||
38 | } | ||
39 | |||
40 | public void deinitalize() | ||
41 | { | ||
42 | Display.unregisterRenderable(cw); | ||
43 | KeyboardInput.unregisterInputable(cw); | ||
44 | } | ||
45 | |||
46 | public void tick() | ||
47 | { | ||
48 | if (cw.hasInput()) | ||
49 | { | ||
50 | String value = cw.getSelected(); | ||
51 | if (value.equals(Database.getVocab(Vocabulary.EscapeMenuQuit))) | ||
52 | { | ||
53 | try { | ||
54 | Display.transition(Database.getTransition(Transitions.Generic), new TitleScreenGameState(), true); | ||
55 | } catch (InterruptedException ex) { | ||
56 | Thread.currentThread().interrupt(); | ||
57 | } | ||
58 | } else if (value.equals(Database.getVocab(Vocabulary.EscapeMenuSave))) | ||
59 | { | ||
60 | parent.setEMS(new SaveEMS()); | ||
61 | } | ||
62 | } | ||
63 | } | ||
64 | |||
65 | public void render(Graphics2D g) | ||
66 | { | ||
67 | g.setBackground(Color.BLACK); | ||
68 | g.clearRect(0, 0, Game.WIDTH, Game.HEIGHT); | ||
69 | } | ||
70 | |||
71 | public void processInput(KeyInput key) | ||
72 | { | ||
73 | if (key.getKey() == KeyEvent.VK_ESCAPE) | ||
74 | { | ||
75 | try { | ||
76 | Display.transition(Database.getTransition(Transitions.Generic), parent.mapView, true); | ||
77 | } catch (InterruptedException ex) { | ||
78 | Thread.currentThread().interrupt(); | ||
79 | } | ||
80 | } | ||
81 | } | ||
82 | |||
83 | } | ||
diff --git a/src/com/fourisland/fourpuzzle/gamestate/menu/MenuGameState.java b/src/com/fourisland/fourpuzzle/gamestate/menu/MenuGameState.java new file mode 100644 index 0000000..884195c --- /dev/null +++ b/src/com/fourisland/fourpuzzle/gamestate/menu/MenuGameState.java | |||
@@ -0,0 +1,67 @@ | |||
1 | /* | ||
2 | * To change this template, choose Tools | Templates | ||
3 | * and open the template in the editor. | ||
4 | */ | ||
5 | |||
6 | package com.fourisland.fourpuzzle.gamestate.menu; | ||
7 | |||
8 | import com.fourisland.fourpuzzle.Audio; | ||
9 | import com.fourisland.fourpuzzle.gamestate.*; | ||
10 | import com.fourisland.fourpuzzle.KeyInput; | ||
11 | import com.fourisland.fourpuzzle.database.Database; | ||
12 | import com.fourisland.fourpuzzle.database.Sound; | ||
13 | import com.fourisland.fourpuzzle.gamestate.mapview.MapViewGameState; | ||
14 | import java.awt.Graphics2D; | ||
15 | |||
16 | /** | ||
17 | * | ||
18 | * @author hatkirby | ||
19 | */ | ||
20 | public class MenuGameState implements GameState { | ||
21 | |||
22 | EscapeMenuState ems; | ||
23 | MapViewGameState mapView; | ||
24 | |||
25 | public MenuGameState(MapViewGameState mapView) | ||
26 | { | ||
27 | this.mapView = mapView; | ||
28 | } | ||
29 | |||
30 | public void initalize() | ||
31 | { | ||
32 | Audio.playSound(Database.getSound(Sound.Selection)); | ||
33 | setEMS(new MenuEMS()); | ||
34 | } | ||
35 | |||
36 | public void deinitalize() | ||
37 | { | ||
38 | this.ems.deinitalize(); | ||
39 | } | ||
40 | |||
41 | public void doGameCycle() | ||
42 | { | ||
43 | ems.tick(); | ||
44 | } | ||
45 | |||
46 | public void render(Graphics2D g) | ||
47 | { | ||
48 | ems.render(g); | ||
49 | } | ||
50 | |||
51 | public void processInput(KeyInput key) | ||
52 | { | ||
53 | ems.processInput(key); | ||
54 | } | ||
55 | |||
56 | public void setEMS(EscapeMenuState ems) | ||
57 | { | ||
58 | if (this.ems != null) | ||
59 | { | ||
60 | this.ems.deinitalize(); | ||
61 | } | ||
62 | |||
63 | this.ems = ems; | ||
64 | this.ems.initalize(this); | ||
65 | } | ||
66 | |||
67 | } | ||
diff --git a/src/com/fourisland/fourpuzzle/gamestate/menu/SaveEMS.java b/src/com/fourisland/fourpuzzle/gamestate/menu/SaveEMS.java new file mode 100644 index 0000000..02e0f41 --- /dev/null +++ b/src/com/fourisland/fourpuzzle/gamestate/menu/SaveEMS.java | |||
@@ -0,0 +1,49 @@ | |||
1 | /* | ||
2 | * To change this template, choose Tools | Templates | ||
3 | * and open the template in the editor. | ||
4 | */ | ||
5 | |||
6 | package com.fourisland.fourpuzzle.gamestate.menu; | ||
7 | |||
8 | import com.fourisland.fourpuzzle.Game; | ||
9 | import com.fourisland.fourpuzzle.KeyInput; | ||
10 | import com.fourisland.fourpuzzle.window.Window; | ||
11 | import java.awt.Graphics2D; | ||
12 | import java.awt.image.BufferedImage; | ||
13 | |||
14 | /** | ||
15 | * | ||
16 | * @author hatkirby | ||
17 | */ | ||
18 | public class SaveEMS implements EscapeMenuState { | ||
19 | |||
20 | MenuGameState parent; | ||
21 | BufferedImage cacheBase; | ||
22 | |||
23 | public void initalize(MenuGameState mgs) | ||
24 | { | ||
25 | parent = mgs; | ||
26 | cacheBase = Window.Default.getImage(Game.WIDTH-Window.Default.getFullWidth(0), Window.Default.getFullHeight(Game.HEIGHT)/3+Window.Default.getFullHeight(0)); | ||
27 | } | ||
28 | |||
29 | public void deinitalize() | ||
30 | { | ||
31 | //throw new UnsupportedOperationException("Not supported yet."); | ||
32 | } | ||
33 | |||
34 | public void tick() | ||
35 | { | ||
36 | //throw new UnsupportedOperationException("Not supported yet."); | ||
37 | } | ||
38 | |||
39 | public void render(Graphics2D g) | ||
40 | { | ||
41 | g.drawImage(cacheBase, 0, 0, null); | ||
42 | } | ||
43 | |||
44 | public void processInput(KeyInput key) | ||
45 | { | ||
46 | //throw new UnsupportedOperationException("Not supported yet."); | ||
47 | } | ||
48 | |||
49 | } | ||