aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPacien TRAN-GIRARD2014-05-24 21:55:12 +0200
committerPacien TRAN-GIRARD2014-05-24 21:55:12 +0200
commitb101af8db0558a686cabbe80d75b48d42afdc9ae (patch)
tree1490722486f1575b463c5ea57e8493ad878f8443 /src
parent7f66d1282a49ec8d6a5260aab05aa0a49d931b30 (diff)
downloadesieequest-b101af8db0558a686cabbe80d75b48d42afdc9ae.tar.gz
Better sound toggling
Diffstat (limited to 'src')
-rw-r--r--src/esieequest/controller/commands/Command.java2
-rw-r--r--src/esieequest/controller/commands/ToggleSoundCommand.java20
-rw-r--r--src/esieequest/view/app/UserInterface.java17
-rw-r--r--src/esieequest/view/web/WebInterface.java22
4 files changed, 30 insertions, 31 deletions
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 {
24 QUIT(new QuitCommand()), 24 QUIT(new QuitCommand()),
25 HELP(new HelpCommand()), 25 HELP(new HelpCommand()),
26 ALEA(new AleaCommand()), 26 ALEA(new AleaCommand()),
27 SOUND(new NewCommand()), 27 SOUND(new ToggleSoundCommand()),
28 28
29 // map related 29 // map related
30 GO(new GoCommand()), 30 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 @@
1package esieequest.controller.commands;
2
3import esieequest.model.Game;
4import esieequest.view.Viewable;
5
6/**
7 * Mute/unmute the game musics.
8 *
9 * @author Pacien TRAN-GIRARD
10 */
11public class ToggleSoundCommand implements Executable {
12
13 @Override
14 public void execute(final String argument, final Game game, final Viewable view) {
15
16 view.toggleSound();
17
18 }
19
20}
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 {
163 163
164 this.soundButton = new JButton(Text.TOGGLE_SOUND_BUTTON.toString()); 164 this.soundButton = new JButton(Text.TOGGLE_SOUND_BUTTON.toString());
165 this.soundButton.setToolTipText(Text.TOGGLE_SOUND_TOOLTIP.toString()); 165 this.soundButton.setToolTipText(Text.TOGGLE_SOUND_TOOLTIP.toString());
166 this.newButton.setActionCommand(Command.SOUND.name()); 166 this.soundButton.setActionCommand(Command.SOUND.name());
167 this.gamePanel.add(this.soundButton); 167 this.gamePanel.add(this.soundButton);
168 168
169 this.filePanel = new JPanel(); 169 this.filePanel = new JPanel();
@@ -512,14 +512,6 @@ abstract class UserInterface implements Viewable, ActionListener {
512 } 512 }
513 513
514 /** 514 /**
515 * Toggles the sound (music).
516 */
517 private void toggleAudio() {
518 this.muted = !this.muted;
519 this.setAudioGain();
520 }
521
522 /**
523 * Sets the gain. 515 * Sets the gain.
524 * 516 *
525 * PulseAudio does not comply with the JSAPI => pause/play instead of muting 517 * PulseAudio does not comply with the JSAPI => pause/play instead of muting
@@ -536,7 +528,7 @@ abstract class UserInterface implements Viewable, ActionListener {
536 // this.audio.setGain(0.0f); 528 // this.audio.setGain(0.0f);
537 this.audio.pause(); 529 this.audio.pause();
538 } else if (this.audio.isPaused()) { 530 } else if (this.audio.isPaused()) {
539 // this.audio.setGain(-1.0f);$ 531 // this.audio.setGain(-1.0f);
540 this.audio.resume(); 532 this.audio.resume();
541 } 533 }
542 } 534 }
@@ -549,8 +541,6 @@ abstract class UserInterface implements Viewable, ActionListener {
549 public void actionPerformed(final ActionEvent actionEvent) { 541 public void actionPerformed(final ActionEvent actionEvent) {
550 if (actionEvent.getActionCommand() == Command.INVENTORY.name()) { 542 if (actionEvent.getActionCommand() == Command.INVENTORY.name()) {
551 this.toggleInventory(); 543 this.toggleInventory();
552 } else if (actionEvent.getActionCommand() == Text.TOGGLE_SOUND_BUTTON.toString()) {
553 this.toggleAudio();
554 } else if (actionEvent.getActionCommand() == Command.LOAD.name()) { 544 } else if (actionEvent.getActionCommand() == Command.LOAD.name()) {
555 final JFileChooser fileChooser = new JFileChooser(); 545 final JFileChooser fileChooser = new JFileChooser();
556 fileChooser.setFileFilter(new FileNameExtensionFilter(UserInterface.SAVE_LABEL, 546 fileChooser.setFileFilter(new FileNameExtensionFilter(UserInterface.SAVE_LABEL,
@@ -677,7 +667,8 @@ abstract class UserInterface implements Viewable, ActionListener {
677 667
678 @Override 668 @Override
679 public void toggleSound() { 669 public void toggleSound() {
680 return; 670 this.muted = !this.muted;
671 this.setAudioGain();
681 } 672 }
682 673
683 @Override 674 @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 {
225 225
226 this.soundButton.setText(Text.TOGGLE_SOUND_BUTTON.toString()); 226 this.soundButton.setText(Text.TOGGLE_SOUND_BUTTON.toString());
227 this.soundButton.setTitle(Text.TOGGLE_SOUND_TOOLTIP.toString()); 227 this.soundButton.setTitle(Text.TOGGLE_SOUND_TOOLTIP.toString());
228 this.soundButton.addClickHandler(new ClickHandler() { 228 this.soundButton.addClickHandler(this.makeClickHandler(Command.SOUND.name()));
229 @Override
230 public void onClick(final ClickEvent event) {
231 WebInterface.this.toggleAudio();
232 }
233 });
234 229
235 this.loadButton.setText(Text.LOAD_GAME_BUTTON.toString()); 230 this.loadButton.setText(Text.LOAD_GAME_BUTTON.toString());
236 this.loadButton.setTitle(Text.LOAD_GAME_TOOLTIP.toString()); 231 this.loadButton.setTitle(Text.LOAD_GAME_TOOLTIP.toString());
@@ -313,16 +308,6 @@ class WebInterface extends Composite implements Viewable {
313 } 308 }
314 309
315 /** 310 /**
316 * Toggles the sound (music).
317 */
318 private void toggleAudio() {
319 if (this.audio == null) {
320 return;
321 }
322 this.audio.setMuted(!this.audio.isMuted());
323 }
324
325 /**
326 * Sets the illustration of the side of the room. 311 * Sets the illustration of the side of the room.
327 * 312 *
328 * @param illustration 313 * @param illustration
@@ -464,7 +449,10 @@ class WebInterface extends Composite implements Viewable {
464 449
465 @Override 450 @Override
466 public void toggleSound() { 451 public void toggleSound() {
467 return; 452 if (this.audio == null) {
453 return;
454 }
455 this.audio.setMuted(!this.audio.isMuted());
468 } 456 }
469 457
470 @Override 458 @Override