From e37dc7b99ffa2c518bb1ab8a5d46074587d1c911 Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Sun, 18 May 2014 14:44:41 +0200 Subject: Refactor graphical and web interfaces --- src/esieequest/controller/GameEngine.java | 2 +- .../controller/commands/AleaCommand.java | 6 +- src/esieequest/controller/commands/Command.java | 2 +- src/esieequest/controller/commands/DoCommand.java | 2 +- .../controller/commands/DropCommand.java | 4 +- src/esieequest/controller/commands/GoCommand.java | 6 +- .../controller/commands/LoadCommand.java | 4 +- .../controller/commands/LookCommand.java | 2 +- src/esieequest/controller/commands/NewCommand.java | 2 +- .../controller/commands/QuitCommand.java | 2 +- .../controller/commands/TakeCommand.java | 6 +- .../controller/commands/TalkCommand.java | 2 +- .../controller/commands/TurnCommand.java | 2 +- src/esieequest/controller/commands/UseCommand.java | 4 +- src/esieequest/controller/utils/ListUtils.java | 2 +- src/esieequest/model/Text.java | 49 +++- src/esieequest/model/doors/LockedDoor.java | 2 +- src/esieequest/model/items/Beamer.java | 4 +- src/esieequest/model/items/Inventory.java | 4 +- src/esieequest/model/items/Item.java | 2 +- src/esieequest/model/items/Note.java | 2 +- src/esieequest/model/items/SimpleItem.java | 2 +- src/esieequest/model/map/Room.java | 8 +- src/esieequest/view/app/UserInterface.java | 325 ++++++++++++--------- src/esieequest/view/text/TextInterface.java | 2 +- src/esieequest/view/web/WebInterface.java | 51 +++- src/esieequest/view/web/WebInterface.ui.xml | 35 +-- 27 files changed, 308 insertions(+), 226 deletions(-) diff --git a/src/esieequest/controller/GameEngine.java b/src/esieequest/controller/GameEngine.java index df83384..8e53888 100644 --- a/src/esieequest/controller/GameEngine.java +++ b/src/esieequest/controller/GameEngine.java @@ -67,7 +67,7 @@ public class GameEngine { final Command command = input.getCommand(); if (command == null) { - this.view.echo(Text.UNKNOWN_COMMAND.getText()); + this.view.echo(Text.UNKNOWN_COMMAND.toString()); return; } diff --git a/src/esieequest/controller/commands/AleaCommand.java b/src/esieequest/controller/commands/AleaCommand.java index 33f4deb..ff73537 100644 --- a/src/esieequest/controller/commands/AleaCommand.java +++ b/src/esieequest/controller/commands/AleaCommand.java @@ -24,12 +24,12 @@ public class AleaCommand implements Executable { try { destinationRoom = Room.valueOf(forcedRoomName.toUpperCase()); } catch (final Exception exception) { - view.echo(Text.NO_SUCH_ROOM.getText()); + view.echo(Text.NO_SUCH_ROOM.toString()); return; } - view.echo(Text.ALEA_OVERRIDE_ENABLED.getText()); + view.echo(Text.ALEA_OVERRIDE_ENABLED.toString()); } else { - view.echo(Text.ALEA_OVERRIDE_DISABLED.getText()); + view.echo(Text.ALEA_OVERRIDE_DISABLED.toString()); } TransporterDoor.forceDestination(destinationRoom); diff --git a/src/esieequest/controller/commands/Command.java b/src/esieequest/controller/commands/Command.java index 094b0cf..ca8909c 100644 --- a/src/esieequest/controller/commands/Command.java +++ b/src/esieequest/controller/commands/Command.java @@ -94,7 +94,7 @@ public enum Command { * @return a String listing all the names of the Command-s */ public static String listCommandsNamesString() { - return ListUtils.listToString(Command.listCommandsNames(), Text.HELP_PREFIX.getText(), null, Text.HELP_SUFFIX.getText()); + return ListUtils.listToString(Command.listCommandsNames(), Text.HELP_PREFIX.toString(), null, Text.HELP_SUFFIX.toString()); } } diff --git a/src/esieequest/controller/commands/DoCommand.java b/src/esieequest/controller/commands/DoCommand.java index 95269de..646ac2a 100644 --- a/src/esieequest/controller/commands/DoCommand.java +++ b/src/esieequest/controller/commands/DoCommand.java @@ -28,7 +28,7 @@ public class DoCommand implements Executable { return; } - view.echo(Text.NOTHING_TO_DO.getText()); + view.echo(Text.NOTHING_TO_DO.toString()); } diff --git a/src/esieequest/controller/commands/DropCommand.java b/src/esieequest/controller/commands/DropCommand.java index b253d98..4e6f877 100644 --- a/src/esieequest/controller/commands/DropCommand.java +++ b/src/esieequest/controller/commands/DropCommand.java @@ -19,12 +19,12 @@ public class DropCommand implements Executable { final String itemName = argument; if (itemName == null) { - view.echo(Text.NO_ITEM_SPECIFIED.getText()); + view.echo(Text.NO_ITEM_SPECIFIED.toString()); return; } if (!game.getPlayer().getInventory().hasItem(itemName)) { - view.echo(Text.NO_SUCH_ITEM.getText()); + view.echo(Text.NO_SUCH_ITEM.toString()); return; } diff --git a/src/esieequest/controller/commands/GoCommand.java b/src/esieequest/controller/commands/GoCommand.java index 1c528fa..f536f64 100644 --- a/src/esieequest/controller/commands/GoCommand.java +++ b/src/esieequest/controller/commands/GoCommand.java @@ -22,14 +22,14 @@ public class GoCommand implements Executable { try { direction = Direction.valueOf(argument.toUpperCase()); } catch (final Exception exception) { - view.echo(Text.NO_SUCH_DIRECTION.getText()); + view.echo(Text.NO_SUCH_DIRECTION.toString()); return; } final Door door = game.getPlayer().getCurrentRoom().getSide(direction).getDoor(); if (door == null) { - view.echo(Text.NO_DOOR.getText()); + view.echo(Text.NO_DOOR.toString()); return; } @@ -43,7 +43,7 @@ public class GoCommand implements Executable { // handle challenge mode if (game.getPlayer().walk()) { - view.echo(Text.CHALLENGE_FAILED.getText()); + view.echo(Text.CHALLENGE_FAILED.toString()); view.disable(); } diff --git a/src/esieequest/controller/commands/LoadCommand.java b/src/esieequest/controller/commands/LoadCommand.java index 807b3b3..8d6fd29 100644 --- a/src/esieequest/controller/commands/LoadCommand.java +++ b/src/esieequest/controller/commands/LoadCommand.java @@ -24,7 +24,7 @@ public class LoadCommand implements Executable { try { datas = (JSONObject) JSONValue.parseWithException(jsonString); } catch (final ParseException e) { - view.echo(Text.PARSING_ERROR_PREFIX.getText() + e.getMessage() + Text.PARSING_ERROR_SUFFIX.getText()); + view.echo(Text.PARSING_ERROR_PREFIX.toString() + e.getMessage() + Text.PARSING_ERROR_SUFFIX.toString()); return; } @@ -32,7 +32,7 @@ public class LoadCommand implements Executable { game.newGame(false, false); game.deserialise(datas); } catch (final Exception e) { - view.echo(Text.DESERIALISING_ERROR_PREFIX.getText() + e.getMessage() + Text.DESERIALISING_ERROR_SUFFIX.getText()); + view.echo(Text.DESERIALISING_ERROR_PREFIX.toString() + e.getMessage() + Text.DESERIALISING_ERROR_SUFFIX.toString()); e.printStackTrace(); return; } diff --git a/src/esieequest/controller/commands/LookCommand.java b/src/esieequest/controller/commands/LookCommand.java index 5006a66..ece4ddc 100644 --- a/src/esieequest/controller/commands/LookCommand.java +++ b/src/esieequest/controller/commands/LookCommand.java @@ -23,7 +23,7 @@ public class LookCommand implements Executable { informations.add(game.getPlayer().getCurrentRoom().getInformations()); informations.add(Text.DIRECTION_PREFIX + game.getPlayer().getCurrentDirection().name().toLowerCase() + Text.DIRECTION_SUFFIX); - view.echo(Joiner.on(Text.NEW_LINE.getText()).join(informations)); + view.echo(Joiner.on(Text.NEW_LINE.toString()).join(informations)); } } diff --git a/src/esieequest/controller/commands/NewCommand.java b/src/esieequest/controller/commands/NewCommand.java index 7b510e4..4ce45d0 100644 --- a/src/esieequest/controller/commands/NewCommand.java +++ b/src/esieequest/controller/commands/NewCommand.java @@ -25,7 +25,7 @@ public class NewCommand implements Executable { view.enable(); view.updateLocation(game.getPlayer().getCurrentRoom(), game.getPlayer().getCurrentDirection(), game.getPlayer().getCurrentSide()); - view.echo(Text.WELCOME.getText()); + view.echo(Text.WELCOME.toString()); } diff --git a/src/esieequest/controller/commands/QuitCommand.java b/src/esieequest/controller/commands/QuitCommand.java index be53589..4453597 100644 --- a/src/esieequest/controller/commands/QuitCommand.java +++ b/src/esieequest/controller/commands/QuitCommand.java @@ -14,7 +14,7 @@ public class QuitCommand implements Executable { @Override public void execute(final String argument, final Game game, final Viewable view) { - view.echo(Text.QUIT.getText()); + view.echo(Text.QUIT.toString()); view.disable(); } diff --git a/src/esieequest/controller/commands/TakeCommand.java b/src/esieequest/controller/commands/TakeCommand.java index f83c218..4e615c7 100644 --- a/src/esieequest/controller/commands/TakeCommand.java +++ b/src/esieequest/controller/commands/TakeCommand.java @@ -23,14 +23,14 @@ public class TakeCommand implements Executable { final String itemName = argument; final Room currentRoom = game.getPlayer().getCurrentRoom(); if (!currentRoom.hasItem(itemName)) { - view.echo(Text.NO_SUCH_ITEM.getText()); + view.echo(Text.NO_SUCH_ITEM.toString()); return; } item = currentRoom.getItem(itemName); } else { final Side currentSide = game.getPlayer().getCurrentSide(); if (currentSide.getInventory().getSize() != 1) { - view.echo(Text.NO_ITEM.getText()); + view.echo(Text.NO_ITEM.toString()); return; } item = currentSide.getInventory().getItem(); @@ -40,7 +40,7 @@ public class TakeCommand implements Executable { final int maximumWeight = game.getPlayer().getInventoryWeightLimit(); final int futureWeight = game.getPlayer().getInventory().getTotalWeight() + item.getWeight(); if (futureWeight > maximumWeight) { - view.echo(Text.INVENTORY_FULL.getText()); + view.echo(Text.INVENTORY_FULL.toString()); return; } diff --git a/src/esieequest/controller/commands/TalkCommand.java b/src/esieequest/controller/commands/TalkCommand.java index b3168ae..228f954 100644 --- a/src/esieequest/controller/commands/TalkCommand.java +++ b/src/esieequest/controller/commands/TalkCommand.java @@ -15,7 +15,7 @@ public class TalkCommand implements Executable { public void execute(final String argument, final Game game, final Viewable view) { if (!game.getPlayer().getCurrentSide().hasCharacter()) { - view.echo(Text.NO_CHARACTER.getText()); + view.echo(Text.NO_CHARACTER.toString()); return; } diff --git a/src/esieequest/controller/commands/TurnCommand.java b/src/esieequest/controller/commands/TurnCommand.java index e28ad2c..d4b6ee9 100644 --- a/src/esieequest/controller/commands/TurnCommand.java +++ b/src/esieequest/controller/commands/TurnCommand.java @@ -22,7 +22,7 @@ public class TurnCommand implements Executable { try { orientation = Orientation.valueOf(argument.toUpperCase()); } catch (final Exception exception) { - view.echo(Text.NO_SUCH_DIRECTION.getText()); + view.echo(Text.NO_SUCH_DIRECTION.toString()); return; } diff --git a/src/esieequest/controller/commands/UseCommand.java b/src/esieequest/controller/commands/UseCommand.java index 3328c7c..c90bb8f 100644 --- a/src/esieequest/controller/commands/UseCommand.java +++ b/src/esieequest/controller/commands/UseCommand.java @@ -18,12 +18,12 @@ public class UseCommand implements Executable { final String itemName = argument.toLowerCase(); if (itemName == null) { - view.echo(Text.NO_ITEM_SPECIFIED.getText()); + view.echo(Text.NO_ITEM_SPECIFIED.toString()); return; } if (!game.getPlayer().getInventory().hasItem(itemName)) { - view.echo(Text.NO_SUCH_ITEM.getText()); + view.echo(Text.NO_SUCH_ITEM.toString()); return; } diff --git a/src/esieequest/controller/utils/ListUtils.java b/src/esieequest/controller/utils/ListUtils.java index cb90edc..c904390 100644 --- a/src/esieequest/controller/utils/ListUtils.java +++ b/src/esieequest/controller/utils/ListUtils.java @@ -33,7 +33,7 @@ public class ListUtils { if (list.isEmpty()) { str.append(empty); } else { - str.append(Joiner.on(Text.LIST_SEPARATOR.getText()).join(list)); + str.append(Joiner.on(Text.LIST_SEPARATOR.toString()).join(list)); } str.append(suffix); diff --git a/src/esieequest/model/Text.java b/src/esieequest/model/Text.java index a72ff4a..d70b86f 100644 --- a/src/esieequest/model/Text.java +++ b/src/esieequest/model/Text.java @@ -9,6 +9,43 @@ public enum Text { // @formatter:off + // interface + DEFAULT_CONSOLE("Want to start a new game? Click on the 'New' button at the top left corner."), + DEFAULT_QUEST_TITLE("ESIEEquest"), + CURRENT_QUEST_PREFIX("Current quest: "), + + NOT_IMPLEMENTED("Not implementer... Yet."), + + NEW_GAME_BUTTON("New"), + NEW_GAME_TOOLTIP("New game"), + + LOAD_GAME_BUTTON("Load"), + LOAD_GAME_TOOLTIP("Load a game"), + + SAVE_GAME_BUTTON("Save"), + SAVE_GAME_TOOLTIP("Save the current game"), + + TOGGLE_SOUND_BUTTON("Sound"), + TOGGLE_SOUND_TOOLTIP("Toggle sound"), + + GO_FORWARD_BUTTON("↥"), + GO_FORWARD_TOOLTIP("Go forward"), + + GO_BACK_BUTTON("↧"), + GO_BACK_TOOLTIP("Go back"), + + TURN_LEFT_BUTTON("↰"), + TURN_LEFT_TOOLTIP("Turn left"), + + TURN_RIGHT_BUTTON("↱"), + TURN_RIGHT_TOOLTIP("Turn right"), + + INVENTORY_BUTTON("⇱"), + INVENTORY_TOOLTIP("Open inventory"), + + ACTION_BUTTON("⇲"), + ACTION_TOOLTIP("Talk/Take item"), + // messages WELCOME("Welcome to ESIEEquest! ESIEEquest is a new, amazingly boring adventure game."), CHALLENGE_FAILED("Challenge failed: you died from exhaustion..."), @@ -25,8 +62,6 @@ public enum Text { BEAMER_ROOM_MEMORISED("The coordinates of the current location have been memorised: "), BEAMER_TELEPORTED("Zap! You have reached your destination. The device's memory has been cleared."), - CURRENT_QUEST_PREFIX("Current quest: "), - // objects NOTE_PREFIX("It is written: "), NOTE_ATHANASE("In case of logical trouble: find Athanase, office #3254."), @@ -62,6 +97,7 @@ public enum Text { // formatting LIST_SEPARATOR(", "), FILENAME_SEPARATOR("_"), + COMMAND_SEPARATOR(" "), NEW_LINE("\n"), SPACE(" "), @@ -98,16 +134,9 @@ public enum Text { this.text = text; } - /** - * @return the text - */ - public String getText() { - return this.text; - } - @Override public String toString() { - return this.getText(); + return this.text; } } diff --git a/src/esieequest/model/doors/LockedDoor.java b/src/esieequest/model/doors/LockedDoor.java index 868623a..1fbbe6f 100644 --- a/src/esieequest/model/doors/LockedDoor.java +++ b/src/esieequest/model/doors/LockedDoor.java @@ -32,7 +32,7 @@ public class LockedDoor extends Door { @Override public boolean cross(final Game game, final Viewable view) { if (!this.isAuthorised(game.getPlayer())) { - view.echo(Text.DOOR_LOCKED.getText()); + view.echo(Text.DOOR_LOCKED.toString()); return false; } return super.cross(game, view); diff --git a/src/esieequest/model/items/Beamer.java b/src/esieequest/model/items/Beamer.java index 49e75a4..b452e87 100644 --- a/src/esieequest/model/items/Beamer.java +++ b/src/esieequest/model/items/Beamer.java @@ -35,10 +35,10 @@ public class Beamer extends SimpleItem { public void use(final Game game, final Viewable view) { if (this.room == null) { this.room = game.getPlayer().getCurrentRoom(); - view.echo(Text.BEAMER_ROOM_MEMORISED.getText() + this.room.hashCode()); + view.echo(Text.BEAMER_ROOM_MEMORISED.toString() + this.room.hashCode()); } else { game.getPlayer().goToRoom(this.room); - view.echo(Text.BEAMER_TELEPORTED.getText()); + view.echo(Text.BEAMER_TELEPORTED.toString()); this.room = null; } } diff --git a/src/esieequest/model/items/Inventory.java b/src/esieequest/model/items/Inventory.java index a4a0e84..53339f5 100644 --- a/src/esieequest/model/items/Inventory.java +++ b/src/esieequest/model/items/Inventory.java @@ -112,7 +112,7 @@ public class Inventory implements SerialisableList { * @return the list of the Item-s in a String */ public String listItemsNamesString() { - return ListUtils.listToString(new ArrayList(this.items.keySet()), Text.INVENTORY_PREFIX.getText(), Text.ITEMS_NO_ITEM.getText(), Text.INVENTORY_SUFFIX.getText()); + return ListUtils.listToString(new ArrayList(this.items.keySet()), Text.INVENTORY_PREFIX.toString(), Text.ITEMS_NO_ITEM.toString(), Text.INVENTORY_SUFFIX.toString()); } /** @@ -179,7 +179,7 @@ public class Inventory implements SerialisableList { * @return informations about the inventory weight */ public String getWeightString() { - return Text.INVENTORY_WEIGHT_PREFIX.getText() + this.getTotalWeight() + Text.INVENTORY_WEIGHT_SUFFIX.getText(); + return Text.INVENTORY_WEIGHT_PREFIX.toString() + this.getTotalWeight() + Text.INVENTORY_WEIGHT_SUFFIX.toString(); } /** diff --git a/src/esieequest/model/items/Item.java b/src/esieequest/model/items/Item.java index a3c4f8f..434d9b2 100644 --- a/src/esieequest/model/items/Item.java +++ b/src/esieequest/model/items/Item.java @@ -25,7 +25,7 @@ public enum Item implements Mappable, SerialisableObject { BEAMER(new Beamer("Beamer")), // scenario - NOTE(new Note("Note", Text.NOTE_ATHANASE.getText())), + NOTE(new Note("Note", Text.NOTE_ATHANASE.toString())), BANANA(new SimpleItem("Banana", 0, false)), TRANSPONDER(new Transponder()), DISK(new SimpleItem("Bootloader disk", 0, false)), diff --git a/src/esieequest/model/items/Note.java b/src/esieequest/model/items/Note.java index aac5cea..28c2f53 100644 --- a/src/esieequest/model/items/Note.java +++ b/src/esieequest/model/items/Note.java @@ -28,7 +28,7 @@ public class Note extends SimpleItem { @Override public void use(final Game game, final Viewable view) { - view.echo(Text.NOTE_PREFIX.getText() + this.text); + view.echo(Text.NOTE_PREFIX.toString() + this.text); } } diff --git a/src/esieequest/model/items/SimpleItem.java b/src/esieequest/model/items/SimpleItem.java index e33820f..7eb99e3 100644 --- a/src/esieequest/model/items/SimpleItem.java +++ b/src/esieequest/model/items/SimpleItem.java @@ -62,7 +62,7 @@ public class SimpleItem implements SerialisableObject { * the View */ public void use(final Game game, final Viewable view) { - view.echo(Text.NO_USE.getText()); + view.echo(Text.NO_USE.toString()); } @Override diff --git a/src/esieequest/model/map/Room.java b/src/esieequest/model/map/Room.java index e335a92..4fceacd 100644 --- a/src/esieequest/model/map/Room.java +++ b/src/esieequest/model/map/Room.java @@ -210,11 +210,11 @@ public enum Room implements SerialisableObject { final ArrayList informations = new ArrayList(); informations.add(Text.LOCATION_PREFIX + this.getDescription() + Text.LOCATION_SUFFIX); - informations.add(ListUtils.listToString(this.listExitsDirectionsNames(), Text.EXITS_PREFIX.getText(), Text.EXITS_NO_EXIT.getText(), Text.EXITS_SUFFIX.getText())); - informations.add(ListUtils.listToString(this.listItemsNames(), Text.ITEMS_PREFIX.getText(), Text.ITEMS_NO_ITEM.getText(), Text.ITEMS_SUFFIX.getText())); - informations.add(ListUtils.listToString(this.listCharactersNames(), Text.CHARACTERS_PREFIX.getText(), Text.CHARACTERS_NO_CHARACTER.getText(), Text.CHARACTERS_SUFFIX.getText())); + informations.add(ListUtils.listToString(this.listExitsDirectionsNames(), Text.EXITS_PREFIX.toString(), Text.EXITS_NO_EXIT.toString(), Text.EXITS_SUFFIX.toString())); + informations.add(ListUtils.listToString(this.listItemsNames(), Text.ITEMS_PREFIX.toString(), Text.ITEMS_NO_ITEM.toString(), Text.ITEMS_SUFFIX.toString())); + informations.add(ListUtils.listToString(this.listCharactersNames(), Text.CHARACTERS_PREFIX.toString(), Text.CHARACTERS_NO_CHARACTER.toString(), Text.CHARACTERS_SUFFIX.toString())); - return Joiner.on(Text.SPACE.getText()).join(informations); + return Joiner.on(Text.SPACE.toString()).join(informations); } /** diff --git a/src/esieequest/view/app/UserInterface.java b/src/esieequest/view/app/UserInterface.java index f25a233..1d73e79 100644 --- a/src/esieequest/view/app/UserInterface.java +++ b/src/esieequest/view/app/UserInterface.java @@ -5,15 +5,16 @@ import java.awt.Dimension; import java.awt.Font; import java.awt.Graphics; import java.awt.GridLayout; +import java.awt.Image; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.image.BufferedImage; import java.net.URL; -import java.util.HashMap; +import java.util.HashSet; +import java.util.Set; import javax.swing.JButton; import javax.swing.JLabel; -import javax.swing.JLayeredPane; import javax.swing.JPanel; import javax.swing.JTextField; import javax.swing.JTextPane; @@ -37,28 +38,62 @@ import esieequest.view.Viewable; * The Swing based graphical user interface. * * @author Pacien TRAN-GIRARD + * @author Benoît LUBRANO DI SBARAGLIONE */ abstract class UserInterface implements Viewable, ActionListener { + private static final String ILLUSTRATION_EXT = ".html"; + private GameEngine gameEngine; private JPanel layout; - private JPanel consolePanel; - private JPanel inventoryPanel; private JTextPane questTextPane; - private JTextPane infoTextPane; private JLabel imageLabel; - private HashMap gameButtons; - private HashMap controlButtons; + private JPanel menuPanel; + private JPanel questPanel; + private JPanel gamePanel; + + private final Set gameButtons; + + private JButton newButton; + private JButton soundButton; + private JPanel filePanel; + private JButton saveButton; + + private JPanel imagePanel; + + private JPanel userPanel; + private JPanel dispPanel; + + private JPanel consolePanel; + private JPanel inventoryPanel; + + private JPanel controlPanel; + private JPanel topControlPanel; + private JPanel bottomControlPanel; + + private JTextPane infoTextPane; private JTextField inputField; + private final Set controlButtons; + + private JButton forwardButton; + private JButton inventoryButton; + private JButton actionButton; + private JButton backButton; + private JButton leftButton; + private JButton rightButton; + /** * The default constructor. */ public UserInterface() { + this.gameButtons = new HashSet<>(); + this.controlButtons = new HashSet<>(); + this.buildUI(); this.setActionListener(this); this.setControlsState(false); @@ -68,161 +103,150 @@ abstract class UserInterface implements Viewable, ActionListener { * Creates the interface widgets. */ private void buildUI() { + + // main window this.layout = new JPanel(); this.layout.setLayout(new BorderLayout(0, 0)); - final JPanel menuPanel = new JPanel(); - this.layout.add(menuPanel, BorderLayout.NORTH); - menuPanel.setLayout(new BorderLayout(0, 0)); + // top bar + this.menuPanel = new JPanel(); + this.layout.add(this.menuPanel, BorderLayout.NORTH); + this.menuPanel.setLayout(new BorderLayout(0, 0)); - final JPanel questPanel = new JPanel(); - menuPanel.add(questPanel, BorderLayout.CENTER); + this.questPanel = new JPanel(); + this.menuPanel.add(this.questPanel, BorderLayout.CENTER); this.questTextPane = new JTextPane(); this.questTextPane.setEditable(false); - this.questTextPane.setText("ESIEEquest"); - questPanel.add(this.questTextPane); + this.questTextPane.setText(Text.DEFAULT_QUEST_TITLE.toString()); + this.questPanel.add(this.questTextPane); - final JPanel gamePanel = new JPanel(); - menuPanel.add(gamePanel, BorderLayout.WEST); + this.gamePanel = new JPanel(); + this.menuPanel.add(this.gamePanel, BorderLayout.WEST); - final JButton newButton = new JButton("New"); - newButton.setToolTipText("New game"); - gamePanel.add(newButton); + this.newButton = new JButton(Text.NEW_GAME_BUTTON.toString()); + this.newButton.setToolTipText(Text.NEW_GAME_TOOLTIP.toString()); + this.newButton.setActionCommand(Command.NEW.name()); + this.gamePanel.add(this.newButton); + this.gameButtons.add(this.newButton); - final JButton soundButton = new JButton("Sound"); - soundButton.setToolTipText("Toggle sound"); - gamePanel.add(soundButton); + this.soundButton = new JButton(Text.TOGGLE_SOUND_BUTTON.toString()); + this.soundButton.setToolTipText(Text.TOGGLE_SOUND_TOOLTIP.toString()); + this.soundButton.setActionCommand(Command.SOUND.name()); + this.gamePanel.add(this.soundButton); + this.gameButtons.add(this.soundButton); - final JPanel filePanel = new JPanel(); - menuPanel.add(filePanel, BorderLayout.EAST); + this.filePanel = new JPanel(); + this.menuPanel.add(this.filePanel, BorderLayout.EAST); - final JButton loadButton = new JButton("Load"); - loadButton.setToolTipText("Load a game"); - filePanel.add(loadButton); + final JButton loadButton = new JButton(Text.LOAD_GAME_BUTTON.toString()); + loadButton.setToolTipText(Text.LOAD_GAME_TOOLTIP.toString()); + loadButton.setActionCommand(Command.LOAD.name()); + this.filePanel.add(loadButton); + this.gameButtons.add(loadButton); - final JButton saveButton = new JButton("Save"); - saveButton.setToolTipText("Save the current game"); - filePanel.add(saveButton); + this.saveButton = new JButton(Text.SAVE_GAME_BUTTON.toString()); + this.saveButton.setToolTipText(Text.SAVE_GAME_TOOLTIP.toString()); + this.saveButton.setActionCommand(Command.SAVE.name()); + this.filePanel.add(this.saveButton); + this.gameButtons.add(this.saveButton); - final JPanel imagePanel = new JPanel(); - this.layout.add(imagePanel, BorderLayout.CENTER); - imagePanel.setLayout(new BorderLayout(0, 0)); + // central illustration panel + this.imagePanel = new JPanel(); + this.layout.add(this.imagePanel, BorderLayout.CENTER); + this.imagePanel.setLayout(new BorderLayout(0, 0)); this.imageLabel = new JLabel(); - imagePanel.add(this.imageLabel); + this.imagePanel.add(this.imageLabel); - final JPanel userPanel = new JPanel(); - this.layout.add(userPanel, BorderLayout.SOUTH); - userPanel.setLayout(new BorderLayout(0, 0)); + // bottom panel + this.userPanel = new JPanel(); + this.layout.add(this.userPanel, BorderLayout.SOUTH); + this.userPanel.setLayout(new BorderLayout(0, 0)); - final JLayeredPane dispPanel = new JLayeredPane(); - dispPanel.setBorder(new EmptyBorder(5, 5, 5, 0)); - userPanel.add(dispPanel, BorderLayout.CENTER); - dispPanel.setLayout(new BorderLayout(0, 0)); + // console and inventory + this.dispPanel = new JPanel(); + this.dispPanel.setBorder(new EmptyBorder(5, 5, 5, 0)); + this.userPanel.add(this.dispPanel, BorderLayout.CENTER); + this.dispPanel.setLayout(new BorderLayout(0, 0)); this.consolePanel = new JPanel(); - dispPanel.add(this.consolePanel, BorderLayout.CENTER); + this.dispPanel.add(this.consolePanel, BorderLayout.CENTER); this.consolePanel.setLayout(new BorderLayout(0, 0)); this.infoTextPane = new JTextPane(); this.consolePanel.add(this.infoTextPane, BorderLayout.CENTER); this.infoTextPane.setEditable(false); - this.infoTextPane.setText("Welcome to ESIEEquest!"); + this.infoTextPane.setText(Text.DEFAULT_CONSOLE.toString()); this.inputField = new JTextField(); this.consolePanel.add(this.inputField, BorderLayout.SOUTH); this.inputField.setColumns(10); this.inventoryPanel = new JPanel(); - dispPanel.add(this.inventoryPanel, BorderLayout.NORTH); + this.dispPanel.add(this.inventoryPanel, BorderLayout.NORTH); this.inventoryPanel.setLayout(new GridLayout(4, 3, 0, 0)); - final JPanel controlPanel = new JPanel(); - controlPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); - userPanel.add(controlPanel, BorderLayout.EAST); - controlPanel.setLayout(new BorderLayout(0, 0)); + final JTextPane emptyTextPane = new JTextPane(); + emptyTextPane.setText(Text.INVENTORY_EMPTY.toString()); + this.inventoryPanel.add(emptyTextPane); + this.inventoryPanel.setVisible(false); - final JPanel topControlPanel = new JPanel(); - controlPanel.add(topControlPanel, BorderLayout.NORTH); - topControlPanel.setLayout(new BorderLayout(0, 0)); + // control buttons + this.controlPanel = new JPanel(); + this.controlPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); + this.userPanel.add(this.controlPanel, BorderLayout.EAST); + this.controlPanel.setLayout(new BorderLayout(0, 0)); + + this.topControlPanel = new JPanel(); + this.controlPanel.add(this.topControlPanel, BorderLayout.NORTH); + this.topControlPanel.setLayout(new BorderLayout(0, 0)); + + this.forwardButton = new JButton(Text.GO_FORWARD_BUTTON.toString()); + this.forwardButton.setToolTipText(Text.GO_FORWARD_TOOLTIP.toString()); + this.forwardButton.setActionCommand(Command.FORWARD.name()); + this.topControlPanel.add(this.forwardButton, BorderLayout.CENTER); + this.controlButtons.add(this.forwardButton); + + this.inventoryButton = new JButton(Text.INVENTORY_BUTTON.toString()); + this.inventoryButton.setToolTipText(Text.INVENTORY_TOOLTIP.toString()); + this.topControlPanel.add(this.inventoryButton, BorderLayout.WEST); + this.controlButtons.add(this.inventoryButton); + + this.actionButton = new JButton(Text.ACTION_BUTTON.toString()); + this.actionButton.setToolTipText(Text.ACTION_TOOLTIP.toString()); + this.actionButton.setActionCommand(Command.DO.name()); + this.topControlPanel.add(this.actionButton, BorderLayout.EAST); + this.controlButtons.add(this.actionButton); + + this.bottomControlPanel = new JPanel(); + this.controlPanel.add(this.bottomControlPanel, BorderLayout.SOUTH); + this.bottomControlPanel.setLayout(new BorderLayout(0, 0)); + + this.backButton = new JButton(Text.GO_BACK_BUTTON.toString()); + this.backButton.setToolTipText(Text.GO_BACK_TOOLTIP.toString()); + this.backButton.setActionCommand(Command.BACK.name()); + this.bottomControlPanel.add(this.backButton, BorderLayout.CENTER); + this.controlButtons.add(this.backButton); + + this.leftButton = new JButton(Text.TURN_LEFT_BUTTON.toString()); + this.leftButton.setToolTipText(Text.TURN_LEFT_TOOLTIP.toString()); + this.leftButton.setActionCommand(Command.TURN.name() + Text.COMMAND_SEPARATOR.toString() + Orientation.LEFT.name()); + this.bottomControlPanel.add(this.leftButton, BorderLayout.WEST); + this.controlButtons.add(this.leftButton); + + this.rightButton = new JButton(Text.TURN_RIGHT_BUTTON.toString()); + this.rightButton.setToolTipText(Text.TURN_RIGHT_TOOLTIP.toString()); + this.rightButton.setActionCommand(Command.TURN.name() + Text.COMMAND_SEPARATOR.toString() + Orientation.RIGHT.name()); + this.bottomControlPanel.add(this.rightButton, BorderLayout.EAST); + this.controlButtons.add(this.rightButton); final Font font = new Font("Dialog", Font.BOLD, 19); - - final JButton forwardButton = new JButton("↥"); - forwardButton.setFont(font); - forwardButton.setToolTipText("Go forward"); - topControlPanel.add(forwardButton, BorderLayout.CENTER); - - final JButton inventoryButton = new JButton("⇱"); - inventoryButton.setFont(font); - inventoryButton.setToolTipText("Open inventory"); - topControlPanel.add(inventoryButton, BorderLayout.WEST); - - final JButton actionButton = new JButton("⇲"); - actionButton.setFont(font); - actionButton.setToolTipText("Talk/Take item"); - topControlPanel.add(actionButton, BorderLayout.EAST); - - final JPanel bottomControlPanel = new JPanel(); - controlPanel.add(bottomControlPanel, BorderLayout.SOUTH); - bottomControlPanel.setLayout(new BorderLayout(0, 0)); - - final JButton backButton = new JButton("↧"); - backButton.setFont(font); - backButton.setToolTipText("Go back"); - bottomControlPanel.add(backButton, BorderLayout.CENTER); - - final JButton leftButton = new JButton("↰"); - leftButton.setFont(font); - leftButton.setToolTipText("Turn left"); - bottomControlPanel.add(leftButton, BorderLayout.WEST); - - final JButton rightButton = new JButton("↱"); - rightButton.setFont(font); - rightButton.setToolTipText("Turn right"); - bottomControlPanel.add(rightButton, BorderLayout.EAST); - final Dimension squareButton = new Dimension(50, 50); - forwardButton.setPreferredSize(squareButton); - inventoryButton.setPreferredSize(squareButton); - actionButton.setPreferredSize(squareButton); - backButton.setPreferredSize(squareButton); - leftButton.setPreferredSize(squareButton); - rightButton.setPreferredSize(squareButton); - - newButton.setActionCommand(Command.NEW.name()); - soundButton.setActionCommand(Command.SOUND.name()); - loadButton.setActionCommand(Command.LOAD.name()); - saveButton.setActionCommand(Command.SAVE.name()); - - forwardButton.setActionCommand(Command.FORWARD.name()); - // inventoryButton.setActionCommand(Command.INVENTORY.name()); - actionButton.setActionCommand(Command.DO.name()); - backButton.setActionCommand(Command.BACK.name()); - leftButton.setActionCommand(Command.TURN.name() + " " + Orientation.LEFT); - rightButton.setActionCommand(Command.TURN.name() + " " + Orientation.RIGHT); - - this.gameButtons = new HashMap(); - - this.gameButtons.put("newButton", newButton); - this.gameButtons.put("soundButton", soundButton); - this.gameButtons.put("loadButton", loadButton); - this.gameButtons.put("saveButton", saveButton); - - this.controlButtons = new HashMap(); - - this.controlButtons.put("forwardButton", forwardButton); - this.controlButtons.put("inventoryButton", inventoryButton); - this.controlButtons.put("actionButton", actionButton); - this.controlButtons.put("backButton", backButton); - this.controlButtons.put("leftButton", leftButton); - this.controlButtons.put("rightButton", rightButton); - - final JTextPane emptyTextPane = new JTextPane(); - emptyTextPane.setText(Text.INVENTORY_EMPTY.getText()); - this.inventoryPanel.add(emptyTextPane); - this.inventoryPanel.setVisible(false); + for (final JButton controlButton : this.controlButtons) { + controlButton.setFont(font); + controlButton.setPreferredSize(squareButton); + } } @@ -238,14 +262,14 @@ abstract class UserInterface implements Viewable, ActionListener { /** * Sets the action listener for the given JButtons. * - * @param hashMap - * the map of the JButtons + * @param buttons + * the JButton Set * @param actionListener * the action listener */ - private void setActionListener(final HashMap hashMap, final ActionListener actionListener) { - for (final JButton vButton : hashMap.values()) { - vButton.addActionListener(actionListener); + private void setActionListener(final Set buttons, final ActionListener actionListener) { + for (final JButton button : buttons) { + button.addActionListener(actionListener); } } @@ -276,8 +300,8 @@ abstract class UserInterface implements Viewable, ActionListener { */ private void setControlsState(final boolean state) { this.inputField.setEnabled(state); - this.gameButtons.get("saveButton").setEnabled(state); - for (final JButton vButton : this.controlButtons.values()) { + this.saveButton.setEnabled(state); + for (final JButton vButton : this.controlButtons) { vButton.setEnabled(state); } } @@ -295,29 +319,41 @@ abstract class UserInterface implements Viewable, ActionListener { /** * Sets the Room's illustration. * - * Placeholder generation from http://stackoverflow.com/a/17802477/1348634 + * @param imageName + * the name of the image */ private void setIllustration(final String imageName) { - final URL imageURL = this.getClass().getClassLoader().getResource(imageName + ".jpg"); + final URL imageURL = this.getClass().getClassLoader().getResource(imageName + UserInterface.ILLUSTRATION_EXT); final StretchIcon imageIcon; if (imageURL == null) { - final BufferedImage bufferedImage = new BufferedImage(240, 135, BufferedImage.TYPE_BYTE_BINARY); - final Graphics graphics = bufferedImage.getGraphics(); - graphics.drawString(imageName, 5, 10 + 5); - imageIcon = new StretchIcon(bufferedImage, true); + imageIcon = new StretchIcon(this.generatePlaceholderImage(imageName), true); } else { imageIcon = new StretchIcon(imageURL, true); } this.imageLabel.setIcon(imageIcon); } + /** + * Placeholder image generation from + * http://stackoverflow.com/a/17802477/1348634 + * + * @param text + * the image text + * @return the Image + */ + private Image generatePlaceholderImage(final String text) { + final BufferedImage bufferedImage = new BufferedImage(240, 135, BufferedImage.TYPE_BYTE_BINARY); + final Graphics graphics = bufferedImage.getGraphics(); + graphics.drawString(text, 5, 10 + 5); + return bufferedImage; + } + /** * Opens the inventory (switches to the inventory tab). */ private void openInventory() { this.consolePanel.setVisible(false); this.inventoryPanel.setVisible(true); - // this.inventoryButton.addStyleName("button-activated"); } /** @@ -326,7 +362,6 @@ abstract class UserInterface implements Viewable, ActionListener { private void closeInventory() { this.inventoryPanel.setVisible(false); this.consolePanel.setVisible(true); - // this.inventoryButton.removeStyleName("button-activated"); } /** @@ -346,7 +381,7 @@ abstract class UserInterface implements Viewable, ActionListener { */ @Override public void actionPerformed(final ActionEvent actionEvent) { - if (actionEvent.getActionCommand() == "⇱") { + if (actionEvent.getActionCommand() == Text.INVENTORY_BUTTON.toString()) { this.toggleInventory(); } else { this.gameEngine.interpret(actionEvent.getActionCommand()); @@ -367,7 +402,7 @@ abstract class UserInterface implements Viewable, ActionListener { @Override public void disable() { this.setControlsState(false); - this.setQuestLabel("ESIEEquest"); + this.setQuestLabel(Text.DEFAULT_QUEST_TITLE.toString()); } @Override @@ -385,7 +420,7 @@ abstract class UserInterface implements Viewable, ActionListener { @Override public void updateLocation(final Room room, final Direction direction, final Side side) { this.echo(room.getInformations()); - this.setIllustration(room.name() + Text.FILENAME_SEPARATOR.getText() + direction.name()); + this.setIllustration(room.name() + Text.FILENAME_SEPARATOR.toString() + direction.name()); } @Override @@ -394,14 +429,14 @@ abstract class UserInterface implements Viewable, ActionListener { if (inventory.getSize() < 1) { final JTextPane emptyTextPane = new JTextPane(); - emptyTextPane.setText(Text.INVENTORY_EMPTY.getText()); + emptyTextPane.setText(Text.INVENTORY_EMPTY.toString()); this.inventoryPanel.add(emptyTextPane); return; } for (final Item item : inventory.getItems().values()) { final JButton button = new JButton(item.getName()); - button.setActionCommand(Command.USE.name() + " " + item.getName()); + button.setActionCommand(Command.USE.name() + Text.COMMAND_SEPARATOR.toString() + item.getName()); button.addActionListener(this); this.inventoryPanel.add(button); } diff --git a/src/esieequest/view/text/TextInterface.java b/src/esieequest/view/text/TextInterface.java index 7f282b1..5e701d3 100644 --- a/src/esieequest/view/text/TextInterface.java +++ b/src/esieequest/view/text/TextInterface.java @@ -83,7 +83,7 @@ abstract class TextInterface implements Viewable { @Override public void updateQuest(final Quest quest) { - this.echo(Text.CURRENT_QUEST_PREFIX.getText() + quest.getTitle()); + this.echo(Text.CURRENT_QUEST_PREFIX.toString() + quest.getTitle()); } @Override diff --git a/src/esieequest/view/web/WebInterface.java b/src/esieequest/view/web/WebInterface.java index 28f1bd2..14dfa1d 100644 --- a/src/esieequest/view/web/WebInterface.java +++ b/src/esieequest/view/web/WebInterface.java @@ -93,7 +93,7 @@ class WebInterface extends Composite implements Viewable { public WebInterface() { this.initWidget(WebInterface.uiBinder.createAndBindUi(this)); - final Label emptyLabel = new Label(Text.INVENTORY_EMPTY.getText()); + final Label emptyLabel = new Label(Text.INVENTORY_EMPTY.toString()); this.inventoryPanel.add(emptyLabel); this.bindInputField(); @@ -161,15 +161,13 @@ class WebInterface extends Composite implements Viewable { * Binds the buttons to send a defined command to the controller. */ private void bindButtons() { + // menu + this.newButton.setText(Text.NEW_GAME_BUTTON.toString()); + this.newButton.setTitle(Text.NEW_GAME_TOOLTIP.toString()); this.newButton.addClickHandler(this.makeClickHandler(Command.NEW.name())); - this.loadButton.addClickHandler(this.makeClickHandler(Command.LOAD.name())); - this.saveButton.addClickHandler(this.makeClickHandler(Command.SAVE.name())); - this.actionButton.addClickHandler(this.makeClickHandler(Command.DO.name())); - this.forwardButton.addClickHandler(this.makeClickHandler(Command.FORWARD.name())); - this.backButton.addClickHandler(this.makeClickHandler(Command.BACK.name())); - this.leftButton.addClickHandler(this.makeClickHandler(Command.TURN.name() + " " + Orientation.LEFT)); - this.rightButton.addClickHandler(this.makeClickHandler(Command.TURN.name() + " " + Orientation.RIGHT)); + this.soundButton.setText(Text.TOGGLE_SOUND_BUTTON.toString()); + this.soundButton.setTitle(Text.TOGGLE_SOUND_TOOLTIP.toString()); this.soundButton.addClickHandler(new ClickHandler() { @Override public void onClick(final ClickEvent event) { @@ -177,12 +175,37 @@ class WebInterface extends Composite implements Viewable { } }); + this.loadButton.setText(Text.LOAD_GAME_BUTTON.toString()); + this.loadButton.setTitle(Text.LOAD_GAME_TOOLTIP.toString()); + this.loadButton.addClickHandler(this.makeClickHandler(Command.LOAD.name())); + + this.saveButton.setText(Text.SAVE_GAME_BUTTON.toString()); + this.saveButton.setTitle(Text.SAVE_GAME_TOOLTIP.toString()); + this.saveButton.addClickHandler(this.makeClickHandler(Command.SAVE.name())); + + // controls + this.actionButton.setTitle(Text.ACTION_TOOLTIP.toString()); + this.actionButton.addClickHandler(this.makeClickHandler(Command.DO.name())); + + this.inventoryButton.setTitle(Text.INVENTORY_TOOLTIP.toString()); this.inventoryButton.addClickHandler(new ClickHandler() { @Override public void onClick(final ClickEvent event) { WebInterface.this.toggleInventory(); } }); + this.forwardButton.setTitle(Text.GO_FORWARD_TOOLTIP.toString()); + this.forwardButton.addClickHandler(this.makeClickHandler(Command.FORWARD.name())); + + this.backButton.setTitle(Text.GO_BACK_TOOLTIP.toString()); + this.backButton.addClickHandler(this.makeClickHandler(Command.BACK.name())); + + this.leftButton.setTitle(Text.TURN_LEFT_TOOLTIP.toString()); + this.leftButton.addClickHandler(this.makeClickHandler(Command.TURN.name() + Text.COMMAND_SEPARATOR.toString() + Orientation.LEFT.name())); + + this.rightButton.setTitle(Text.TURN_RIGHT_TOOLTIP.toString()); + this.rightButton.addClickHandler(this.makeClickHandler(Command.TURN.name() + Text.COMMAND_SEPARATOR.toString() + Orientation.RIGHT.name())); + } /** @@ -220,7 +243,7 @@ class WebInterface extends Composite implements Viewable { */ private void setMusic(final String music) { // TODO - this.echo("Not implemented."); + this.echo(Text.NOT_IMPLEMENTED.toString()); } /** @@ -228,7 +251,7 @@ class WebInterface extends Composite implements Viewable { */ private void toggleSound() { // TODO - this.echo("Not implemented."); + this.echo(Text.NOT_IMPLEMENTED.toString()); } /** @@ -286,7 +309,7 @@ class WebInterface extends Composite implements Viewable { @Override public void disable() { this.setControlsEnabled(false); - this.setQuestLabel("ESIEEquest"); + this.setQuestLabel(Text.DEFAULT_QUEST_TITLE.toString()); } @Override @@ -302,7 +325,7 @@ class WebInterface extends Composite implements Viewable { @Override public void updateLocation(final Room room, final Direction direction, final Side side) { - this.setIllustration(room.name() + Text.FILENAME_SEPARATOR.getText() + direction.name()); + this.setIllustration(room.name() + Text.FILENAME_SEPARATOR.toString() + direction.name()); this.echo(room.getInformations()); } @@ -311,14 +334,14 @@ class WebInterface extends Composite implements Viewable { this.inventoryPanel.clear(); if (inventory.getSize() < 1) { - final Label emptyLabel = new Label(Text.INVENTORY_EMPTY.getText()); + final Label emptyLabel = new Label(Text.INVENTORY_EMPTY.toString()); this.inventoryPanel.add(emptyLabel); return; } for (final Item item : inventory.getItems().values()) { final Button button = new Button(item.getName()); - button.addClickHandler(this.makeClickHandler(Command.USE.name() + " " + item.getName())); + button.addClickHandler(this.makeClickHandler(Command.USE.name() + Text.COMMAND_SEPARATOR.toString() + item.getName())); this.inventoryPanel.add(button); } diff --git a/src/esieequest/view/web/WebInterface.ui.xml b/src/esieequest/view/web/WebInterface.ui.xml index 6de3d85..b48688b 100644 --- a/src/esieequest/view/web/WebInterface.ui.xml +++ b/src/esieequest/view/web/WebInterface.ui.xml @@ -5,20 +5,19 @@ - + - + - + - + - + @@ -38,16 +37,12 @@ width="" height="" animationVertical="true" animationDuration="125" ui:field="bottomPanel"> - Console - + + - Inventory - - - + + @@ -61,29 +56,29 @@ + enabled="false" /> + enabled="false" /> + ui:field="actionButton" enabled="false" /> + enabled="false" /> + enabled="false" /> + enabled="false" /> -- cgit v1.2.3