Energy saving: music and sounds (#2128)

This commit is contained in:
Jack Rainy
2020-03-12 08:35:45 +02:00
committed by GitHub
parent 528392baab
commit c7e8dfb8fb
3 changed files with 11 additions and 4 deletions

View File

@ -96,7 +96,7 @@ class UncivGame(
Gdx.app.postRunnable {
CameraStageBaseScreen.resetFonts()
autoLoadGame()
thread { startMusic() }
thread(name="Music") { startMusic() }
isInitialized = true
}
}
@ -114,6 +114,7 @@ class UncivGame(
}
fun startMusic() {
if (settings.musicVolume < 0.01) return
val musicFile = Gdx.files.local(musicLocation)
if (musicFile.exists()) {

View File

@ -16,7 +16,8 @@ object Sounds {
}
fun play(sound: UncivSound) {
if (sound == UncivSound.Silent) return
get(sound).play(UncivGame.Current.settings.soundEffectsVolume)
val volume = UncivGame.Current.settings.soundEffectsVolume
if (sound == UncivSound.Silent || volume < 0.01) return
get(sound).play(volume)
}
}

View File

@ -201,7 +201,12 @@ class WorldScreenOptionsPopup(val worldScreen:WorldScreen) : Popup(worldScreen){
override fun changed(event: ChangeEvent?, actor: Actor?) {
UncivGame.Current.settings.musicVolume = musicVolumeSlider.value
UncivGame.Current.settings.save()
UncivGame.Current.music?.volume = 0.4f * musicVolumeSlider.value
val music = UncivGame.Current.music
if (music == null) // restart music, if it was off at the app start
thread(name="Music") { UncivGame.Current.startMusic() }
music?.volume = 0.4f * musicVolumeSlider.value
}
})
innerTable.add(musicVolumeSlider).pad(10f).row()