TradeType Enum marginal cleanup and Gold Font symbol (#4127)

This commit is contained in:
SomeTroglodyte 2021-06-13 21:22:44 +02:00 committed by GitHub
parent 5f66c57de5
commit 85158ab29d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 45 additions and 34 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

@ -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)
}
}
}

View File

@ -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
}
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 }
}

View File

@ -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'
}