diff --git a/core/src/com/unciv/ui/tilegroups/CityButton.kt b/core/src/com/unciv/ui/tilegroups/CityButton.kt index 38172b5ec9..a8c8916780 100644 --- a/core/src/com/unciv/ui/tilegroups/CityButton.kt +++ b/core/src/com/unciv/ui/tilegroups/CityButton.kt @@ -2,7 +2,6 @@ package com.unciv.ui.tilegroups import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.math.Interpolation -import com.badlogic.gdx.scenes.scene2d.Actor import com.badlogic.gdx.scenes.scene2d.Group import com.badlogic.gdx.scenes.scene2d.Touchable import com.badlogic.gdx.scenes.scene2d.actions.Actions @@ -25,8 +24,7 @@ class CityButton(val city: CityInfo, internal val tileGroup: WorldTileGroup, ski touchable= Touchable.disabled } - var buttonDownClickArea: Actor? = null - fun isButtonMoved() = buttonDownClickArea != null + var isButtonMoved=false fun update(isCityViewable:Boolean) { val cityButtonText = city.population.population.toString() + " | " + city.name @@ -43,26 +41,24 @@ class CityButton(val city: CityInfo, internal val tileGroup: WorldTileGroup, ski touchable = Touchable.enabled label.touchable = Touchable.enabled - // clicking anywhere else on the button opens the city screen immediately - onClickEvent { _, x, y -> - if (!isButtonMoved()) { - if (hit(x, y, true) == label) { - // clicking on the label swings that label a little down to allow selection of units there. - // this also allows to target selected units to move to the city tile from elsewhere. - // second tap on the label will go to the city screen - moveButtonDown() - if (unitTable.selectedUnit == null || unitTable.selectedUnit!!.currentMovement==0f) - tileGroup.selectCity(city) - } else { - UnCivGame.Current.screen = CityScreen(city) - } + // clicking on the button swings the button a little down to allow selection of units there. + // this also allows to target selected units to move to the city tile from elsewhere. + // second tap on the button will go to the city screen + onClick { + if (!isButtonMoved) { + moveButtonDown() + if (unitTable.selectedUnit == null || unitTable.selectedUnit!!.currentMovement == 0f) + tileGroup.selectCity(city) + + } else { + UnCivGame.Current.screen = CityScreen(city) } } } // when deselected, move city button to its original position - if (isButtonMoved() + if (isButtonMoved && unitTable.selectedCity != city && unitTable.selectedUnit?.currentTile != city.ccenterTile) { @@ -107,44 +103,22 @@ class CityButton(val city: CityInfo, internal val tileGroup: WorldTileGroup, ski setOrigin(Align.center) centerX(tileGroup) touchable = Touchable.enabled - updateClickArea() - } private fun moveButtonDown() { - val floatAction = Actions.sequence( + val moveButtonAction = Actions.sequence( Actions.moveBy(0f, -height, 0.4f, Interpolation.swingOut), - Actions.run { - buttonDownClickArea = Actor().onClick { - UnCivGame.Current.screen = CityScreen(city) - } - tileGroup.cityButtonLayerGroup.addActor(buttonDownClickArea) - updateClickArea() - } + Actions.run { isButtonMoved=true } ) - tileGroup.addAction(floatAction) + parent.addAction(moveButtonAction) // Move the whole cityButtonLayerGroup down, so the citybutton remains clickable } private fun moveButtonUp() { val floatAction = Actions.sequence( Actions.moveBy(0f, height, 0.4f, Interpolation.sine), - Actions.run { - buttonDownClickArea?.remove() - buttonDownClickArea = null - } + Actions.run {isButtonMoved=false} ) - tileGroup.addAction(floatAction) - } - - private fun updateClickArea() { - buttonDownClickArea?.let { clickArea -> - clickArea.setSize(width, height) - clickArea.setScale(scaleX, scaleY) - clickArea.setOrigin(Align.center) - clickArea.centerX(tileGroup.cityButtonLayerGroup) - clickArea.y = y-height - clickArea.touchable = Touchable.enabled - } + parent.addAction(floatAction) } private fun getConstructionGroup(cityConstructions: CityConstructions): Group { diff --git a/core/src/com/unciv/ui/tilegroups/WorldTileGroup.kt b/core/src/com/unciv/ui/tilegroups/WorldTileGroup.kt index 2411d262c1..e00f08295f 100644 --- a/core/src/com/unciv/ui/tilegroups/WorldTileGroup.kt +++ b/core/src/com/unciv/ui/tilegroups/WorldTileGroup.kt @@ -67,7 +67,7 @@ class WorldTileGroup(internal val worldScreen: WorldScreen, tileInfo: TileInfo) if (city != null && tileInfo.isCityCenter()) { if (cityButton == null) { cityButton = CityButton(city, this, CameraStageBaseScreen.skin) - addActor(cityButton) + cityButtonLayerGroup.addActor(cityButton) } cityButton!!.update(viewable) diff --git a/core/src/com/unciv/ui/worldscreen/TileGroupMap.kt b/core/src/com/unciv/ui/worldscreen/TileGroupMap.kt index 9221079294..4d473f51ef 100644 --- a/core/src/com/unciv/ui/worldscreen/TileGroupMap.kt +++ b/core/src/com/unciv/ui/worldscreen/TileGroupMap.kt @@ -48,8 +48,8 @@ class TileGroupMap(val tileGroups:Collection, padding:Float): G for(group in miscLayers) addActor(group) for(group in circleCrosshairFogLayers) addActor(group) for(group in tileGroups) addActor(group) // The above layers are for the visual layers, this is for the clickability - for(group in cityButtonLayers) addActor(group) // city buttons clickability for(group in unitLayers) addActor(group) // Aaand units above everything else. + for(group in cityButtonLayers) addActor(group) // city buttons clickability // there are tiles "below the zero",