Skip to content

Commit

Permalink
Resolves #12307 - Unit icon falls back to UnitTypeIcons/<unitType> su…
Browse files Browse the repository at this point in the history
…ccessfully
  • Loading branch information
yairm210 committed Oct 20, 2024
1 parent 9497c17 commit e0864be
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 27 deletions.
4 changes: 2 additions & 2 deletions core/src/com/unciv/logic/civilization/Notification.kt
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class Notification() : IsPartOfGameInfoSerialization, Json.Serializable {

companion object {
fun safeValueOf(name: String): NotificationCategory? =
values().firstOrNull { it.name == name }
entries.firstOrNull { it.name == name }
}
}

Expand All @@ -74,7 +74,7 @@ class Notification() : IsPartOfGameInfoSerialization, Json.Serializable {
ruleset.nations.containsKey(icon) ->
ImageGetter.getNationPortrait(ruleset.nations[icon]!!, iconSize)
ruleset.units.containsKey(icon) ->
ImageGetter.getUnitIcon(icon)
ImageGetter.getUnitIcon(ruleset.units[icon]!!)
else ->
ImageGetter.getImage(icon)
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/com/unciv/ui/components/widgets/UnitIconGroup.kt
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ private class FlagBackground(drawable: TextureRegionDrawable, size: Float) : Ima
class UnitIconGroup(val unit: MapUnit, val size: Float) : Group() {
var actionGroup: Group? = null

private val flagIcon = ImageGetter.getUnitIcon(unit.name, unit.civ.nation.getInnerColor())
private val flagIcon = ImageGetter.getUnitIcon(unit.baseUnit, unit.civ.nation.getInnerColor())
private var flagBg: FlagBackground = FlagBackground(getBackgroundDrawableForUnit(), size)
private var flagSelection: Image = getBackgroundSelectionForUnit()
private var flagMask: Image? = getBackgroundMaskForUnit()
Expand Down
9 changes: 5 additions & 4 deletions core/src/com/unciv/ui/images/ImageGetter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import com.unciv.json.json
import com.unciv.models.ruleset.PerpetualConstruction
import com.unciv.models.ruleset.Ruleset
import com.unciv.models.ruleset.nation.Nation
import com.unciv.models.ruleset.unit.BaseUnit
import com.unciv.models.skins.SkinCache
import com.unciv.models.tilesets.TileSetCache
import com.unciv.ui.components.extensions.center
Expand Down Expand Up @@ -249,10 +250,10 @@ object ImageGetter {

fun getRandomNationPortrait(size: Float): Portrait = PortraitNation(Constants.random, size)

fun getUnitIcon(unitName: String, color: Color = Color.BLACK): Image =
if (imageExists("UnitIcons/$unitName"))
getImage("UnitIcons/$unitName").apply { this.color = color }
else getImage("UnitTypeIcons/$unitName").apply { this.color = color }
fun getUnitIcon(unit: BaseUnit, color: Color = Color.BLACK): Image =
if (imageExists("UnitIcons/${unit.name}"))
getImage("UnitIcons/${unit.name}").apply { this.color = color }
else getImage("UnitTypeIcons/${unit.type}").apply { this.color = color }

fun getConstructionPortrait(construction: String, size: Float): Group {
if (ruleset.buildings.containsKey(construction)) {
Expand Down
19 changes: 4 additions & 15 deletions core/src/com/unciv/ui/screens/cityscreen/CityStatsTable.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,21 @@ import com.badlogic.gdx.scenes.scene2d.ui.Label
import com.badlogic.gdx.scenes.scene2d.ui.Table
import com.badlogic.gdx.utils.Align
import com.unciv.Constants
import com.unciv.UncivGame
import com.unciv.logic.city.City
import com.unciv.logic.city.CityFlags
import com.unciv.logic.city.CityFocus
import com.unciv.logic.city.CityResources
import com.unciv.logic.city.GreatPersonPointsBreakdown
import com.unciv.logic.city.*
import com.unciv.models.Counter
import com.unciv.models.ruleset.Building
import com.unciv.models.ruleset.tile.TileResource
import com.unciv.models.ruleset.unique.UniqueType
import com.unciv.models.stats.Stat
import com.unciv.models.translations.tr
import com.unciv.ui.components.extensions.addSeparator
import com.unciv.ui.components.extensions.center
import com.unciv.ui.components.extensions.colorFromRGB
import com.unciv.ui.components.extensions.surroundWithCircle
import com.unciv.ui.components.extensions.toGroup
import com.unciv.ui.components.extensions.toLabel
import com.unciv.ui.components.extensions.toTextButton
import com.unciv.ui.components.extensions.*
import com.unciv.ui.components.fonts.Fonts
import com.unciv.ui.components.input.KeyboardBinding
import com.unciv.ui.components.input.onActivation
import com.unciv.ui.components.input.onClick
import com.unciv.ui.components.widgets.ExpanderTab
import com.unciv.ui.images.ImageGetter
import com.unciv.ui.screens.basescreen.BaseScreen
import com.unciv.ui.screens.civilopediascreen.CivilopediaScreen
import kotlin.math.ceil
import kotlin.math.round
import com.unciv.ui.components.widgets.AutoScrollPane as ScrollPane
Expand Down Expand Up @@ -364,7 +352,8 @@ class CityStatsTable(private val cityScreen: CityScreen) : Table() {

val info = Table()

info.add(ImageGetter.getUnitIcon(greatPersonName, Color.GOLD).toGroup(20f))
val greatPerson = city.getRuleset().units[greatPersonName] ?: continue
info.add(ImageGetter.getUnitIcon(greatPerson, Color.GOLD).toGroup(20f))
.left().padBottom(4f).padRight(5f)
info.add("{$greatPersonName} (+$gppPerTurn)".toLabel(hideIcons = true)).left().padBottom(4f).expandX().row()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ class SpecialistAllocationTable(private val cityScreen: CityScreen) : Table(Base
// greatPersonPoints is a Counter so iteration order is potentially random:
// Sort by unit name without collator to ensure consistency in those rare mods where one Specialist gives points to several GP counters
for ((gpName, gpPoints) in specialist.greatPersonPoints.asSequence().sortedBy { it.key }) {
addWrapping(gpPoints, Color.GOLD, ImageGetter.getUnitIcon(gpName, Color.GOLD))
val greatPerson = city.getRuleset().units[gpName] ?: continue
addWrapping(gpPoints, Color.GOLD, ImageGetter.getUnitIcon(greatPerson, Color.GOLD))
}

// This uses Stats.iterator() which ensures consistent Stat order and returns no zero value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ enum class CityOverviewTabColumn : ISortableGridContentProvider<City, EmpireOver
override val defaultSort get() = SortableGrid.SortDirection.Ascending
override fun getComparator() = compareBy<City, String>(collator) { it.name.tr(hideIcons = true) }
override fun getHeaderActor(iconSize: Float) =
ImageGetter.getUnitIcon("Settler")
ImageGetter.getImage("UnitIcons/Settler").apply { color = Color.BLACK }
.surroundWithCircle(iconSize)
override fun getEntryValue(item: City) = 0 // make sure that `stat!!` in the super isn't used
override fun getEntryActor(item: City, iconSize: Float, actionContext: EmpireOverviewScreen) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ open class UnitOverviewTabHelpers {
val enable = canEnable && unitAction.action != null
val unitToUpgradeTo = (unitAction as UpgradeUnitAction).unitToUpgradeTo
val selectKey = getUnitIdentifier(unit, unitToUpgradeTo)
val upgradeIcon = ImageGetter.getUnitIcon(unitToUpgradeTo.name,
val upgradeIcon = ImageGetter.getUnitIcon(unitToUpgradeTo,
if (enable) Color.GREEN else Color.GREEN.darken(0.5f))
upgradeIcon.onClick {
UnitUpgradeMenu(actionContext.overviewScreen.stage, upgradeIcon, unit, unitAction, enable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class GreatPersonPickerScreen(val worldScreen: WorldScreen, val civInfo: Civiliz

for (unit in greatPersonUnits) {
val button =
PickerPane.getPickerOptionButton(ImageGetter.getUnitIcon(unit.name), unit.name)
PickerPane.getPickerOptionButton(ImageGetter.getUnitIcon(unit), unit.name)
button.pack()
button.isEnabled = !useMayaLongCount || unit.name in civInfo.greatPeople.longCountGPPool
if (button.isEnabled) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class UnitRenamePopup(val screen: BaseScreen, val unit: MapUnit, val actionOnClo
AskTextPopup(
screen,
label = "Choose name for [${unit.baseUnit.name}]",
icon = ImageGetter.getUnitIcon(unit.name).surroundWithCircle(80f),
icon = ImageGetter.getUnitIcon(unit.baseUnit).surroundWithCircle(80f),
defaultText = unit.instanceName ?: unit.baseUnit.name.tr(hideIcons = true),
validate = { it != unit.name },
actionOnOk = { userInput ->
Expand Down

0 comments on commit e0864be

Please sign in to comment.