diff options
-rw-r--r-- | src/com/fourisland/frigidearth/InventoryOverlay.java | 117 | ||||
-rw-r--r-- | src/com/fourisland/frigidearth/Item.java | 2 | ||||
-rw-r--r-- | src/com/fourisland/frigidearth/Main.java | 5 | ||||
-rw-r--r-- | src/com/fourisland/frigidearth/MapViewGameState.java | 19 |
4 files changed, 142 insertions, 1 deletions
diff --git a/src/com/fourisland/frigidearth/InventoryOverlay.java b/src/com/fourisland/frigidearth/InventoryOverlay.java new file mode 100644 index 0000000..21f2194 --- /dev/null +++ b/src/com/fourisland/frigidearth/InventoryOverlay.java | |||
@@ -0,0 +1,117 @@ | |||
1 | /* | ||
2 | * To change this template, choose Tools | Templates | ||
3 | * and open the template in the editor. | ||
4 | */ | ||
5 | package com.fourisland.frigidearth; | ||
6 | |||
7 | import java.awt.Color; | ||
8 | import java.awt.Graphics2D; | ||
9 | import java.awt.event.KeyEvent; | ||
10 | |||
11 | /** | ||
12 | * | ||
13 | * @author hatkirby | ||
14 | */ | ||
15 | public class InventoryOverlay implements Renderable, Inputable | ||
16 | { | ||
17 | private final int TILE_WIDTH = 12; | ||
18 | private final int TILE_HEIGHT = 12; | ||
19 | private final int LIST_HEIGHT = 13; | ||
20 | |||
21 | private int id = 0; | ||
22 | private int scroll = 0; | ||
23 | private int width = 0; | ||
24 | |||
25 | public InventoryOverlay() | ||
26 | { | ||
27 | for (Item item : Main.currentGame.inventory) | ||
28 | { | ||
29 | if (item.getItemName().length() > width) | ||
30 | { | ||
31 | width = item.getItemName().length(); | ||
32 | } | ||
33 | } | ||
34 | |||
35 | width += 2; | ||
36 | } | ||
37 | |||
38 | public void render(Graphics2D g) | ||
39 | { | ||
40 | g.setColor(Color.BLACK); | ||
41 | g.fillRect(TILE_WIDTH, TILE_HEIGHT, width*TILE_WIDTH, Math.min(LIST_HEIGHT+2,Main.currentGame.inventory.size()+1)*TILE_HEIGHT); | ||
42 | |||
43 | if (scroll > 0) | ||
44 | { | ||
45 | g.drawImage(SystemFont.getCharacter((char) 24, Color.WHITE), (1+width/2)*TILE_WIDTH, TILE_HEIGHT, TILE_WIDTH, TILE_HEIGHT, null); | ||
46 | } | ||
47 | |||
48 | for (int i=scroll; i<Math.min(scroll+LIST_HEIGHT, Main.currentGame.inventory.size()); i++) | ||
49 | { | ||
50 | if (i == id) | ||
51 | { | ||
52 | g.drawImage(SystemFont.getCharacter((char) 26, Color.WHITE), TILE_WIDTH, (i-scroll+2)*TILE_HEIGHT, TILE_WIDTH, TILE_HEIGHT, null); | ||
53 | } | ||
54 | |||
55 | String name = Main.currentGame.inventory.get(i).getItemName().toLowerCase(); | ||
56 | for (int j=0; j<name.length(); j++) | ||
57 | { | ||
58 | g.drawImage(SystemFont.getCharacter(name.charAt(j), Main.currentGame.inventory.get(i).getDisplayColor()), (3+j)*TILE_WIDTH, (i-scroll+2)*TILE_HEIGHT, TILE_WIDTH, TILE_HEIGHT, null); | ||
59 | } | ||
60 | } | ||
61 | |||
62 | if (scroll + LIST_HEIGHT < Main.currentGame.inventory.size()) | ||
63 | { | ||
64 | g.drawImage(SystemFont.getCharacter((char) 25, Color.WHITE), (1+width/2)*TILE_WIDTH, (LIST_HEIGHT+2)*TILE_HEIGHT, TILE_WIDTH, TILE_HEIGHT, null); | ||
65 | } | ||
66 | } | ||
67 | |||
68 | public void processInput(KeyEvent e) | ||
69 | { | ||
70 | switch (e.getKeyCode()) | ||
71 | { | ||
72 | case KeyEvent.VK_ESCAPE: | ||
73 | Main.removeRenderable(this); | ||
74 | Main.removeInputable(this); | ||
75 | |||
76 | return; | ||
77 | |||
78 | case KeyEvent.VK_UP: | ||
79 | if (id != 0) | ||
80 | { | ||
81 | id--; | ||
82 | |||
83 | if (id < scroll) | ||
84 | { | ||
85 | scroll=id; | ||
86 | } | ||
87 | } | ||
88 | |||
89 | break; | ||
90 | |||
91 | case KeyEvent.VK_DOWN: | ||
92 | if (id != (Main.currentGame.inventory.size()-1)) | ||
93 | { | ||
94 | id++; | ||
95 | |||
96 | if (id > (scroll+LIST_HEIGHT-1)) | ||
97 | { | ||
98 | scroll++; | ||
99 | } | ||
100 | } | ||
101 | |||
102 | break; | ||
103 | |||
104 | case KeyEvent.VK_ENTER: | ||
105 | if (Main.currentGame.inventory.get(id).useItem()) | ||
106 | { | ||
107 | Main.currentGame.inventory.remove(id); | ||
108 | ((MapViewGameState) Main.getGameState()).tick(); | ||
109 | Main.removeRenderable(this); | ||
110 | Main.removeInputable(this); | ||
111 | |||
112 | return; | ||
113 | } | ||
114 | } | ||
115 | } | ||
116 | |||
117 | } | ||
diff --git a/src/com/fourisland/frigidearth/Item.java b/src/com/fourisland/frigidearth/Item.java index 717d09c..1fe4027 100644 --- a/src/com/fourisland/frigidearth/Item.java +++ b/src/com/fourisland/frigidearth/Item.java | |||
@@ -73,6 +73,8 @@ public enum Item | |||
73 | 73 | ||
74 | public boolean useItem() | 74 | public boolean useItem() |
75 | { | 75 | { |
76 | ((MapViewGameState) Main.getGameState()).printMessage("There's nothing to use the key on!"); | ||
77 | |||
76 | return false; | 78 | return false; |
77 | } | 79 | } |
78 | }; | 80 | }; |
diff --git a/src/com/fourisland/frigidearth/Main.java b/src/com/fourisland/frigidearth/Main.java index 09aa273..e7a5d44 100644 --- a/src/com/fourisland/frigidearth/Main.java +++ b/src/com/fourisland/frigidearth/Main.java | |||
@@ -91,6 +91,11 @@ public class Main extends Canvas | |||
91 | render(gameCanvas); | 91 | render(gameCanvas); |
92 | } | 92 | } |
93 | 93 | ||
94 | public static GameState getGameState() | ||
95 | { | ||
96 | return gameState; | ||
97 | } | ||
98 | |||
94 | public static void addRenderable(Renderable renderable) | 99 | public static void addRenderable(Renderable renderable) |
95 | { | 100 | { |
96 | renderables.add(renderable); | 101 | renderables.add(renderable); |
diff --git a/src/com/fourisland/frigidearth/MapViewGameState.java b/src/com/fourisland/frigidearth/MapViewGameState.java index 793fae9..bbfb9ac 100644 --- a/src/com/fourisland/frigidearth/MapViewGameState.java +++ b/src/com/fourisland/frigidearth/MapViewGameState.java | |||
@@ -899,10 +899,27 @@ public class MapViewGameState implements GameState | |||
899 | break; | 899 | break; |
900 | } | 900 | } |
901 | 901 | ||
902 | case KeyEvent.VK_I: | ||
903 | if (Main.currentGame.inventory.isEmpty()) | ||
904 | { | ||
905 | printMessage("You have no items"); | ||
906 | } else { | ||
907 | InventoryOverlay io = new InventoryOverlay(); | ||
908 | Main.addRenderable(io); | ||
909 | Main.addInputable(io); | ||
910 | |||
911 | return; | ||
912 | } | ||
913 | |||
902 | default: | 914 | default: |
903 | return; | 915 | return; |
904 | } | 916 | } |
905 | 917 | ||
918 | tick(); | ||
919 | } | ||
920 | |||
921 | public void tick() | ||
922 | { | ||
906 | // Move mobs | 923 | // Move mobs |
907 | for (Mob mob : mobs) | 924 | for (Mob mob : mobs) |
908 | { | 925 | { |
@@ -1122,7 +1139,7 @@ public class MapViewGameState implements GameState | |||
1122 | return true; | 1139 | return true; |
1123 | } | 1140 | } |
1124 | 1141 | ||
1125 | private void printMessage(String message) | 1142 | public void printMessage(String message) |
1126 | { | 1143 | { |
1127 | String temp = message; | 1144 | String temp = message; |
1128 | 1145 | ||