Added SetFontColor function to Label, because thed default way is a bit annoying

This commit is contained in:
Yair Morgenstern 2018-05-25 11:34:55 +03:00
parent c40ebb3942
commit 7503c67f18
6 changed files with 21 additions and 24 deletions

View File

@ -8,6 +8,7 @@ import com.unciv.models.gamebasics.GameBasics
import com.unciv.models.gamebasics.Unit import com.unciv.models.gamebasics.Unit
import com.unciv.ui.cityscreen.addClickListener import com.unciv.ui.cityscreen.addClickListener
import com.unciv.ui.utils.ImageGetter import com.unciv.ui.utils.ImageGetter
import com.unciv.ui.utils.setFontColor
class GreatPersonPickerScreen : PickerScreen() { class GreatPersonPickerScreen : PickerScreen() {
private var theChosenOne: Unit? = null private var theChosenOne: Unit? = null
@ -19,8 +20,7 @@ class GreatPersonPickerScreen : PickerScreen() {
val button = Button(skin) val button = Button(skin)
button.add(ImageGetter.getUnitIcon(unit.name)).size(30f).pad(10f) button.add(ImageGetter.getUnitIcon(unit.name)).size(30f).pad(10f)
button.add(Label(unit.name, skin).apply { style = Label.LabelStyle(style).apply { fontColor= Color.WHITE} }) button.add(Label(unit.name, skin).setFontColor(Color.WHITE)).pad(10f)
.pad(10f)
button.pack() button.pack()
button.addClickListener { button.addClickListener {
theChosenOne = unit theChosenOne = unit

View File

@ -13,6 +13,7 @@ import com.unciv.ui.cityscreen.addClickListener
import com.unciv.ui.utils.CameraStageBaseScreen import com.unciv.ui.utils.CameraStageBaseScreen
import com.unciv.ui.utils.ImageGetter import com.unciv.ui.utils.ImageGetter
import com.unciv.ui.utils.center import com.unciv.ui.utils.center
import com.unciv.ui.utils.setFontColor
class WorldTileGroup(tileInfo: TileInfo) : TileGroup(tileInfo) { class WorldTileGroup(tileInfo: TileInfo) : TileGroup(tileInfo) {
@ -60,9 +61,7 @@ class WorldTileGroup(tileInfo: TileInfo) : TileGroup(tileInfo) {
val cityButtonText = city.name + " (" + city.population.population + ")" val cityButtonText = city.name + " (" + city.population.population + ")"
val label = Label(cityButtonText, CameraStageBaseScreen.skin) val label = Label(cityButtonText, CameraStageBaseScreen.skin)
val labelStyle = Label.LabelStyle(label.style) label.setFontColor(city.civInfo.getCivilization().getColor())
labelStyle.fontColor = city.civInfo.getCivilization().getColor()
label.style = labelStyle
if (city.civInfo.isPlayerCivilization()) if (city.civInfo.isPlayerCivilization())
label.addClickListener { label.addClickListener {
UnCivGame.Current.screen = CityScreen(city) UnCivGame.Current.screen = CityScreen(city)

View File

@ -115,3 +115,5 @@ fun Actor.center(parent:Actor){ centerX(parent); centerY(parent)}
fun Actor.centerX(parent:Stage){ x = parent.width/2 - width/2 } fun Actor.centerX(parent:Stage){ x = parent.width/2 - width/2 }
fun Actor.centerY(parent:Stage){ y = parent.height/2- height/2} fun Actor.centerY(parent:Stage){ y = parent.height/2- height/2}
fun Actor.center(parent:Stage){ centerX(parent); centerY(parent)} fun Actor.center(parent:Stage){ centerX(parent); centerY(parent)}
fun Label.setFontColor(color:Color): Label {style=Label.LabelStyle(style).apply { fontColor=color }; return this}

View File

@ -13,6 +13,7 @@ import com.unciv.ui.cityscreen.addClickListener
import com.unciv.ui.utils.CameraStageBaseScreen import com.unciv.ui.utils.CameraStageBaseScreen
import com.unciv.ui.utils.ImageGetter import com.unciv.ui.utils.ImageGetter
import com.unciv.ui.utils.disable import com.unciv.ui.utils.disable
import com.unciv.ui.utils.setFontColor
import kotlin.math.max import kotlin.math.max
class BattleTable(val worldScreen: WorldScreen): Table() { class BattleTable(val worldScreen: WorldScreen): Table() {
@ -60,13 +61,11 @@ class BattleTable(val worldScreen: WorldScreen): Table() {
clear() clear()
row().pad(5f) row().pad(5f)
val attackerLabel = Label(attacker.getName(), skin) val attackerLabel = Label(attacker.getName(), skin)
attackerLabel.style= Label.LabelStyle(attackerLabel.style) .setFontColor(attacker.getCivilization().getCivilization().getColor())
attackerLabel.style.fontColor=attacker.getCivilization().getCivilization().getColor()
add(attackerLabel) add(attackerLabel)
val defenderLabel = Label(defender.getName(), skin) val defenderLabel = Label(defender.getName(), skin)
defenderLabel.style= Label.LabelStyle(defenderLabel.style) .setFontColor(defender.getCivilization().getCivilization().getColor())
defenderLabel.style.fontColor=defender.getCivilization().getCivilization().getColor()
add(defenderLabel) add(defenderLabel)
row().pad(5f) row().pad(5f)

View File

@ -9,23 +9,19 @@ import com.unciv.models.gamebasics.GameBasics
import com.unciv.models.gamebasics.ResourceType import com.unciv.models.gamebasics.ResourceType
import com.unciv.models.stats.Stats import com.unciv.models.stats.Stats
import com.unciv.ui.cityscreen.addClickListener import com.unciv.ui.cityscreen.addClickListener
import com.unciv.ui.utils.CameraStageBaseScreen import com.unciv.ui.utils.*
import com.unciv.ui.utils.ImageGetter
import com.unciv.ui.utils.centerY
import com.unciv.ui.utils.colorFromRGB
import kotlin.math.abs import kotlin.math.abs
import kotlin.math.ceil import kotlin.math.ceil
class WorldScreenTopBar(val screen: WorldScreen) : Table() { class WorldScreenTopBar(val screen: WorldScreen) : Table() {
val labelStyle = Label.LabelStyle(Label("", CameraStageBaseScreen.skin).style) val labelSkin = CameraStageBaseScreen.skin
.apply { fontColor = Color.valueOf("f5f5f5ff") }
private val turnsLabel = Label("Turns: 0/400", labelStyle) private val turnsLabel = Label("Turns: 0/400",labelSkin)
private val goldLabel = Label("Gold:", labelStyle).apply { color = colorFromRGB(225, 217, 71) } private val goldLabel = Label("Gold:", labelSkin).setFontColor(colorFromRGB(225, 217, 71) )
private val scienceLabel = Label("Science:", labelStyle).apply { color = colorFromRGB(78, 140, 151) } private val scienceLabel = Label("Science:", labelSkin).setFontColor(colorFromRGB(78, 140, 151) )
private val happinessLabel = Label("Happiness:", labelStyle) private val happinessLabel = Label("Happiness:", labelSkin)
private val cultureLabel = Label("Culture:", labelStyle).apply { color = colorFromRGB(210, 94, 210) } private val cultureLabel = Label("Culture:", labelSkin).setFontColor(colorFromRGB(210, 94, 210) )
private val resourceLabels = HashMap<String, Label>() private val resourceLabels = HashMap<String, Label>()
private val resourceImages = HashMap<String, Image>() private val resourceImages = HashMap<String, Image>()
private val happinessImage = ImageGetter.getStatIcon("Happiness") private val happinessImage = ImageGetter.getStatIcon("Happiness")
@ -51,7 +47,7 @@ class WorldScreenTopBar(val screen: WorldScreen) : Table() {
val resourceImage = ImageGetter.getImage(fileName) val resourceImage = ImageGetter.getImage(fileName)
resourceImages.put(resource.name, resourceImage) resourceImages.put(resource.name, resourceImage)
resourceTable.add(resourceImage).size(20f) resourceTable.add(resourceImage).size(20f)
val resourceLabel = Label("0", labelStyle) val resourceLabel = Label("0", labelSkin)
resourceLabels.put(resource.name, resourceLabel) resourceLabels.put(resource.name, resourceLabel)
resourceTable.add(resourceLabel) resourceTable.add(resourceLabel)
} }
@ -127,10 +123,10 @@ class WorldScreenTopBar(val screen: WorldScreen) : Table() {
happinessLabel.setText(getHappinessText(civInfo)) happinessLabel.setText(getHappinessText(civInfo))
if (civInfo.happiness < 0) { if (civInfo.happiness < 0) {
happinessLabel.color = Color.valueOf("ef5350") happinessLabel.setFontColor(Color.valueOf("ef5350"))
happinessImage.drawable = ImageGetter.getStatIcon("Malcontent").drawable happinessImage.drawable = ImageGetter.getStatIcon("Malcontent").drawable
} else { } else {
happinessLabel.color = colorFromRGB(92, 194, 77) happinessLabel.setFontColor(colorFromRGB(92, 194, 77))
happinessImage.drawable = ImageGetter.getStatIcon("Happiness").drawable happinessImage.drawable = ImageGetter.getStatIcon("Happiness").drawable
} }

View File

@ -11,6 +11,7 @@ import com.unciv.ui.cityscreen.addClickListener
import com.unciv.ui.utils.CameraStageBaseScreen import com.unciv.ui.utils.CameraStageBaseScreen
import com.unciv.ui.utils.ImageGetter import com.unciv.ui.utils.ImageGetter
import com.unciv.ui.utils.disable import com.unciv.ui.utils.disable
import com.unciv.ui.utils.setFontColor
import com.unciv.ui.worldscreen.WorldScreen import com.unciv.ui.worldscreen.WorldScreen
class UnitActionsTable(val worldScreen: WorldScreen) : Table(){ class UnitActionsTable(val worldScreen: WorldScreen) : Table(){
@ -50,7 +51,7 @@ class UnitActionsTable(val worldScreen: WorldScreen) : Table(){
val actionButton = Button(CameraStageBaseScreen.skin) val actionButton = Button(CameraStageBaseScreen.skin)
actionButton.add(getIconForUnitAction(unitAction.name)).size(20f).pad(5f) actionButton.add(getIconForUnitAction(unitAction.name)).size(20f).pad(5f)
actionButton.add(Label(unitAction.name,CameraStageBaseScreen.skin) actionButton.add(Label(unitAction.name,CameraStageBaseScreen.skin)
.apply { style= Label.LabelStyle(style); style.fontColor = Color.WHITE }) .setFontColor(Color.WHITE))
actionButton.pack() actionButton.pack()
actionButton.addClickListener({ unitAction.action(); UnCivGame.Current.worldScreen!!.update() }) actionButton.addClickListener({ unitAction.action(); UnCivGame.Current.worldScreen!!.update() })
if (!unitAction.canAct) actionButton.disable() if (!unitAction.canAct) actionButton.disable()