added buttons for controlling music (#8256)

* added buttons for controlling music

* translations

* checks

* added `Music` to translations
This commit is contained in:
alexban011 2022-12-29 21:20:45 +02:00 committed by GitHub
parent fb62ddb711
commit 0273f8a38b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 3 deletions

View File

@ -688,6 +688,9 @@ Sound effects volume =
Music volume =
City ambient sound volume =
Pause between tracks =
Pause =
Music =
Skip =
Currently playing: [title] =
Download music =
Downloading... =

View File

@ -35,12 +35,22 @@ fun soundTab(
addMusicVolumeSlider(this, settings, music)
addMusicPauseSlider(this, settings, music)
addMusicCurrentlyPlaying(this, music)
addButton(this, "Pause", action = { music.pause(0.5f) })
addButton(this, "Resume", action = { music.resume(0.5f) })
addButton(this, "Skip", action = { music.chooseTrack(flags = MusicTrackChooserFlags.none) })
row()
}
if (!UncivGame.Current.musicController.isDefaultFileAvailable())
addDownloadMusic(this, optionsPopup)
}
private fun addButton(table: Table, text: String, action: () -> Unit) {
val button = text.toTextButton()
table.add(button)
button.onClick { action.invoke() }
}
private fun addDownloadMusic(table: Table, optionsPopup: OptionsPopup) {
val downloadMusicButton = "Download music".toTextButton()
table.add(downloadMusicButton).colspan(2).row()
@ -99,7 +109,7 @@ private fun addCitySoundsVolumeSlider(table: Table, settings: GameSettings) {
table.add(citySoundVolumeSlider).pad(5f).row()
}
private fun addMusicVolumeSlider(table: Table, settings: GameSettings, music: MusicController) {
fun addMusicVolumeSlider(table: Table, settings: GameSettings, music: MusicController) {
table.add("Music volume".tr()).left().fillX()
val musicVolumeSlider = UncivSlider(
@ -118,7 +128,7 @@ private fun addMusicVolumeSlider(table: Table, settings: GameSettings, music: Mu
table.add(musicVolumeSlider).pad(5f).row()
}
private fun addMusicPauseSlider(table: Table, settings: GameSettings, music: MusicController) {
fun addMusicPauseSlider(table: Table, settings: GameSettings, music: MusicController) {
// map to/from 0-1-2..10-12-14..30-35-40..60-75-90-105-120
fun posToLength(pos: Float): Float = when (pos) {
in 0f..10f -> pos
@ -154,7 +164,7 @@ private fun addMusicPauseSlider(table: Table, settings: GameSettings, music: Mus
table.add(pauseLengthSlider).pad(5f).row()
}
private fun addMusicCurrentlyPlaying(table: Table, music: MusicController) {
fun addMusicCurrentlyPlaying(table: Table, music: MusicController) {
val label = WrappableLabel("", table.width - 10f, Color(-0x2f5001), 16)
label.wrap = true
table.add(label).padTop(20f).colspan(2).fillX().row()

View File

@ -1,9 +1,14 @@
package com.unciv.ui.worldscreen.mainmenu
import com.badlogic.gdx.Gdx
import com.unciv.UncivGame
import com.unciv.models.metadata.GameSetupInfo
import com.unciv.ui.audio.MusicTrackChooserFlags
import com.unciv.ui.civilopedia.CivilopediaScreen
import com.unciv.ui.newgamescreen.NewGameScreen
import com.unciv.ui.options.addMusicCurrentlyPlaying
import com.unciv.ui.options.addMusicPauseSlider
import com.unciv.ui.options.addMusicVolumeSlider
import com.unciv.ui.popup.Popup
import com.unciv.ui.saves.LoadGameScreen
import com.unciv.ui.saves.SaveGameScreen
@ -50,6 +55,10 @@ class WorldScreenMenuPopup(val worldScreen: WorldScreen) : Popup(worldScreen) {
close()
WorldScreenCommunityPopup(worldScreen).open(force = true)
}.row()
addButton("Music") {
close()
WorldScreenMusicButton(worldScreen).open(force = true)
}.row()
addCloseButton()
pack()
}
@ -76,3 +85,23 @@ class WorldScreenCommunityPopup(val worldScreen: WorldScreen) : Popup(worldScree
addCloseButton()
}
}
class WorldScreenMusicButton(val worldScreen: WorldScreen) : Popup(worldScreen) {
init {
val musicController = UncivGame.Current.musicController
val settings = UncivGame.Current.settings
defaults().fillX()
addMusicVolumeSlider(this, settings, musicController)
row()
addMusicPauseSlider(this , settings, musicController)
row()
addMusicCurrentlyPlaying(this, musicController)
row()
addButton("Pause", action = { musicController.pause(0.5f) })
addButton("Resume", action = { musicController.resume(0.5f) })
addButton("Skip", action = { musicController.chooseTrack(flags = MusicTrackChooserFlags.none) }).row()
addCloseButton()
}
}