summary refs log tree commit diff stats
path: root/src/com/fourisland
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/fourisland')
-rwxr-xr-xsrc/com/fourisland/fourpuzzle/gamestate/TitleScreenGameState.java72
-rw-r--r--src/com/fourisland/fourpuzzle/util/PauseTimer.java41
-rwxr-xr-xsrc/com/fourisland/fourpuzzle/window/ChoiceWindow.java68
-rwxr-xr-xsrc/com/fourisland/fourpuzzle/window/SystemChoiceArea.java56
-rwxr-xr-xsrc/com/fourisland/fourpuzzle/window/SystemGraphic.java10
-rw-r--r--src/com/fourisland/fourpuzzle/window/Window.java116
6 files changed, 253 insertions, 110 deletions
diff --git a/src/com/fourisland/fourpuzzle/gamestate/TitleScreenGameState.java b/src/com/fourisland/fourpuzzle/gamestate/TitleScreenGameState.java index 2f5dc97..998d33a 100755 --- a/src/com/fourisland/fourpuzzle/gamestate/TitleScreenGameState.java +++ b/src/com/fourisland/fourpuzzle/gamestate/TitleScreenGameState.java
@@ -10,6 +10,7 @@ import com.fourisland.fourpuzzle.gamestate.mapview.MapViewGameState;
10import com.fourisland.fourpuzzle.transition.SquareTransition; 10import com.fourisland.fourpuzzle.transition.SquareTransition;
11import com.fourisland.fourpuzzle.transition.TransitionDirection; 11import com.fourisland.fourpuzzle.transition.TransitionDirection;
12import com.fourisland.fourpuzzle.util.ObjectLoader; 12import com.fourisland.fourpuzzle.util.ObjectLoader;
13import com.fourisland.fourpuzzle.util.PauseTimer;
13import com.fourisland.fourpuzzle.window.ChoiceWindow; 14import com.fourisland.fourpuzzle.window.ChoiceWindow;
14import java.awt.Graphics2D; 15import java.awt.Graphics2D;
15import java.awt.event.KeyEvent; 16import java.awt.event.KeyEvent;
@@ -38,29 +39,62 @@ public class TitleScreenGameState implements GameState {
38 Audio.stopMusic(); 39 Audio.stopMusic();
39 } 40 }
40 41
42 PauseTimer pt = new PauseTimer(0);
41 public void processInput() 43 public void processInput()
42 { 44 {
43 if (Game.getKey().getKeyCode() == KeyEvent.VK_ENTER) 45 if (pt.isElapsed())
44 { 46 {
45 Game.setSaveFile(new SaveFile()); 47 if (Game.getKey().getKeyCode() == KeyEvent.VK_ENTER)
46 48 {
47 new Thread(new Runnable() { 49 if (choices.getSelected().equals(Database.getVocab("NewGame")))
48 public void run() { 50 {
49 try { 51 Game.setSaveFile(new SaveFile());
50 Display.transition(new SquareTransition(TransitionDirection.Out)); 52
51 } catch (InterruptedException ex) { 53 new Thread(new Runnable() {
52 Thread.currentThread().interrupt(); 54 public void run() {
53 } 55 try {
54 56 Display.transition(new SquareTransition(TransitionDirection.Out));
55 Game.setGameState(new MapViewGameState("TestMap", 1, 2)); 57 } catch (InterruptedException ex) {
56 58 Thread.currentThread().interrupt();
57 try { 59 }
58 Display.transition(new SquareTransition(TransitionDirection.In)); 60
59 } catch (InterruptedException ex) { 61 Game.setGameState(new MapViewGameState("TestMap", 1, 2));
60 Thread.currentThread().interrupt(); 62
61 } 63 try {
64 Display.transition(new SquareTransition(TransitionDirection.In));
65 } catch (InterruptedException ex) {
66 Thread.currentThread().interrupt();
67 }
68 }
69 }).start();
70 } else if (choices.getSelected().equals(Database.getVocab("LoadGame")))
71 {
72 // Do nothing, yet
73 } else if (choices.getSelected().equals(Database.getVocab("EndGame")))
74 {
75 new Thread(new Runnable() {
76 public void run() {
77 try {
78 Display.transition(new SquareTransition(TransitionDirection.Out));
79 } catch (InterruptedException ex) {
80 Thread.currentThread().interrupt();
81 }
82
83 System.exit(0);
84 }
85 }).start();
62 } 86 }
63 }).start(); 87 } else if (Game.getKey().getKeyCode() == KeyEvent.VK_UP)
88 {
89 choices.moveUp();
90
91 pt.setTimer(1);
92 } else if (Game.getKey().getKeyCode() == KeyEvent.VK_DOWN)
93 {
94 choices.moveDown();
95
96 pt.setTimer(1);
97 }
64 } 98 }
65 } 99 }
66 100
diff --git a/src/com/fourisland/fourpuzzle/util/PauseTimer.java b/src/com/fourisland/fourpuzzle/util/PauseTimer.java new file mode 100644 index 0000000..0e52b0f --- /dev/null +++ b/src/com/fourisland/fourpuzzle/util/PauseTimer.java
@@ -0,0 +1,41 @@
1/*
2 * To change this template, choose Tools | Templates
3 * and open the template in the editor.
4 */
5
6package com.fourisland.fourpuzzle.util;
7
8/**
9 *
10 * @author hatkirby
11 */
12public class PauseTimer {
13
14 private int ticks;
15 public PauseTimer(int ticks)
16 {
17 this.ticks = ticks;
18 }
19
20 Interval in = Interval.createTickInterval(1);
21 public boolean isElapsed()
22 {
23 if (in.isElapsed())
24 {
25 if (ticks == 0)
26 {
27 return true;
28 } else {
29 ticks--;
30 }
31 }
32
33 return false;
34 }
35
36 public void setTimer(int ticks)
37 {
38 this.ticks = ticks;
39 }
40
41}
diff --git a/src/com/fourisland/fourpuzzle/window/ChoiceWindow.java b/src/com/fourisland/fourpuzzle/window/ChoiceWindow.java index 40fff30..3b30acc 100755 --- a/src/com/fourisland/fourpuzzle/window/ChoiceWindow.java +++ b/src/com/fourisland/fourpuzzle/window/ChoiceWindow.java
@@ -5,18 +5,13 @@
5 5
6package com.fourisland.fourpuzzle.window; 6package com.fourisland.fourpuzzle.window;
7 7
8import com.fourisland.fourpuzzle.util.TransparentPixelFilter; 8import com.fourisland.fourpuzzle.Audio;
9import java.awt.Font; 9import java.awt.Font;
10import java.awt.Toolkit;
11import java.awt.Graphics2D; 10import java.awt.Graphics2D;
12import java.awt.Rectangle; 11import java.awt.Rectangle;
13import java.awt.TexturePaint; 12import java.awt.TexturePaint;
14import java.awt.image.BufferedImage; 13import java.awt.image.BufferedImage;
15import java.awt.image.FilteredImageSource;
16import java.util.List; 14import java.util.List;
17import static com.fourisland.fourpuzzle.window.SystemChoiceArea.*;
18
19/* TODO Find a more elegant way to implement window, it looks terrible now */
20 15
21/** 16/**
22 * 17 *
@@ -35,7 +30,7 @@ public class ChoiceWindow {
35 numChoices = choices.size(); 30 numChoices = choices.size();
36 this.center = center; 31 this.center = center;
37 32
38 createGraphic(new BufferedImage(TopLeft.getWidth()+getWidth()+TopRight.getWidth(), TopLeft.getHeight()+getHeight()+BottomLeft.getHeight(), BufferedImage.TYPE_INT_ARGB).createGraphics()); 33 createGraphic(new BufferedImage(Window.Default.getFullWidth(width), Window.Default.getFullHeight(height), BufferedImage.TYPE_INT_ARGB).createGraphics());
39 } 34 }
40 35
41 private int width; 36 private int width;
@@ -57,36 +52,38 @@ public class ChoiceWindow {
57 width += SPACER*2; 52 width += SPACER*2;
58 height -= SPACER; 53 height -= SPACER;
59 54
60 BufferedImage temp = new BufferedImage(TopLeft.getWidth()+getWidth()+TopRight.getWidth(), TopLeft.getHeight()+getHeight()+BottomLeft.getHeight(), BufferedImage.TYPE_INT_ARGB); 55 cacheBase = new BufferedImage(Window.Default.getFullWidth(width), Window.Default.getFullHeight(height), BufferedImage.TYPE_INT_ARGB);
61 Graphics2D g = temp.createGraphics();
62
63 g.drawImage(SystemGraphic.getChoiceArea(TopLeft), 0, 0, null);
64 g.drawImage(SystemGraphic.getChoiceArea(Top), TopLeft.getWidth(), 0, getWidth(),Top.getHeight(), null);
65 g.drawImage(SystemGraphic.getChoiceArea(TopRight), TopLeft.getWidth()+getWidth(), 0, null);
66 g.drawImage(SystemGraphic.getChoiceArea(Left), 0, TopLeft.getHeight(), Left.getWidth(),getHeight(), null);
67 g.drawImage(SystemGraphic.getChoiceArea(BottomLeft), 0, TopLeft.getHeight()+getHeight(), null);
68 g.drawImage(SystemGraphic.getChoiceArea(Bottom), BottomLeft.getWidth(), (getHeight()+TopLeft.getHeight()+BottomLeft.getHeight())-Bottom.getHeight(), getWidth(),Bottom.getHeight(), null);
69 g.drawImage(SystemGraphic.getChoiceArea(BottomRight), BottomRight.getWidth()+getWidth(), TopRight.getHeight()+getHeight(), null);
70 g.drawImage(SystemGraphic.getChoiceArea(Right), (getWidth()+TopLeft.getWidth()+TopRight.getWidth())-Right.getWidth(), TopRight.getHeight(), Right.getWidth(),getHeight(), null);
71
72 cacheBase = new BufferedImage(TopLeft.getWidth()+getWidth()+TopRight.getWidth(), TopLeft.getHeight()+getHeight()+BottomLeft.getHeight(), BufferedImage.TYPE_INT_ARGB);
73 Graphics2D g2 = cacheBase.createGraphics(); 56 Graphics2D g2 = cacheBase.createGraphics();
74 57
75 g2.drawImage(SystemGraphic.getMessageBackground(), 1, 1, TopLeft.getWidth()+getWidth()+TopRight.getWidth()-2, TopLeft.getHeight()+getHeight()+BottomLeft.getHeight()-2, null); 58 g2.drawImage(SystemGraphic.getMessageBackground(), 1, 1, Window.Default.getFullWidth(width)-2, Window.Default.getFullHeight(height)-2, null);
76 g2.drawImage(Toolkit.getDefaultToolkit().createImage(new FilteredImageSource(temp.getSource(), new TransparentPixelFilter(SystemGraphic.getTransparentColor().getRGB()))), 0, 0, null); 59 g2.drawImage(Window.Default.getImage(width, height), 0, 0, null);
60 }
61
62 public void render(Graphics2D g2, int x, int y)
63 {
64 g2.drawImage(cacheBase, x, y, null);
65
77 g2.setFont(g2.getFont().deriveFont(Font.BOLD)); 66 g2.setFont(g2.getFont().deriveFont(Font.BOLD));
78 67
79 int ty = TopLeft.getHeight()+g2.getFontMetrics().getHeight()-SPACER; 68 int fh = g2.getFontMetrics().getHeight();
69 int ty = Window.Default.getTopY()+fh-SPACER+y;
80 for (String choice : choices) 70 for (String choice : choices)
81 { 71 {
82 int tx = TopLeft.getWidth(); 72 int fw = g2.getFontMetrics().stringWidth(choice);
73 int tx = Window.Default.getLeftX()+x;
83 74
84 if (center) 75 if (center)
85 { 76 {
86 tx += ((width/2)-(g2.getFontMetrics().stringWidth(choice)/2)); 77 tx += ((width/2)-(fw/2));
78 }
79
80 if (getSelected().equals(choice))
81 {
82 g2.drawImage(SystemGraphic.getSelectionBackground(), tx, ty-fh, fw+SPACER-2, fh+SPACER-2, null);
83 g2.drawImage(Window.Selector.getImage(fw-Window.Selector.getLeftX(), fh-Window.Selector.getTopY()), tx-SPACER, ty-fh, null);
87 } 84 }
88 85
89 g2.setPaint(new TexturePaint(SystemGraphic.getTextColor(), new Rectangle(tx, ty, g2.getFontMetrics().stringWidth(choice),g2.getFontMetrics().getHeight()))); 86 g2.setPaint(new TexturePaint(SystemGraphic.getTextColor(), new Rectangle(tx, ty, fw, fh)));
90 g2.drawString(choice, tx, ty); 87 g2.drawString(choice, tx, ty);
91 88
92 ty+=(SPACER+g2.getFontMetrics().getHeight()); 89 ty+=(SPACER+g2.getFontMetrics().getHeight());
@@ -95,11 +92,6 @@ public class ChoiceWindow {
95 g2.setFont(g2.getFont().deriveFont(Font.PLAIN)); 92 g2.setFont(g2.getFont().deriveFont(Font.PLAIN));
96 } 93 }
97 94
98 public void render(Graphics2D g2, int x, int y)
99 {
100 g2.drawImage(cacheBase, x, y, null);
101 }
102
103 public int getWidth() 95 public int getWidth()
104 { 96 {
105 return width; 97 return width;
@@ -113,12 +105,22 @@ public class ChoiceWindow {
113 int selected = 0; 105 int selected = 0;
114 public void moveUp() 106 public void moveUp()
115 { 107 {
116 selected--; 108 if (selected > 0)
109 {
110 Audio.playSound("Cursor1");
111
112 selected--;
113 }
117 } 114 }
118 115
119 public void moveDown() 116 public void moveDown()
120 { 117 {
121 selected++; 118 if (selected < (choices.size()-1))
119 {
120 Audio.playSound("Cursor1");
121
122 selected++;
123 }
122 } 124 }
123 125
124 public String getSelected() 126 public String getSelected()
diff --git a/src/com/fourisland/fourpuzzle/window/SystemChoiceArea.java b/src/com/fourisland/fourpuzzle/window/SystemChoiceArea.java deleted file mode 100755 index 5fc115f..0000000 --- a/src/com/fourisland/fourpuzzle/window/SystemChoiceArea.java +++ /dev/null
@@ -1,56 +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
8/**
9 *
10 * @author hatkirby
11 */
12public enum SystemChoiceArea
13{
14 Top(47, 0, 1, 9),
15 TopRight(56, 0, 8, 9),
16 Right(56, 15, 8, 1),
17 BottomRight(56, 25, 8, 9),
18 Bottom(47, 24, 1, 9),
19 BottomLeft(32, 24, 11, 9),
20 Left(32, 15, 11, 1),
21 TopLeft(32, 0, 8, 8),
22 UpArrow(43, 9, 10, 6),
23 DownArrow(43, 17, 10, 6);
24
25 private final int x;
26 private final int y;
27 private final int width;
28 private final int height;
29 private SystemChoiceArea(int x, int y, int width, int height)
30 {
31 this.x = x;
32 this.y = y;
33 this.width = width;
34 this.height = height;
35 }
36
37 public int getX()
38 {
39 return x;
40 }
41
42 public int getY()
43 {
44 return y;
45 }
46
47 public int getWidth()
48 {
49 return width;
50 }
51
52 public int getHeight()
53 {
54 return height;
55 }
56} \ No newline at end of file
diff --git a/src/com/fourisland/fourpuzzle/window/SystemGraphic.java b/src/com/fourisland/fourpuzzle/window/SystemGraphic.java index ea67f41..24e0104 100755 --- a/src/com/fourisland/fourpuzzle/window/SystemGraphic.java +++ b/src/com/fourisland/fourpuzzle/window/SystemGraphic.java
@@ -7,6 +7,7 @@ package com.fourisland.fourpuzzle.window;
7 7
8import com.fourisland.fourpuzzle.util.ObjectLoader; 8import com.fourisland.fourpuzzle.util.ObjectLoader;
9import java.awt.Color; 9import java.awt.Color;
10import java.awt.Rectangle;
10import java.awt.image.BufferedImage; 11import java.awt.image.BufferedImage;
11 12
12/** 13/**
@@ -32,9 +33,14 @@ public class SystemGraphic {
32 return systemGraphic.getSubimage(0, 0, 32, 32); 33 return systemGraphic.getSubimage(0, 0, 32, 32);
33 } 34 }
34 35
35 public static BufferedImage getChoiceArea(SystemChoiceArea sca) 36 public static BufferedImage getSelectionBackground()
36 { 37 {
37 return systemGraphic.getSubimage(sca.getX(), sca.getY(), sca.getWidth(), sca.getHeight()); 38 return systemGraphic.getSubimage(79, 15, 1, 1);
39 }
40
41 public static BufferedImage getChoiceArea(Rectangle sca)
42 {
43 return systemGraphic.getSubimage(sca.x, sca.y, sca.width, sca.height);
38 } 44 }
39 45
40 public static BufferedImage getTextColor() 46 public static BufferedImage getTextColor()
diff --git a/src/com/fourisland/fourpuzzle/window/Window.java b/src/com/fourisland/fourpuzzle/window/Window.java new file mode 100644 index 0000000..fa40cba --- /dev/null +++ b/src/com/fourisland/fourpuzzle/window/Window.java
@@ -0,0 +1,116 @@
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.util.TransparentPixelFilter;
9import java.awt.Graphics2D;
10import java.awt.Image;
11import java.awt.Rectangle;
12import java.awt.Toolkit;
13import java.awt.image.BufferedImage;
14import java.awt.image.FilteredImageSource;
15
16/**
17 *
18 * @author hatkirby
19 */
20public enum Window
21{
22 Default(32),
23 Selector(64);
24
25 private enum SystemArea
26 {
27 TOP(15, 0, 1, 9),
28 TOP_RIGHT(24, 0, 8, 9),
29 RIGHT(24, 15, 8, 1),
30 BOTTOM_RIGHT(24, 25, 8, 9),
31 BOTTOM(15, 24, 1, 9),
32 BOTTOM_LEFT(0, 24, 11, 9),
33 LEFT(0, 15, 11, 1),
34 TOP_LEFT(0, 0, 8, 8);
35
36 private final int x;
37 private final int y;
38 private final int width;
39 private final int height;
40 private SystemArea(int x, int y, int width, int height)
41 {
42 this.x = x;
43 this.y = y;
44 this.width = width;
45 this.height = height;
46 }
47 }
48
49 private int x;
50 private Window(int x)
51 {
52 this.x = x;
53 }
54
55 private int getX(SystemArea sa)
56 {
57 return x+sa.x;
58 }
59
60 private int getY(SystemArea sa)
61 {
62 return sa.y;
63 }
64
65 private int getWidth(SystemArea sa)
66 {
67 return sa.width;
68 }
69
70 private int getHeight(SystemArea sa)
71 {
72 return sa.height;
73 }
74
75 private Rectangle getBounds(SystemArea sa)
76 {
77 return new Rectangle(getX(sa), getY(sa), getWidth(sa), getHeight(sa));
78 }
79
80 public int getFullWidth(int width)
81 {
82 return getWidth(SystemArea.TOP_LEFT) + getWidth(SystemArea.TOP_RIGHT) + width;
83 }
84
85 public int getFullHeight(int height)
86 {
87 return getHeight(SystemArea.TOP_LEFT) + getHeight(SystemArea.BOTTOM_LEFT) + height;
88 }
89
90 public int getLeftX()
91 {
92 return getWidth(SystemArea.TOP_LEFT);
93 }
94
95 public int getTopY()
96 {
97 return getHeight(SystemArea.TOP_LEFT);
98 }
99
100 public Image getImage(int width, int height)
101 {
102 BufferedImage temp = new BufferedImage(getFullWidth(width), getFullHeight(height), BufferedImage.TYPE_INT_ARGB);
103 Graphics2D g = temp.createGraphics();
104
105 g.drawImage(SystemGraphic.getChoiceArea(getBounds(SystemArea.TOP_LEFT)), 0, 0, null);
106 g.drawImage(SystemGraphic.getChoiceArea(getBounds(SystemArea.TOP)), getWidth(SystemArea.TOP_LEFT), 0, width, getHeight(SystemArea.TOP), null);
107 g.drawImage(SystemGraphic.getChoiceArea(getBounds(SystemArea.TOP_RIGHT)), getWidth(SystemArea.TOP_LEFT)+width, 0, null);
108 g.drawImage(SystemGraphic.getChoiceArea(getBounds(SystemArea.LEFT)), 0, getHeight(SystemArea.TOP_LEFT), getWidth(SystemArea.LEFT),height, null);
109 g.drawImage(SystemGraphic.getChoiceArea(getBounds(SystemArea.BOTTOM_LEFT)), 0, getHeight(SystemArea.TOP_LEFT)+height, null);
110 g.drawImage(SystemGraphic.getChoiceArea(getBounds(SystemArea.BOTTOM)), getWidth(SystemArea.BOTTOM_LEFT), (height+getHeight(SystemArea.TOP_LEFT)+getHeight(SystemArea.BOTTOM_LEFT))-getHeight(SystemArea.BOTTOM), width, getHeight(SystemArea.BOTTOM), null);
111 g.drawImage(SystemGraphic.getChoiceArea(getBounds(SystemArea.BOTTOM_RIGHT)), getWidth(SystemArea.BOTTOM_RIGHT)+width, getHeight(SystemArea.TOP_RIGHT)+height, null);
112 g.drawImage(SystemGraphic.getChoiceArea(getBounds(SystemArea.RIGHT)), (width+getWidth(SystemArea.TOP_LEFT)+getWidth(SystemArea.TOP_RIGHT))-getWidth(SystemArea.RIGHT), getHeight(SystemArea.TOP_RIGHT), getWidth(SystemArea.RIGHT), height, null);
113
114 return Toolkit.getDefaultToolkit().createImage(new FilteredImageSource(temp.getSource(), new TransparentPixelFilter(SystemGraphic.getTransparentColor().getRGB())));
115 }
116} \ No newline at end of file