mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-09 15:29:32 +07:00
Respect visualMods for Sound - CheckBox, formats, modchange detect (#4295)
* Respect visualMods for Sound - CheckBox, formats, modchange detect * Respect visualMods for Sound - german patch
This commit is contained in:
@ -990,8 +990,7 @@ Current mods = Installierte Modifikationen
|
|||||||
Downloadable mods = Verfügbare Modifikationen
|
Downloadable mods = Verfügbare Modifikationen
|
||||||
Next page = Nächste Seite
|
Next page = Nächste Seite
|
||||||
Open Github page = Auf Github öffnen
|
Open Github page = Auf Github öffnen
|
||||||
Enable as permanent visual mod = Als permanente visuelle Modifikation aktivieren
|
Permanent audiovisual mod = Permanente audiovisuelle Mod
|
||||||
Disable as permanent visual mod = Als permanente visuelle Modifikation deaktivieren
|
|
||||||
Installed = Installiert
|
Installed = Installiert
|
||||||
Downloaded! = Heruntergeladen!
|
Downloaded! = Heruntergeladen!
|
||||||
Could not download mod = Konnte Modifikation nicht herunterladen
|
Could not download mod = Konnte Modifikation nicht herunterladen
|
||||||
|
@ -991,8 +991,7 @@ Current mods =
|
|||||||
Downloadable mods =
|
Downloadable mods =
|
||||||
Next page =
|
Next page =
|
||||||
Open Github page =
|
Open Github page =
|
||||||
Enable as permanent visual mod =
|
Permanent audiovisual mod =
|
||||||
Disable as permanent visual mod =
|
|
||||||
Installed =
|
Installed =
|
||||||
Downloaded! =
|
Downloaded! =
|
||||||
Could not download mod =
|
Could not download mod =
|
||||||
|
@ -419,20 +419,18 @@ class ModManagementScreen: PickerScreen(disableScroll = true) {
|
|||||||
val visualMods = game.settings.visualMods
|
val visualMods = game.settings.visualMods
|
||||||
val isVisual = visualMods.contains(mod.name)
|
val isVisual = visualMods.contains(mod.name)
|
||||||
modStateImages[mod.name]?.isVisual = isVisual
|
modStateImages[mod.name]?.isVisual = isVisual
|
||||||
if (!isVisual) {
|
|
||||||
modActionTable.add("Enable as permanent visual mod".toTextButton().onClick {
|
val visualCheckBox = CheckBox("Permanent audiovisual mod", skin)
|
||||||
|
visualCheckBox.isChecked = isVisual
|
||||||
|
modActionTable.add(visualCheckBox)
|
||||||
|
visualCheckBox.onChange {
|
||||||
|
if (visualCheckBox.isChecked)
|
||||||
visualMods.add(mod.name)
|
visualMods.add(mod.name)
|
||||||
game.settings.save()
|
else
|
||||||
ImageGetter.setNewRuleset(ImageGetter.ruleset)
|
|
||||||
refreshModActions(mod)
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
modActionTable.add("Disable as permanent visual mod".toTextButton().onClick {
|
|
||||||
visualMods.remove(mod.name)
|
visualMods.remove(mod.name)
|
||||||
game.settings.save()
|
game.settings.save()
|
||||||
ImageGetter.setNewRuleset(ImageGetter.ruleset)
|
ImageGetter.setNewRuleset(ImageGetter.ruleset)
|
||||||
refreshModActions(mod)
|
refreshModActions(mod)
|
||||||
})
|
|
||||||
}
|
}
|
||||||
modActionTable.row()
|
modActionTable.row()
|
||||||
}
|
}
|
||||||
@ -502,4 +500,10 @@ class ModManagementScreen: PickerScreen(disableScroll = true) {
|
|||||||
modStateImages.remove(mod.name)
|
modStateImages.remove(mod.name)
|
||||||
refreshInstalledModTable()
|
refreshInstalledModTable()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun resize(width: Int, height: Int) {
|
||||||
|
if (stage.viewport.screenWidth != width || stage.viewport.screenHeight != height) {
|
||||||
|
game.setScreen(ModManagementScreen())
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,42 +16,66 @@ import java.io.File
|
|||||||
* app lifetime.
|
* app lifetime.
|
||||||
*/
|
*/
|
||||||
object Sounds {
|
object Sounds {
|
||||||
|
private enum class SupportedExtensions { mp3, ogg, wav } // Gdx won't do aac/m4a
|
||||||
|
|
||||||
private val soundMap = HashMap<UncivSound, Sound?>()
|
private val soundMap = HashMap<UncivSound, Sound?>()
|
||||||
|
|
||||||
private val separator = File.separator // just a shorthand for readability
|
private val separator = File.separator // just a shorthand for readability
|
||||||
|
|
||||||
private var modListHash = Int.MIN_VALUE
|
private var modListHash = Int.MIN_VALUE
|
||||||
/** Ensure cache is not outdated _and_ build list of folders to look for sounds */
|
|
||||||
|
/** Ensure cache is not outdated */
|
||||||
|
private fun checkCache() {
|
||||||
|
if (!UncivGame.isCurrentInitialized()) return
|
||||||
|
val game = UncivGame.Current
|
||||||
|
|
||||||
|
// Get a hash covering all mods - quickly, so don't map cast or copy the Set types
|
||||||
|
val hash1 = if (game.isGameInfoInitialized()) game.gameInfo.ruleSet.mods.hashCode() else 0
|
||||||
|
val newHash = hash1.xor(game.settings.visualMods.hashCode())
|
||||||
|
// If hash the same, leave the cache as is
|
||||||
|
if (modListHash != Int.MIN_VALUE && modListHash == newHash) return
|
||||||
|
|
||||||
|
// Seems the mod list has changed - clear the cache
|
||||||
|
for (sound in soundMap.values) sound?.dispose()
|
||||||
|
soundMap.clear()
|
||||||
|
modListHash = newHash
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Build list of folders to look for sounds */
|
||||||
private fun getFolders(): Sequence<String> {
|
private fun getFolders(): Sequence<String> {
|
||||||
if (!UncivGame.isCurrentInitialized() || !UncivGame.Current.isGameInfoInitialized()) // Allow sounds from main menu
|
if (!UncivGame.isCurrentInitialized())
|
||||||
|
// Sounds before main menu shouldn't happen, but just in case return a default ""
|
||||||
|
// which translates to the built-in assets/sounds folder
|
||||||
return sequenceOf("")
|
return sequenceOf("")
|
||||||
|
val game = UncivGame.Current
|
||||||
|
|
||||||
// Allow mod sounds - preferentially so they can override built-in sounds
|
// Allow mod sounds - preferentially so they can override built-in sounds
|
||||||
val modList = UncivGame.Current.gameInfo.ruleSet.mods
|
// audiovisual mods first, these are already available when game.gameInfo is not
|
||||||
val newHash = modList.hashCode()
|
val modList: MutableSet<String> = game.settings.visualMods
|
||||||
if (modListHash == Int.MIN_VALUE || modListHash != newHash) {
|
if (game.isGameInfoInitialized())
|
||||||
// Seems the mod list has changed - start over
|
modList.addAll(game.gameInfo.ruleSet.mods) // Sounds from game mods
|
||||||
for (sound in soundMap.values) sound?.dispose()
|
|
||||||
soundMap.clear()
|
|
||||||
modListHash = newHash
|
|
||||||
}
|
|
||||||
// Should we also look in UncivGame.Current.settings.visualMods?
|
|
||||||
return modList.asSequence()
|
return modList.asSequence()
|
||||||
.map { "mods$separator$it$separator" } +
|
.map { "mods$separator$it$separator" } +
|
||||||
sequenceOf("")
|
sequenceOf("") // represents builtin sounds folder
|
||||||
}
|
}
|
||||||
|
|
||||||
fun get(sound: UncivSound): Sound? {
|
fun get(sound: UncivSound): Sound? {
|
||||||
|
checkCache()
|
||||||
if (sound in soundMap) return soundMap[sound]
|
if (sound in soundMap) return soundMap[sound]
|
||||||
val fileName = sound.value
|
val fileName = sound.value
|
||||||
var file: FileHandle? = null
|
var file: FileHandle? = null
|
||||||
for (modFolder in getFolders()) {
|
for ( (modFolder, extension) in getFolders().flatMap {
|
||||||
val path = "${modFolder}sounds$separator$fileName.mp3"
|
folder -> SupportedExtensions.values().asSequence().map { folder to it }
|
||||||
|
} ) {
|
||||||
|
val path = "${modFolder}sounds$separator$fileName.${extension.name}"
|
||||||
file = Gdx.files.internal(path)
|
file = Gdx.files.internal(path)
|
||||||
if (file.exists()) break
|
if (file.exists()) break
|
||||||
}
|
}
|
||||||
val newSound =
|
val newSound =
|
||||||
if (file == null || !file.exists()) null
|
if (file == null || !file.exists()) null
|
||||||
else Gdx.audio.newSound(file)
|
else Gdx.audio.newSound(file)
|
||||||
|
|
||||||
// Store Sound for reuse or remember that the actual file is missing
|
// Store Sound for reuse or remember that the actual file is missing
|
||||||
soundMap[sound] = newSound
|
soundMap[sound] = newSound
|
||||||
return newSound
|
return newSound
|
||||||
|
Reference in New Issue
Block a user