mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-15 02:09:21 +07:00
City sounds again (#10590)
* Fix City ambience sounds stopping when switching to next/previous cities * Fix City ambience sounds no longer fade in
This commit is contained in:
@ -14,7 +14,7 @@ class CityAmbiencePlayer(
|
|||||||
val volume = UncivGame.Current.settings.citySoundsVolume
|
val volume = UncivGame.Current.settings.citySoundsVolume
|
||||||
if (volume > 0f) {
|
if (volume > 0f) {
|
||||||
UncivGame.Current.musicController
|
UncivGame.Current.musicController
|
||||||
.playOverlay(city.civ.getEra().citySound, volume = volume, isLooping = true)
|
.playOverlay(city.civ.getEra().citySound, volume = volume, isLooping = true, fadeIn = true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,7 +46,11 @@ import com.unciv.ui.screens.worldscreen.WorldScreen
|
|||||||
class CityScreen(
|
class CityScreen(
|
||||||
internal val city: City,
|
internal val city: City,
|
||||||
initSelectedConstruction: IConstruction? = null,
|
initSelectedConstruction: IConstruction? = null,
|
||||||
initSelectedTile: Tile? = null
|
initSelectedTile: Tile? = null,
|
||||||
|
/** City ambience sound player proxies can be passed from one CityScreen instance to the next
|
||||||
|
* to avoid premature stops or rewinds. Only the fresh CityScreen from WorldScreen or Overview
|
||||||
|
* will instantiate a new CityAmbiencePlayer and start playing. */
|
||||||
|
ambiencePlayer: CityAmbiencePlayer? = null
|
||||||
): BaseScreen(), RecreateOnResize {
|
): BaseScreen(), RecreateOnResize {
|
||||||
companion object {
|
companion object {
|
||||||
/** Distance from stage edges to floating widgets */
|
/** Distance from stage edges to floating widgets */
|
||||||
@ -119,7 +123,7 @@ class CityScreen(
|
|||||||
// val should be OK as buying tiles is what changes this, and that would re-create the whole CityScreen
|
// val should be OK as buying tiles is what changes this, and that would re-create the whole CityScreen
|
||||||
private val nextTileToOwn = city.expansion.chooseNewTileToOwn()
|
private val nextTileToOwn = city.expansion.chooseNewTileToOwn()
|
||||||
|
|
||||||
private val cityAmbiencePlayer = CityAmbiencePlayer(city)
|
private var cityAmbiencePlayer: CityAmbiencePlayer? = ambiencePlayer ?: CityAmbiencePlayer(city)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
if (city.isWeLoveTheKingDayActive() && UncivGame.Current.settings.citySoundsVolume > 0) {
|
if (city.isWeLoveTheKingDayActive() && UncivGame.Current.settings.citySoundsVolume > 0) {
|
||||||
@ -487,21 +491,32 @@ class CityScreen(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun passOnCityAmbiencePlayer(): CityAmbiencePlayer? {
|
||||||
|
val player = cityAmbiencePlayer
|
||||||
|
cityAmbiencePlayer = null
|
||||||
|
return player
|
||||||
|
}
|
||||||
|
|
||||||
fun page(delta: Int) {
|
fun page(delta: Int) {
|
||||||
|
// Normal order is create new, then dispose old. But CityAmbiencePlayer delegates to a single instance of MusicController,
|
||||||
|
// leading to one extra play followed by a stop for the city ambience sounds. To avoid that, we pass our player on and relinquish control.
|
||||||
|
|
||||||
val civInfo = city.civ
|
val civInfo = city.civ
|
||||||
val numCities = civInfo.cities.size
|
val numCities = civInfo.cities.size
|
||||||
if (numCities == 0) return
|
if (numCities == 0) return
|
||||||
val indexOfCity = civInfo.cities.indexOf(city)
|
val indexOfCity = civInfo.cities.indexOf(city)
|
||||||
val indexOfNextCity = (indexOfCity + delta + numCities) % numCities
|
val indexOfNextCity = (indexOfCity + delta + numCities) % numCities
|
||||||
val newCityScreen = CityScreen(civInfo.cities[indexOfNextCity])
|
val newCityScreen = CityScreen(civInfo.cities[indexOfNextCity], ambiencePlayer = passOnCityAmbiencePlayer())
|
||||||
newCityScreen.update()
|
newCityScreen.update()
|
||||||
game.replaceCurrentScreen(newCityScreen)
|
game.replaceCurrentScreen(newCityScreen)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun recreate(): BaseScreen = CityScreen(city)
|
// Don't use passOnCityAmbiencePlayer here - continuing play on the replacement screen would be nice,
|
||||||
|
// but the rapid firing of several resize events will get that un-synced, they would no longer stop on leaving.
|
||||||
|
override fun recreate(): BaseScreen = CityScreen(city, selectedConstruction, selectedTile)
|
||||||
|
|
||||||
override fun dispose() {
|
override fun dispose() {
|
||||||
cityAmbiencePlayer.dispose()
|
cityAmbiencePlayer?.dispose()
|
||||||
super.dispose()
|
super.dispose()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user