mirror of
https://github.com/yairm210/Unciv.git
synced 2025-01-24 10:01:39 +07:00
EventBus removal - deleted GameSounds, play mp sounds directly
This commit is contained in:
parent
296a499ae6
commit
62259d977d
@ -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?",
|
||||
|
@ -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()
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user