From 611fd21d13fe2ee223fcf7ca647be20131887c96 Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Mon, 19 May 2014 23:25:31 +0200 Subject: Implement audio (WebInterface) --- src/esieequest/controller/commands/Command.java | 1 - .../controller/commands/SoundCommand.java | 19 ------------ src/esieequest/model/Text.java | 2 +- src/esieequest/model/events/Quest.java | 2 +- src/esieequest/model/events/Scene.java | 5 ++-- src/esieequest/view/app/UserInterface.java | 28 ++++++++++++++++- src/esieequest/view/web/WebInterface.java | 35 +++++++++++++++------- 7 files changed, 56 insertions(+), 36 deletions(-) delete mode 100644 src/esieequest/controller/commands/SoundCommand.java diff --git a/src/esieequest/controller/commands/Command.java b/src/esieequest/controller/commands/Command.java index 0879bef..a29b79b 100644 --- a/src/esieequest/controller/commands/Command.java +++ b/src/esieequest/controller/commands/Command.java @@ -22,7 +22,6 @@ public enum Command { LOAD(new LoadCommand()), SAVE(new SaveCommand()), QUIT(new QuitCommand()), - SOUND(new SoundCommand()), HELP(new HelpCommand()), ALEA(new AleaCommand()), diff --git a/src/esieequest/controller/commands/SoundCommand.java b/src/esieequest/controller/commands/SoundCommand.java deleted file mode 100644 index fbd11d7..0000000 --- a/src/esieequest/controller/commands/SoundCommand.java +++ /dev/null @@ -1,19 +0,0 @@ -package esieequest.controller.commands; - -import esieequest.model.Game; -import esieequest.view.Viewable; - -/** - * Allows the user to enable or disable the game's sounds. - * - * @author Pacien TRAN-GIRARD - */ -public class SoundCommand implements Executable { - - @Override - public void execute(final String argument, final Game game, final Viewable view) { - // TODO Auto-generated method stub - - } - -} diff --git a/src/esieequest/model/Text.java b/src/esieequest/model/Text.java index d70b86f..8e916fc 100644 --- a/src/esieequest/model/Text.java +++ b/src/esieequest/model/Text.java @@ -14,7 +14,7 @@ public enum Text { DEFAULT_QUEST_TITLE("ESIEEquest"), CURRENT_QUEST_PREFIX("Current quest: "), - NOT_IMPLEMENTED("Not implementer... Yet."), + NOT_IMPLEMENTED("Not implemented... Yet."), NEW_GAME_BUTTON("New"), NEW_GAME_TOOLTIP("New game"), diff --git a/src/esieequest/model/events/Quest.java b/src/esieequest/model/events/Quest.java index ac523e2..84bc80b 100644 --- a/src/esieequest/model/events/Quest.java +++ b/src/esieequest/model/events/Quest.java @@ -12,7 +12,7 @@ public enum Quest { // @formatter:off WHAT_HAPPENED("What happened?!?!"), - FIND_ATHANASE("Find Athanase"), + //FIND_ATHANASE("Find Athanase"), FEED_ATHANASE("Feed Athanase"), FIND_DISK("Find the Disk"), FIND_TRANSPONDER("Find the Transponder"), diff --git a/src/esieequest/model/events/Scene.java b/src/esieequest/model/events/Scene.java index eebd9f6..91ae7c2 100644 --- a/src/esieequest/model/events/Scene.java +++ b/src/esieequest/model/events/Scene.java @@ -13,8 +13,9 @@ public enum Scene { // @formatter:off - INTRO("Testing is the future...", "...", 2500), - END("...and the future starts with you!", "...", 2500), + INTRO("THIS SOFTWARE COMES WITH ABSOLUTELY NO WARRANTY!", "...", 90000), + TRANSPONDER_ACTIVATED("Stalemate Resolved.", "...", 2500), + END("Good work getting this far, future-starter!", "...", 2500), ; diff --git a/src/esieequest/view/app/UserInterface.java b/src/esieequest/view/app/UserInterface.java index cb8d6aa..d7d8b44 100644 --- a/src/esieequest/view/app/UserInterface.java +++ b/src/esieequest/view/app/UserInterface.java @@ -51,8 +51,12 @@ import esieequest.view.Viewable; */ abstract class UserInterface implements Viewable, ActionListener { + private static final String ILLUSTRATION_DIR = "res/frame/"; private static final String ILLUSTRATION_EXT = ".html"; + private static final String SOUND_DIR = "res/audio/"; + private static final String SOUND_EXT = ".ogg"; + private GameEngine gameEngine; @Getter @@ -137,7 +141,6 @@ abstract class UserInterface implements Viewable, ActionListener { 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.filePanel = new JPanel(); @@ -438,6 +441,25 @@ abstract class UserInterface implements Viewable, ActionListener { } } + /** + * Sets the current music playing. + * + * @param fileName + * the URL of the audio file + */ + private void playAudio(final String fileName) { + // TODO Auto-generated method stub + this.echo(Text.NOT_IMPLEMENTED.toString()); + } + + /** + * Toggles the sound (music). + */ + private void toggleAudio() { + // TODO Auto-generated method stub + this.echo(Text.NOT_IMPLEMENTED.toString()); + } + /** * Translates the received ActionEvent into the corresponding game command * and forwards it to the game engine. @@ -446,6 +468,8 @@ abstract class UserInterface implements Viewable, ActionListener { public void actionPerformed(final ActionEvent actionEvent) { if (actionEvent.getActionCommand() == Text.INVENTORY_BUTTON.toString()) { this.toggleInventory(); + } else if (actionEvent.getActionCommand() == Text.TOGGLE_SOUND_BUTTON.toString()) { + this.toggleAudio(); } else { this.gameEngine.interpret(actionEvent.getActionCommand()); this.clearInputField(); @@ -478,6 +502,7 @@ abstract class UserInterface implements Viewable, ActionListener { @Override public void updateQuest(final Quest quest) { this.setQuestLabel(quest.getTitle()); + this.playAudio(quest.name()); } @Override @@ -516,6 +541,7 @@ abstract class UserInterface implements Viewable, ActionListener { @Override public void playScene(final Scene scene) { scene.getCallback().call(); + this.playAudio(scene.name()); } } diff --git a/src/esieequest/view/web/WebInterface.java b/src/esieequest/view/web/WebInterface.java index 0bd5776..a85fc78 100644 --- a/src/esieequest/view/web/WebInterface.java +++ b/src/esieequest/view/web/WebInterface.java @@ -6,6 +6,7 @@ import com.google.gwt.event.dom.client.ClickHandler; import com.google.gwt.event.dom.client.KeyCodes; import com.google.gwt.event.dom.client.KeyDownEvent; import com.google.gwt.event.dom.client.KeyDownHandler; +import com.google.gwt.media.client.Audio; import com.google.gwt.uibinder.client.UiBinder; import com.google.gwt.uibinder.client.UiField; import com.google.gwt.user.client.Event; @@ -42,9 +43,12 @@ import esieequest.view.Viewable; */ class WebInterface extends Composite implements Viewable { - private static final String ILLUSTRATION_DIR = "illustrations/"; + private static final String ILLUSTRATION_DIR = "res/frame/"; private static final String ILLUSTRATION_EXT = ".html"; + private static final String SOUND_DIR = "res/audio/"; + private static final String SOUND_EXT = ".ogg"; + private GameEngine gameEngine; private static WebInterfaceUiBinder uiBinder = GWT.create(WebInterfaceUiBinder.class); @@ -82,6 +86,8 @@ class WebInterface extends Composite implements Viewable { @UiField Button leftButton; + private Audio audio; + /** * The web user interface binder interface. */ @@ -104,6 +110,12 @@ class WebInterface extends Composite implements Viewable { this.bindInputField(); this.bindKeys(); this.bindButtons(); + + this.audio = Audio.createIfSupported(); + if (this.audio == null) { + return; + } + this.bottomPanel.add(this.audio); } /** @@ -206,7 +218,7 @@ class WebInterface extends Composite implements Viewable { this.soundButton.addClickHandler(new ClickHandler() { @Override public void onClick(final ClickEvent event) { - WebInterface.this.toggleSound(); + WebInterface.this.toggleAudio(); } }); @@ -275,22 +287,21 @@ class WebInterface extends Composite implements Viewable { } /** - * Sets the current music playing in loop. + * Sets the current music playing. * - * @param music - * the music URL + * @param fileName + * the URL of the audio file */ - private void setMusic(final String music) { - // TODO - this.echo(Text.NOT_IMPLEMENTED.toString()); + private void playAudio(final String fileName) { + this.audio.setSrc(WebInterface.SOUND_DIR + fileName + WebInterface.SOUND_EXT); + this.audio.play(); } /** * Toggles the sound (music). */ - private void toggleSound() { - // TODO - this.echo(Text.NOT_IMPLEMENTED.toString()); + private void toggleAudio() { + this.audio.setMuted(!this.audio.isMuted()); } /** @@ -361,6 +372,7 @@ class WebInterface extends Composite implements Viewable { @Override public void updateQuest(final Quest quest) { this.setQuestLabel(quest.getTitle()); + this.playAudio(quest.name()); } @Override @@ -401,6 +413,7 @@ class WebInterface extends Composite implements Viewable { this.setQuestLabel(scene.getTitle()); this.echo(scene.getText()); this.setIllustration(scene.name()); + this.playAudio(scene.name()); new Timer() { @Override -- cgit v1.2.3