Multiple selected units are more obvious on-map

This commit is contained in:
Yair Morgenstern 2020-09-11 17:09:50 +03:00
parent f63005ad3c
commit 5a44d7e098
2 changed files with 72 additions and 60 deletions

View File

@ -286,33 +286,34 @@ class WorldMapHolder(internal val worldScreen: WorldScreen, internal val tileMap
val playerViewableTilePositions = viewingCiv.viewableTiles.map { it.position }.toHashSet() val playerViewableTilePositions = viewingCiv.viewableTiles.map { it.position }.toHashSet()
for (tileGroup in tileGroups.values){ for (tileGroup in tileGroups.values) {
tileGroup.update(viewingCiv) tileGroup.update(viewingCiv)
if(tileGroup.tileInfo.improvement==Constants.barbarianEncampment if (tileGroup.tileInfo.improvement == Constants.barbarianEncampment
&& tileGroup.tileInfo.position in viewingCiv.exploredTiles) && tileGroup.tileInfo.position in viewingCiv.exploredTiles)
tileGroup.showCircle(Color.RED) tileGroup.showCircle(Color.RED)
val unitsInTile = tileGroup.tileInfo.getUnits() val unitsInTile = tileGroup.tileInfo.getUnits()
val canSeeEnemy = unitsInTile.any() && unitsInTile.first().civInfo.isAtWarWith(viewingCiv) val canSeeEnemy = unitsInTile.any() && unitsInTile.first().civInfo.isAtWarWith(viewingCiv)
&& tileGroup.showMilitaryUnit(viewingCiv) && tileGroup.showMilitaryUnit(viewingCiv)
if(tileGroup.isViewable(viewingCiv) && canSeeEnemy) if (tileGroup.isViewable(viewingCiv) && canSeeEnemy)
tileGroup.showCircle(Color.RED) // Display ALL viewable enemies with a red circle so that users don't need to go "hunting" for enemy units tileGroup.showCircle(Color.RED) // Display ALL viewable enemies with a red circle so that users don't need to go "hunting" for enemy units
} }
val unitTable = worldScreen.bottomUnitTable val unitTable = worldScreen.bottomUnitTable
when { when {
unitTable.selectedCity!=null -> { unitTable.selectedCity != null -> {
val city = unitTable.selectedCity!! val city = unitTable.selectedCity!!
updateTilegroupsForSelectedCity(city, playerViewableTilePositions) updateTilegroupsForSelectedCity(city, playerViewableTilePositions)
} }
unitTable.selectedUnit!=null -> { unitTable.selectedUnit != null -> {
val unit = unitTable.selectedUnit!! for (unit in unitTable.selectedUnits) {
updateTilegroupsForSelectedUnit(unit, playerViewableTilePositions) updateTilegroupsForSelectedUnit(unit, playerViewableTilePositions)
}
} }
unitActionOverlay!=null -> { unitActionOverlay != null -> {
unitActionOverlay!!.remove() unitActionOverlay!!.remove()
unitActionOverlay=null unitActionOverlay = null
} }
} }

View File

@ -107,50 +107,56 @@ class UnitTable(val worldScreen: WorldScreen) : Table(){
} }
if(selectedUnit!=null) { // set texts - this is valid even when it's the same unit, because movement points and health change if(selectedUnit!=null) { // set texts - this is valid even when it's the same unit, because movement points and health change
separator.isVisible=true if(selectedUnits.size==1) { //single selected unit
val unit = selectedUnit!! separator.isVisible = true
var nameLabelText = unit.name.tr() val unit = selectedUnit!!
if(unit.health<100) nameLabelText+=" ("+unit.health+")" var nameLabelText = unit.name.tr()
if(nameLabelText!=unitNameLabel.text.toString()){ if (unit.health < 100) nameLabelText += " (" + unit.health + ")"
unitNameLabel.setText(nameLabelText) if (nameLabelText != unitNameLabel.text.toString()) {
selectedUnitHasChanged=true // We need to reload the health bar of the unit in the icon - happens e.g. when picking the Heal Instantly promotion unitNameLabel.setText(nameLabelText)
selectedUnitHasChanged = true // We need to reload the health bar of the unit in the icon - happens e.g. when picking the Heal Instantly promotion
}
unitDescriptionTable.clear()
unitDescriptionTable.defaults().pad(2f)
unitDescriptionTable.add(ImageGetter.getStatIcon("Movement")).size(20f)
unitDescriptionTable.add(unit.getMovementString()).padRight(10f)
if (!unit.type.isCivilian()) {
unitDescriptionTable.add(ImageGetter.getStatIcon("Strength")).size(20f)
unitDescriptionTable.add(unit.baseUnit().strength.toString()).padRight(10f)
}
if (unit.baseUnit().rangedStrength != 0) {
unitDescriptionTable.add(ImageGetter.getStatIcon("RangedStrength")).size(20f)
unitDescriptionTable.add(unit.baseUnit().rangedStrength.toString()).padRight(10f)
}
if (unit.type.isRanged()) {
unitDescriptionTable.add(ImageGetter.getStatIcon("Range")).size(20f)
unitDescriptionTable.add(unit.getRange().toString()).padRight(10f)
}
if (unit.baseUnit.interceptRange > 0) {
unitDescriptionTable.add(ImageGetter.getStatIcon("InterceptRange")).size(20f)
val range = if (unit.type.isRanged()) unit.getRange() else unit.baseUnit.interceptRange
unitDescriptionTable.add(range.toString()).padRight(10f)
}
if (!unit.type.isCivilian()) {
unitDescriptionTable.add("XP")
unitDescriptionTable.add(unit.promotions.XP.toString() + "/" + unit.promotions.xpForNextPromotion())
}
if (unit.promotions.promotions.size != promotionsTable.children.size) // The unit has been promoted! Reload promotions!
selectedUnitHasChanged = true
} }
else { // multiple selected units
unitNameLabel.setText("")
unitDescriptionTable.clear() unitDescriptionTable.clear()
unitDescriptionTable.defaults().pad(2f)
unitDescriptionTable.add(ImageGetter.getStatIcon("Movement")).size(20f)
unitDescriptionTable.add(unit.getMovementString()).padRight(10f)
if (!unit.type.isCivilian()) {
unitDescriptionTable.add(ImageGetter.getStatIcon("Strength")).size(20f)
unitDescriptionTable.add(unit.baseUnit().strength.toString()).padRight(10f)
} }
if (unit.baseUnit().rangedStrength!=0) {
unitDescriptionTable.add(ImageGetter.getStatIcon("RangedStrength")).size(20f)
unitDescriptionTable.add(unit.baseUnit().rangedStrength.toString()).padRight(10f)
}
if(unit.type.isRanged()){
unitDescriptionTable.add(ImageGetter.getStatIcon("Range")).size(20f)
unitDescriptionTable.add(unit.getRange().toString()).padRight(10f)
}
if(unit.baseUnit.interceptRange > 0){
unitDescriptionTable.add(ImageGetter.getStatIcon("InterceptRange")).size(20f)
val range = if(unit.type.isRanged()) unit.getRange() else unit.baseUnit.interceptRange
unitDescriptionTable.add(range.toString()).padRight(10f)
}
if (!unit.type.isCivilian()) {
unitDescriptionTable.add("XP")
unitDescriptionTable.add(unit.promotions.XP.toString()+"/"+unit.promotions.xpForNextPromotion())
}
if(unit.promotions.promotions.size != promotionsTable.children.size) // The unit has been promoted! Reload promotions!
selectedUnitHasChanged = true
} }
else if (selectedCity != null) { else if (selectedCity != null) {
separator.isVisible=true separator.isVisible=true
val city = selectedCity!! val city = selectedCity!!
@ -178,16 +184,21 @@ class UnitTable(val worldScreen: WorldScreen) : Table(){
unitDescriptionTable.clearListeners() unitDescriptionTable.clearListeners()
if(selectedUnit!=null) { if(selectedUnit!=null) {
unitIconHolder.add(UnitGroup(selectedUnit!!,30f)).pad(5f) if(selectedUnits.size==1) { // single selected unit
for(promotion in selectedUnit!!.promotions.promotions.sorted()) unitIconHolder.add(UnitGroup(selectedUnit!!, 30f)).pad(5f)
promotionsTable.add(ImageGetter.getPromotionIcon(promotion)) for (promotion in selectedUnit!!.promotions.promotions.sorted())
promotionsTable.add(ImageGetter.getPromotionIcon(promotion))
// Since Clear also clears the listeners, we need to re-add it every time // Since Clear also clears the listeners, we need to re-add it every time
promotionsTable.onClick { promotionsTable.onClick {
if(selectedUnit==null || selectedUnit!!.promotions.promotions.isEmpty()) return@onClick if (selectedUnit == null || selectedUnit!!.promotions.promotions.isEmpty()) return@onClick
UncivGame.Current.setScreen(PromotionPickerScreen(selectedUnit!!)) UncivGame.Current.setScreen(PromotionPickerScreen(selectedUnit!!))
}
}
else { // multiple selected units
for (unit in selectedUnits)
unitIconHolder.add(UnitGroup(unit, 30f)).pad(5f)
} }
} }
pack() pack()
@ -206,7 +217,7 @@ class UnitTable(val worldScreen: WorldScreen) : Table(){
fun tileSelected(selectedTile: TileInfo) { fun tileSelected(selectedTile: TileInfo) {
val previouslySelectedUnit = selectedUnit val previouslySelectedUnit = selectedUnit
val previousNumberOfSelectedUnits = selectedUnits.size
if (selectedTile.isCityCenter() if (selectedTile.isCityCenter()
&& (selectedTile.getOwner() == worldScreen.viewingCiv || worldScreen.viewingCiv.isSpectator())) { && (selectedTile.getOwner() == worldScreen.viewingCiv || worldScreen.viewingCiv.isSpectator())) {
@ -228,7 +239,7 @@ class UnitTable(val worldScreen: WorldScreen) : Table(){
isVisible = false isVisible = false
} }
if (selectedUnit != previouslySelectedUnit) if (selectedUnit != previouslySelectedUnit || selectedUnits.size != previousNumberOfSelectedUnits)
selectedUnitHasChanged = true selectedUnitHasChanged = true
} }