From b101af8db0558a686cabbe80d75b48d42afdc9ae Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Sat, 24 May 2014 21:55:12 +0200 Subject: Better sound toggling --- src/esieequest/controller/commands/Command.java | 2 +- .../controller/commands/ToggleSoundCommand.java | 20 ++++++++++++++++++++ src/esieequest/view/app/UserInterface.java | 17 ++++------------- src/esieequest/view/web/WebInterface.java | 22 +++++----------------- 4 files changed, 30 insertions(+), 31 deletions(-) create mode 100644 src/esieequest/controller/commands/ToggleSoundCommand.java (limited to 'src') diff --git a/src/esieequest/controller/commands/Command.java b/src/esieequest/controller/commands/Command.java index 906a312..829ebf8 100644 --- a/src/esieequest/controller/commands/Command.java +++ b/src/esieequest/controller/commands/Command.java @@ -24,7 +24,7 @@ public enum Command { QUIT(new QuitCommand()), HELP(new HelpCommand()), ALEA(new AleaCommand()), - SOUND(new NewCommand()), + SOUND(new ToggleSoundCommand()), // map related GO(new GoCommand()), diff --git a/src/esieequest/controller/commands/ToggleSoundCommand.java b/src/esieequest/controller/commands/ToggleSoundCommand.java new file mode 100644 index 0000000..0d8a62b --- /dev/null +++ b/src/esieequest/controller/commands/ToggleSoundCommand.java @@ -0,0 +1,20 @@ +package esieequest.controller.commands; + +import esieequest.model.Game; +import esieequest.view.Viewable; + +/** + * Mute/unmute the game musics. + * + * @author Pacien TRAN-GIRARD + */ +public class ToggleSoundCommand implements Executable { + + @Override + public void execute(final String argument, final Game game, final Viewable view) { + + view.toggleSound(); + + } + +} diff --git a/src/esieequest/view/app/UserInterface.java b/src/esieequest/view/app/UserInterface.java index 37dde80..fee5427 100644 --- a/src/esieequest/view/app/UserInterface.java +++ b/src/esieequest/view/app/UserInterface.java @@ -163,7 +163,7 @@ abstract class UserInterface implements Viewable, ActionListener { this.soundButton = new JButton(Text.TOGGLE_SOUND_BUTTON.toString()); this.soundButton.setToolTipText(Text.TOGGLE_SOUND_TOOLTIP.toString()); - this.newButton.setActionCommand(Command.SOUND.name()); + this.soundButton.setActionCommand(Command.SOUND.name()); this.gamePanel.add(this.soundButton); this.filePanel = new JPanel(); @@ -511,14 +511,6 @@ abstract class UserInterface implements Viewable, ActionListener { } } - /** - * Toggles the sound (music). - */ - private void toggleAudio() { - this.muted = !this.muted; - this.setAudioGain(); - } - /** * Sets the gain. * @@ -536,7 +528,7 @@ abstract class UserInterface implements Viewable, ActionListener { // this.audio.setGain(0.0f); this.audio.pause(); } else if (this.audio.isPaused()) { - // this.audio.setGain(-1.0f);$ + // this.audio.setGain(-1.0f); this.audio.resume(); } } @@ -549,8 +541,6 @@ abstract class UserInterface implements Viewable, ActionListener { public void actionPerformed(final ActionEvent actionEvent) { if (actionEvent.getActionCommand() == Command.INVENTORY.name()) { this.toggleInventory(); - } else if (actionEvent.getActionCommand() == Text.TOGGLE_SOUND_BUTTON.toString()) { - this.toggleAudio(); } else if (actionEvent.getActionCommand() == Command.LOAD.name()) { final JFileChooser fileChooser = new JFileChooser(); fileChooser.setFileFilter(new FileNameExtensionFilter(UserInterface.SAVE_LABEL, @@ -677,7 +667,8 @@ abstract class UserInterface implements Viewable, ActionListener { @Override public void toggleSound() { - return; + this.muted = !this.muted; + this.setAudioGain(); } @Override diff --git a/src/esieequest/view/web/WebInterface.java b/src/esieequest/view/web/WebInterface.java index 82264fa..1880bee 100644 --- a/src/esieequest/view/web/WebInterface.java +++ b/src/esieequest/view/web/WebInterface.java @@ -225,12 +225,7 @@ class WebInterface extends Composite implements Viewable { 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) { - WebInterface.this.toggleAudio(); - } - }); + this.soundButton.addClickHandler(this.makeClickHandler(Command.SOUND.name())); this.loadButton.setText(Text.LOAD_GAME_BUTTON.toString()); this.loadButton.setTitle(Text.LOAD_GAME_TOOLTIP.toString()); @@ -312,16 +307,6 @@ class WebInterface extends Composite implements Viewable { this.audio.play(); } - /** - * Toggles the sound (music). - */ - private void toggleAudio() { - if (this.audio == null) { - return; - } - this.audio.setMuted(!this.audio.isMuted()); - } - /** * Sets the illustration of the side of the room. * @@ -464,7 +449,10 @@ class WebInterface extends Composite implements Viewable { @Override public void toggleSound() { - return; + if (this.audio == null) { + return; + } + this.audio.setMuted(!this.audio.isMuted()); } @Override -- cgit v1.2.3