Changed unit selection in cities, to accomodate air units in the future

This commit is contained in:
Yair Morgenstern 2019-07-05 11:15:40 +03:00
parent eedc0e30f2
commit 32a45968aa
5 changed files with 40 additions and 29 deletions

View File

@ -21,8 +21,8 @@ android {
applicationId "com.unciv.app" applicationId "com.unciv.app"
minSdkVersion 14 minSdkVersion 14
targetSdkVersion 28 targetSdkVersion 28
versionCode 268 versionCode 269
versionName "2.17.13" versionName "2.17.14"
} }
// Had to add this crap for Travis to build, it wanted to sign the app // Had to add this crap for Travis to build, it wanted to sign the app

View File

@ -289,6 +289,7 @@ class MapUnit {
fun canFortify(): Boolean { fun canFortify(): Boolean {
if(type.isWaterUnit()) return false if(type.isWaterUnit()) return false
if(type.isCivilian()) return false if(type.isCivilian()) return false
if(type.isAirUnit()) return false
if(isEmbarked()) return false if(isEmbarked()) return false
if(hasUnique("No defensive terrain bonus")) return false if(hasUnique("No defensive terrain bonus")) return false
if(isFortified()) return false if(isFortified()) return false

View File

@ -56,7 +56,7 @@ class TileMapHolder(internal val worldScreen: WorldScreen, internal val tileMap:
}) })
tileGroup.cityButtonLayerGroup.onClick("") { 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 if (previousSelectedUnit != null && previousSelectedUnit.getTile() != tileInfo
&& previousSelectedUnit.canMoveTo(tileInfo) && previousSelectedUnit.movementAlgs().canReach(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 // 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){ if(newSelectedUnit==null || newSelectedUnit.type==UnitType.Civilian){
@ -123,7 +124,7 @@ class TileMapHolder(internal val worldScreen: WorldScreen, internal val tileMap:
worldScreen.shouldUpdate = true worldScreen.shouldUpdate = true
} }
private fun moveHere(selectedUnit: MapUnit, tileInfo: TileInfo) { private fun addTileOverlaysWithUnitMovement(selectedUnit: MapUnit, tileInfo: TileInfo) {
thread { thread {
/** LibGdx sometimes has these weird errors when you try to edit the UI layout from 2 separate threads. /** 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. * 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 { } else {
// add "move to" button // add "move to" button
val moveHereButtonDto = MoveHereButtonDto(selectedUnit, tileInfo, turnsToGetThere) val moveHereButtonDto = MoveHereButtonDto(selectedUnit, tileInfo, turnsToGetThere)
addMoveHereButtonToTile(moveHereButtonDto) addTileOverlays(tileInfo, moveHereButtonDto)
} }
worldScreen.shouldUpdate = true 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 size = 60f
val moveHereButton = Group().apply { width = size;height = size; } val moveHereButton = Group().apply { width = size;height = size; }
moveHereButton.addActor(ImageGetter.getCircle().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 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) { fun setCenterPosition(vector: Vector2, immediately: Boolean = false, selectUnit: Boolean = true) {
val tileGroup = tileGroups.values.first { it.tileInfo.position == vector } val tileGroup = tileGroups.values.first { it.tileInfo.position == vector }

View File

@ -54,8 +54,8 @@ class UnitActions {
actionList += UnitAction( actionList += UnitAction(
"Fortify", "Fortify",
false, false,
currentAction = true, true,
title = "Fortification".tr() + " " + unit.getFortificationTurns() * 20 + "%" "Fortification".tr() + " " + unit.getFortificationTurns() * 20 + "%"
) )
} }

View File

@ -193,7 +193,10 @@ class UnitTable(val worldScreen: WorldScreen) : Table(){
fun tileSelected(selectedTile: TileInfo) { fun tileSelected(selectedTile: TileInfo) {
val previouslySelectedUnit = selectedUnit 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 && selectedUnit!=selectedTile.militaryUnit
&& (selectedTile.civilianUnit==null || selectedUnit!=selectedTile.civilianUnit)){ && (selectedTile.civilianUnit==null || selectedUnit!=selectedTile.civilianUnit)){
selectedUnit = selectedTile.militaryUnit selectedUnit = selectedTile.militaryUnit