From 157e6e81a8331fd9093f53f1b867b41cc537d3f7 Mon Sep 17 00:00:00 2001 From: martin Date: Tue, 14 May 2019 13:37:44 +0200 Subject: [PATCH] don't flood the player with similar messages about spotted enemies. instead cycle through units by clicking the message multiple times. --- .../jsons/Translations/Notifications.json | 12 ++++++-- core/src/com/unciv/logic/GameInfo.kt | 30 +++++++++++++++---- .../logic/civilization/CivilizationInfo.kt | 7 ++++- .../unciv/logic/civilization/Notification.kt | 10 +++---- .../ui/worldscreen/NotificationsScroll.kt | 7 +++-- 5 files changed, 51 insertions(+), 15 deletions(-) diff --git a/android/assets/jsons/Translations/Notifications.json b/android/assets/jsons/Translations/Notifications.json index 2ff9bf8e2e..87b7467951 100644 --- a/android/assets/jsons/Translations/Notifications.json +++ b/android/assets/jsons/Translations/Notifications.json @@ -315,8 +315,16 @@ Simplified_Chinese:"在我们的领土附近发现了一个敌人的[unit]" Portuguese:"Um(a) [unit] inimigo(a) foi vista dentro de nosso território" Japanese:"私たちの領土に敵[unit]が発見されました" - } - + }, + + "[amount] enemy units were spotted near our territory": { + German:"[amount] feindliche Einheiten wurden nahe unserer Grenzen entdeckt" + }, + + "[amount] enemy units were spotted in our territory": { + German:"[amount] feindliche Einheiten wurden in unseren Grenzen entdeckt" + }, + "The civilization of [civName] has been destroyed!":{ Italian:"La civiltà [civName] è stata distrutta!" Russian:"Цивилизация [civName] была уничтожена!" diff --git a/core/src/com/unciv/logic/GameInfo.kt b/core/src/com/unciv/logic/GameInfo.kt index d7f4728b04..eec8cf8abb 100644 --- a/core/src/com/unciv/logic/GameInfo.kt +++ b/core/src/com/unciv/logic/GameInfo.kt @@ -73,12 +73,32 @@ class GameInfo { && (it.getOwner() == thisPlayer || it.neighbors.any { neighbor -> neighbor.getOwner() == thisPlayer }) } - for (enemyUnitTile in enemyUnitsCloseToTerritory) { - val inOrNear = if (enemyUnitTile.getOwner() == thisPlayer) "in" else "near" - val unitName = enemyUnitTile.militaryUnit!!.name - thisPlayer.addNotification("An enemy [$unitName] was spotted $inOrNear our territory", enemyUnitTile.position, Color.RED) - } + // enemy units ON our territory + addEnemyUnitNotification( + thisPlayer, + enemyUnitsCloseToTerritory.filter { it.getOwner()==thisPlayer }, + "in" + ) + // enemy units NEAR our territory + addEnemyUnitNotification( + thisPlayer, + enemyUnitsCloseToTerritory.filter { it.getOwner()!=thisPlayer }, + "near" + ) + } + private fun addEnemyUnitNotification(thisPlayer: CivilizationInfo, tiles: List, inOrNear: String) { + // don't flood the player with similar messages. instead cycle through units by clicking the message multiple times. + if (tiles.size < 3) { + for (tile in tiles) { + val unitName = tile.militaryUnit!!.name + thisPlayer.addNotification("An enemy [$unitName] was spotted $inOrNear our territory", tile.position, Color.RED) + } + } + else { + val positions = tiles.map { it.position } + thisPlayer.addNotification("[${positions.size}] enemy units were spotted $inOrNear our territory", positions, Color.RED) + } } fun placeBarbarianUnit(tileToPlace: TileInfo?) { diff --git a/core/src/com/unciv/logic/civilization/CivilizationInfo.kt b/core/src/com/unciv/logic/civilization/CivilizationInfo.kt index c59bfef5ce..57c648af58 100644 --- a/core/src/com/unciv/logic/civilization/CivilizationInfo.kt +++ b/core/src/com/unciv/logic/civilization/CivilizationInfo.kt @@ -501,8 +501,13 @@ class CivilizationInfo { } fun addNotification(text: String, location: Vector2?,color: Color) { + val locations = if(location!=null) listOf(location) else emptyList() + addNotification(text, locations, color) + } + + fun addNotification(text: String, locations: List, color: Color) { if(playerType==PlayerType.AI) return // no point in lengthening the saved game info if no one will read it - notifications.add(Notification(text, location,color)) + notifications.add(Notification(text, locations,color)) } fun addGreatPerson(greatPerson: String, city:CityInfo = cities.random()) { diff --git a/core/src/com/unciv/logic/civilization/Notification.kt b/core/src/com/unciv/logic/civilization/Notification.kt index 5969f21f63..1320de7adc 100644 --- a/core/src/com/unciv/logic/civilization/Notification.kt +++ b/core/src/com/unciv/logic/civilization/Notification.kt @@ -5,14 +5,14 @@ import com.badlogic.gdx.math.Vector2 class Notification { var text: String = "" - var location: Vector2? = null - var color:Color = Color.BLACK + var locations: List = listOf() + var color: Color = Color.BLACK internal constructor() // Needed for json deserialization - constructor(text: String, location: Vector2?,color: Color) { + constructor(text: String, location: List = listOf(), color: Color) { this.text = text - this.location = location - this.color=color + this.locations = location + this.color = color } } diff --git a/core/src/com/unciv/ui/worldscreen/NotificationsScroll.kt b/core/src/com/unciv/ui/worldscreen/NotificationsScroll.kt index 2e3ee57881..ae30787ef6 100644 --- a/core/src/com/unciv/ui/worldscreen/NotificationsScroll.kt +++ b/core/src/com/unciv/ui/worldscreen/NotificationsScroll.kt @@ -33,8 +33,11 @@ class NotificationsScroll(internal val worldScreen: WorldScreen) : ScrollPane(nu add(listItem).pad(3f) touchable = Touchable.enabled onClick { - if (notification.location != null) - worldScreen.tileMapHolder.setCenterPosition(notification.location!!) + if (notification.locations.isNotEmpty()) { + var index = notification.locations.indexOf(worldScreen.tileMapHolder.selectedTile?.position) + index = ++index % notification.locations.size // cycle through locations + worldScreen.tileMapHolder.setCenterPosition(notification.locations[index]) + } } }