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.ui.cityscreen.addClickListener
import com.unciv.ui.utils.ImageGetter
import com.unciv.ui.utils.setFontColor
class GreatPersonPickerScreen : PickerScreen() {
private var theChosenOne: Unit? = null
@ -19,8 +20,7 @@ class GreatPersonPickerScreen : PickerScreen() {
val button = Button(skin)
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} })
.pad(10f)
button.add(Label(unit.name, skin).setFontColor(Color.WHITE)).pad(10f)
button.pack()
button.addClickListener {
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.ImageGetter
import com.unciv.ui.utils.center
import com.unciv.ui.utils.setFontColor
class WorldTileGroup(tileInfo: TileInfo) : TileGroup(tileInfo) {
@ -60,9 +61,7 @@ class WorldTileGroup(tileInfo: TileInfo) : TileGroup(tileInfo) {
val cityButtonText = city.name + " (" + city.population.population + ")"
val label = Label(cityButtonText, CameraStageBaseScreen.skin)
val labelStyle = Label.LabelStyle(label.style)
labelStyle.fontColor = city.civInfo.getCivilization().getColor()
label.style = labelStyle
label.setFontColor(city.civInfo.getCivilization().getColor())
if (city.civInfo.isPlayerCivilization())
label.addClickListener {
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.centerY(parent:Stage){ y = parent.height/2- height/2}
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.ImageGetter
import com.unciv.ui.utils.disable
import com.unciv.ui.utils.setFontColor
import kotlin.math.max
class BattleTable(val worldScreen: WorldScreen): Table() {
@ -60,13 +61,11 @@ class BattleTable(val worldScreen: WorldScreen): Table() {
clear()
row().pad(5f)
val attackerLabel = Label(attacker.getName(), skin)
attackerLabel.style= Label.LabelStyle(attackerLabel.style)
attackerLabel.style.fontColor=attacker.getCivilization().getCivilization().getColor()
.setFontColor(attacker.getCivilization().getCivilization().getColor())
add(attackerLabel)
val defenderLabel = Label(defender.getName(), skin)
defenderLabel.style= Label.LabelStyle(defenderLabel.style)
defenderLabel.style.fontColor=defender.getCivilization().getCivilization().getColor()
.setFontColor(defender.getCivilization().getCivilization().getColor())
add(defenderLabel)
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.stats.Stats
import com.unciv.ui.cityscreen.addClickListener
import com.unciv.ui.utils.CameraStageBaseScreen
import com.unciv.ui.utils.ImageGetter
import com.unciv.ui.utils.centerY
import com.unciv.ui.utils.colorFromRGB
import com.unciv.ui.utils.*
import kotlin.math.abs
import kotlin.math.ceil
class WorldScreenTopBar(val screen: WorldScreen) : Table() {
val labelStyle = Label.LabelStyle(Label("", CameraStageBaseScreen.skin).style)
.apply { fontColor = Color.valueOf("f5f5f5ff") }
val labelSkin = CameraStageBaseScreen.skin
private val turnsLabel = Label("Turns: 0/400", labelStyle)
private val goldLabel = Label("Gold:", labelStyle).apply { color = colorFromRGB(225, 217, 71) }
private val scienceLabel = Label("Science:", labelStyle).apply { color = colorFromRGB(78, 140, 151) }
private val happinessLabel = Label("Happiness:", labelStyle)
private val cultureLabel = Label("Culture:", labelStyle).apply { color = colorFromRGB(210, 94, 210) }
private val turnsLabel = Label("Turns: 0/400",labelSkin)
private val goldLabel = Label("Gold:", labelSkin).setFontColor(colorFromRGB(225, 217, 71) )
private val scienceLabel = Label("Science:", labelSkin).setFontColor(colorFromRGB(78, 140, 151) )
private val happinessLabel = Label("Happiness:", labelSkin)
private val cultureLabel = Label("Culture:", labelSkin).setFontColor(colorFromRGB(210, 94, 210) )
private val resourceLabels = HashMap<String, Label>()
private val resourceImages = HashMap<String, Image>()
private val happinessImage = ImageGetter.getStatIcon("Happiness")
@ -51,7 +47,7 @@ class WorldScreenTopBar(val screen: WorldScreen) : Table() {
val resourceImage = ImageGetter.getImage(fileName)
resourceImages.put(resource.name, resourceImage)
resourceTable.add(resourceImage).size(20f)
val resourceLabel = Label("0", labelStyle)
val resourceLabel = Label("0", labelSkin)
resourceLabels.put(resource.name, resourceLabel)
resourceTable.add(resourceLabel)
}
@ -127,10 +123,10 @@ class WorldScreenTopBar(val screen: WorldScreen) : Table() {
happinessLabel.setText(getHappinessText(civInfo))
if (civInfo.happiness < 0) {
happinessLabel.color = Color.valueOf("ef5350")
happinessLabel.setFontColor(Color.valueOf("ef5350"))
happinessImage.drawable = ImageGetter.getStatIcon("Malcontent").drawable
} else {
happinessLabel.color = colorFromRGB(92, 194, 77)
happinessLabel.setFontColor(colorFromRGB(92, 194, 77))
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.ImageGetter
import com.unciv.ui.utils.disable
import com.unciv.ui.utils.setFontColor
import com.unciv.ui.worldscreen.WorldScreen
class UnitActionsTable(val worldScreen: WorldScreen) : Table(){
@ -50,7 +51,7 @@ class UnitActionsTable(val worldScreen: WorldScreen) : Table(){
val actionButton = Button(CameraStageBaseScreen.skin)
actionButton.add(getIconForUnitAction(unitAction.name)).size(20f).pad(5f)
actionButton.add(Label(unitAction.name,CameraStageBaseScreen.skin)
.apply { style= Label.LabelStyle(style); style.fontColor = Color.WHITE })
.setFontColor(Color.WHITE))
actionButton.pack()
actionButton.addClickListener({ unitAction.action(); UnCivGame.Current.worldScreen!!.update() })
if (!unitAction.canAct) actionButton.disable()