From 5a44d7e098968f98338de4ebe4502fe47ddb5c50 Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Fri, 11 Sep 2020 17:09:50 +0300 Subject: [PATCH] Multiple selected units are more obvious on-map --- .../unciv/ui/worldscreen/WorldMapHolder.kt | 19 +-- .../unciv/ui/worldscreen/unit/UnitTable.kt | 113 ++++++++++-------- 2 files changed, 72 insertions(+), 60 deletions(-) diff --git a/core/src/com/unciv/ui/worldscreen/WorldMapHolder.kt b/core/src/com/unciv/ui/worldscreen/WorldMapHolder.kt index b8a97565c3..fe6f2ed7ba 100644 --- a/core/src/com/unciv/ui/worldscreen/WorldMapHolder.kt +++ b/core/src/com/unciv/ui/worldscreen/WorldMapHolder.kt @@ -286,33 +286,34 @@ class WorldMapHolder(internal val worldScreen: WorldScreen, internal val tileMap val playerViewableTilePositions = viewingCiv.viewableTiles.map { it.position }.toHashSet() - for (tileGroup in tileGroups.values){ + for (tileGroup in tileGroups.values) { tileGroup.update(viewingCiv) - if(tileGroup.tileInfo.improvement==Constants.barbarianEncampment + if (tileGroup.tileInfo.improvement == Constants.barbarianEncampment && tileGroup.tileInfo.position in viewingCiv.exploredTiles) tileGroup.showCircle(Color.RED) val unitsInTile = tileGroup.tileInfo.getUnits() val canSeeEnemy = unitsInTile.any() && unitsInTile.first().civInfo.isAtWarWith(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 } val unitTable = worldScreen.bottomUnitTable when { - unitTable.selectedCity!=null -> { + unitTable.selectedCity != null -> { val city = unitTable.selectedCity!! updateTilegroupsForSelectedCity(city, playerViewableTilePositions) } - unitTable.selectedUnit!=null -> { - val unit = unitTable.selectedUnit!! - updateTilegroupsForSelectedUnit(unit, playerViewableTilePositions) + unitTable.selectedUnit != null -> { + for (unit in unitTable.selectedUnits) { + updateTilegroupsForSelectedUnit(unit, playerViewableTilePositions) + } } - unitActionOverlay!=null -> { + unitActionOverlay != null -> { unitActionOverlay!!.remove() - unitActionOverlay=null + unitActionOverlay = null } } diff --git a/core/src/com/unciv/ui/worldscreen/unit/UnitTable.kt b/core/src/com/unciv/ui/worldscreen/unit/UnitTable.kt index 5adc5d15ea..0eeb6eb192 100644 --- a/core/src/com/unciv/ui/worldscreen/unit/UnitTable.kt +++ b/core/src/com/unciv/ui/worldscreen/unit/UnitTable.kt @@ -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 - separator.isVisible=true - val unit = selectedUnit!! - var nameLabelText = unit.name.tr() - if(unit.health<100) nameLabelText+=" ("+unit.health+")" - if(nameLabelText!=unitNameLabel.text.toString()){ - 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 + if(selectedUnits.size==1) { //single selected unit + separator.isVisible = true + val unit = selectedUnit!! + var nameLabelText = unit.name.tr() + if (unit.health < 100) nameLabelText += " (" + unit.health + ")" + if (nameLabelText != unitNameLabel.text.toString()) { + 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 } - - - 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) + else { // multiple selected units + unitNameLabel.setText("") + unitDescriptionTable.clear() } - - 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) { separator.isVisible=true val city = selectedCity!! @@ -178,16 +184,21 @@ class UnitTable(val worldScreen: WorldScreen) : Table(){ unitDescriptionTable.clearListeners() if(selectedUnit!=null) { - unitIconHolder.add(UnitGroup(selectedUnit!!,30f)).pad(5f) - for(promotion in selectedUnit!!.promotions.promotions.sorted()) - promotionsTable.add(ImageGetter.getPromotionIcon(promotion)) + if(selectedUnits.size==1) { // single selected unit + unitIconHolder.add(UnitGroup(selectedUnit!!, 30f)).pad(5f) + 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 - promotionsTable.onClick { - if(selectedUnit==null || selectedUnit!!.promotions.promotions.isEmpty()) return@onClick - UncivGame.Current.setScreen(PromotionPickerScreen(selectedUnit!!)) + // Since Clear also clears the listeners, we need to re-add it every time + promotionsTable.onClick { + if (selectedUnit == null || selectedUnit!!.promotions.promotions.isEmpty()) return@onClick + UncivGame.Current.setScreen(PromotionPickerScreen(selectedUnit!!)) + } + } + else { // multiple selected units + for (unit in selectedUnits) + unitIconHolder.add(UnitGroup(unit, 30f)).pad(5f) } - } pack() @@ -206,7 +217,7 @@ class UnitTable(val worldScreen: WorldScreen) : Table(){ fun tileSelected(selectedTile: TileInfo) { val previouslySelectedUnit = selectedUnit - + val previousNumberOfSelectedUnits = selectedUnits.size if (selectedTile.isCityCenter() && (selectedTile.getOwner() == worldScreen.viewingCiv || worldScreen.viewingCiv.isSpectator())) { @@ -228,7 +239,7 @@ class UnitTable(val worldScreen: WorldScreen) : Table(){ isVisible = false } - if (selectedUnit != previouslySelectedUnit) + if (selectedUnit != previouslySelectedUnit || selectedUnits.size != previousNumberOfSelectedUnits) selectedUnitHasChanged = true }