From 0d4651e54f40f4dad929c419e92e37a15926f7be Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Sun, 18 May 2014 17:41:26 +0200 Subject: Update control buttons state according to location --- src/esieequest/controller/commands/BackCommand.java | 2 +- src/esieequest/controller/commands/DropCommand.java | 1 + src/esieequest/controller/commands/GoCommand.java | 2 +- src/esieequest/controller/commands/LoadCommand.java | 2 +- src/esieequest/controller/commands/NewCommand.java | 2 +- src/esieequest/controller/commands/TakeCommand.java | 1 + src/esieequest/controller/commands/TurnCommand.java | 2 +- src/esieequest/model/Player.java | 9 +++++++++ src/esieequest/view/Viewable.java | 2 +- src/esieequest/view/app/UserInterface.java | 8 ++++++-- src/esieequest/view/text/TextInterface.java | 2 +- src/esieequest/view/web/WebInterface.java | 6 +++++- 12 files changed, 29 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/esieequest/controller/commands/BackCommand.java b/src/esieequest/controller/commands/BackCommand.java index 299bda9..847d396 100644 --- a/src/esieequest/controller/commands/BackCommand.java +++ b/src/esieequest/controller/commands/BackCommand.java @@ -15,7 +15,7 @@ public class BackCommand implements Executable { game.getPlayer().goToPreviousRoom(); - view.updateLocation(game.getPlayer().getCurrentRoom(), game.getPlayer().getCurrentDirection(), game.getPlayer().getCurrentSide()); + view.updateLocation(game.getPlayer().getCurrentRoom(), game.getPlayer().getCurrentDirection(), game.getPlayer().getCurrentSide(), game.getPlayer().canGoBack()); } diff --git a/src/esieequest/controller/commands/DropCommand.java b/src/esieequest/controller/commands/DropCommand.java index 4e6f877..ee71b1e 100644 --- a/src/esieequest/controller/commands/DropCommand.java +++ b/src/esieequest/controller/commands/DropCommand.java @@ -31,6 +31,7 @@ public class DropCommand implements Executable { final Item item = game.getPlayer().getInventory().takeItem(itemName); game.getPlayer().getCurrentSide().getInventory().putItem(item); + view.updateLocation(game.getPlayer().getCurrentRoom(), game.getPlayer().getCurrentDirection(), game.getPlayer().getCurrentSide(), game.getPlayer().canGoBack()); view.updateInventory(game.getPlayer().getInventory()); } diff --git a/src/esieequest/controller/commands/GoCommand.java b/src/esieequest/controller/commands/GoCommand.java index f536f64..136379f 100644 --- a/src/esieequest/controller/commands/GoCommand.java +++ b/src/esieequest/controller/commands/GoCommand.java @@ -39,7 +39,7 @@ public class GoCommand implements Executable { return; } - view.updateLocation(game.getPlayer().getCurrentRoom(), direction, game.getPlayer().getCurrentSide()); + view.updateLocation(game.getPlayer().getCurrentRoom(), direction, game.getPlayer().getCurrentSide(), game.getPlayer().canGoBack()); // handle challenge mode if (game.getPlayer().walk()) { diff --git a/src/esieequest/controller/commands/LoadCommand.java b/src/esieequest/controller/commands/LoadCommand.java index 8d6fd29..8a69544 100644 --- a/src/esieequest/controller/commands/LoadCommand.java +++ b/src/esieequest/controller/commands/LoadCommand.java @@ -39,7 +39,7 @@ public class LoadCommand implements Executable { // view.updateQuest(); // view.updateInventory(game.getPlayer().getItems()); - view.updateLocation(game.getPlayer().getCurrentRoom(), game.getPlayer().getCurrentDirection(), game.getPlayer().getCurrentSide()); + view.updateLocation(game.getPlayer().getCurrentRoom(), game.getPlayer().getCurrentDirection(), game.getPlayer().getCurrentSide(), game.getPlayer().canGoBack()); } diff --git a/src/esieequest/controller/commands/NewCommand.java b/src/esieequest/controller/commands/NewCommand.java index 4ce45d0..e0e45ab 100644 --- a/src/esieequest/controller/commands/NewCommand.java +++ b/src/esieequest/controller/commands/NewCommand.java @@ -24,7 +24,7 @@ public class NewCommand implements Executable { view.enable(); - view.updateLocation(game.getPlayer().getCurrentRoom(), game.getPlayer().getCurrentDirection(), game.getPlayer().getCurrentSide()); + view.updateLocation(game.getPlayer().getCurrentRoom(), game.getPlayer().getCurrentDirection(), game.getPlayer().getCurrentSide(), game.getPlayer().canGoBack()); view.echo(Text.WELCOME.toString()); } diff --git a/src/esieequest/controller/commands/TakeCommand.java b/src/esieequest/controller/commands/TakeCommand.java index 4e615c7..b92f4e5 100644 --- a/src/esieequest/controller/commands/TakeCommand.java +++ b/src/esieequest/controller/commands/TakeCommand.java @@ -47,6 +47,7 @@ public class TakeCommand implements Executable { game.getPlayer().getCurrentRoom().removeItem(item); game.getPlayer().getInventory().putItem(item); + view.updateLocation(game.getPlayer().getCurrentRoom(), game.getPlayer().getCurrentDirection(), game.getPlayer().getCurrentSide(), game.getPlayer().canGoBack()); view.updateInventory(game.getPlayer().getInventory()); } diff --git a/src/esieequest/controller/commands/TurnCommand.java b/src/esieequest/controller/commands/TurnCommand.java index d4b6ee9..f985087 100644 --- a/src/esieequest/controller/commands/TurnCommand.java +++ b/src/esieequest/controller/commands/TurnCommand.java @@ -30,7 +30,7 @@ public class TurnCommand implements Executable { final Direction newDirection = currentDirection.rotate(orientation); game.getPlayer().setCurrentDirection(newDirection); - view.updateLocation(game.getPlayer().getCurrentRoom(), newDirection, game.getPlayer().getCurrentSide()); + view.updateLocation(game.getPlayer().getCurrentRoom(), newDirection, game.getPlayer().getCurrentSide(), game.getPlayer().canGoBack()); } diff --git a/src/esieequest/model/Player.java b/src/esieequest/model/Player.java index ea8af35..23e3a54 100644 --- a/src/esieequest/model/Player.java +++ b/src/esieequest/model/Player.java @@ -101,6 +101,15 @@ public class Player implements SerialisableObject { } } + /** + * Tells if the Player can go back. + * + * @return false if the Player's Room history is empty. + */ + public boolean canGoBack() { + return !this.previousRooms.isEmpty(); + } + /** * Clears the previous rooms history. */ diff --git a/src/esieequest/view/Viewable.java b/src/esieequest/view/Viewable.java index d4da79b..eb9c50a 100644 --- a/src/esieequest/view/Viewable.java +++ b/src/esieequest/view/Viewable.java @@ -63,7 +63,7 @@ public interface Viewable { * @param side * the side of a room */ - public void updateLocation(final Room room, final Direction direction, final Side side); + public void updateLocation(final Room room, final Direction direction, final Side side, final boolean canGoBack); /** * Updates the view to display the items contained in the inventory diff --git a/src/esieequest/view/app/UserInterface.java b/src/esieequest/view/app/UserInterface.java index 1d73e79..220afc1 100644 --- a/src/esieequest/view/app/UserInterface.java +++ b/src/esieequest/view/app/UserInterface.java @@ -418,9 +418,13 @@ abstract class UserInterface implements Viewable, ActionListener { } @Override - public void updateLocation(final Room room, final Direction direction, final Side side) { - this.echo(room.getInformations()); + public void updateLocation(final Room room, final Direction direction, final Side side, final boolean canGoBack) { this.setIllustration(room.name() + Text.FILENAME_SEPARATOR.toString() + direction.name()); + this.backButton.setEnabled(canGoBack); + this.forwardButton.setEnabled(side.hasDoor()); + this.actionButton.setEnabled(side.hasCharacter() || side.getInventory().getSize() > 0); + + this.echo(room.getInformations()); } @Override diff --git a/src/esieequest/view/text/TextInterface.java b/src/esieequest/view/text/TextInterface.java index 5e701d3..3fc0399 100644 --- a/src/esieequest/view/text/TextInterface.java +++ b/src/esieequest/view/text/TextInterface.java @@ -87,7 +87,7 @@ abstract class TextInterface implements Viewable { } @Override - public void updateLocation(final Room room, final Direction direction, final Side side) { + public void updateLocation(final Room room, final Direction direction, final Side side, final boolean canGoBack) { this.echo(room.getInformations()); } diff --git a/src/esieequest/view/web/WebInterface.java b/src/esieequest/view/web/WebInterface.java index 07bb60a..fe67b72 100644 --- a/src/esieequest/view/web/WebInterface.java +++ b/src/esieequest/view/web/WebInterface.java @@ -327,8 +327,12 @@ class WebInterface extends Composite implements Viewable { } @Override - public void updateLocation(final Room room, final Direction direction, final Side side) { + public void updateLocation(final Room room, final Direction direction, final Side side, final boolean canGoBack) { this.setIllustration(room.name() + Text.FILENAME_SEPARATOR.toString() + direction.name()); + this.backButton.setEnabled(canGoBack); + this.forwardButton.setEnabled(side.hasDoor()); + this.actionButton.setEnabled(side.hasCharacter() || side.getInventory().getSize() > 0); + this.echo(room.getInformations()); } -- cgit v1.2.3