From e7bf1fad7c4b8eab1b898cab031641a0c93c912c Mon Sep 17 00:00:00 2001 From: SomeTroglodyte <63000004+SomeTroglodyte@users.noreply.github.com> Date: Mon, 2 Aug 2021 18:01:08 +0200 Subject: [PATCH] Tweak UncivSlider and make the one on NewGameScreen permanently show the value tip (#4728) --- core/src/com/unciv/ui/newgamescreen/GameOptionsTable.kt | 5 +++-- core/src/com/unciv/ui/utils/UncivSlider.kt | 8 ++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/core/src/com/unciv/ui/newgamescreen/GameOptionsTable.kt b/core/src/com/unciv/ui/newgamescreen/GameOptionsTable.kt index f969b1017b..549f6472eb 100644 --- a/core/src/com/unciv/ui/newgamescreen/GameOptionsTable.kt +++ b/core/src/com/unciv/ui/newgamescreen/GameOptionsTable.kt @@ -96,9 +96,10 @@ class GameOptionsTable( val slider = UncivSlider(0f,numberOfCityStates.toFloat(),1f) { gameParameters.numberOfCityStates = it.toInt() } - slider.value = gameParameters.numberOfCityStates.toFloat() + slider.permanentTip = true slider.isDisabled = locked - add(slider).row() + add(slider).padTop(10f).row() + slider.value = gameParameters.numberOfCityStates.toFloat() } private fun Table.addSelectBox(text: String, values: Collection, initialState: String, onChange: (newValue: String) -> Unit) { diff --git a/core/src/com/unciv/ui/utils/UncivSlider.kt b/core/src/com/unciv/ui/utils/UncivSlider.kt index caa90105a3..33bc36e6b3 100644 --- a/core/src/com/unciv/ui/utils/UncivSlider.kt +++ b/core/src/com/unciv/ui/utils/UncivSlider.kt @@ -81,7 +81,9 @@ class UncivSlider ( // Value tip format var tipFormat = "%.1f" - + + var permanentTip = false + // Detect changes in isDragging private var hasFocus = false @@ -153,7 +155,8 @@ class UncivSlider ( tipLabel.setText(getTipText!!(slider.value)) if (!tipHideTask.isScheduled) showTip() tipHideTask.cancel() - Timer.schedule(tipHideTask, hideDelay) + if (!permanentTip) + Timer.schedule(tipHideTask, hideDelay) val enableMinus = slider.value > slider.minValue minusButton?.touchable = if(enableMinus) Touchable.enabled else Touchable.disabled @@ -210,6 +213,7 @@ class UncivSlider ( private fun showTip() { if (tipContainer.hasParent()) return tipContainer.pack() + if (needsLayout()) pack() val pos = slider.localToParentCoordinates(Vector2(slider.width / 2, slider.height)) tipContainer.run { setOrigin(Align.bottom)