don't flood the player with similar messages about spotted enemies. instead cycle through units by clicking the message multiple times.

This commit is contained in:
martin
2019-05-14 13:37:44 +02:00
committed by Yair Morgenstern
parent c11915c978
commit 157e6e81a8
5 changed files with 51 additions and 15 deletions

View File

@ -315,7 +315,15 @@
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!"

View File

@ -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<TileInfo>, 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?) {

View File

@ -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<Vector2>, 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()) {

View File

@ -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<Vector2> = listOf()
var color: Color = Color.BLACK
internal constructor() // Needed for json deserialization
constructor(text: String, location: Vector2?,color: Color) {
constructor(text: String, location: List<Vector2> = listOf(), color: Color) {
this.text = text
this.location = location
this.color=color
this.locations = location
this.color = color
}
}

View File

@ -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])
}
}
}