mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-13 01:08:25 +07:00
EventBus removal - deleted GameSounds, play mp sounds directly
This commit is contained in:
@ -19,7 +19,6 @@ import com.unciv.models.ruleset.RulesetCache
|
|||||||
import com.unciv.models.skins.SkinCache
|
import com.unciv.models.skins.SkinCache
|
||||||
import com.unciv.models.tilesets.TileSetCache
|
import com.unciv.models.tilesets.TileSetCache
|
||||||
import com.unciv.models.translations.Translations
|
import com.unciv.models.translations.Translations
|
||||||
import com.unciv.ui.audio.GameSounds
|
|
||||||
import com.unciv.ui.audio.MusicController
|
import com.unciv.ui.audio.MusicController
|
||||||
import com.unciv.ui.audio.MusicMood
|
import com.unciv.ui.audio.MusicMood
|
||||||
import com.unciv.ui.audio.MusicTrackChooserFlags
|
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
|
settings = files.getGeneralSettings() // needed for the screen
|
||||||
Display.setScreenMode(settings.screenMode, settings)
|
Display.setScreenMode(settings.screenMode, settings)
|
||||||
setAsRootScreen(GameStartScreen()) // NOT dependent on any atlas or skin
|
setAsRootScreen(GameStartScreen()) // NOT dependent on any atlas or skin
|
||||||
GameSounds.init()
|
|
||||||
|
|
||||||
musicController = MusicController() // early, but at this point does only copy volume from settings
|
musicController = MusicController() // early, but at this point does only copy volume from settings
|
||||||
installAudioHooks()
|
installAudioHooks()
|
||||||
@ -292,7 +290,7 @@ open class UncivGame(val isConsoleMode: Boolean = false) : Game(), PlatformSpeci
|
|||||||
fun popScreen(): BaseScreen? {
|
fun popScreen(): BaseScreen? {
|
||||||
if (screenStack.size == 1) {
|
if (screenStack.size == 1) {
|
||||||
musicController.pause()
|
musicController.pause()
|
||||||
UncivGame.Current.settings.autoPlay.stopAutoPlay()
|
settings.autoPlay.stopAutoPlay()
|
||||||
ConfirmPopup(
|
ConfirmPopup(
|
||||||
screen = screenStack.last(),
|
screen = screenStack.last(),
|
||||||
question = "Do you want to exit the game?",
|
question = "Do you want to exit the game?",
|
||||||
|
@ -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.GameUpdateResult.Type.UNCHANGED
|
||||||
import com.unciv.logic.multiplayer.storage.FileStorageRateLimitReached
|
import com.unciv.logic.multiplayer.storage.FileStorageRateLimitReached
|
||||||
import com.unciv.logic.multiplayer.storage.OnlineMultiplayerServer
|
import com.unciv.logic.multiplayer.storage.OnlineMultiplayerServer
|
||||||
|
import com.unciv.ui.audio.SoundPlayer
|
||||||
import com.unciv.ui.components.extensions.isLargerThan
|
import com.unciv.ui.components.extensions.isLargerThan
|
||||||
import com.unciv.utils.debug
|
import com.unciv.utils.debug
|
||||||
import com.unciv.utils.launchOnGLThread
|
import com.unciv.utils.launchOnGLThread
|
||||||
@ -120,9 +121,23 @@ class OnlineMultiplayerGame(
|
|||||||
preview = gameInfo
|
preview = gameInfo
|
||||||
withGLContext {
|
withGLContext {
|
||||||
EventBus.send(MultiplayerGameUpdated(name, gameInfo))
|
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 equals(other: Any?): Boolean = other is OnlineMultiplayerGame && fileHandle == other.fileHandle
|
||||||
override fun hashCode(): Int = fileHandle.hashCode()
|
override fun hashCode(): Int = fileHandle.hashCode()
|
||||||
}
|
}
|
||||||
|
@ -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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -164,12 +164,7 @@ object SoundPlayer {
|
|||||||
return GetSoundResult(newSound, true)
|
return GetSoundResult(newSound, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** Play a sound once. Will not play if the sound is [UncivSound.Silent] or the volume is too low.
|
||||||
* 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].
|
|
||||||
*
|
|
||||||
* Sources are mods from a loaded game, then mods marked as permanent audiovisual,
|
* 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.
|
* and lastly Unciv's own assets/sounds. Will fail silently if the sound file cannot be found.
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user