From 32a45968aa2b78f7efa4698ad32984bf1f4dd7eb Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Fri, 5 Jul 2019 11:15:40 +0300 Subject: [PATCH] Changed unit selection in cities, to accomodate air units in the future --- android/build.gradle | 4 +- core/src/com/unciv/logic/map/MapUnit.kt | 1 + .../com/unciv/ui/worldscreen/TileMapHolder.kt | 55 +++++++++++-------- .../unciv/ui/worldscreen/unit/UnitActions.kt | 4 +- .../unciv/ui/worldscreen/unit/UnitTable.kt | 5 +- 5 files changed, 40 insertions(+), 29 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index de37080223..370b686559 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -21,8 +21,8 @@ android { applicationId "com.unciv.app" minSdkVersion 14 targetSdkVersion 28 - versionCode 268 - versionName "2.17.13" + versionCode 269 + versionName "2.17.14" } // Had to add this crap for Travis to build, it wanted to sign the app diff --git a/core/src/com/unciv/logic/map/MapUnit.kt b/core/src/com/unciv/logic/map/MapUnit.kt index 2dbb9d6b2e..81c29a5822 100644 --- a/core/src/com/unciv/logic/map/MapUnit.kt +++ b/core/src/com/unciv/logic/map/MapUnit.kt @@ -289,6 +289,7 @@ class MapUnit { fun canFortify(): Boolean { if(type.isWaterUnit()) return false if(type.isCivilian()) return false + if(type.isAirUnit()) return false if(isEmbarked()) return false if(hasUnique("No defensive terrain bonus")) return false if(isFortified()) return false diff --git a/core/src/com/unciv/ui/worldscreen/TileMapHolder.kt b/core/src/com/unciv/ui/worldscreen/TileMapHolder.kt index 752332c992..c6a06ccde0 100644 --- a/core/src/com/unciv/ui/worldscreen/TileMapHolder.kt +++ b/core/src/com/unciv/ui/worldscreen/TileMapHolder.kt @@ -56,7 +56,7 @@ class TileMapHolder(internal val worldScreen: WorldScreen, internal val tileMap: }) tileGroup.cityButtonLayerGroup.onClick("") { - showAircraft(tileGroup.tileInfo.getCity()!!) + onTileClicked(tileGroup.tileInfo) } } @@ -104,8 +104,9 @@ class TileMapHolder(internal val worldScreen: WorldScreen, internal val tileMap: if (previousSelectedUnit != null && previousSelectedUnit.getTile() != tileInfo && previousSelectedUnit.canMoveTo(tileInfo) && previousSelectedUnit.movementAlgs().canReach(tileInfo)) { // this can take a long time, because of the unit-to-tile calculation needed, so we put it in a different thread - moveHere(previousSelectedUnit, tileInfo) + addTileOverlaysWithUnitMovement(previousSelectedUnit, tileInfo) } + else addTileOverlays(tileInfo) // no unit movement but display the units in the tile etc. if(newSelectedUnit==null || newSelectedUnit.type==UnitType.Civilian){ @@ -123,7 +124,7 @@ class TileMapHolder(internal val worldScreen: WorldScreen, internal val tileMap: worldScreen.shouldUpdate = true } - private fun moveHere(selectedUnit: MapUnit, tileInfo: TileInfo) { + private fun addTileOverlaysWithUnitMovement(selectedUnit: MapUnit, tileInfo: TileInfo) { thread { /** LibGdx sometimes has these weird errors when you try to edit the UI layout from 2 separate threads. * And so, all UI editing will be done on the main thread. @@ -140,7 +141,7 @@ class TileMapHolder(internal val worldScreen: WorldScreen, internal val tileMap: } else { // add "move to" button val moveHereButtonDto = MoveHereButtonDto(selectedUnit, tileInfo, turnsToGetThere) - addMoveHereButtonToTile(moveHereButtonDto) + addTileOverlays(tileInfo, moveHereButtonDto) } worldScreen.shouldUpdate = true } @@ -148,8 +149,32 @@ class TileMapHolder(internal val worldScreen: WorldScreen, internal val tileMap: } } + private fun addTileOverlays(tileInfo: TileInfo, moveHereDto:MoveHereButtonDto?=null){ + val table = Table().apply { defaults().pad(10f) } + if(moveHereDto!=null) + table.add(getMoveHereButton(moveHereDto)) - private fun addMoveHereButtonToTile(dto: MoveHereButtonDto) { + if (tileInfo.isCityCenter() && tileInfo.getOwner()==worldScreen.currentPlayerCiv) { + for (unit in tileInfo.getCity()!!.getCenterTile().getUnits()) { + val unitGroup = UnitGroup(unit, 60f).surroundWithCircle(80f) + unitGroup.circle.color = Color.GRAY.cpy().apply { a = 0.5f } + if (unit.currentMovement == 0f) unitGroup.color.a = 0.5f + unitGroup.touchable = Touchable.enabled + unitGroup.onClick { + worldScreen.bottomBar.unitTable.selectedUnit = unit + worldScreen.bottomBar.unitTable.selectedCity = null + worldScreen.shouldUpdate = true + removeUnitActionOverlay = true + } + table.add(unitGroup) + } + } + + addOverlayOnTileGroup(tileInfo, table) + table.moveBy(0f,60f) + } + + private fun getMoveHereButton(dto: MoveHereButtonDto): Group { val size = 60f val moveHereButton = Group().apply { width = size;height = size; } moveHereButton.addActor(ImageGetter.getCircle().apply { width = size; height = size }) @@ -171,7 +196,7 @@ class TileMapHolder(internal val worldScreen: WorldScreen, internal val tileMap: } else moveHereButton.color.a = 0.5f - addOverlayOnTileGroup(dto.tileInfo, moveHereButton) + return moveHereButton } @@ -295,24 +320,6 @@ class TileMapHolder(internal val worldScreen: WorldScreen, internal val tileMap: } } - private fun showAircraft(city:CityInfo){ - if (city.getCenterTile().airUnits.isEmpty()) return - val airUnitsTable = Table().apply { defaults().pad(10f) } - for(unit in city.getCenterTile().airUnits){ - val unitGroup = UnitGroup(unit,60f).surroundWithCircle(80f) - unitGroup.circle.color = Color.GRAY.cpy().apply { a=0.5f } - unitGroup.touchable=Touchable.enabled - unitGroup.onClick { - worldScreen.bottomBar.unitTable.selectedUnit=unit - worldScreen.shouldUpdate=true - unitGroup.circle.color = Color.WHITE - } - airUnitsTable.add(unitGroup) - } - airUnitsTable.height=60f - unitActionOverlay?.remove() - addOverlayOnTileGroup(city.getCenterTile(),airUnitsTable) - } fun setCenterPosition(vector: Vector2, immediately: Boolean = false, selectUnit: Boolean = true) { val tileGroup = tileGroups.values.first { it.tileInfo.position == vector } diff --git a/core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt b/core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt index 6e9f7878bd..0d477640f6 100644 --- a/core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt +++ b/core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt @@ -54,8 +54,8 @@ class UnitActions { actionList += UnitAction( "Fortify", false, - currentAction = true, - title = "Fortification".tr() + " " + unit.getFortificationTurns() * 20 + "%" + true, + "Fortification".tr() + " " + unit.getFortificationTurns() * 20 + "%" ) } diff --git a/core/src/com/unciv/ui/worldscreen/unit/UnitTable.kt b/core/src/com/unciv/ui/worldscreen/unit/UnitTable.kt index f4f24b1b65..35766e2d6a 100644 --- a/core/src/com/unciv/ui/worldscreen/unit/UnitTable.kt +++ b/core/src/com/unciv/ui/worldscreen/unit/UnitTable.kt @@ -193,7 +193,10 @@ class UnitTable(val worldScreen: WorldScreen) : Table(){ fun tileSelected(selectedTile: TileInfo) { val previouslySelectedUnit = selectedUnit - if(selectedTile.militaryUnit!=null && selectedTile.militaryUnit!!.civInfo == worldScreen.currentPlayerCiv + if(selectedTile.isCityCenter() && selectedTile.getOwner()==worldScreen.currentPlayerCiv){ + citySelected(selectedTile.getCity()!!) + } + else if(selectedTile.militaryUnit!=null && selectedTile.militaryUnit!!.civInfo == worldScreen.currentPlayerCiv && selectedUnit!=selectedTile.militaryUnit && (selectedTile.civilianUnit==null || selectedUnit!=selectedTile.civilianUnit)){ selectedUnit = selectedTile.militaryUnit