mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-27 05:46:43 -04:00
Fixed slider sound playing when opening NewGameScreen and MapEditor (#6932)
* fixed slider sound playing in some of the tabs * made "initial" value mandatory to avoid such issues in the future * initial values now taken from gameParameters * whitespaces
This commit is contained in:
parent
93afb26c62
commit
0661bbc31b
@ -73,7 +73,7 @@ class MapEditorEditTab(
|
|||||||
defaults().pad(10f).left()
|
defaults().pad(10f).left()
|
||||||
add(brushLabel)
|
add(brushLabel)
|
||||||
brushCell = add().padLeft(0f)
|
brushCell = add().padLeft(0f)
|
||||||
brushSlider = UncivSlider(1f,6f,1f, getTipText = { getBrushTip(it).tr() }) {
|
brushSlider = UncivSlider(1f,6f,1f, initial = 1f, getTipText = { getBrushTip(it).tr() }) {
|
||||||
brushSize = if (it > 5f) -1 else it.toInt()
|
brushSize = if (it > 5f) -1 else it.toInt()
|
||||||
brushLabel.setText("Brush ([${getBrushTip(it).take(1)}]):".tr())
|
brushLabel.setText("Brush ([${getBrushTip(it).take(1)}]):".tr())
|
||||||
}
|
}
|
||||||
@ -237,7 +237,7 @@ class MapEditorEditTab(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Used for starting locations - no temp tile as brushAction needs to access tile.tileMap */
|
/** Used for starting locations - no temp tile as brushAction needs to access tile.tileMap */
|
||||||
private fun directPaintTile(tile: TileInfo) {
|
private fun directPaintTile(tile: TileInfo) {
|
||||||
brushAction(tile)
|
brushAction(tile)
|
||||||
editorScreen.isDirty = true
|
editorScreen.isDirty = true
|
||||||
|
@ -39,8 +39,8 @@ class GameOptionsTable(
|
|||||||
defaults().pad(5f)
|
defaults().pad(5f)
|
||||||
|
|
||||||
// We assign this first to make sure addBaseRulesetSelectBox doesn't reference a null object
|
// We assign this first to make sure addBaseRulesetSelectBox doesn't reference a null object
|
||||||
modCheckboxes =
|
modCheckboxes =
|
||||||
if (isPortrait)
|
if (isPortrait)
|
||||||
getModCheckboxes(isPortrait = true)
|
getModCheckboxes(isPortrait = true)
|
||||||
else getModCheckboxes()
|
else getModCheckboxes()
|
||||||
|
|
||||||
@ -53,13 +53,13 @@ class GameOptionsTable(
|
|||||||
// align left and right edges with other SelectBoxes but allow independent dropdown width
|
// align left and right edges with other SelectBoxes but allow independent dropdown width
|
||||||
add(Table().apply {
|
add(Table().apply {
|
||||||
val turnSlider = addMaxTurnsSlider()
|
val turnSlider = addMaxTurnsSlider()
|
||||||
if (turnSlider != null)
|
if (turnSlider != null)
|
||||||
add(turnSlider).padTop(10f).row()
|
add(turnSlider).padTop(10f).row()
|
||||||
cityStateSlider = addCityStatesSlider()
|
cityStateSlider = addCityStatesSlider()
|
||||||
}).colspan(2).fillX().row()
|
}).colspan(2).fillX().row()
|
||||||
}).row()
|
}).row()
|
||||||
addVictoryTypeCheckboxes()
|
addVictoryTypeCheckboxes()
|
||||||
|
|
||||||
|
|
||||||
val checkboxTable = Table().apply { defaults().left().pad(2.5f) }
|
val checkboxTable = Table().apply { defaults().left().pad(2.5f) }
|
||||||
checkboxTable.addNoBarbariansCheckbox()
|
checkboxTable.addNoBarbariansCheckbox()
|
||||||
@ -97,7 +97,7 @@ class GameOptionsTable(
|
|||||||
private fun Table.addNuclearWeaponsCheckbox() =
|
private fun Table.addNuclearWeaponsCheckbox() =
|
||||||
addCheckbox("Enable Nuclear Weapons", gameParameters.nuclearWeaponsEnabled)
|
addCheckbox("Enable Nuclear Weapons", gameParameters.nuclearWeaponsEnabled)
|
||||||
{ gameParameters.nuclearWeaponsEnabled = it }
|
{ gameParameters.nuclearWeaponsEnabled = it }
|
||||||
|
|
||||||
private fun Table.addIsOnlineMultiplayerCheckbox() =
|
private fun Table.addIsOnlineMultiplayerCheckbox() =
|
||||||
addCheckbox("Online Multiplayer", gameParameters.isOnlineMultiplayer)
|
addCheckbox("Online Multiplayer", gameParameters.isOnlineMultiplayer)
|
||||||
{
|
{
|
||||||
@ -122,13 +122,12 @@ class GameOptionsTable(
|
|||||||
if (maxCityStates == 0) return null
|
if (maxCityStates == 0) return null
|
||||||
|
|
||||||
add("{Number of City-States}:".toLabel()).left().expandX()
|
add("{Number of City-States}:".toLabel()).left().expandX()
|
||||||
val slider = UncivSlider(0f, maxCityStates.toFloat(), 1f) {
|
val slider = UncivSlider(0f, maxCityStates.toFloat(), 1f, initial = gameParameters.numberOfCityStates.toFloat()) {
|
||||||
gameParameters.numberOfCityStates = it.toInt()
|
gameParameters.numberOfCityStates = it.toInt()
|
||||||
}
|
}
|
||||||
slider.permanentTip = true
|
slider.permanentTip = true
|
||||||
slider.isDisabled = locked
|
slider.isDisabled = locked
|
||||||
add(slider).padTop(10f).row()
|
add(slider).padTop(10f).row()
|
||||||
slider.value = gameParameters.numberOfCityStates.toFloat()
|
|
||||||
return slider
|
return slider
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,14 +136,13 @@ class GameOptionsTable(
|
|||||||
return null
|
return null
|
||||||
|
|
||||||
add("{Max Turns}:".toLabel()).left().expandX()
|
add("{Max Turns}:".toLabel()).left().expandX()
|
||||||
val slider = UncivSlider(250f, 1500f, 50f) {
|
val slider = UncivSlider(250f, 1500f, 50f, initial = gameParameters.maxTurns.toFloat()) {
|
||||||
gameParameters.maxTurns = it.toInt()
|
gameParameters.maxTurns = it.toInt()
|
||||||
}
|
}
|
||||||
slider.permanentTip = true
|
slider.permanentTip = true
|
||||||
slider.isDisabled = locked
|
slider.isDisabled = locked
|
||||||
val snapValues = floatArrayOf(250f,300f,350f,400f,450f,500f,550f,600f,650f,700f,750f,800f,900f,1000f,1250f,1500f)
|
val snapValues = floatArrayOf(250f,300f,350f,400f,450f,500f,550f,600f,650f,700f,750f,800f,900f,1000f,1250f,1500f)
|
||||||
slider.setSnapToValues(snapValues, 250f)
|
slider.setSnapToValues(snapValues, 250f)
|
||||||
slider.value = gameParameters.maxTurns.toFloat()
|
|
||||||
return slider
|
return slider
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -152,8 +150,8 @@ class GameOptionsTable(
|
|||||||
add(text.toLabel()).left()
|
add(text.toLabel()).left()
|
||||||
val selectBox = TranslatedSelectBox(values, initialState, BaseScreen.skin)
|
val selectBox = TranslatedSelectBox(values, initialState, BaseScreen.skin)
|
||||||
selectBox.isDisabled = locked
|
selectBox.isDisabled = locked
|
||||||
selectBox.onChange {
|
selectBox.onChange {
|
||||||
val changedValue = onChange(selectBox.selected.value)
|
val changedValue = onChange(selectBox.selected.value)
|
||||||
if (changedValue != null) selectBox.setSelected(changedValue)
|
if (changedValue != null) selectBox.setSelected(changedValue)
|
||||||
}
|
}
|
||||||
onChange(selectBox.selected.value)
|
onChange(selectBox.selected.value)
|
||||||
@ -168,7 +166,7 @@ class GameOptionsTable(
|
|||||||
private fun Table.addBaseRulesetSelectBox() {
|
private fun Table.addBaseRulesetSelectBox() {
|
||||||
val sortedBaseRulesets = RulesetCache.getSortedBaseRulesets()
|
val sortedBaseRulesets = RulesetCache.getSortedBaseRulesets()
|
||||||
if (sortedBaseRulesets.size < 2) return
|
if (sortedBaseRulesets.size < 2) return
|
||||||
|
|
||||||
addSelectBox(
|
addSelectBox(
|
||||||
"{Base Ruleset}:",
|
"{Base Ruleset}:",
|
||||||
sortedBaseRulesets,
|
sortedBaseRulesets,
|
||||||
@ -176,7 +174,7 @@ class GameOptionsTable(
|
|||||||
) { newBaseRuleset ->
|
) { newBaseRuleset ->
|
||||||
val previousSelection = gameParameters.baseRuleset
|
val previousSelection = gameParameters.baseRuleset
|
||||||
if (newBaseRuleset == gameParameters.baseRuleset) return@addSelectBox null
|
if (newBaseRuleset == gameParameters.baseRuleset) return@addSelectBox null
|
||||||
|
|
||||||
// Check if this mod is well-defined
|
// Check if this mod is well-defined
|
||||||
val baseRulesetErrors = RulesetCache[newBaseRuleset]!!.checkModLinks()
|
val baseRulesetErrors = RulesetCache[newBaseRuleset]!!.checkModLinks()
|
||||||
if (baseRulesetErrors.isError()) {
|
if (baseRulesetErrors.isError()) {
|
||||||
@ -184,7 +182,7 @@ class GameOptionsTable(
|
|||||||
ToastPopup(toastMessage, previousScreen as BaseScreen, 5000L)
|
ToastPopup(toastMessage, previousScreen as BaseScreen, 5000L)
|
||||||
return@addSelectBox previousSelection
|
return@addSelectBox previousSelection
|
||||||
}
|
}
|
||||||
|
|
||||||
// If so, add it to the current ruleset
|
// If so, add it to the current ruleset
|
||||||
gameParameters.baseRuleset = newBaseRuleset
|
gameParameters.baseRuleset = newBaseRuleset
|
||||||
onChooseMod(newBaseRuleset)
|
onChooseMod(newBaseRuleset)
|
||||||
@ -201,13 +199,13 @@ class GameOptionsTable(
|
|||||||
modCheckboxes!!.disableAllCheckboxes()
|
modCheckboxes!!.disableAllCheckboxes()
|
||||||
} else if (modLinkErrors.isWarnUser()) {
|
} else if (modLinkErrors.isWarnUser()) {
|
||||||
val toastMessage =
|
val toastMessage =
|
||||||
"{The mod combination you selected has problems.}\n{You can play it, but don't expect everything to work!}".tr() +
|
"{The mod combination you selected has problems.}\n{You can play it, but don't expect everything to work!}".tr() +
|
||||||
"\n\n${modLinkErrors.getErrorText()}"
|
"\n\n${modLinkErrors.getErrorText()}"
|
||||||
ToastPopup(toastMessage, previousScreen as BaseScreen, 5000L)
|
ToastPopup(toastMessage, previousScreen as BaseScreen, 5000L)
|
||||||
}
|
}
|
||||||
|
|
||||||
modCheckboxes!!.setBaseRuleset(newBaseRuleset)
|
modCheckboxes!!.setBaseRuleset(newBaseRuleset)
|
||||||
|
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -223,7 +221,7 @@ class GameOptionsTable(
|
|||||||
addSelectBox("{Starting Era}:", eras, gameParameters.startingEra)
|
addSelectBox("{Starting Era}:", eras, gameParameters.startingEra)
|
||||||
{ gameParameters.startingEra = it; null }
|
{ gameParameters.startingEra = it; null }
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun addVictoryTypeCheckboxes() {
|
private fun addVictoryTypeCheckboxes() {
|
||||||
add("{Victory Conditions}:".toLabel()).colspan(2).row()
|
add("{Victory Conditions}:".toLabel()).colspan(2).row()
|
||||||
|
|
||||||
|
@ -253,22 +253,21 @@ class MapParametersTable(
|
|||||||
table.add("RNG Seed".toLabel()).left()
|
table.add("RNG Seed".toLabel()).left()
|
||||||
table.add(seedTextField).fillX().padBottom(10f).row()
|
table.add(seedTextField).fillX().padBottom(10f).row()
|
||||||
|
|
||||||
fun addSlider(text: String, getValue:()->Float, min:Float, max:Float, onChange: (value:Float)->Unit): UncivSlider {
|
fun addSlider(text: String, getValue:()->Float, min: Float, max: Float, onChange: (value: Float)->Unit): UncivSlider {
|
||||||
val slider = UncivSlider(min, max, (max - min) / 20, onChange = onChange)
|
val slider = UncivSlider(min, max, (max - min) / 20, onChange = onChange, initial = getValue())
|
||||||
slider.value = getValue()
|
|
||||||
table.add(text.toLabel()).left()
|
table.add(text.toLabel()).left()
|
||||||
table.add(slider).fillX().row()
|
table.add(slider).fillX().row()
|
||||||
advancedSliders[slider] = getValue
|
advancedSliders[slider] = getValue
|
||||||
return slider
|
return slider
|
||||||
}
|
}
|
||||||
|
|
||||||
addSlider("Map Elevation", {mapParameters.elevationExponent}, 0.6f,0.8f)
|
addSlider("Map Elevation", {mapParameters.elevationExponent}, 0.6f, 0.8f)
|
||||||
{ mapParameters.elevationExponent = it }
|
{ mapParameters.elevationExponent = it }
|
||||||
|
|
||||||
addSlider("Temperature extremeness", {mapParameters.temperatureExtremeness}, 0.4f,0.8f)
|
addSlider("Temperature extremeness", {mapParameters.temperatureExtremeness}, 0.4f, 0.8f)
|
||||||
{ mapParameters.temperatureExtremeness = it }
|
{ mapParameters.temperatureExtremeness = it }
|
||||||
|
|
||||||
addSlider("Resource richness", {mapParameters.resourceRichness},0f,0.5f)
|
addSlider("Resource richness", {mapParameters.resourceRichness},0f, 0.5f)
|
||||||
{ mapParameters.resourceRichness = it }
|
{ mapParameters.resourceRichness = it }
|
||||||
|
|
||||||
addSlider("Vegetation richness", {mapParameters.vegetationRichness}, 0f, 1f)
|
addSlider("Vegetation richness", {mapParameters.vegetationRichness}, 0f, 1f)
|
||||||
|
@ -20,14 +20,14 @@ import kotlin.math.sign
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Modified Gdx [Slider]
|
* Modified Gdx [Slider]
|
||||||
*
|
*
|
||||||
* Has +/- buttons at the end for easier single steps
|
* Has +/- buttons at the end for easier single steps
|
||||||
* Shows a timed tip with the actual value every time it changes
|
* Shows a timed tip with the actual value every time it changes
|
||||||
* Disables listeners of any ScrollPanes this is nested in while dragging
|
* Disables listeners of any ScrollPanes this is nested in while dragging
|
||||||
*
|
*
|
||||||
* Note: No attempt is made to distinguish sources of value changes, so the initial setting
|
* Note: No attempt is made to distinguish sources of value changes, so the initial setting
|
||||||
* of the value when a screen is initialized will also trigger the 'tip'. This is intentional.
|
* of the value when a screen is initialized will also trigger the 'tip'. This is intentional.
|
||||||
*
|
*
|
||||||
* @param min Initializes [Slider.min]
|
* @param min Initializes [Slider.min]
|
||||||
* @param max Initializes [Slider.max]
|
* @param max Initializes [Slider.max]
|
||||||
* @param step Initializes [Slider.stepSize]
|
* @param step Initializes [Slider.stepSize]
|
||||||
@ -41,7 +41,7 @@ class UncivSlider (
|
|||||||
step: Float,
|
step: Float,
|
||||||
vertical: Boolean = false,
|
vertical: Boolean = false,
|
||||||
plusMinus: Boolean = true,
|
plusMinus: Boolean = true,
|
||||||
initial: Float = min,
|
initial: Float,
|
||||||
sound: UncivSound = UncivSound.Slider,
|
sound: UncivSound = UncivSound.Slider,
|
||||||
private val getTipText: ((Float) -> String)? = null,
|
private val getTipText: ((Float) -> String)? = null,
|
||||||
onChange: ((Float) -> Unit)? = null
|
onChange: ((Float) -> Unit)? = null
|
||||||
@ -112,7 +112,7 @@ class UncivSlider (
|
|||||||
slider.setSnapToValues(values, threshold)
|
slider.setSnapToValues(values, threshold)
|
||||||
}
|
}
|
||||||
|
|
||||||
// java format string for the value tip, set by changing stepSize
|
// java format string for the value tip, set by changing stepSize
|
||||||
private var tipFormat = "%.1f"
|
private var tipFormat = "%.1f"
|
||||||
|
|
||||||
/** Prevents hiding the value tooltip over the slider knob */
|
/** Prevents hiding the value tooltip over the slider knob */
|
||||||
@ -139,9 +139,9 @@ class UncivSlider (
|
|||||||
minusButton.onClick {
|
minusButton.onClick {
|
||||||
addToValue(-stepSize)
|
addToValue(-stepSize)
|
||||||
}
|
}
|
||||||
add(minusButton).apply {
|
add(minusButton).apply {
|
||||||
if (vertical) padBottom(padding) else padLeft(padding)
|
if (vertical) padBottom(padding) else padLeft(padding)
|
||||||
}
|
}
|
||||||
if (vertical) row()
|
if (vertical) row()
|
||||||
} else minusButton = null
|
} else minusButton = null
|
||||||
|
|
||||||
@ -161,7 +161,7 @@ class UncivSlider (
|
|||||||
} else plusButton = null
|
} else plusButton = null
|
||||||
|
|
||||||
row()
|
row()
|
||||||
value = initial // set initial value late so the tooltip can work with the layout
|
value = initial // set initial value late so the tooltip can work with the layout
|
||||||
|
|
||||||
// Add the listener late so the setting of the initial value is silent
|
// Add the listener late so the setting of the initial value is silent
|
||||||
slider.addListener(object : ChangeListener() {
|
slider.addListener(object : ChangeListener() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user