From d515955b309f268178a5bf7bad9a3b3b8cbae4d3 Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Fri, 19 Mar 2021 15:38:14 +0200 Subject: [PATCH] Better icons for notifications (there's a lot of work to do here) --- .../com/unciv/logic/city/CityConstructions.kt | 7 ++++--- .../com/unciv/logic/city/PopulationManager.kt | 2 +- .../logic/civilization/CivilizationInfo.kt | 5 ++--- .../unciv/logic/civilization/TechManager.kt | 2 +- .../diplomacy/DiplomacyManager.kt | 12 ++++++------ core/src/com/unciv/logic/map/MapUnit.kt | 2 +- core/src/com/unciv/ui/utils/ImageGetter.kt | 5 +++-- .../ui/worldscreen/NotificationsScroll.kt | 19 +++++++++++++++---- 8 files changed, 33 insertions(+), 21 deletions(-) diff --git a/core/src/com/unciv/logic/city/CityConstructions.kt b/core/src/com/unciv/logic/city/CityConstructions.kt index 75d6d31259..a1e6f2b0d1 100644 --- a/core/src/com/unciv/logic/city/CityConstructions.kt +++ b/core/src/com/unciv/logic/city/CityConstructions.kt @@ -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 + val buildingIcon = "BuildingIcons/${construction.name}" if (construction is Building && construction.isWonder) { cityInfo.civInfo.popupAlerts.add(PopupAlert(AlertType.WonderBuilt, construction.name)) for (civ in cityInfo.civInfo.gameInfo.civilizations) { 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 - 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 - 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) { diff --git a/core/src/com/unciv/logic/city/PopulationManager.kt b/core/src/com/unciv/logic/city/PopulationManager.kt index 89e72a2aa1..deb2823bd1 100644 --- a/core/src/com/unciv/logic/city/PopulationManager.kt +++ b/core/src/com/unciv/logic/city/PopulationManager.kt @@ -52,7 +52,7 @@ class PopulationManager { fun nextTurn(food: Int) { foodStored += food 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 (population > 1) population-- foodStored = 0 diff --git a/core/src/com/unciv/logic/civilization/CivilizationInfo.kt b/core/src/com/unciv/logic/civilization/CivilizationInfo.kt index 286731f444..5302a3955b 100644 --- a/core/src/com/unciv/logic/civilization/CivilizationInfo.kt +++ b/core/src/com/unciv/logic/civilization/CivilizationInfo.kt @@ -553,9 +553,8 @@ class CivilizationInfo { addNotification(text, color, LocationAction(locations)) } - fun addNotification(text: String, location: Vector2?, notificationIcon: String) { - val locations = if (location != null) listOf(location) else emptyList() - addNotification(text, LocationAction(locations), notificationIcon) + fun addNotification(text: String, location: Vector2, vararg notificationIcons: String) { + addNotification(text, LocationAction(listOf(location)), *notificationIcons) } diff --git a/core/src/com/unciv/logic/civilization/TechManager.kt b/core/src/com/unciv/logic/civilization/TechManager.kt index c467fdda7b..e058f5ec45 100644 --- a/core/src/com/unciv/logic/civilization/TechManager.kt +++ b/core/src/com/unciv/logic/civilization/TechManager.kt @@ -241,7 +241,7 @@ class TechManager { } 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)) val currentEra = civInfo.getEra() diff --git a/core/src/com/unciv/logic/civilization/diplomacy/DiplomacyManager.kt b/core/src/com/unciv/logic/civilization/diplomacy/DiplomacyManager.kt index 2cad574b26..2d7e1c8537 100644 --- a/core/src/com/unciv/logic/civilization/diplomacy/DiplomacyManager.kt +++ b/core/src/com/unciv/logic/civilization/diplomacy/DiplomacyManager.kt @@ -307,8 +307,8 @@ class DiplomacyManager() { trades.remove(trade) val otherCivTrades = otherCiv().getDiplomacyManager(civInfo).trades otherCivTrades.removeAll { it.equals(trade.reverse()) } - civInfo.addNotification("One of our trades with [$otherCivName] has been cut short", NotificationIcon.Trade) - otherCiv().addNotification("One of our trades with [${civInfo.civName}] 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, civInfo.civName) civInfo.updateDetailedCivResources() } } @@ -487,11 +487,11 @@ class DiplomacyManager() { 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)) 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) @@ -618,10 +618,10 @@ class DiplomacyManager() { setFlag(DiplomacyFlags.DeclarationOfFriendship, 30) otherCivDiplomacy().setFlag(DiplomacyFlags.DeclarationOfFriendship, 30) 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() }) { - 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() } } diff --git a/core/src/com/unciv/logic/map/MapUnit.kt b/core/src/com/unciv/logic/map/MapUnit.kt index 46424db237..b51e1394bd 100644 --- a/core/src/com/unciv/logic/map/MapUnit.kt +++ b/core/src/com/unciv/logic/map/MapUnit.kt @@ -628,7 +628,7 @@ class MapUnit { actions.add { val tech = researchableAncientEraTechs.random(tileBasedRandom).name 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) } diff --git a/core/src/com/unciv/ui/utils/ImageGetter.kt b/core/src/com/unciv/ui/utils/ImageGetter.kt index d6f2b973b4..5a5befe266 100644 --- a/core/src/com/unciv/ui/utils/ImageGetter.kt +++ b/core/src/com/unciv/ui/utils/ImageGetter.kt @@ -285,7 +285,9 @@ object ImageGetter { 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()) { Constants.ancientEra -> colorFromRGB(255, 87, 35) Constants.classicalEra -> colorFromRGB(233, 31, 99) @@ -298,7 +300,6 @@ object ImageGetter { else -> Color.WHITE.cpy() } 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 { diff --git a/core/src/com/unciv/ui/worldscreen/NotificationsScroll.kt b/core/src/com/unciv/ui/worldscreen/NotificationsScroll.kt index da0d82c54f..2257c35bf3 100644 --- a/core/src/com/unciv/ui/worldscreen/NotificationsScroll.kt +++ b/core/src/com/unciv/ui/worldscreen/NotificationsScroll.kt @@ -2,6 +2,7 @@ package com.unciv.ui.worldscreen import com.unciv.ui.utils.AutoScrollPane as ScrollPane 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.ui.Table 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 listItem = Table() - if (notification.icons.isNotEmpty()) - for(icon in notification.icons) - listItem.add(ImageGetter.getImage(icon)).size(20f).padRight(5f) + val iconSize = 20f + if (notification.icons.isNotEmpty()) { + 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() - .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.add(label)