From 85158ab29d7d8fafba6540d6276f7793c0fec284 Mon Sep 17 00:00:00 2001 From: SomeTroglodyte <63000004+SomeTroglodyte@users.noreply.github.com> Date: Sun, 13 Jun 2021 21:22:44 +0200 Subject: [PATCH] TradeType Enum marginal cleanup and Gold Font symbol (#4127) --- android/Images/EmojiIcons/Gold.png | Bin 0 -> 1390 bytes core/src/com/unciv/logic/trade/TradeOffer.kt | 46 ++++++++++--------- core/src/com/unciv/logic/trade/TradeType.kt | 31 ++++++++----- core/src/com/unciv/ui/utils/Fonts.kt | 2 + 4 files changed, 45 insertions(+), 34 deletions(-) create mode 100644 android/Images/EmojiIcons/Gold.png diff --git a/android/Images/EmojiIcons/Gold.png b/android/Images/EmojiIcons/Gold.png new file mode 100644 index 0000000000000000000000000000000000000000..63f4b3dc6394ca469ae525b67a71c9b50e8577f6 GIT binary patch literal 1390 zcmV-!1(EuRP)6Xl?G=R+l2XTvZ(v_YHgTDd1``KjvX zxrs|r686ochzPGU7j@hVq(W;u^AYP!UQ1sFfNM$EHBA>*d_A!Qh$eDyrQF z0N|;yLnziJ=wXp(0Kj-!@>KC_6}k7j^rePXcCz|Ie)5w4SSowm@h(KIr4NWycfs)7 z-UVV2rHaE}jvRjelc?1!dw(r_9EY6)8y1iNe1OjCdp%(iDrs2RcLCsH;za!VE4+T~ zN)?sZW;iN{{rc0bdn!xFDl)9^B~*M{lJOcB?Um|d*(06hJ0qy@Nv$LxJqC(6ioha_ zbkZ3R!P%uBXL#a7Vs8mZd0cM`IupRt`$U0Y2BSK1aAFP z6|T*0UcA_E_I4qL0B30W+vzjGH_Jbj&inOSZk9yQr|%wNMk+_LlOrNne-OIg*T+$XfWmwA!3VD%B;`B( z=58KSqLGsRYN2)adO=0)qw90}+k0eJ1m$4uO{*`F*mq|L)u>*+4>IoU(>4G*M_O5p zr2))SgoaHju(WKd_(1EAUxxZ;EoM&<#)e*Y;Ri8}##QW>^yCz%*dHat{Q!JiFEz_7 zGjk(-iJ)kmCQ@9_BYsASuu6*dYvxw~f-@*Zg_O_rh(tx{uT{4s(zrR7K{Af%=X)BF zLHnS7LkWO!(;^kWNCaHdn+9;_{FYfObQc(kwY+}mj({=yB!HO(h&9irnJFSBdas86 z*_$e;6}R+=ovRc8czy>SVKQpGPZ&D-jbW>zMElgvu5QfHPVFVDhluc2DuiNeCpu%_ zWwet%OvRu?b4Py!5an!p;n!?WXgP(k6;kXw8M!6R_y8+20Wzq8?wP~jSzz1&B^ugy zCU$=Ex6Jrt2(ZxGqBQ1@JEFY|(C44Vrf%rbc&>5?yv1u<&8I$X5di=gW*W>)2}EnL wukL>1*|Gg9KXo~V0R|XgfB^;=;D3m}0qWZEkkx$3?*IS*07*qoM6N<$f{%KNfdBvi literal 0 HcmV?d00001 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' }