Added icons for unit actions

This commit is contained in:
Yair Morgenstern 2018-05-23 22:59:05 +03:00
parent 9cbdee4b12
commit c8ddf6dc63
3 changed files with 33 additions and 20 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

View file

@ -1,18 +1,13 @@
package com.unciv.ui.worldscreen.unit
import com.badlogic.gdx.scenes.scene2d.ui.TextButton
import com.unciv.UnCivGame
import com.unciv.logic.automation.WorkerAutomation
import com.unciv.logic.map.MapUnit
import com.unciv.logic.map.TileInfo
import com.unciv.logic.map.UnitType
import com.unciv.models.gamebasics.Building
import com.unciv.models.gamebasics.GameBasics
import com.unciv.ui.cityscreen.addClickListener
import com.unciv.ui.pickerscreens.ImprovementPickerScreen
import com.unciv.ui.pickerscreens.TechPickerScreen
import com.unciv.ui.utils.CameraStageBaseScreen
import com.unciv.ui.utils.disable
import com.unciv.ui.worldscreen.WorldScreen
import java.util.*
@ -27,9 +22,6 @@ class UnitActions {
}
}
fun getUnitActionButtons(unit:MapUnit,worldScreen: WorldScreen): List<TextButton> {
return getUnitActions(unit, worldScreen).map { getUnitActionButton(it) }
}
fun getUnitActions(unit:MapUnit,worldScreen: WorldScreen): List<UnitAction> {
val tile = unit.getTile()
@ -70,10 +62,7 @@ class UnitActions {
}
if (unit.name == "Worker") {
val improvementButtonText: String
if (tile.improvementInProgress == null) improvementButtonText = "Construct\r\nimprovement"
else improvementButtonText = tile.improvementInProgress!! + "\r\nin progress"
actionList += UnitAction(improvementButtonText,
actionList += UnitAction("Construct improvement",
{ worldScreen.game.screen = ImprovementPickerScreen(tile) },
unit.currentMovement != 0f &&
!tile.isCityCenter() || GameBasics.TileImprovements.values.any { tile.canBuildImprovement(it, unit.civInfo) })
@ -144,11 +133,5 @@ class UnitActions {
return actionList
}
private fun getUnitActionButton(unitAction: UnitAction): TextButton {
val actionButton = TextButton(unitAction.name, CameraStageBaseScreen.skin)
actionButton.addClickListener({ unitAction.action(); UnCivGame.Current.worldScreen!!.update() })
if (!unitAction.canAct) actionButton.disable()
return actionButton
}
}

View file

@ -1,10 +1,16 @@
package com.unciv.ui.worldscreen.unit
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.scenes.scene2d.ui.Button
import com.badlogic.gdx.scenes.scene2d.ui.Image
import com.badlogic.gdx.scenes.scene2d.ui.Label
import com.badlogic.gdx.scenes.scene2d.ui.Table
import com.unciv.UnCivGame
import com.unciv.logic.map.MapUnit
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.worldscreen.WorldScreen
class UnitActionsTable(val worldScreen: WorldScreen) : Table(){
@ -13,7 +19,19 @@ class UnitActionsTable(val worldScreen: WorldScreen) : Table(){
when(unitAction){
"Move unit" -> return ImageGetter.getStatIcon("Movement")
"Stop movement"-> return ImageGetter.getStatIcon("Movement").apply { color= Color.RED }
"Fortify" -> return ImageGetter.getImage("UnitIcons/Shield.png").apply { color= Color.BLACK }
"Construct improvement" -> return ImageGetter.getImage("UnitIcons/Worker.png")
"Automate" -> return ImageGetter.getImage("UnitIcons/Great Engineer.png")
"Stop automation" -> return ImageGetter.getImage("OtherIcons/Stop.png")
"Found city" -> return ImageGetter.getImage("UnitIcons/Settler.png")
"Discover Technology" -> return ImageGetter.getImage("UnitIcons/Great Scientist.png")
"Construct Academy" -> return ImageGetter.getImage("ImprovementIcons/Academy_(Civ5).png")
"Start Golden Age" -> return ImageGetter.getImage("UnitIcons/Great Artist.png")
"Construct Landmark" -> return ImageGetter.getImage("ImprovementIcons/Landmark_(Civ5).png")
"Hurry Wonder" -> return ImageGetter.getImage("UnitIcons/Great Engineer.png")
"Construct Manufactory" -> return ImageGetter.getImage("ImprovementIcons/Manufactory_(Civ5).png")
"Conduct Trade Mission" -> return ImageGetter.getImage("UnitIcons/Great Merchant.png")
"Construct Customs House" -> return ImageGetter.getImage("ImprovementIcons/Customs_house_(Civ5).png")
else -> return ImageGetter.getImage("StatIcons/Star.png")
}
}
@ -21,9 +39,21 @@ class UnitActionsTable(val worldScreen: WorldScreen) : Table(){
fun update(unit: MapUnit?){
clear()
if (unit == null) return
for (button in UnitActions().getUnitActionButtons(unit, worldScreen))
for (button in UnitActions().getUnitActions(unit, worldScreen).map { getUnitActionButton(it) })
add(button).colspan(2).pad(5f)
.size(button.width * worldScreen.buttonScale, button.height * worldScreen.buttonScale).row()
pack()
}
private fun getUnitActionButton(unitAction: UnitAction): Button {
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 })
actionButton.pack()
actionButton.addClickListener({ unitAction.action(); UnCivGame.Current.worldScreen!!.update() })
if (!unitAction.canAct) actionButton.disable()
return actionButton
}
}