mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-28 22:37:02 -04:00
Fix tooltips on Android with physical keyboard detected (#9527)
This commit is contained in:
parent
ac57bea8c1
commit
e036d27935
@ -8,7 +8,7 @@ import com.badlogic.gdx.scenes.scene2d.Group
|
|||||||
import com.badlogic.gdx.scenes.scene2d.InputEvent
|
import com.badlogic.gdx.scenes.scene2d.InputEvent
|
||||||
import com.badlogic.gdx.scenes.scene2d.InputListener
|
import com.badlogic.gdx.scenes.scene2d.InputListener
|
||||||
import com.badlogic.gdx.scenes.scene2d.Touchable
|
import com.badlogic.gdx.scenes.scene2d.Touchable
|
||||||
import com.badlogic.gdx.scenes.scene2d.actions.Actions
|
import com.badlogic.gdx.scenes.scene2d.actions.TemporalAction
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.Container
|
import com.badlogic.gdx.scenes.scene2d.ui.Container
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.Label
|
import com.badlogic.gdx.scenes.scene2d.ui.Label
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
||||||
@ -49,6 +49,11 @@ class UncivTooltip <T: Actor>(
|
|||||||
/** current visibility state of the Tooltip */
|
/** current visibility state of the Tooltip */
|
||||||
var state: TipState = TipState.Hidden
|
var state: TipState = TipState.Hidden
|
||||||
private set
|
private set
|
||||||
|
|
||||||
|
// Needed for Android with physical keyboard detected, to avoid tips staying on-screen after
|
||||||
|
// touching buttons (exit fires, sometimes very late, with "to" actor being the label of the button)
|
||||||
|
private var touchDownSeen = false
|
||||||
|
|
||||||
private val contentWidth: Float
|
private val contentWidth: Float
|
||||||
private val contentHeight: Float
|
private val contentHeight: Float
|
||||||
|
|
||||||
@ -82,8 +87,8 @@ class UncivTooltip <T: Actor>(
|
|||||||
setPosition(pos.x - originX, pos.y - originY)
|
setPosition(pos.x - originX, pos.y - originY)
|
||||||
if (useAnimation) {
|
if (useAnimation) {
|
||||||
isTransform = true
|
isTransform = true
|
||||||
color.a = 0.2f
|
color.a = 0.1f
|
||||||
setScale(0.05f)
|
setScale(0.1f)
|
||||||
} else {
|
} else {
|
||||||
isTransform = false
|
isTransform = false
|
||||||
color.a = 1f
|
color.a = 1f
|
||||||
@ -93,14 +98,7 @@ class UncivTooltip <T: Actor>(
|
|||||||
target.stage.addActor(container)
|
target.stage.addActor(container)
|
||||||
|
|
||||||
if (useAnimation) {
|
if (useAnimation) {
|
||||||
state = TipState.Showing
|
startShowAction(TipState.Shown)
|
||||||
container.addAction(Actions.sequence(
|
|
||||||
Actions.parallel(
|
|
||||||
Actions.fadeIn(tipAnimationDuration, Interpolation.fade),
|
|
||||||
Actions.scaleTo(1f, 1f, tipAnimationDuration, Interpolation.fade)
|
|
||||||
),
|
|
||||||
Actions.run { if (state == TipState.Showing) state = TipState.Shown }
|
|
||||||
))
|
|
||||||
} else
|
} else
|
||||||
state = TipState.Shown
|
state = TipState.Shown
|
||||||
}
|
}
|
||||||
@ -114,15 +112,7 @@ class UncivTooltip <T: Actor>(
|
|||||||
state = TipState.Shown // edge case. may actually only be partially 'shown' - animate hide anyway
|
state = TipState.Shown // edge case. may actually only be partially 'shown' - animate hide anyway
|
||||||
}
|
}
|
||||||
if (useAnimation) {
|
if (useAnimation) {
|
||||||
state = TipState.Hiding
|
startShowAction(TipState.Hidden)
|
||||||
container.addAction(Actions.sequence(
|
|
||||||
Actions.parallel(
|
|
||||||
Actions.alpha(0.2f, tipAnimationDuration, Interpolation.fade),
|
|
||||||
Actions.scaleTo(0.05f, 0.05f, tipAnimationDuration, Interpolation.fade)
|
|
||||||
),
|
|
||||||
Actions.removeActor(),
|
|
||||||
Actions.run { if (state == TipState.Hiding) state = TipState.Hidden }
|
|
||||||
))
|
|
||||||
} else {
|
} else {
|
||||||
container.remove()
|
container.remove()
|
||||||
state = TipState.Hidden
|
state = TipState.Hidden
|
||||||
@ -142,6 +132,46 @@ class UncivTooltip <T: Actor>(
|
|||||||
private fun Actor.getEdgePoint(align: Int) =
|
private fun Actor.getEdgePoint(align: Int) =
|
||||||
Vector2(getOriginX(width,align),getOriginY(height,align))
|
Vector2(getOriginX(width,align),getOriginY(height,align))
|
||||||
|
|
||||||
|
private fun startShowAction(endState: TipState) {
|
||||||
|
container.clearActions()
|
||||||
|
container.addAction(ShowAction(endState))
|
||||||
|
}
|
||||||
|
|
||||||
|
private inner class ShowAction(
|
||||||
|
private val endState: TipState
|
||||||
|
) : TemporalAction(tipAnimationDuration, Interpolation.fade) {
|
||||||
|
private val transitionState: TipState
|
||||||
|
private val valueAdd: Float
|
||||||
|
private val valueMul: Float
|
||||||
|
|
||||||
|
init {
|
||||||
|
if (endState == TipState.Shown) {
|
||||||
|
transitionState = TipState.Showing
|
||||||
|
valueAdd = 0.1f
|
||||||
|
valueMul = 0.9f
|
||||||
|
} else {
|
||||||
|
transitionState = TipState.Hiding
|
||||||
|
valueAdd = 1f
|
||||||
|
valueMul = -0.9f
|
||||||
|
}
|
||||||
|
state = transitionState
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun update(percent: Float) {
|
||||||
|
if (!target.hasParent()) {
|
||||||
|
hide(true)
|
||||||
|
finish()
|
||||||
|
}
|
||||||
|
val value = percent * valueMul + valueAdd
|
||||||
|
target.color.a = value
|
||||||
|
target.setScale(value)
|
||||||
|
}
|
||||||
|
override fun end() {
|
||||||
|
if (state == transitionState) state = endState
|
||||||
|
if (endState == TipState.Hidden) target.remove()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//endregion
|
//endregion
|
||||||
//region events
|
//region events
|
||||||
|
|
||||||
@ -152,11 +182,13 @@ class UncivTooltip <T: Actor>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun exit(event: InputEvent?, x: Float, y: Float, pointer: Int, toActor: Actor?) {
|
override fun exit(event: InputEvent?, x: Float, y: Float, pointer: Int, toActor: Actor?) {
|
||||||
if (toActor != null && toActor.isDescendantOf(target)) return
|
if (!touchDownSeen && toActor != null && toActor.isDescendantOf(target)) return
|
||||||
|
touchDownSeen = false
|
||||||
hide()
|
hide()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun touchDown(event: InputEvent?, x: Float, y: Float, pointer: Int, button: Int ): Boolean {
|
override fun touchDown(event: InputEvent?, x: Float, y: Float, pointer: Int, button: Int ): Boolean {
|
||||||
|
touchDownSeen = true
|
||||||
container.toFront() // this is a no-op if it has no parent
|
container.toFront() // this is a no-op if it has no parent
|
||||||
return super.touchDown(event, x, y, pointer, button)
|
return super.touchDown(event, x, y, pointer, button)
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ class UnitActionsTable(val worldScreen: WorldScreen) : Table() {
|
|||||||
if (!worldScreen.canChangeState) return // No actions when it's not your turn or spectator!
|
if (!worldScreen.canChangeState) return // No actions when it's not your turn or spectator!
|
||||||
for (unitAction in UnitActions.getUnitActions(unit)) {
|
for (unitAction in UnitActions.getUnitActions(unit)) {
|
||||||
val button = getUnitActionButton(unit, unitAction)
|
val button = getUnitActionButton(unit, unitAction)
|
||||||
if (unitAction is UpgradeUnitAction) {
|
if (unitAction is UpgradeUnitAction && GUI.keyboardAvailable) {
|
||||||
val tipTitle = "«RED»${unitAction.type.key}«»: {Upgrade}"
|
val tipTitle = "«RED»${unitAction.type.key}«»: {Upgrade}"
|
||||||
val tipActor = BaseUnitDescriptions.getUpgradeTooltipActor(tipTitle, unit.baseUnit, unitAction.unitToUpgradeTo)
|
val tipActor = BaseUnitDescriptions.getUpgradeTooltipActor(tipTitle, unit.baseUnit, unitAction.unitToUpgradeTo)
|
||||||
button.addListener(UncivTooltip(button, tipActor
|
button.addListener(UncivTooltip(button, tipActor
|
||||||
|
Loading…
x
Reference in New Issue
Block a user