From 8394c66e0ba2fbbfcdc5738b7485e934d05773b9 Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Tue, 20 May 2014 21:00:08 +0200 Subject: Stop music on quit --- src/esieequest/controller/commands/GoCommand.java | 2 +- src/esieequest/controller/commands/NewCommand.java | 2 +- src/esieequest/controller/commands/QuitCommand.java | 3 ++- src/esieequest/model/items/Disk.java | 2 +- src/esieequest/view/Viewable.java | 9 +++++++-- src/esieequest/view/app/UserInterface.java | 9 +++++++-- src/esieequest/view/text/TextInterface.java | 9 +++++++-- src/esieequest/view/web/WebInterface.java | 20 +++++++++++++++++--- 8 files changed, 43 insertions(+), 13 deletions(-) diff --git a/src/esieequest/controller/commands/GoCommand.java b/src/esieequest/controller/commands/GoCommand.java index 1078d49..a68f5ad 100644 --- a/src/esieequest/controller/commands/GoCommand.java +++ b/src/esieequest/controller/commands/GoCommand.java @@ -45,7 +45,7 @@ public class GoCommand implements Executable { // handle challenge mode if (game.getPlayer().walk()) { view.echo(Text.CHALLENGE_FAILED.toString()); - view.disable(); + view.disableInput(); } } diff --git a/src/esieequest/controller/commands/NewCommand.java b/src/esieequest/controller/commands/NewCommand.java index 7283989..571b4a9 100644 --- a/src/esieequest/controller/commands/NewCommand.java +++ b/src/esieequest/controller/commands/NewCommand.java @@ -35,7 +35,7 @@ public class NewCommand implements Executable { .getCurrentDirection(), game.getPlayer().getCurrentSide(), game.getPlayer() .canGoBack()); - view.enable(); + view.enableInput(); } }); diff --git a/src/esieequest/controller/commands/QuitCommand.java b/src/esieequest/controller/commands/QuitCommand.java index 4453597..024b35f 100644 --- a/src/esieequest/controller/commands/QuitCommand.java +++ b/src/esieequest/controller/commands/QuitCommand.java @@ -15,7 +15,8 @@ public class QuitCommand implements Executable { public void execute(final String argument, final Game game, final Viewable view) { view.echo(Text.QUIT.toString()); - view.disable(); + view.disableInput(); + view.stopMusic(); } diff --git a/src/esieequest/model/items/Disk.java b/src/esieequest/model/items/Disk.java index e83ac8c..b534ad8 100644 --- a/src/esieequest/model/items/Disk.java +++ b/src/esieequest/model/items/Disk.java @@ -31,7 +31,7 @@ public class Disk extends SimpleItem { game.getPlayer().getInventory().removeItem(Item.DISK); game.getPlayer().getCurrentSide().getInventory().putItem(Item.DISK); - view.disable(); + view.disableInput(); Scene.RUN_CONSOLE.setCallback(new Callback() { @Override diff --git a/src/esieequest/view/Viewable.java b/src/esieequest/view/Viewable.java index 845b4ea..fa53e1a 100644 --- a/src/esieequest/view/Viewable.java +++ b/src/esieequest/view/Viewable.java @@ -31,12 +31,12 @@ public interface Viewable { /** * Enables the user interface. */ - public void enable(); + public void enableInput(); /** * Disables the user interface. */ - public void disable(); + public void disableInput(); /** * Displays a message. @@ -83,4 +83,9 @@ public interface Viewable { */ public void playScene(final Scene scene); + /** + * Stops the music currently playing. + */ + public void stopMusic(); + } diff --git a/src/esieequest/view/app/UserInterface.java b/src/esieequest/view/app/UserInterface.java index d7d8b44..b3d5a77 100644 --- a/src/esieequest/view/app/UserInterface.java +++ b/src/esieequest/view/app/UserInterface.java @@ -482,12 +482,12 @@ abstract class UserInterface implements Viewable, ActionListener { } @Override - public void enable() { + public void enableInput() { this.setControlsState(true); } @Override - public void disable() { + public void disableInput() { this.setControlsState(false); this.setQuestLabel(Text.DEFAULT_QUEST_TITLE.toString()); } @@ -544,4 +544,9 @@ abstract class UserInterface implements Viewable, ActionListener { this.playAudio(scene.name()); } + @Override + public void stopMusic() { + return; + } + } diff --git a/src/esieequest/view/text/TextInterface.java b/src/esieequest/view/text/TextInterface.java index c735640..308a4e0 100644 --- a/src/esieequest/view/text/TextInterface.java +++ b/src/esieequest/view/text/TextInterface.java @@ -64,7 +64,7 @@ abstract class TextInterface implements Viewable { } @Override - public void enable() { + public void enableInput() { if (!this.running) { this.running = true; this.run(); @@ -72,7 +72,7 @@ abstract class TextInterface implements Viewable { } @Override - public void disable() { + public void disableInput() { this.running = false; } @@ -102,4 +102,9 @@ abstract class TextInterface implements Viewable { scene.getCallback().call(); } + @Override + public void stopMusic() { + return; + } + } diff --git a/src/esieequest/view/web/WebInterface.java b/src/esieequest/view/web/WebInterface.java index d417d24..6a4ac35 100644 --- a/src/esieequest/view/web/WebInterface.java +++ b/src/esieequest/view/web/WebInterface.java @@ -297,6 +297,9 @@ class WebInterface extends Composite implements Viewable { * the URL of the audio file */ private void playAudio(final String fileName) { + if (this.audio == null) { + return; + } this.audio.setSrc(WebInterface.SOUND_DIR + fileName + WebInterface.SOUND_EXT); this.audio.play(); } @@ -305,6 +308,9 @@ class WebInterface extends Composite implements Viewable { * Toggles the sound (music). */ private void toggleAudio() { + if (this.audio == null) { + return; + } this.audio.setMuted(!this.audio.isMuted()); } @@ -367,12 +373,12 @@ class WebInterface extends Composite implements Viewable { } @Override - public void enable() { + public void enableInput() { this.setControlsEnabled(true); } @Override - public void disable() { + public void disableInput() { this.setControlsEnabled(false); this.setQuestLabel(Text.DEFAULT_QUEST_TITLE.toString()); } @@ -422,7 +428,7 @@ class WebInterface extends Composite implements Viewable { @Override public void playScene(final Scene scene) { - this.disable(); + this.disableInput(); this.setQuestLabel(scene.getTitle()); this.echo(scene.getText()); @@ -438,4 +444,12 @@ class WebInterface extends Composite implements Viewable { this.timer.schedule(scene.getDuration()); } + @Override + public void stopMusic() { + if (this.audio == null) { + return; + } + this.audio.setMuted(true); + } + } -- cgit v1.2.3