mirror of
https://github.com/magefree/mage.git
synced 2025-12-22 03:22:00 -08:00
Audio manager. Added playing sounds for paging in collection viewer.
This commit is contained in:
parent
5a0ca8025d
commit
d62b512a72
19 changed files with 166 additions and 0 deletions
BIN
Mage.Client/plugins/sounds/OnAddArtifact.wav
Normal file
BIN
Mage.Client/plugins/sounds/OnAddArtifact.wav
Normal file
Binary file not shown.
BIN
Mage.Client/plugins/sounds/OnAddPermanent.wav
Normal file
BIN
Mage.Client/plugins/sounds/OnAddPermanent.wav
Normal file
Binary file not shown.
BIN
Mage.Client/plugins/sounds/OnAttack.wav
Normal file
BIN
Mage.Client/plugins/sounds/OnAttack.wav
Normal file
Binary file not shown.
BIN
Mage.Client/plugins/sounds/OnBlock.wav
Normal file
BIN
Mage.Client/plugins/sounds/OnBlock.wav
Normal file
Binary file not shown.
BIN
Mage.Client/plugins/sounds/OnButtonCancel.wav
Normal file
BIN
Mage.Client/plugins/sounds/OnButtonCancel.wav
Normal file
Binary file not shown.
BIN
Mage.Client/plugins/sounds/OnButtonOk.wav
Normal file
BIN
Mage.Client/plugins/sounds/OnButtonOk.wav
Normal file
Binary file not shown.
BIN
Mage.Client/plugins/sounds/OnDraw.wav
Normal file
BIN
Mage.Client/plugins/sounds/OnDraw.wav
Normal file
Binary file not shown.
BIN
Mage.Client/plugins/sounds/OnEndTurn.wav
Normal file
BIN
Mage.Client/plugins/sounds/OnEndTurn.wav
Normal file
Binary file not shown.
BIN
Mage.Client/plugins/sounds/OnHover.wav
Normal file
BIN
Mage.Client/plugins/sounds/OnHover.wav
Normal file
Binary file not shown.
BIN
Mage.Client/plugins/sounds/OnNextPage.wav
Normal file
BIN
Mage.Client/plugins/sounds/OnNextPage.wav
Normal file
Binary file not shown.
BIN
Mage.Client/plugins/sounds/OnNextPhase.wav
Normal file
BIN
Mage.Client/plugins/sounds/OnNextPhase.wav
Normal file
Binary file not shown.
BIN
Mage.Client/plugins/sounds/OnPrevPage.wav
Normal file
BIN
Mage.Client/plugins/sounds/OnPrevPage.wav
Normal file
Binary file not shown.
BIN
Mage.Client/plugins/sounds/OnStackNew.wav
Normal file
BIN
Mage.Client/plugins/sounds/OnStackNew.wav
Normal file
Binary file not shown.
BIN
Mage.Client/plugins/sounds/OnSummon-.wav
Normal file
BIN
Mage.Client/plugins/sounds/OnSummon-.wav
Normal file
Binary file not shown.
BIN
Mage.Client/plugins/sounds/OnSummon.wav
Normal file
BIN
Mage.Client/plugins/sounds/OnSummon.wav
Normal file
Binary file not shown.
BIN
Mage.Client/plugins/sounds/OnTapPermanent.wav
Normal file
BIN
Mage.Client/plugins/sounds/OnTapPermanent.wav
Normal file
Binary file not shown.
|
|
@ -78,6 +78,7 @@ public final class Constants {
|
||||||
public static final String RESOURCE_PATH_MANA_LARGE = IO.imageBaseDir + "symbols" + File.separator + "large";
|
public static final String RESOURCE_PATH_MANA_LARGE = IO.imageBaseDir + "symbols" + File.separator + "large";
|
||||||
public static final String RESOURCE_PATH_MANA_MEDIUM = IO.imageBaseDir + "symbols" + File.separator + "medium";
|
public static final String RESOURCE_PATH_MANA_MEDIUM = IO.imageBaseDir + "symbols" + File.separator + "medium";
|
||||||
public static final String RESOURCE_PATH_SET = IO.imageBaseDir + "sets" + File.separator;
|
public static final String RESOURCE_PATH_SET = IO.imageBaseDir + "sets" + File.separator;
|
||||||
|
public static final String BASE_SOUND_PATH = "plugins" + File.separator + "sounds" + File.separator;
|
||||||
|
|
||||||
public interface IO {
|
public interface IO {
|
||||||
public static final String imageBaseDir = "plugins" + File.separator + "images" + File.separator;
|
public static final String imageBaseDir = "plugins" + File.separator + "images" + File.separator;
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,7 @@ import mage.client.components.HoverButton;
|
||||||
import mage.client.components.arcane.GlowText;
|
import mage.client.components.arcane.GlowText;
|
||||||
import mage.client.components.arcane.ManaSymbols;
|
import mage.client.components.arcane.ManaSymbols;
|
||||||
import mage.client.plugins.impl.Plugins;
|
import mage.client.plugins.impl.Plugins;
|
||||||
|
import mage.client.util.AudioManager;
|
||||||
import mage.client.util.Command;
|
import mage.client.util.Command;
|
||||||
import mage.client.util.ImageHelper;
|
import mage.client.util.ImageHelper;
|
||||||
import mage.components.ImagePanel;
|
import mage.components.ImagePanel;
|
||||||
|
|
@ -94,6 +95,7 @@ public class MageBook extends JComponent {
|
||||||
pageLeft.setVisible(false);
|
pageLeft.setVisible(false);
|
||||||
}
|
}
|
||||||
pageRight.setVisible(true);
|
pageRight.setVisible(true);
|
||||||
|
AudioManager.playPrevPage();
|
||||||
showCards();
|
showCards();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -107,6 +109,7 @@ public class MageBook extends JComponent {
|
||||||
currentPage++;
|
currentPage++;
|
||||||
pageLeft.setVisible(true);
|
pageLeft.setVisible(true);
|
||||||
pageRight.setVisible(false);
|
pageRight.setVisible(false);
|
||||||
|
AudioManager.playNextPage();
|
||||||
showCards();
|
showCards();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
162
Mage.Client/src/main/java/mage/client/util/AudioManager.java
Normal file
162
Mage.Client/src/main/java/mage/client/util/AudioManager.java
Normal file
|
|
@ -0,0 +1,162 @@
|
||||||
|
package mage.client.util;
|
||||||
|
|
||||||
|
import mage.client.constants.Constants;
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
|
import javax.sound.sampled.*;
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Manager class for playing audio files.
|
||||||
|
*
|
||||||
|
* @author nantuko
|
||||||
|
*/
|
||||||
|
public class AudioManager {
|
||||||
|
|
||||||
|
private static final Logger log = Logger.getLogger(AudioManager.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AudioManager singleton.
|
||||||
|
*/
|
||||||
|
private static AudioManager audioManager = null;
|
||||||
|
|
||||||
|
|
||||||
|
public static AudioManager getManager() {
|
||||||
|
if (audioManager == null) {
|
||||||
|
audioManager = new AudioManager();
|
||||||
|
audioManager.nextPageClip = audioManager.loadClip(Constants.BASE_SOUND_PATH + "OnNextPage.wav");
|
||||||
|
audioManager.prevPageClip = audioManager.loadClip(Constants.BASE_SOUND_PATH + "OnPrevPage.wav");
|
||||||
|
audioManager.nextPhaseClip = audioManager.loadClip(Constants.BASE_SOUND_PATH + "OnNextPhase.wav");
|
||||||
|
audioManager.endTurnClip = audioManager.loadClip(Constants.BASE_SOUND_PATH + "OnEndTurn.wav");
|
||||||
|
audioManager.tapPermanentClip = audioManager.loadClip(Constants.BASE_SOUND_PATH + "OnTapPermanent.wav");
|
||||||
|
audioManager.summonClip = audioManager.loadClip(Constants.BASE_SOUND_PATH + "OnSummon.wav");
|
||||||
|
audioManager.drawClip = audioManager.loadClip(Constants.BASE_SOUND_PATH + "OnDraw.wav");
|
||||||
|
audioManager.buttonOkClip = audioManager.loadClip(Constants.BASE_SOUND_PATH + "OnButtonOk.wav");
|
||||||
|
audioManager.buttonCancelClip = audioManager.loadClip(Constants.BASE_SOUND_PATH + "OnButtonCancel.wav");
|
||||||
|
audioManager.attackClip = audioManager.loadClip(Constants.BASE_SOUND_PATH + "OnAttack.wav");
|
||||||
|
audioManager.blockClip = audioManager.loadClip(Constants.BASE_SOUND_PATH + "OnBlock.wav");
|
||||||
|
audioManager.addPermanentClip = audioManager.loadClip(Constants.BASE_SOUND_PATH + "OnAddPermanent.wav");
|
||||||
|
audioManager.addArtifactClip = audioManager.loadClip(Constants.BASE_SOUND_PATH + "OnAddArtifact.wav");
|
||||||
|
audioManager.updateStackClip = audioManager.loadClip(Constants.BASE_SOUND_PATH + "OnStackNew.wav");
|
||||||
|
audioManager.onHover = audioManager.loadClip(Constants.BASE_SOUND_PATH + "OnHover.wav");
|
||||||
|
}
|
||||||
|
return audioManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void playNextPage() {
|
||||||
|
checkAndPlayClip(getManager().nextPageClip);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void playPrevPage() {
|
||||||
|
checkAndPlayClip(getManager().prevPageClip);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void playNextPhase() {
|
||||||
|
checkAndPlayClip(getManager().nextPhaseClip);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void playEndTurn() {
|
||||||
|
checkAndPlayClip(getManager().endTurnClip);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void playTapPermanent() {
|
||||||
|
checkAndPlayClip(getManager().tapPermanentClip);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void playSummon() {
|
||||||
|
checkAndPlayClip(getManager().summonClip);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void playDraw() {
|
||||||
|
checkAndPlayClip(getManager().drawClip);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void playButtonOk() {
|
||||||
|
checkAndPlayClip(getManager().buttonOkClip);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void playButtonCancel() {
|
||||||
|
checkAndPlayClip(getManager().buttonCancelClip);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void playAttack() {
|
||||||
|
checkAndPlayClip(getManager().attackClip);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void playBlock() {
|
||||||
|
checkAndPlayClip(getManager().blockClip);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void playAddPermanent() {
|
||||||
|
checkAndPlayClip(getManager().addPermanentClip);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void playAddArtifact() {
|
||||||
|
checkAndPlayClip(getManager().addArtifactClip);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void playStackNew() {
|
||||||
|
checkAndPlayClip(getManager().updateStackClip);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void playOnHover() {
|
||||||
|
checkAndPlayClip(getManager().onHover);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void checkAndPlayClip(Clip clip) {
|
||||||
|
try {
|
||||||
|
if (clip != null) {
|
||||||
|
audioManager.play(clip);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void play(final Clip clip) {
|
||||||
|
new Thread(new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
clip.setFramePosition(0);
|
||||||
|
clip.start();
|
||||||
|
}
|
||||||
|
}).run();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Clip loadClip(String filename) {
|
||||||
|
try {
|
||||||
|
File soundFile = new File(filename);
|
||||||
|
AudioInputStream soundIn = AudioSystem
|
||||||
|
.getAudioInputStream(soundFile);
|
||||||
|
AudioFormat format = new AudioFormat(
|
||||||
|
AudioFormat.Encoding.PCM_SIGNED, AudioSystem.NOT_SPECIFIED,
|
||||||
|
16, 2, 4, AudioSystem.NOT_SPECIFIED, true);
|
||||||
|
DataLine.Info info = new DataLine.Info(Clip.class, format);
|
||||||
|
|
||||||
|
Clip clip = (Clip) AudioSystem.getLine(info);
|
||||||
|
clip.open(soundIn);
|
||||||
|
|
||||||
|
return clip;
|
||||||
|
} catch (Exception e) {
|
||||||
|
//e.printStackTrace();
|
||||||
|
log.error("Couldn't load sound: " + filename + ".");
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Clip nextPageClip = null;
|
||||||
|
private Clip prevPageClip = null;
|
||||||
|
private Clip nextPhaseClip = null;
|
||||||
|
private Clip endTurnClip = null;
|
||||||
|
private Clip tapPermanentClip = null;
|
||||||
|
private Clip summonClip = null;
|
||||||
|
private Clip drawClip = null;
|
||||||
|
private Clip buttonOkClip = null;
|
||||||
|
private Clip buttonCancelClip = null;
|
||||||
|
private Clip attackClip = null;
|
||||||
|
private Clip blockClip = null;
|
||||||
|
private Clip addPermanentClip = null;
|
||||||
|
private Clip addArtifactClip = null;
|
||||||
|
private Clip updateStackClip = null;
|
||||||
|
private Clip onHover = null;
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue