mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-04 15:27:50 +07:00
TradeType Enum marginal cleanup and Gold Font symbol (#4127)
This commit is contained in:
BIN
android/Images/EmojiIcons/Gold.png
Normal file
BIN
android/Images/EmojiIcons/Gold.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.4 KiB |
@ -5,26 +5,30 @@ import com.unciv.UncivGame
|
|||||||
import com.unciv.models.metadata.GameSpeed
|
import com.unciv.models.metadata.GameSpeed
|
||||||
import com.unciv.models.translations.tr
|
import com.unciv.models.translations.tr
|
||||||
import com.unciv.ui.utils.Fonts
|
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 {
|
init {
|
||||||
// Duration needs to be part of the variables defined at the top, so that it will be copied over with copy()
|
// Duration needs to be part of the variables defined in the primary constructor,
|
||||||
duration = when(type){
|
// so that it will be copied over with the automatically generated copy()
|
||||||
TradeType.Gold, TradeType.Technology, TradeType.Introduction, TradeType.WarDeclaration, TradeType.City -> -1 /** -1 for offers that are immediate (e.g. gold transfer) */
|
val gameSpeed = UncivGame.Current.gameInfo.gameParameters.gameSpeed
|
||||||
else -> when(UncivGame.Current.gameInfo.gameParameters.gameSpeed){
|
duration = when {
|
||||||
GameSpeed.Quick -> if (name==Constants.peaceTreaty) 10 else 25
|
type.isImmediate -> -1 // -1 for offers that are immediate (e.g. gold transfer)
|
||||||
else -> ((if (name==Constants.peaceTreaty) 10 else 30) * UncivGame.Current.gameInfo.gameParameters.gameSpeed.modifier).toInt()
|
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 {
|
fun getOfferText(): String {
|
||||||
var offerText = when(type){
|
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"
|
TradeType.City -> UncivGame.Current.gameInfo.getCities().firstOrNull{ it.id == name }?.name ?: "Non-existent city"
|
||||||
else -> name
|
else -> name
|
||||||
}.tr()
|
}.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
|
if (duration > 0) offerText += "\n" + duration + Fonts.turn
|
||||||
|
|
||||||
return offerText
|
return offerText
|
||||||
}
|
}
|
||||||
|
}
|
||||||
private companion object{
|
|
||||||
val tradesToNotHaveNumbers = listOf(TradeType.Technology, TradeType.City,
|
|
||||||
TradeType.Introduction, TradeType.Treaty, TradeType.WarDeclaration)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
@ -1,16 +1,23 @@
|
|||||||
package com.unciv.logic.trade
|
package com.unciv.logic.trade
|
||||||
|
|
||||||
enum class TradeType{
|
/** Enum that classifies Trade Types
|
||||||
Gold,
|
* @param numberType How the value number is formatted - None, Simple number or with a Gold symbol
|
||||||
Gold_Per_Turn,
|
* @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 */
|
/** Treaties are shared by both sides - like peace treaty and defensive pact */
|
||||||
Treaty,
|
Treaty (TradeTypeNumberType.None, false),
|
||||||
/** Agreements are one-sided, like open borders */
|
/** Agreements are one-sided, like open borders */
|
||||||
Agreement,
|
Agreement (TradeTypeNumberType.Simple, false),
|
||||||
Luxury_Resource,
|
Luxury_Resource (TradeTypeNumberType.Simple, false),
|
||||||
Strategic_Resource,
|
Strategic_Resource (TradeTypeNumberType.Simple, false),
|
||||||
Technology,
|
Technology (TradeTypeNumberType.None, true),
|
||||||
Introduction,
|
Introduction (TradeTypeNumberType.None, true),
|
||||||
WarDeclaration,
|
WarDeclaration (TradeTypeNumberType.None, true),
|
||||||
City
|
City (TradeTypeNumberType.None, true);
|
||||||
}
|
|
||||||
|
enum class TradeTypeNumberType { None, Simple, Gold }
|
||||||
|
}
|
||||||
|
@ -89,6 +89,7 @@ class NativeBitmapFontData(val fontImplementation: NativeFontImplementation) : B
|
|||||||
Fonts.movement -> Fonts.extractPixmapFromTextureRegion(ImageGetter.getDrawable("StatIcons/Movement").region)
|
Fonts.movement -> Fonts.extractPixmapFromTextureRegion(ImageGetter.getDrawable("StatIcons/Movement").region)
|
||||||
Fonts.turn -> Fonts.extractPixmapFromTextureRegion(ImageGetter.getDrawable("EmojiIcons/Turn").region)
|
Fonts.turn -> Fonts.extractPixmapFromTextureRegion(ImageGetter.getDrawable("EmojiIcons/Turn").region)
|
||||||
Fonts.production -> Fonts.extractPixmapFromTextureRegion(ImageGetter.getDrawable("EmojiIcons/Production").region)
|
Fonts.production -> Fonts.extractPixmapFromTextureRegion(ImageGetter.getDrawable("EmojiIcons/Production").region)
|
||||||
|
Fonts.gold -> Fonts.extractPixmapFromTextureRegion(ImageGetter.getDrawable("EmojiIcons/Gold").region)
|
||||||
else -> fontImplementation.getCharPixmap(ch)
|
else -> fontImplementation.getCharPixmap(ch)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -152,4 +153,5 @@ object Fonts {
|
|||||||
const val movement = '➡' // U+27A1 'black rightwards arrow'
|
const val movement = '➡' // U+27A1 'black rightwards arrow'
|
||||||
const val range = '…' // U+2026 'horizontal ellipsis'
|
const val range = '…' // U+2026 'horizontal ellipsis'
|
||||||
const val production = '⚙' // U+2699 'gear'
|
const val production = '⚙' // U+2699 'gear'
|
||||||
|
const val gold = '¤' // U+00A4 'currency sign'
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user