diff --git a/android/Images/EmojiIcons/Gold.png b/android/Images/EmojiIcons/Gold.png new file mode 100644 index 0000000000..63f4b3dc63 Binary files /dev/null and b/android/Images/EmojiIcons/Gold.png differ diff --git a/core/src/com/unciv/logic/trade/TradeOffer.kt b/core/src/com/unciv/logic/trade/TradeOffer.kt index cacf2b4aad..fa4087c98e 100644 --- a/core/src/com/unciv/logic/trade/TradeOffer.kt +++ b/core/src/com/unciv/logic/trade/TradeOffer.kt @@ -5,26 +5,30 @@ import com.unciv.UncivGame import com.unciv.models.metadata.GameSpeed import com.unciv.models.translations.tr import com.unciv.ui.utils.Fonts +import com.unciv.logic.trade.TradeType.TradeTypeNumberType -data class TradeOffer(var name:String, var type: TradeType, var amount:Int=1, var duration:Int=-1) { +data class TradeOffer(val name:String, val type:TradeType, var amount:Int = 1, var duration: Int = -1) { init { - // Duration needs to be part of the variables defined at the top, so that it will be copied over with copy() - duration = when(type){ - TradeType.Gold, TradeType.Technology, TradeType.Introduction, TradeType.WarDeclaration, TradeType.City -> -1 /** -1 for offers that are immediate (e.g. gold transfer) */ - else -> when(UncivGame.Current.gameInfo.gameParameters.gameSpeed){ - GameSpeed.Quick -> if (name==Constants.peaceTreaty) 10 else 25 - else -> ((if (name==Constants.peaceTreaty) 10 else 30) * UncivGame.Current.gameInfo.gameParameters.gameSpeed.modifier).toInt() + // Duration needs to be part of the variables defined in the primary constructor, + // so that it will be copied over with the automatically generated copy() + val gameSpeed = UncivGame.Current.gameInfo.gameParameters.gameSpeed + duration = when { + type.isImmediate -> -1 // -1 for offers that are immediate (e.g. gold transfer) + name == Constants.peaceTreaty -> 10 + gameSpeed == GameSpeed.Quick -> 25 + else -> (30 * gameSpeed.modifier).toInt() } - } - } - constructor() : this("", TradeType.Gold) // so that the json deserializer can work - fun equals(offer: TradeOffer): Boolean { - return offer.name==name - && offer.type==type - && offer.amount==amount } + constructor() : this("", TradeType.Gold) // so that the json deserializer can work + + @Suppress("CovariantEquals") // This is an overload, not an override of the built-in equals(Any?) + fun equals(offer: TradeOffer): Boolean { + return offer.name == name + && offer.type == type + && offer.amount == amount + } fun getOfferText(): String { var offerText = when(type){ @@ -33,14 +37,12 @@ data class TradeOffer(var name:String, var type: TradeType, var amount:Int=1, va TradeType.City -> UncivGame.Current.gameInfo.getCities().firstOrNull{ it.id == name }?.name ?: "Non-existent city" else -> name }.tr() - if (type !in tradesToNotHaveNumbers || name=="Research Agreement") offerText += " ($amount)" + + if (type.numberType == TradeTypeNumberType.Simple || name == Constants.researchAgreement) offerText += " ($amount)" + else if (type.numberType == TradeTypeNumberType.Gold) offerText += " ($amount${Fonts.gold})" + if (duration > 0) offerText += "\n" + duration + Fonts.turn + return offerText } - - private companion object{ - val tradesToNotHaveNumbers = listOf(TradeType.Technology, TradeType.City, - TradeType.Introduction, TradeType.Treaty, TradeType.WarDeclaration) - } - -} \ No newline at end of file +} diff --git a/core/src/com/unciv/logic/trade/TradeType.kt b/core/src/com/unciv/logic/trade/TradeType.kt index 41c336d843..8edde1b09b 100644 --- a/core/src/com/unciv/logic/trade/TradeType.kt +++ b/core/src/com/unciv/logic/trade/TradeType.kt @@ -1,16 +1,23 @@ package com.unciv.logic.trade -enum class TradeType{ - Gold, - Gold_Per_Turn, +/** Enum that classifies Trade Types + * @param numberType How the value number is formatted - None, Simple number or with a Gold symbol + * @param isImmediate Trade is a one-time effect without duration + */ +@Suppress("EnumEntryName") // We do want the underscores in our names +enum class TradeType(val numberType: TradeTypeNumberType, val isImmediate: Boolean) { + Gold (TradeTypeNumberType.Gold, true), + Gold_Per_Turn (TradeTypeNumberType.Gold, false), /** Treaties are shared by both sides - like peace treaty and defensive pact */ - Treaty, + Treaty (TradeTypeNumberType.None, false), /** Agreements are one-sided, like open borders */ - Agreement, - Luxury_Resource, - Strategic_Resource, - Technology, - Introduction, - WarDeclaration, - City -} \ No newline at end of file + Agreement (TradeTypeNumberType.Simple, false), + Luxury_Resource (TradeTypeNumberType.Simple, false), + Strategic_Resource (TradeTypeNumberType.Simple, false), + Technology (TradeTypeNumberType.None, true), + Introduction (TradeTypeNumberType.None, true), + WarDeclaration (TradeTypeNumberType.None, true), + City (TradeTypeNumberType.None, true); + + enum class TradeTypeNumberType { None, Simple, Gold } +} diff --git a/core/src/com/unciv/ui/utils/Fonts.kt b/core/src/com/unciv/ui/utils/Fonts.kt index 9438f913a8..391b2b06b4 100644 --- a/core/src/com/unciv/ui/utils/Fonts.kt +++ b/core/src/com/unciv/ui/utils/Fonts.kt @@ -89,6 +89,7 @@ class NativeBitmapFontData(val fontImplementation: NativeFontImplementation) : B Fonts.movement -> Fonts.extractPixmapFromTextureRegion(ImageGetter.getDrawable("StatIcons/Movement").region) Fonts.turn -> Fonts.extractPixmapFromTextureRegion(ImageGetter.getDrawable("EmojiIcons/Turn").region) Fonts.production -> Fonts.extractPixmapFromTextureRegion(ImageGetter.getDrawable("EmojiIcons/Production").region) + Fonts.gold -> Fonts.extractPixmapFromTextureRegion(ImageGetter.getDrawable("EmojiIcons/Gold").region) else -> fontImplementation.getCharPixmap(ch) } } @@ -152,4 +153,5 @@ object Fonts { const val movement = '➡' // U+27A1 'black rightwards arrow' const val range = '…' // U+2026 'horizontal ellipsis' const val production = '⚙' // U+2699 'gear' + const val gold = '¤' // U+00A4 'currency sign' }