diff options
author | Pacien TRAN-GIRARD | 2014-05-17 19:39:05 +0200 |
---|---|---|
committer | Pacien TRAN-GIRARD | 2014-05-17 19:41:04 +0200 |
commit | b416d4d7d8a2b42f7a0e8b105a3b6ce14d2a50ae (patch) | |
tree | 799f1353afc513107856baeaa1cbf524edc7583d /src | |
parent | 8fccd229648982ffc13a2dc5a79d4da71713351a (diff) | |
download | esieequest-b416d4d7d8a2b42f7a0e8b105a3b6ce14d2a50ae.tar.gz |
Implement graphical inventory
Diffstat (limited to 'src')
-rw-r--r-- | src/esieequest/controller/commands/DropCommand.java | 2 | ||||
-rw-r--r-- | src/esieequest/controller/commands/TakeCommand.java | 2 | ||||
-rw-r--r-- | src/esieequest/controller/commands/UseCommand.java | 2 | ||||
-rw-r--r-- | src/esieequest/model/Text.java | 2 | ||||
-rw-r--r-- | src/esieequest/model/items/Inventory.java | 2 | ||||
-rw-r--r-- | src/esieequest/view/Viewable.java | 6 | ||||
-rw-r--r-- | src/esieequest/view/app/UserInterface.java | 91 | ||||
-rw-r--r-- | src/esieequest/view/text/TextInterface.java | 8 | ||||
-rw-r--r-- | src/esieequest/view/web/WebInterface.java | 40 | ||||
-rw-r--r-- | src/esieequest/view/web/WebInterface.ui.xml | 17 |
10 files changed, 129 insertions, 43 deletions
diff --git a/src/esieequest/controller/commands/DropCommand.java b/src/esieequest/controller/commands/DropCommand.java index 09b2394..b253d98 100644 --- a/src/esieequest/controller/commands/DropCommand.java +++ b/src/esieequest/controller/commands/DropCommand.java | |||
@@ -31,6 +31,8 @@ public class DropCommand implements Executable { | |||
31 | final Item item = game.getPlayer().getInventory().takeItem(itemName); | 31 | final Item item = game.getPlayer().getInventory().takeItem(itemName); |
32 | game.getPlayer().getCurrentSide().getInventory().putItem(item); | 32 | game.getPlayer().getCurrentSide().getInventory().putItem(item); |
33 | 33 | ||
34 | view.updateInventory(game.getPlayer().getInventory()); | ||
35 | |||
34 | } | 36 | } |
35 | 37 | ||
36 | } | 38 | } |
diff --git a/src/esieequest/controller/commands/TakeCommand.java b/src/esieequest/controller/commands/TakeCommand.java index 8b8a461..f83c218 100644 --- a/src/esieequest/controller/commands/TakeCommand.java +++ b/src/esieequest/controller/commands/TakeCommand.java | |||
@@ -47,6 +47,8 @@ public class TakeCommand implements Executable { | |||
47 | game.getPlayer().getCurrentRoom().removeItem(item); | 47 | game.getPlayer().getCurrentRoom().removeItem(item); |
48 | game.getPlayer().getInventory().putItem(item); | 48 | game.getPlayer().getInventory().putItem(item); |
49 | 49 | ||
50 | view.updateInventory(game.getPlayer().getInventory()); | ||
51 | |||
50 | } | 52 | } |
51 | 53 | ||
52 | } | 54 | } |
diff --git a/src/esieequest/controller/commands/UseCommand.java b/src/esieequest/controller/commands/UseCommand.java index 00fc234..3328c7c 100644 --- a/src/esieequest/controller/commands/UseCommand.java +++ b/src/esieequest/controller/commands/UseCommand.java | |||
@@ -15,7 +15,7 @@ public class UseCommand implements Executable { | |||
15 | @Override | 15 | @Override |
16 | public void execute(final String argument, final Game game, final Viewable view) { | 16 | public void execute(final String argument, final Game game, final Viewable view) { |
17 | 17 | ||
18 | final String itemName = argument; | 18 | final String itemName = argument.toLowerCase(); |
19 | 19 | ||
20 | if (itemName == null) { | 20 | if (itemName == null) { |
21 | view.echo(Text.NO_ITEM_SPECIFIED.getText()); | 21 | view.echo(Text.NO_ITEM_SPECIFIED.getText()); |
diff --git a/src/esieequest/model/Text.java b/src/esieequest/model/Text.java index 1b47c6f..d46b4b1 100644 --- a/src/esieequest/model/Text.java +++ b/src/esieequest/model/Text.java | |||
@@ -53,6 +53,8 @@ public enum Text { | |||
53 | INVENTORY_WEIGHT_PREFIX("Total inventory weight: "), | 53 | INVENTORY_WEIGHT_PREFIX("Total inventory weight: "), |
54 | INVENTORY_WEIGHT_SUFFIX("."), | 54 | INVENTORY_WEIGHT_SUFFIX("."), |
55 | 55 | ||
56 | INVENTORY_EMPTY("Your inventory is empty."), | ||
57 | |||
56 | // formatting | 58 | // formatting |
57 | LIST_SEPARATOR(", "), | 59 | LIST_SEPARATOR(", "), |
58 | NEW_LINE("\n"), | 60 | NEW_LINE("\n"), |
diff --git a/src/esieequest/model/items/Inventory.java b/src/esieequest/model/items/Inventory.java index 68d1838..a4a0e84 100644 --- a/src/esieequest/model/items/Inventory.java +++ b/src/esieequest/model/items/Inventory.java | |||
@@ -4,6 +4,7 @@ import java.util.ArrayList; | |||
4 | import java.util.Arrays; | 4 | import java.util.Arrays; |
5 | import java.util.Collection; | 5 | import java.util.Collection; |
6 | 6 | ||
7 | import lombok.Getter; | ||
7 | import net.pacien.util.IntrinsicMap; | 8 | import net.pacien.util.IntrinsicMap; |
8 | 9 | ||
9 | import org.json.simple.JSONArray; | 10 | import org.json.simple.JSONArray; |
@@ -21,6 +22,7 @@ import esieequest.model.Text; | |||
21 | */ | 22 | */ |
22 | public class Inventory implements SerialisableList { | 23 | public class Inventory implements SerialisableList { |
23 | 24 | ||
25 | @Getter | ||
24 | private final IntrinsicMap<String, Item> items; | 26 | private final IntrinsicMap<String, Item> items; |
25 | 27 | ||
26 | /** | 28 | /** |
diff --git a/src/esieequest/view/Viewable.java b/src/esieequest/view/Viewable.java index d2aeaff..0b23b8c 100644 --- a/src/esieequest/view/Viewable.java +++ b/src/esieequest/view/Viewable.java | |||
@@ -1,10 +1,8 @@ | |||
1 | package esieequest.view; | 1 | package esieequest.view; |
2 | 2 | ||
3 | import java.util.HashMap; | ||
4 | |||
5 | import esieequest.controller.GameEngine; | 3 | import esieequest.controller.GameEngine; |
6 | import esieequest.model.events.Quest; | 4 | import esieequest.model.events.Quest; |
7 | import esieequest.model.items.SimpleItem; | 5 | import esieequest.model.items.Inventory; |
8 | import esieequest.model.map.Direction; | 6 | import esieequest.model.map.Direction; |
9 | import esieequest.model.map.Room; | 7 | import esieequest.model.map.Room; |
10 | import esieequest.model.map.Side; | 8 | import esieequest.model.map.Side; |
@@ -73,6 +71,6 @@ public interface Viewable { | |||
73 | * @param items | 71 | * @param items |
74 | * the items | 72 | * the items |
75 | */ | 73 | */ |
76 | public void updateInventory(final HashMap<String, SimpleItem> items); | 74 | public void updateInventory(final Inventory inventory); |
77 | 75 | ||
78 | } | 76 | } |
diff --git a/src/esieequest/view/app/UserInterface.java b/src/esieequest/view/app/UserInterface.java index f492090..c4e072d 100644 --- a/src/esieequest/view/app/UserInterface.java +++ b/src/esieequest/view/app/UserInterface.java | |||
@@ -4,6 +4,7 @@ import java.awt.BorderLayout; | |||
4 | import java.awt.Dimension; | 4 | import java.awt.Dimension; |
5 | import java.awt.Font; | 5 | import java.awt.Font; |
6 | import java.awt.Graphics; | 6 | import java.awt.Graphics; |
7 | import java.awt.GridLayout; | ||
7 | import java.awt.event.ActionEvent; | 8 | import java.awt.event.ActionEvent; |
8 | import java.awt.event.ActionListener; | 9 | import java.awt.event.ActionListener; |
9 | import java.awt.image.BufferedImage; | 10 | import java.awt.image.BufferedImage; |
@@ -12,6 +13,7 @@ import java.util.HashMap; | |||
12 | 13 | ||
13 | import javax.swing.JButton; | 14 | import javax.swing.JButton; |
14 | import javax.swing.JLabel; | 15 | import javax.swing.JLabel; |
16 | import javax.swing.JLayeredPane; | ||
15 | import javax.swing.JPanel; | 17 | import javax.swing.JPanel; |
16 | import javax.swing.JTextField; | 18 | import javax.swing.JTextField; |
17 | import javax.swing.JTextPane; | 19 | import javax.swing.JTextPane; |
@@ -21,8 +23,10 @@ import com.wordpress.tipsforjava.swing.StretchIcon; | |||
21 | 23 | ||
22 | import esieequest.controller.GameEngine; | 24 | import esieequest.controller.GameEngine; |
23 | import esieequest.controller.commands.Command; | 25 | import esieequest.controller.commands.Command; |
26 | import esieequest.model.Text; | ||
24 | import esieequest.model.events.Quest; | 27 | import esieequest.model.events.Quest; |
25 | import esieequest.model.items.SimpleItem; | 28 | import esieequest.model.items.Inventory; |
29 | import esieequest.model.items.Item; | ||
26 | import esieequest.model.map.Direction; | 30 | import esieequest.model.map.Direction; |
27 | import esieequest.model.map.Orientation; | 31 | import esieequest.model.map.Orientation; |
28 | import esieequest.model.map.Room; | 32 | import esieequest.model.map.Room; |
@@ -39,6 +43,8 @@ abstract class UserInterface implements Viewable, ActionListener { | |||
39 | private GameEngine gameEngine; | 43 | private GameEngine gameEngine; |
40 | 44 | ||
41 | private JPanel layout; | 45 | private JPanel layout; |
46 | private JPanel consolePanel; | ||
47 | private JPanel inventoryPanel; | ||
42 | 48 | ||
43 | private JTextPane questTextPane; | 49 | private JTextPane questTextPane; |
44 | private JTextPane infoTextPane; | 50 | private JTextPane infoTextPane; |
@@ -110,20 +116,28 @@ abstract class UserInterface implements Viewable, ActionListener { | |||
110 | this.layout.add(userPanel, BorderLayout.SOUTH); | 116 | this.layout.add(userPanel, BorderLayout.SOUTH); |
111 | userPanel.setLayout(new BorderLayout(0, 0)); | 117 | userPanel.setLayout(new BorderLayout(0, 0)); |
112 | 118 | ||
113 | final JPanel dispPanel = new JPanel(); | 119 | final JLayeredPane dispPanel = new JLayeredPane(); |
114 | dispPanel.setBorder(new EmptyBorder(5, 5, 5, 0)); | 120 | dispPanel.setBorder(new EmptyBorder(5, 5, 5, 0)); |
115 | userPanel.add(dispPanel, BorderLayout.CENTER); | 121 | userPanel.add(dispPanel, BorderLayout.CENTER); |
116 | dispPanel.setLayout(new BorderLayout(0, 0)); | 122 | dispPanel.setLayout(new BorderLayout(0, 0)); |
117 | 123 | ||
124 | this.consolePanel = new JPanel(); | ||
125 | dispPanel.add(this.consolePanel, BorderLayout.CENTER); | ||
126 | this.consolePanel.setLayout(new BorderLayout(0, 0)); | ||
127 | |||
118 | this.infoTextPane = new JTextPane(); | 128 | this.infoTextPane = new JTextPane(); |
129 | this.consolePanel.add(this.infoTextPane, BorderLayout.CENTER); | ||
119 | this.infoTextPane.setEditable(false); | 130 | this.infoTextPane.setEditable(false); |
120 | this.infoTextPane.setText("Welcome to ESIEEquest!"); | 131 | this.infoTextPane.setText("Welcome to ESIEEquest!"); |
121 | dispPanel.add(this.infoTextPane); | ||
122 | 132 | ||
123 | this.inputField = new JTextField(); | 133 | this.inputField = new JTextField(); |
124 | dispPanel.add(this.inputField, BorderLayout.SOUTH); | 134 | this.consolePanel.add(this.inputField, BorderLayout.SOUTH); |
125 | this.inputField.setColumns(10); | 135 | this.inputField.setColumns(10); |
126 | 136 | ||
137 | this.inventoryPanel = new JPanel(); | ||
138 | dispPanel.add(this.inventoryPanel, BorderLayout.NORTH); | ||
139 | this.inventoryPanel.setLayout(new GridLayout(4, 3, 0, 0)); | ||
140 | |||
127 | final JPanel controlPanel = new JPanel(); | 141 | final JPanel controlPanel = new JPanel(); |
128 | controlPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); | 142 | controlPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); |
129 | userPanel.add(controlPanel, BorderLayout.EAST); | 143 | userPanel.add(controlPanel, BorderLayout.EAST); |
@@ -142,7 +156,7 @@ abstract class UserInterface implements Viewable, ActionListener { | |||
142 | 156 | ||
143 | final JButton inventoryButton = new JButton("⇱"); | 157 | final JButton inventoryButton = new JButton("⇱"); |
144 | inventoryButton.setFont(font); | 158 | inventoryButton.setFont(font); |
145 | inventoryButton.setToolTipText("Use item"); | 159 | inventoryButton.setToolTipText("Open inventory"); |
146 | topControlPanel.add(inventoryButton, BorderLayout.WEST); | 160 | topControlPanel.add(inventoryButton, BorderLayout.WEST); |