From 51b8172ae18b9e354e3a97fd26f61b46287e1dcf Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Sat, 3 May 2014 20:45:20 +0200 Subject: Add placeholder image generation for GUI view --- .../controller/commands/BackCommand.java | 3 +- src/esieequest/controller/commands/GoCommand.java | 4 +-- src/esieequest/controller/commands/NewCommand.java | 1 + .../controller/commands/TurnCommand.java | 4 +-- src/esieequest/view/Viewable.java | 15 ++++------ src/esieequest/view/app/UserInterface.java | 33 +++++++++++++--------- src/esieequest/view/text/TextInterface.java | 8 ++---- src/esieequest/view/web/WebInterface.java | 9 ++---- 8 files changed, 37 insertions(+), 40 deletions(-) (limited to 'src') diff --git a/src/esieequest/controller/commands/BackCommand.java b/src/esieequest/controller/commands/BackCommand.java index 627df59..299bda9 100644 --- a/src/esieequest/controller/commands/BackCommand.java +++ b/src/esieequest/controller/commands/BackCommand.java @@ -14,7 +14,8 @@ public class BackCommand implements Executable { public void execute(final String argument, final Game game, final Viewable view) { game.getPlayer().goToPreviousRoom(); - view.updateRoom(game.getPlayer().getCurrentRoom()); + + view.updateLocation(game.getPlayer().getCurrentRoom(), game.getPlayer().getCurrentDirection(), game.getPlayer().getCurrentSide()); } diff --git a/src/esieequest/controller/commands/GoCommand.java b/src/esieequest/controller/commands/GoCommand.java index ccb974b..9ebdf49 100644 --- a/src/esieequest/controller/commands/GoCommand.java +++ b/src/esieequest/controller/commands/GoCommand.java @@ -39,8 +39,8 @@ public class GoCommand implements Executable { return; } - view.updateRoom(game.getPlayer().getCurrentRoom()); - + view.updateLocation(game.getPlayer().getCurrentRoom(), direction, game.getPlayer().getCurrentSide()); + // handle challenge mode if (game.getPlayer().walk()) { view.echo(Text.CHALLENGE_FAILED.getText()); diff --git a/src/esieequest/controller/commands/NewCommand.java b/src/esieequest/controller/commands/NewCommand.java index 3c23882..dcb4f8f 100644 --- a/src/esieequest/controller/commands/NewCommand.java +++ b/src/esieequest/controller/commands/NewCommand.java @@ -21,6 +21,7 @@ public class NewCommand implements Executable { game.getPlayer().setCurrentRoom(Room.AMPHITHEATER_SEAT); view.enable(); + view.updateLocation(game.getPlayer().getCurrentRoom(), game.getPlayer().getCurrentDirection(), game.getPlayer().getCurrentSide()); view.echo(Text.WELCOME.getText()); } diff --git a/src/esieequest/controller/commands/TurnCommand.java b/src/esieequest/controller/commands/TurnCommand.java index a03fbab..4f6eb4c 100644 --- a/src/esieequest/controller/commands/TurnCommand.java +++ b/src/esieequest/controller/commands/TurnCommand.java @@ -30,8 +30,8 @@ public class TurnCommand implements Executable { final Direction newDirection = currentDirection.rotate(orientation); game.getPlayer().setCurrentDirection(newDirection); - view.updateSide(game.getPlayer().getCurrentSide()); - + view.updateLocation(game.getPlayer().getCurrentRoom(), newDirection, game.getPlayer().getCurrentSide()); + } } diff --git a/src/esieequest/view/Viewable.java b/src/esieequest/view/Viewable.java index 6fc8592..5d2675f 100644 --- a/src/esieequest/view/Viewable.java +++ b/src/esieequest/view/Viewable.java @@ -5,6 +5,7 @@ import java.util.HashMap; import esieequest.controller.GameEngine; import esieequest.model.events.Quest; import esieequest.model.items.SimpleItem; +import esieequest.model.map.Direction; import esieequest.model.map.Room; import esieequest.model.map.Side; @@ -47,20 +48,16 @@ public interface Viewable { public void disable(); /** - * Updates the view to match the current room. + * Updates the view to match the current location. * * @param room - * the room to display - */ - public void updateRoom(Room room); - - /** - * Updates the view to match a side of a room. - * + * the room + * @param direction + * the current direction * @param side * the side of a room */ - public void updateSide(Side side); + public void updateLocation(Room room, Direction direction, Side side); /** * Updates the view to match the current quest. diff --git a/src/esieequest/view/app/UserInterface.java b/src/esieequest/view/app/UserInterface.java index ba6d786..66a0af1 100644 --- a/src/esieequest/view/app/UserInterface.java +++ b/src/esieequest/view/app/UserInterface.java @@ -3,8 +3,10 @@ package esieequest.view.app; import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.Font; +import java.awt.Graphics; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.awt.image.BufferedImage; import java.net.URL; import java.util.HashMap; @@ -21,6 +23,7 @@ import esieequest.controller.GameEngine; import esieequest.controller.commands.Command; import esieequest.model.events.Quest; import esieequest.model.items.SimpleItem; +import esieequest.model.map.Direction; import esieequest.model.map.Orientation; import esieequest.model.map.Room; import esieequest.model.map.Side; @@ -52,6 +55,7 @@ abstract class UserInterface implements Viewable, ActionListener { public UserInterface() { this.buildUI(); this.inputField.addActionListener(this); + this.setActionListener(this); this.setControlsState(false); this.inputField.setEnabled(true); } @@ -270,15 +274,21 @@ abstract class UserInterface implements Viewable, ActionListener { } /** - * Updates the room illustration. + * Updates the room's illustration. + * + * Placeholder generation from http://stackoverflow.com/a/17802477/1348634 */ - private void updateIllustration(final String locationImageName) { - String imageName = locationImageName; - if (imageName == null) { - imageName = "res/img/placeholder.jpg"; + private void updateIllustration(final String imageName) { + final URL imageURL = this.getClass().getClassLoader().getResource(imageName + ".jpg"); + 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); + } else { + imageIcon = new StretchIcon(imageURL, true); } - final URL imageURL = this.getClass().getClassLoader().getResource(imageName); - final StretchIcon imageIcon = new StretchIcon(imageURL, true); this.imageLabel.setIcon(imageIcon); } @@ -314,14 +324,9 @@ abstract class UserInterface implements Viewable, ActionListener { } @Override - public void updateRoom(final Room room) { - // this.updateIllustration(room.getImageName()); + public void updateLocation(final Room room, final Direction direction, final Side side) { this.echo(room.getInformations()); - } - - @Override - public void updateSide(final Side side) { - // this.updateIllustration(side.getImageName()); + this.updateIllustration(room.name() + "_" + direction.name()); } @Override diff --git a/src/esieequest/view/text/TextInterface.java b/src/esieequest/view/text/TextInterface.java index c94eb1a..8f37c53 100644 --- a/src/esieequest/view/text/TextInterface.java +++ b/src/esieequest/view/text/TextInterface.java @@ -6,6 +6,7 @@ import esieequest.controller.GameEngine; import esieequest.controller.commands.Command; import esieequest.model.events.Quest; import esieequest.model.items.SimpleItem; +import esieequest.model.map.Direction; import esieequest.model.map.Room; import esieequest.model.map.Side; import esieequest.view.Viewable; @@ -82,15 +83,10 @@ abstract class TextInterface implements Viewable { } @Override - public void updateRoom(final Room room) { + public void updateLocation(Room room, Direction direction, Side side) { this.echo(room.getInformations()); } - @Override - public void updateSide(final Side side) { - // TODO Auto-generated method stub - } - @Override public void updateQuest(final Quest quest) { this.echo("Current quest: " + quest.getTitle()); diff --git a/src/esieequest/view/web/WebInterface.java b/src/esieequest/view/web/WebInterface.java index baa01e9..08dfe4f 100644 --- a/src/esieequest/view/web/WebInterface.java +++ b/src/esieequest/view/web/WebInterface.java @@ -26,6 +26,7 @@ import esieequest.controller.GameEngine; import esieequest.controller.commands.Command; import esieequest.model.events.Quest; import esieequest.model.items.SimpleItem; +import esieequest.model.map.Direction; import esieequest.model.map.Orientation; import esieequest.model.map.Room; import esieequest.model.map.Side; @@ -291,15 +292,11 @@ class WebInterface extends Composite implements Viewable { } @Override - public void updateRoom(final Room room) { + public void updateLocation(final Room room, final Direction direction, final Side side) { + // TODO: update illustration this.echo(room.getInformations()); } - @Override - public void updateSide(final Side side) { - // this.setIllustration(side.); - } - @Override public void updateQuest(final Quest quest) { this.setQuestLabel(quest.getTitle()); -- cgit v1.2.3