mirror of
https://github.com/yairm210/Unciv.git
synced 2025-03-15 04:14:44 +07:00
toString extension including sign (+/-)
This commit is contained in:
parent
29c647e0f7
commit
338c4bd7e4
@ -4,8 +4,9 @@ import com.unciv.Constants
|
||||
import com.unciv.logic.civilization.Civilization
|
||||
import com.unciv.models.ruleset.tile.ResourceType
|
||||
import com.unciv.models.translations.tr
|
||||
import com.unciv.ui.screens.civilopediascreen.FormattedLine
|
||||
import com.unciv.ui.components.Fonts
|
||||
import com.unciv.ui.components.extensions.toStringSigned
|
||||
import com.unciv.ui.screens.civilopediascreen.FormattedLine
|
||||
import com.unciv.utils.DebugUtils
|
||||
|
||||
object TileDescription {
|
||||
@ -76,8 +77,7 @@ object TileDescription {
|
||||
|
||||
val defenceBonus = tile.getDefensiveBonus()
|
||||
if (defenceBonus != 0f) {
|
||||
var defencePercentString = (defenceBonus * 100).toInt().toString() + "%"
|
||||
if (!defencePercentString.startsWith("-")) defencePercentString = "+$defencePercentString"
|
||||
val defencePercentString = (defenceBonus * 100).toInt().toStringSigned() + "%"
|
||||
lineList += FormattedLine("[$defencePercentString] to unit defence")
|
||||
}
|
||||
if (tile.isImpassible()) lineList += FormattedLine(Constants.impassable)
|
||||
|
@ -22,6 +22,8 @@ fun String.getConsumesAmountString(amount: Int) = "Consumes [$amount] [$this]"
|
||||
/** Convert a [resource name][this] into "Need [amount] more $resource" string (untranslated) */
|
||||
fun String.getNeedMoreAmountString(amount: Int) = "Need [$amount] more [$this]"
|
||||
|
||||
fun Int.toStringSigned() = if (this > 0) "+$this" else this.toString()
|
||||
|
||||
/** Formats the [Duration] into a translated string */
|
||||
fun Duration.format(): String {
|
||||
val sb = StringBuilder()
|
||||
|
@ -4,14 +4,15 @@ import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Button
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.TextField
|
||||
import com.unciv.ui.images.IconCircleGroup
|
||||
import com.unciv.ui.images.ImageGetter
|
||||
import com.unciv.ui.screens.basescreen.BaseScreen
|
||||
import com.unciv.ui.components.UncivTextField
|
||||
import com.unciv.ui.components.extensions.onChange
|
||||
import com.unciv.ui.components.extensions.onClick
|
||||
import com.unciv.ui.components.extensions.surroundWithCircle
|
||||
import com.unciv.ui.components.extensions.toLabel
|
||||
import com.unciv.ui.components.extensions.toStringSigned
|
||||
import com.unciv.ui.images.IconCircleGroup
|
||||
import com.unciv.ui.images.ImageGetter
|
||||
import com.unciv.ui.screens.basescreen.BaseScreen
|
||||
|
||||
/** Simple class for showing a prompt for a positive integer to the user
|
||||
* @param screen The previous screen the user was on
|
||||
@ -90,8 +91,7 @@ class AskNumberPopup(
|
||||
fun addValueButton(value: Int) {
|
||||
centerTable.add(
|
||||
Button(
|
||||
if (value > 0) "+$value".toLabel()
|
||||
else value.toLabel(),
|
||||
value.toStringSigned().toLabel(),
|
||||
skin
|
||||
).apply {
|
||||
onClick {
|
||||
|
Loading…
Reference in New Issue
Block a user