diff --git a/core/src/com/unciv/UncivGame.kt b/core/src/com/unciv/UncivGame.kt index 5d982e3fa6..a6be5deff7 100644 --- a/core/src/com/unciv/UncivGame.kt +++ b/core/src/com/unciv/UncivGame.kt @@ -19,7 +19,6 @@ import com.unciv.models.ruleset.RulesetCache import com.unciv.models.skins.SkinCache import com.unciv.models.tilesets.TileSetCache import com.unciv.models.translations.Translations -import com.unciv.ui.audio.GameSounds import com.unciv.ui.audio.MusicController import com.unciv.ui.audio.MusicMood import com.unciv.ui.audio.MusicTrackChooserFlags @@ -103,7 +102,6 @@ open class UncivGame(val isConsoleMode: Boolean = false) : Game(), PlatformSpeci settings = files.getGeneralSettings() // needed for the screen Display.setScreenMode(settings.screenMode, settings) setAsRootScreen(GameStartScreen()) // NOT dependent on any atlas or skin - GameSounds.init() musicController = MusicController() // early, but at this point does only copy volume from settings installAudioHooks() @@ -292,7 +290,7 @@ open class UncivGame(val isConsoleMode: Boolean = false) : Game(), PlatformSpeci fun popScreen(): BaseScreen? { if (screenStack.size == 1) { musicController.pause() - UncivGame.Current.settings.autoPlay.stopAutoPlay() + settings.autoPlay.stopAutoPlay() ConfirmPopup( screen = screenStack.last(), question = "Do you want to exit the game?", diff --git a/core/src/com/unciv/logic/multiplayer/OnlineMultiplayerGame.kt b/core/src/com/unciv/logic/multiplayer/OnlineMultiplayerGame.kt index e6afeeb169..20d9d31413 100644 --- a/core/src/com/unciv/logic/multiplayer/OnlineMultiplayerGame.kt +++ b/core/src/com/unciv/logic/multiplayer/OnlineMultiplayerGame.kt @@ -9,6 +9,7 @@ import com.unciv.logic.multiplayer.GameUpdateResult.Type.FAILURE import com.unciv.logic.multiplayer.GameUpdateResult.Type.UNCHANGED import com.unciv.logic.multiplayer.storage.FileStorageRateLimitReached import com.unciv.logic.multiplayer.storage.OnlineMultiplayerServer +import com.unciv.ui.audio.SoundPlayer import com.unciv.ui.components.extensions.isLargerThan import com.unciv.utils.debug import com.unciv.utils.launchOnGLThread @@ -120,9 +121,23 @@ class OnlineMultiplayerGame( preview = gameInfo withGLContext { EventBus.send(MultiplayerGameUpdated(name, gameInfo)) + playMultiplayerTurnNotification(gameInfo) } } + + private fun playMultiplayerTurnNotification(gameInfoPreview: GameInfoPreview) { + if (!gameInfoPreview.isUsersTurn()) return + if (UncivGame.isDeepLinkedGameLoading()) return // This means we already arrived here through a turn notification, no need to notify again + + val sound = if (UncivGame.isCurrentGame(gameInfoPreview.gameId)) { + UncivGame.Current.settings.multiplayer.currentGameTurnNotificationSound + } else { + UncivGame.Current.settings.multiplayer.otherGameTurnNotificationSound + } + SoundPlayer.play(sound) + } + override fun equals(other: Any?): Boolean = other is OnlineMultiplayerGame && fileHandle == other.fileHandle override fun hashCode(): Int = fileHandle.hashCode() } diff --git a/core/src/com/unciv/ui/audio/GameSounds.kt b/core/src/com/unciv/ui/audio/GameSounds.kt deleted file mode 100644 index 3e2f18fe3a..0000000000 --- a/core/src/com/unciv/ui/audio/GameSounds.kt +++ /dev/null @@ -1,35 +0,0 @@ -package com.unciv.ui.audio - -import com.unciv.UncivGame -import com.unciv.logic.event.EventBus -import com.unciv.logic.multiplayer.MultiplayerGameUpdated -import com.unciv.logic.multiplayer.isUsersTurn - -/** - * Controls which sounds should be played when something happens while playing the game. - */ -object GameSounds { - private val events = EventBus.EventReceiver() - private val settings get() = UncivGame.Current.settings - private val mpSettings get() = settings.multiplayer - - /** - * Has to be called for sounds to be played. - */ - fun init() { - playMultiplayerTurnNotification() - } - - private fun playMultiplayerTurnNotification() { - events.receive(MultiplayerGameUpdated::class, { it.preview.isUsersTurn() }) { - if (UncivGame.isDeepLinkedGameLoading()) return@receive // This means we already arrived here through a turn notification, no need to notify again - val gameId = it.preview.gameId - val sound = if (UncivGame.isCurrentGame(gameId)) { - mpSettings.currentGameTurnNotificationSound - } else { - mpSettings.otherGameTurnNotificationSound - } - SoundPlayer.play(sound) - } - } -} diff --git a/core/src/com/unciv/ui/audio/SoundPlayer.kt b/core/src/com/unciv/ui/audio/SoundPlayer.kt index 2bdeca9e35..a71791d933 100644 --- a/core/src/com/unciv/ui/audio/SoundPlayer.kt +++ b/core/src/com/unciv/ui/audio/SoundPlayer.kt @@ -164,12 +164,7 @@ object SoundPlayer { return GetSoundResult(newSound, true) } - /** - * Find, cache and play a Sound. - * - * **Attention:** The [GameSounds] object has been set up to control playing all sounds of the game. Chances are that you shouldn't be calling this method - * from anywhere but [GameSounds]. - * + /** Play a sound once. Will not play if the sound is [UncivSound.Silent] or the volume is too low. * Sources are mods from a loaded game, then mods marked as permanent audiovisual, * and lastly Unciv's own assets/sounds. Will fail silently if the sound file cannot be found. *