[Mobile] Sound/Music Adjustment

This commit is contained in:
Anthony Calosa
2021-02-05 01:32:00 +08:00
parent 3fb0f28dde
commit 96a2ccc3a5
17 changed files with 123 additions and 26 deletions

View File

@@ -58,7 +58,7 @@ public class AudioClip implements IAudioClip {
}
@Override
public final void play() {
public final void play(float value) {
if (clips.stream().anyMatch(ClipWrapper::isRunning)) {
// introduce small delay to make a batch sounds more granular,
// e.g. when you auto-tap 4 lands the 4 tap sounds should

View File

@@ -114,4 +114,9 @@ public class AudioMusic implements IAudioMusic {
close();
canResume = false;
}
@Override
public void setVolume(float value) {
//todo
}
}

View File

@@ -78,6 +78,8 @@ public class Forge implements ApplicationListener {
public static int androidVersion = 0;
public static boolean autoCache = false;
public static int lastButtonIndex = 0;
public static float clipVol = 1f;
public static float musicVol = 1f;
public static ApplicationListener getApp(Clipboard clipboard0, IDeviceAdapter deviceAdapter0, String assetDir0, boolean value, boolean androidOrientation, int totalRAM, boolean isTablet, int AndroidAPI, String AndroidRelease, String deviceName) {
if (GuiBase.getInterface() == null) {
@@ -118,6 +120,9 @@ public class Forge implements ApplicationListener {
destroyThis = true; //Prevent back()
ForgePreferences prefs = new ForgePreferences();
clipVol = prefs.getPrefInt(FPref.UI_VOL_SOUNDS)/100f;
musicVol = prefs.getPrefInt(FPref.UI_VOL_SOUNDS)/100f;
String skinName;
if (FileUtil.doesFileExist(ForgeConstants.MAIN_PREFS_FILE)) {
skinName = prefs.getPref(FPref.UI_SKIN);

View File

@@ -1,5 +1,6 @@
package forge.animation;
import forge.Forge;
import forge.Graphics;
import forge.properties.ForgeConstants;
import forge.sound.AudioClip;
@@ -23,7 +24,7 @@ public enum AbilityEffect {
if (soundClip == null) {
soundClip = AudioClip.createClip(ForgeConstants.EFFECTS_DIR + wav);
}
soundClip.play();
soundClip.play(Forge.clipVol);
animation.start();
}

View File

@@ -438,20 +438,58 @@ public class SettingsPage extends TabPage<SettingsScreen> {
localizer.getMessage("nlVibrateAfterLongPress")),
6);
//Sound Options
lstSettings.addItem(new BooleanSetting(FPref.UI_ENABLE_SOUNDS,
localizer.getMessage("cbEnableSounds"),
localizer.getMessage("nlEnableSounds")),
7);
lstSettings.addItem(new BooleanSetting(FPref.UI_ENABLE_MUSIC,
localizer.getMessage("cbEnableMusic"),
localizer.getMessage("nlEnableMusic")) {
@Override
public void select() {
super.select();
//update background music when this setting changes
SoundSystem.instance.changeBackgroundTrack();
if(GuiBase.getInterface().isLibgdxPort()) {
lstSettings.addItem(new CustomSelectSetting(FPref.UI_VOL_SOUNDS,
localizer.getMessage("cbAdjustSoundsVolume"),
localizer.getMessage("nlAdjustSoundsVolume"),
new String[]{"0", "25", "50", "75", "100"}) {
@Override
public void valueChanged(String newValue) {
super.valueChanged(newValue);
try {
int val = Integer.parseInt(newValue);
Forge.clipVol = val/100f;
}
},7);
catch (Exception e) {
Forge.clipVol = 1f;
}
}
}, 7);
lstSettings.addItem(new CustomSelectSetting(FPref.UI_VOL_MUSIC,
localizer.getMessage("cbAdjustMusicVolume"),
localizer.getMessage("nlAdjustMusicVolume"),
new String[]{"0", "25", "50", "75", "100"}) {
@Override
public void valueChanged(String newValue) {
super.valueChanged(newValue);
try {
int val = Integer.parseInt(newValue);
Forge.musicVol = val/100f;
}
catch (Exception e) {
Forge.musicVol = 1f;
}
//update background music when this setting changes
SoundSystem.instance.changeBackgroundTrack();
SoundSystem.instance.adjustVolume(Forge.musicVol);
}
}, 7);
} else {
lstSettings.addItem(new BooleanSetting(FPref.UI_ENABLE_SOUNDS,
localizer.getMessage("cbEnableSounds"),
localizer.getMessage("nlEnableSounds")),
7);
lstSettings.addItem(new BooleanSetting(FPref.UI_ENABLE_MUSIC,
localizer.getMessage("cbEnableMusic"),
localizer.getMessage("nlEnableMusic")) {
@Override
public void select() {
super.select();
//update background music when this setting changes
SoundSystem.instance.changeBackgroundTrack();
}
},7);
}
/*lstSettings.addItem(new BooleanSetting(FPref.UI_ALT_SOUND_SYSTEM,
"Use Alternate Sound System",
"Use the alternate sound system (only use if you have issues with sound not playing or disappearing)."),

View File

@@ -40,7 +40,7 @@ public class AudioClip implements IAudioClip {
}
}
public final void play() {
public final void play(float value) {
if (clip == null) {
return;
}
@@ -50,7 +50,7 @@ public class AudioClip implements IAudioClip {
catch (InterruptedException ex) {
ex.printStackTrace();
}
clip.play();
clip.play(value);
}
public final void loop() {

View File

@@ -40,4 +40,9 @@ public class AudioMusic implements IAudioMusic {
stop();
music.dispose();
}
@Override
public void setVolume(float value) {
music.setVolume(value);
}
}

View File

@@ -84,6 +84,8 @@ cbRandomFoil=zufällige Foil-Karten
cbRandomArtInPools=zufällige Kartenbilder in erzeugten Kartensammlungen
cbEnableSounds=Ton aktiviert
cbEnableMusic=Musik aktiviert
cbAdjustSoundsVolume=Adjust Sound Volume
cbAdjustMusicVolume=Adjust Music Volume
cbAltSoundSystem=Nutze alternatives Sound-System
cbSROptimize=Optimiere Interface für Screenreader
cbUiForTouchScreen=Verbessere Oberfläche für Touchscreens
@@ -182,6 +184,8 @@ nlDisplayCurrentCardColors=Zeigt eine Übersicht der aktuellen Farbe der Karten
SoundOptions=Sound-Optionen
nlEnableSounds=Geräusche während des Spiels
nlEnableMusic=Hintergrundmusik während des Spiels
nlAdjustSoundsVolume=Adjust sound effects volume during the game
nlAdjustMusicVolume=Adjust background music during the game
nlAltSoundSystem=Nutze alternatives Sound-System (nur nutzen, wenn es Probleme mit fehlenden Geräuschen gibt)
nlSrOptimize=Setze verschiedene Optionen, um Forge besser für Screenreader lesbar zu machen
KeyboardShortcuts=Tastenkombinationen

View File

@@ -84,6 +84,8 @@ cbRandomFoil=Random Foil
cbRandomArtInPools=Randomize Card Art in Generated Card Pools
cbEnableSounds=Enable Sounds
cbEnableMusic=Enable Music
cbAdjustSoundsVolume=Adjust Sound Volume
cbAdjustMusicVolume=Adjust Music Volume
cbAltSoundSystem=Use Alternate Sound System
cbSROptimize=Optimize UI for screen readers
cbUiForTouchScreen=Enhance UI for Touchscreens
@@ -182,6 +184,8 @@ nlDisplayCurrentCardColors=Displays the breakdown of the current color of cards
SoundOptions=Sound Options
nlEnableSounds=Enable sound effects during the game
nlEnableMusic=Enable background music during the game
nlAdjustSoundsVolume=Adjust sound effects volume during the game
nlAdjustMusicVolume=Adjust background music during the game
nlAltSoundSystem=Use the alternate sound system (only use if you have issues with sound not playing or disappearing)
nlSrOptimize=Set various options to make FOrge work better with screen readers
KeyboardShortcuts=Keyboard Shortcuts

View File

@@ -84,6 +84,8 @@ cbRandomFoil=Foil Aleatorio
cbRandomArtInPools=Aleatorizar Arte de la Carta en los pools que se generen
cbEnableSounds=Activar sonidos
cbEnableMusic=Activar música
cbAdjustSoundsVolume=Adjust Sound Volume
cbAdjustMusicVolume=Adjust Music Volume
cbAltSoundSystem=Utilizar el sistema de sonido alternativo
cbSROptimize=Optimizar la interfaz de usuario para los lectores de pantalla
cbUiForTouchScreen=Mejorar la interfaz de usuario para pantallas táctiles
@@ -182,6 +184,8 @@ nlDisplayCurrentCardColors=Muestra el color actual de las cartas en el panel de
SoundOptions=Opciones de Sonido
nlEnableSounds=Habilita los efectos de sonido durante el juego
nlEnableMusic=Habilita la música de fondo durante el juego
nlAdjustSoundsVolume=Adjust sound effects volume during the game
nlAdjustMusicVolume=Adjust background music during the game
nlAltSoundSystem=Use el sistema de sonido alternativo (solo use si tiene problemas con el sonido que no se reproduce o desaparece)
nlSrOptimize=Establecer varias opciones para que Forge funcione mejor con los lectores de pantalla
KeyboardShortcuts=Atajos de teclado

View File

@@ -84,6 +84,8 @@ cbRandomFoil=Lamina casuale
cbRandomArtInPools=Randomizza l''arte della carta nei pool di carte generati
cbEnableSounds=Abilita suoni
cbEnableMusic=Abilita musica
cbAdjustSoundsVolume=Adjust Sound Volume
cbAdjustMusicVolume=Adjust Music Volume
cbAltSoundSystem=Usa un sistema audio alternativo
cbSROptimize=Optimize UI for screen readers
cbUiForTouchScreen=Migliora l''interfaccia utente per i touchscreen
@@ -182,6 +184,8 @@ nlDisplayCurrentCardColors=Visualizza la suddivisione del colore corrente delle
SoundOptions=Opzioni audio
nlEnableSounds=Abilita gli effetti sonori durante il gioco
nlEnableMusic=Abilita la musica di sottofondo durante il gioco
nlAdjustSoundsVolume=Adjust sound effects volume during the game
nlAdjustMusicVolume=Adjust background music during the game
nlAltSoundSystem=Utilizza il sistema audio alternativo (utilizza solo se hai problemi con l''audio che non viene riprodotto o che scompare)
nlSrOptimize=Set various options to make FOrge work better with screen readers
KeyboardShortcuts=Tasti rapidi

View File

@@ -84,6 +84,8 @@ cbRandomFoil=随机闪卡
cbRandomArtInPools=在生成的卡池中随机加入闪卡
cbEnableSounds=启用音效
cbEnableMusic=启用背景音乐
cbAdjustSoundsVolume=Adjust Sound Volume
cbAdjustMusicVolume=Adjust Music Volume
cbAltSoundSystem=使用备用音效系统
cbUiForTouchScreen=触摸屏UI增强
cbSROptimize=为屏幕阅读器启用UI优化
@@ -182,6 +184,8 @@ nlDisplayCurrentCardColors=在卡牌详情窗格中显示当前牌的颜色
SoundOptions=声音选项
nlEnableSounds=在游戏中启用声音效果
nlEnableMusic=在游戏中启用背景音乐
nlAdjustSoundsVolume=Adjust sound effects volume during the game
nlAdjustMusicVolume=Adjust background music during the game
nlAltSoundSystem=使用备用音效系统(仅在声音消失的情况使用)
nlSrOptimize=使屏幕阅读器能更好的在forge上使用
KeyboardShortcuts=键盘快捷键

View File

@@ -111,6 +111,8 @@ public class ForgePreferences extends PreferencesStore<ForgePreferences.FPref> {
UI_TIMED_TARGETING_OVERLAY_UPDATES ("true"),
UI_ENABLE_SOUNDS ("true"),
UI_ENABLE_MUSIC ("true"),
UI_VOL_SOUNDS ("100"),
UI_VOL_MUSIC ("100"),
UI_ALT_SOUND_SYSTEM ("false"),
UI_CURRENT_AI_PROFILE ("Default"),
UI_CLONE_MODE_SOURCE ("false"),

View File

@@ -1,7 +1,7 @@
package forge.sound;
public interface IAudioClip {
void play();
void play(float value);
boolean isDone();
void stop();
void loop();

View File

@@ -6,4 +6,5 @@ public interface IAudioMusic {
void resume();
void stop();
void dispose();
void setVolume(float value);
}

View File

@@ -4,7 +4,7 @@ package forge.sound;
public class NoSoundClip implements IAudioClip {
@Override
public void play() { }
public void play(float value) { }
@Override
public boolean isDone() { return false; }

View File

@@ -43,8 +43,14 @@ public class SoundSystem {
* was unavailable or failed to load.
*/
protected IAudioClip fetchResource(final SoundEffectType type) {
if (!FModel.getPreferences().getPrefBoolean(FPref.UI_ENABLE_SOUNDS)) {
return emptySound;
if (GuiBase.getInterface().isLibgdxPort()) {
if (FModel.getPreferences().getPrefInt(FPref.UI_VOL_SOUNDS)<1) {
return emptySound;
}
} else {
if (!FModel.getPreferences().getPrefBoolean(FPref.UI_ENABLE_SOUNDS)) {
return emptySound;
}
}
IAudioClip clip = loadedClips.get(type);
@@ -66,8 +72,14 @@ public class SoundSystem {
* was unavailable or failed to load.
*/
protected IAudioClip fetchResource(final String fileName) {
if (!FModel.getPreferences().getPrefBoolean(FPref.UI_ENABLE_SOUNDS)) {
return emptySound;
if (GuiBase.getInterface().isLibgdxPort()) {
if (FModel.getPreferences().getPrefInt(FPref.UI_VOL_SOUNDS)<1) {
return emptySound;
}
} else {
if (!FModel.getPreferences().getPrefBoolean(FPref.UI_ENABLE_SOUNDS)) {
return emptySound;
}
}
IAudioClip clip = loadedScriptClips.get(fileName);
@@ -101,7 +113,7 @@ public class SoundSystem {
else {
final IAudioClip snd = fetchResource(resourceFileName);
if (!isSynchronized || snd.isDone()) {
snd.play();
snd.play(FModel.getPreferences().getPrefInt(FPref.UI_VOL_SOUNDS)/100f);
}
}
}
@@ -116,7 +128,7 @@ public class SoundSystem {
else {
final IAudioClip snd = fetchResource(type);
if (!isSynchronized || snd.isDone()) {
snd.play();
snd.play(FModel.getPreferences().getPrefInt(FPref.UI_VOL_SOUNDS)/100f);
}
}
}
@@ -182,6 +194,12 @@ public class SoundSystem {
changeBackgroundTrack();
}
public void adjustVolume(float value) {
if (currentTrack != null) {
currentTrack.setVolume(value);
}
}
public void changeBackgroundTrack() {
//ensure old track stopped and disposed of if needed
if (currentTrack != null) {
@@ -189,7 +207,9 @@ public class SoundSystem {
currentTrack = null;
}
if (currentPlaylist == null || !FModel.getPreferences().getPrefBoolean(FPref.UI_ENABLE_MUSIC)) {
if (currentPlaylist == null || GuiBase.getInterface().isLibgdxPort()
? FModel.getPreferences().getPrefInt(FPref.UI_VOL_MUSIC) < 1
: !FModel.getPreferences().getPrefBoolean(FPref.UI_ENABLE_MUSIC)) {
return;
}