mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-30 14:48:56 +07: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:
@ -73,7 +73,7 @@ class MapEditorEditTab(
|
||||
defaults().pad(10f).left()
|
||||
add(brushLabel)
|
||||
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()
|
||||
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) {
|
||||
brushAction(tile)
|
||||
editorScreen.isDirty = true
|
||||
|
@ -39,8 +39,8 @@ class GameOptionsTable(
|
||||
defaults().pad(5f)
|
||||
|
||||
// We assign this first to make sure addBaseRulesetSelectBox doesn't reference a null object
|
||||
modCheckboxes =
|
||||
if (isPortrait)
|
||||
modCheckboxes =
|
||||
if (isPortrait)
|
||||
getModCheckboxes(isPortrait = true)
|
||||
else getModCheckboxes()
|
||||
|
||||
@ -53,13 +53,13 @@ class GameOptionsTable(
|
||||
// align left and right edges with other SelectBoxes but allow independent dropdown width
|
||||
add(Table().apply {
|
||||
val turnSlider = addMaxTurnsSlider()
|
||||
if (turnSlider != null)
|
||||
if (turnSlider != null)
|
||||
add(turnSlider).padTop(10f).row()
|
||||
cityStateSlider = addCityStatesSlider()
|
||||
}).colspan(2).fillX().row()
|
||||
}).row()
|
||||
addVictoryTypeCheckboxes()
|
||||
|
||||
|
||||
|
||||
val checkboxTable = Table().apply { defaults().left().pad(2.5f) }
|
||||
checkboxTable.addNoBarbariansCheckbox()
|
||||
@ -97,7 +97,7 @@ class GameOptionsTable(
|
||||
private fun Table.addNuclearWeaponsCheckbox() =
|
||||
addCheckbox("Enable Nuclear Weapons", gameParameters.nuclearWeaponsEnabled)
|
||||
{ gameParameters.nuclearWeaponsEnabled = it }
|
||||
|
||||
|
||||
private fun Table.addIsOnlineMultiplayerCheckbox() =
|
||||
addCheckbox("Online Multiplayer", gameParameters.isOnlineMultiplayer)
|
||||
{
|
||||
@ -122,13 +122,12 @@ class GameOptionsTable(
|
||||
if (maxCityStates == 0) return null
|
||||
|
||||
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()
|
||||
}
|
||||
slider.permanentTip = true
|
||||
slider.isDisabled = locked
|
||||
add(slider).padTop(10f).row()
|
||||
slider.value = gameParameters.numberOfCityStates.toFloat()
|
||||
return slider
|
||||
}
|
||||
|
||||
@ -137,14 +136,13 @@ class GameOptionsTable(
|
||||
return null
|
||||
|
||||
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()
|
||||
}
|
||||
slider.permanentTip = true
|
||||
slider.isDisabled = locked
|
||||
val snapValues = floatArrayOf(250f,300f,350f,400f,450f,500f,550f,600f,650f,700f,750f,800f,900f,1000f,1250f,1500f)
|
||||
slider.setSnapToValues(snapValues, 250f)
|
||||
slider.value = gameParameters.maxTurns.toFloat()
|
||||
return slider
|
||||
}
|
||||
|
||||
@ -152,8 +150,8 @@ class GameOptionsTable(
|
||||
add(text.toLabel()).left()
|
||||
val selectBox = TranslatedSelectBox(values, initialState, BaseScreen.skin)
|
||||
selectBox.isDisabled = locked
|
||||
selectBox.onChange {
|
||||
val changedValue = onChange(selectBox.selected.value)
|
||||
selectBox.onChange {
|
||||
val changedValue = onChange(selectBox.selected.value)
|
||||
if (changedValue != null) selectBox.setSelected(changedValue)
|
||||
}
|
||||
onChange(selectBox.selected.value)
|
||||
@ -168,7 +166,7 @@ class GameOptionsTable(
|
||||
private fun Table.addBaseRulesetSelectBox() {
|
||||
val sortedBaseRulesets = RulesetCache.getSortedBaseRulesets()
|
||||
if (sortedBaseRulesets.size < 2) return
|
||||
|
||||
|
||||
addSelectBox(
|
||||
"{Base Ruleset}:",
|
||||
sortedBaseRulesets,
|
||||
@ -176,7 +174,7 @@ class GameOptionsTable(
|
||||
) { newBaseRuleset ->
|
||||
val previousSelection = gameParameters.baseRuleset
|
||||
if (newBaseRuleset == gameParameters.baseRuleset) return@addSelectBox null
|
||||
|
||||
|
||||
// Check if this mod is well-defined
|
||||
val baseRulesetErrors = RulesetCache[newBaseRuleset]!!.checkModLinks()
|
||||
if (baseRulesetErrors.isError()) {
|
||||
@ -184,7 +182,7 @@ class GameOptionsTable(
|
||||
ToastPopup(toastMessage, previousScreen as BaseScreen, 5000L)
|
||||
return@addSelectBox previousSelection
|
||||
}
|
||||
|
||||
|
||||
// If so, add it to the current ruleset
|
||||
gameParameters.baseRuleset = newBaseRuleset
|
||||
onChooseMod(newBaseRuleset)
|
||||
@ -201,13 +199,13 @@ class GameOptionsTable(
|
||||
modCheckboxes!!.disableAllCheckboxes()
|
||||
} else if (modLinkErrors.isWarnUser()) {
|
||||
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()}"
|
||||
ToastPopup(toastMessage, previousScreen as BaseScreen, 5000L)
|
||||
}
|
||||
|
||||
|
||||
modCheckboxes!!.setBaseRuleset(newBaseRuleset)
|
||||
|
||||
|
||||
null
|
||||
}
|
||||
}
|
||||
@ -223,7 +221,7 @@ class GameOptionsTable(
|
||||
addSelectBox("{Starting Era}:", eras, gameParameters.startingEra)
|
||||
{ gameParameters.startingEra = it; null }
|
||||
}
|
||||
|
||||
|
||||
private fun addVictoryTypeCheckboxes() {
|
||||
add("{Victory Conditions}:".toLabel()).colspan(2).row()
|
||||
|
||||
|
@ -253,22 +253,21 @@ class MapParametersTable(
|
||||
table.add("RNG Seed".toLabel()).left()
|
||||
table.add(seedTextField).fillX().padBottom(10f).row()
|
||||
|
||||
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)
|
||||
slider.value = getValue()
|
||||
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, initial = getValue())
|
||||
table.add(text.toLabel()).left()
|
||||
table.add(slider).fillX().row()
|
||||
advancedSliders[slider] = getValue
|
||||
return slider
|
||||
}
|
||||
|
||||
addSlider("Map Elevation", {mapParameters.elevationExponent}, 0.6f,0.8f)
|
||||
addSlider("Map Elevation", {mapParameters.elevationExponent}, 0.6f, 0.8f)
|
||||
{ mapParameters.elevationExponent = it }
|
||||
|
||||
addSlider("Temperature extremeness", {mapParameters.temperatureExtremeness}, 0.4f,0.8f)
|
||||
addSlider("Temperature extremeness", {mapParameters.temperatureExtremeness}, 0.4f, 0.8f)
|
||||
{ mapParameters.temperatureExtremeness = it }
|
||||
|
||||
addSlider("Resource richness", {mapParameters.resourceRichness},0f,0.5f)
|
||||
addSlider("Resource richness", {mapParameters.resourceRichness},0f, 0.5f)
|
||||
{ mapParameters.resourceRichness = it }
|
||||
|
||||
addSlider("Vegetation richness", {mapParameters.vegetationRichness}, 0f, 1f)
|
||||
|
@ -20,14 +20,14 @@ import kotlin.math.sign
|
||||
|
||||
/**
|
||||
* Modified Gdx [Slider]
|
||||
*
|
||||
*
|
||||
* Has +/- buttons at the end for easier single steps
|
||||
* Shows a timed tip with the actual value every time it changes
|
||||
* 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
|
||||
* of the value when a screen is initialized will also trigger the 'tip'. This is intentional.
|
||||
*
|
||||
*
|
||||
* @param min Initializes [Slider.min]
|
||||
* @param max Initializes [Slider.max]
|
||||
* @param step Initializes [Slider.stepSize]
|
||||
@ -41,7 +41,7 @@ class UncivSlider (
|
||||
step: Float,
|
||||
vertical: Boolean = false,
|
||||
plusMinus: Boolean = true,
|
||||
initial: Float = min,
|
||||
initial: Float,
|
||||
sound: UncivSound = UncivSound.Slider,
|
||||
private val getTipText: ((Float) -> String)? = null,
|
||||
onChange: ((Float) -> Unit)? = null
|
||||
@ -112,7 +112,7 @@ class UncivSlider (
|
||||
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"
|
||||
|
||||
/** Prevents hiding the value tooltip over the slider knob */
|
||||
@ -139,9 +139,9 @@ class UncivSlider (
|
||||
minusButton.onClick {
|
||||
addToValue(-stepSize)
|
||||
}
|
||||
add(minusButton).apply {
|
||||
add(minusButton).apply {
|
||||
if (vertical) padBottom(padding) else padLeft(padding)
|
||||
}
|
||||
}
|
||||
if (vertical) row()
|
||||
} else minusButton = null
|
||||
|
||||
@ -161,7 +161,7 @@ class UncivSlider (
|
||||
} else plusButton = null
|
||||
|
||||
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
|
||||
slider.addListener(object : ChangeListener() {
|
||||
|
Reference in New Issue
Block a user