Better icons for notifications (there's a lot of work to do here)

This commit is contained in:
Yair Morgenstern 2021-03-19 15:38:14 +02:00
parent 4c260ca954
commit d515955b30
8 changed files with 33 additions and 21 deletions

View File

@ -304,16 +304,17 @@ class CityConstructions {
validateConstructionQueue() // if we've build e.g. the Great Lighthouse, then Lighthouse is no longer relevant in the queue validateConstructionQueue() // if we've build e.g. the Great Lighthouse, then Lighthouse is no longer relevant in the queue
val buildingIcon = "BuildingIcons/${construction.name}"
if (construction is Building && construction.isWonder) { if (construction is Building && construction.isWonder) {
cityInfo.civInfo.popupAlerts.add(PopupAlert(AlertType.WonderBuilt, construction.name)) cityInfo.civInfo.popupAlerts.add(PopupAlert(AlertType.WonderBuilt, construction.name))
for (civ in cityInfo.civInfo.gameInfo.civilizations) { for (civ in cityInfo.civInfo.gameInfo.civilizations) {
if (civ.exploredTiles.contains(cityInfo.location)) if (civ.exploredTiles.contains(cityInfo.location))
civ.addNotification("[${construction.name}] has been built in [${cityInfo.name}]", cityInfo.location, Color.BROWN) civ.addNotification("[${construction.name}] has been built in [${cityInfo.name}]", cityInfo.location, NotificationIcon.Construction, buildingIcon)
else else
civ.addNotification("[${construction.name}] has been built in a faraway land", "BuildingIcons/${construction.name}") civ.addNotification("[${construction.name}] has been built in a faraway land", buildingIcon)
} }
} else } else
cityInfo.civInfo.addNotification("[${construction.name}] has been built in [" + cityInfo.name + "]", cityInfo.location, NotificationIcon.Construction) cityInfo.civInfo.addNotification("[${construction.name}] has been built in [" + cityInfo.name + "]", cityInfo.location, NotificationIcon.Construction, buildingIcon)
} }
fun addBuilding(buildingName: String) { fun addBuilding(buildingName: String) {

View File

@ -52,7 +52,7 @@ class PopulationManager {
fun nextTurn(food: Int) { fun nextTurn(food: Int) {
foodStored += food foodStored += food
if (food < 0) if (food < 0)
cityInfo.civInfo.addNotification("[${cityInfo.name}] is starving!", cityInfo.location, Color.RED) cityInfo.civInfo.addNotification("[${cityInfo.name}] is starving!", cityInfo.location, NotificationIcon.Growth, "OtherIcons/DisbandUnit")
if (foodStored < 0) { // starvation! if (foodStored < 0) { // starvation!
if (population > 1) population-- if (population > 1) population--
foodStored = 0 foodStored = 0

View File

@ -553,9 +553,8 @@ class CivilizationInfo {
addNotification(text, color, LocationAction(locations)) addNotification(text, color, LocationAction(locations))
} }
fun addNotification(text: String, location: Vector2?, notificationIcon: String) { fun addNotification(text: String, location: Vector2, vararg notificationIcons: String) {
val locations = if (location != null) listOf(location) else emptyList() addNotification(text, LocationAction(listOf(location)), *notificationIcons)
addNotification(text, LocationAction(locations), notificationIcon)
} }

View File

@ -241,7 +241,7 @@ class TechManager {
} }
updateTransientBooleans() updateTransientBooleans()
civInfo.addNotification("Research of [$techName] has completed!", Color.BLUE, TechAction(techName)) civInfo.addNotification("Research of [$techName] has completed!", TechAction(techName), NotificationIcon.Science, techName )
civInfo.popupAlerts.add(PopupAlert(AlertType.TechResearched, techName)) civInfo.popupAlerts.add(PopupAlert(AlertType.TechResearched, techName))
val currentEra = civInfo.getEra() val currentEra = civInfo.getEra()

View File

@ -307,8 +307,8 @@ class DiplomacyManager() {
trades.remove(trade) trades.remove(trade)
val otherCivTrades = otherCiv().getDiplomacyManager(civInfo).trades val otherCivTrades = otherCiv().getDiplomacyManager(civInfo).trades
otherCivTrades.removeAll { it.equals(trade.reverse()) } otherCivTrades.removeAll { it.equals(trade.reverse()) }
civInfo.addNotification("One of our trades with [$otherCivName] has been cut short", NotificationIcon.Trade) civInfo.addNotification("One of our trades with [$otherCivName] has been cut short", NotificationIcon.Trade, otherCivName)
otherCiv().addNotification("One of our trades with [${civInfo.civName}] has been cut short", NotificationIcon.Trade) otherCiv().addNotification("One of our trades with [${civInfo.civName}] has been cut short", NotificationIcon.Trade, civInfo.civName)
civInfo.updateDetailedCivResources() civInfo.updateDetailedCivResources()
} }
} }
@ -487,11 +487,11 @@ class DiplomacyManager() {
onWarDeclared() onWarDeclared()
otherCivDiplomacy.onWarDeclared() otherCivDiplomacy.onWarDeclared()
otherCiv.addNotification("[${civInfo.civName}] has declared war on us!", NotificationIcon.War) otherCiv.addNotification("[${civInfo.civName}] has declared war on us!", NotificationIcon.War, civInfo.civName)
otherCiv.popupAlerts.add(PopupAlert(AlertType.WarDeclaration, civInfo.civName)) otherCiv.popupAlerts.add(PopupAlert(AlertType.WarDeclaration, civInfo.civName))
getCommonKnownCivs().forEach { getCommonKnownCivs().forEach {
it.addNotification("[${civInfo.civName}] has declared war on [${otherCiv().civName}]!", NotificationIcon.War) it.addNotification("[${civInfo.civName}] has declared war on [$otherCivName]!", civInfo.civName, NotificationIcon.War, otherCivName)
} }
otherCivDiplomacy.setModifier(DiplomaticModifiers.DeclaredWarOnUs, -20f) otherCivDiplomacy.setModifier(DiplomaticModifiers.DeclaredWarOnUs, -20f)
@ -618,10 +618,10 @@ class DiplomacyManager() {
setFlag(DiplomacyFlags.DeclarationOfFriendship, 30) setFlag(DiplomacyFlags.DeclarationOfFriendship, 30)
otherCivDiplomacy().setFlag(DiplomacyFlags.DeclarationOfFriendship, 30) otherCivDiplomacy().setFlag(DiplomacyFlags.DeclarationOfFriendship, 30)
if (otherCiv().playerType == PlayerType.Human) if (otherCiv().playerType == PlayerType.Human)
otherCiv().addNotification("[${civInfo.civName}] and [${otherCiv().civName}] have signed the Declaration of Friendship!", null, Color.WHITE) otherCiv().addNotification("[${civInfo.civName}] and [$otherCivName] have signed the Declaration of Friendship!", null, Color.WHITE)
for (thirdCiv in getCommonKnownCivs().filter { it.isMajorCiv() }) { for (thirdCiv in getCommonKnownCivs().filter { it.isMajorCiv() }) {
thirdCiv.addNotification("[${civInfo.civName}] and [${otherCiv().civName}] have signed the Declaration of Friendship!", null, Color.WHITE) thirdCiv.addNotification("[${civInfo.civName}] and [$otherCivName] have signed the Declaration of Friendship!", null, Color.WHITE)
thirdCiv.getDiplomacyManager(civInfo).setFriendshipBasedModifier() thirdCiv.getDiplomacyManager(civInfo).setFriendshipBasedModifier()
} }
} }

View File

@ -628,7 +628,7 @@ class MapUnit {
actions.add { actions.add {
val tech = researchableAncientEraTechs.random(tileBasedRandom).name val tech = researchableAncientEraTechs.random(tileBasedRandom).name
civInfo.tech.addTechnology(tech) civInfo.tech.addTechnology(tech)
civInfo.addNotification("We have discovered the lost technology of [$tech] in the ruins!", tile.position, NotificationIcon.Science) civInfo.addNotification("We have discovered the lost technology of [$tech] in the ruins!", tile.position, NotificationIcon.Science, tech)
} }

View File

@ -285,7 +285,9 @@ object ImageGetter {
return iconGroup return iconGroup
} }
fun getTechIconGroup(techName: String, circleSize: Float): Group { fun getTechIconGroup(techName: String, circleSize: Float) = getTechIcon(techName).surroundWithCircle(circleSize)
fun getTechIcon(techName: String): Image {
val techIconColor = when (ruleset.technologies[techName]!!.era()) { val techIconColor = when (ruleset.technologies[techName]!!.era()) {
Constants.ancientEra -> colorFromRGB(255, 87, 35) Constants.ancientEra -> colorFromRGB(255, 87, 35)
Constants.classicalEra -> colorFromRGB(233, 31, 99) Constants.classicalEra -> colorFromRGB(233, 31, 99)
@ -298,7 +300,6 @@ object ImageGetter {
else -> Color.WHITE.cpy() else -> Color.WHITE.cpy()
} }
return getImage("TechIcons/$techName").apply { color = techIconColor.lerp(Color.BLACK, 0.6f) } return getImage("TechIcons/$techName").apply { color = techIconColor.lerp(Color.BLACK, 0.6f) }
.surroundWithCircle(circleSize)
} }
fun getProgressBarVertical(width: Float, height: Float, percentComplete: Float, progressColor: Color, backgroundColor: Color): Table { fun getProgressBarVertical(width: Float, height: Float, percentComplete: Float, progressColor: Color, backgroundColor: Color): Table {

View File

@ -2,6 +2,7 @@ package com.unciv.ui.worldscreen
import com.unciv.ui.utils.AutoScrollPane as ScrollPane import com.unciv.ui.utils.AutoScrollPane as ScrollPane
import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.scenes.scene2d.Actor
import com.badlogic.gdx.scenes.scene2d.Touchable import com.badlogic.gdx.scenes.scene2d.Touchable
import com.badlogic.gdx.scenes.scene2d.ui.Table import com.badlogic.gdx.scenes.scene2d.ui.Table
import com.unciv.logic.civilization.Notification import com.unciv.logic.civilization.Notification
@ -33,11 +34,21 @@ class NotificationsScroll(internal val worldScreen: WorldScreen) : ScrollPane(nu
val label = notification.text.toLabel(Color.BLACK, 30) val label = notification.text.toLabel(Color.BLACK, 30)
val listItem = Table() val listItem = Table()
if (notification.icons.isNotEmpty()) val iconSize = 20f
for(icon in notification.icons) if (notification.icons.isNotEmpty()) {
listItem.add(ImageGetter.getImage(icon)).size(20f).padRight(5f) val ruleset = worldScreen.gameInfo.ruleSet
for (icon in notification.icons) {
val image: Actor = when {
ruleset.technologies.containsKey(icon) -> ImageGetter.getTechIcon(icon)
ruleset.nations.containsKey(icon) -> ImageGetter.getNationIndicator(ruleset.nations[icon]!!, iconSize)
ruleset.units.containsKey(icon) -> ImageGetter.getUnitIcon(icon)
else -> ImageGetter.getImage(icon)
}
listItem.add(image).size(iconSize).padRight(5f)
}
}
else if(notification.color!=null) listItem.add(ImageGetter.getCircle() else if(notification.color!=null) listItem.add(ImageGetter.getCircle()
.apply { color = notification.color }).size(20f).padRight(5f) .apply { color = notification.color }).size(iconSize).padRight(5f)
listItem.background = ImageGetter.getRoundedEdgeTableBackground().apply { setScale(0.5f) } listItem.background = ImageGetter.getRoundedEdgeTableBackground().apply { setScale(0.5f) }
listItem.add(label) listItem.add(label)