[Mobile] set volume when track changes

This commit is contained in:
Anthony Calosa
2021-02-05 02:26:33 +08:00
parent 04fd9709ac
commit d5e1392ae7
5 changed files with 6 additions and 35 deletions

View File

@@ -27,7 +27,6 @@ import forge.properties.ForgeConstants;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.MissingResourceException;

View File

@@ -78,8 +78,6 @@ 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) {
@@ -120,9 +118,6 @@ 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,8 +1,9 @@
package forge.animation;
import forge.Forge;
import forge.Graphics;
import forge.model.FModel;
import forge.properties.ForgeConstants;
import forge.properties.ForgePreferences;
import forge.sound.AudioClip;
public enum AbilityEffect {
@@ -24,7 +25,7 @@ public enum AbilityEffect {
if (soundClip == null) {
soundClip = AudioClip.createClip(ForgeConstants.EFFECTS_DIR + wav);
}
soundClip.play(Forge.clipVol);
soundClip.play(FModel.getPreferences().getPrefInt(ForgePreferences.FPref.UI_VOL_SOUNDS)/100f);
animation.start();
}

View File

@@ -442,19 +442,8 @@ public class SettingsPage extends TabPage<SettingsScreen> {
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;
}
catch (Exception e) {
Forge.clipVol = 1f;
}
}
}, 7);
new String[]{"0", "25", "50", "75", "100"}),
7);
lstSettings.addItem(new CustomSelectSetting(FPref.UI_VOL_MUSIC,
localizer.getMessage("cbAdjustMusicVolume"),
localizer.getMessage("nlAdjustMusicVolume"),
@@ -462,16 +451,8 @@ public class SettingsPage extends TabPage<SettingsScreen> {
@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 {

View File

@@ -194,12 +194,6 @@ 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) {
@@ -228,6 +222,7 @@ public class SoundSystem {
changeBackgroundTrack(); //change track when music completes on its own
}
});
currentTrack.setVolume(FModel.getPreferences().getPrefInt(FPref.UI_VOL_MUSIC)/100f);
} catch (final Exception ex) {
System.err.println("Unable to load music file: " + filename);
}