From c7e8dfb8fb467242ee5564515c3c045bf01cda64 Mon Sep 17 00:00:00 2001 From: Jack Rainy Date: Thu, 12 Mar 2020 08:35:45 +0200 Subject: [PATCH] Energy saving: music and sounds (#2128) --- core/src/com/unciv/UncivGame.kt | 3 ++- core/src/com/unciv/ui/utils/Sounds.kt | 5 +++-- .../ui/worldscreen/mainmenu/WorldScreenOptionsPopup.kt | 7 ++++++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/core/src/com/unciv/UncivGame.kt b/core/src/com/unciv/UncivGame.kt index 14750d9cd1..efd1ffe621 100644 --- a/core/src/com/unciv/UncivGame.kt +++ b/core/src/com/unciv/UncivGame.kt @@ -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()) { diff --git a/core/src/com/unciv/ui/utils/Sounds.kt b/core/src/com/unciv/ui/utils/Sounds.kt index d80a9125c7..24a9e2a136 100644 --- a/core/src/com/unciv/ui/utils/Sounds.kt +++ b/core/src/com/unciv/ui/utils/Sounds.kt @@ -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) } } \ No newline at end of file diff --git a/core/src/com/unciv/ui/worldscreen/mainmenu/WorldScreenOptionsPopup.kt b/core/src/com/unciv/ui/worldscreen/mainmenu/WorldScreenOptionsPopup.kt index a07e6b8624..9625a99c65 100644 --- a/core/src/com/unciv/ui/worldscreen/mainmenu/WorldScreenOptionsPopup.kt +++ b/core/src/com/unciv/ui/worldscreen/mainmenu/WorldScreenOptionsPopup.kt @@ -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()