highlight unit action buttons to show their current action (sleep, fortify, set up)

- works especially well for fortification, will not show that state in the unitTable any more where it caused a layout problem
- in case of set up it's now very clear if a unit is set up or not
This commit is contained in:
martin 2019-05-14 12:10:28 +02:00 committed by Yair Morgenstern
parent 1c3b44af16
commit c11915c978
5 changed files with 50 additions and 31 deletions

View File

@ -26,7 +26,7 @@ class SpecificUnitAutomation{
val createImprovementAction = UnitActions().getUnitActions(unit, UnCivGame.Current.worldScreen)
.firstOrNull { it.name.startsWith("Create") } // could be either fishing boats or oil well
if (createImprovementAction != null)
return createImprovementAction.action() // unit is already gone, can't "explore"
return createImprovementAction.action() // unit is already gone, can't "Explore"
}
}
else UnitAutomation().explore(unit, unit.getDistanceToTiles())

View File

@ -117,7 +117,7 @@ class MapUnit {
}
fun isFortified(): Boolean {
return action!=null && action!!.startsWith("Fortify")
return action?.startsWith("Fortify") == true
}
fun getFortificationTurns(): Int {
@ -311,7 +311,7 @@ class MapUnit {
if (action == "automation") WorkerAutomation(this).automateWorkerAction()
if(action == "explore") UnitAutomation().automatedExplore(this)
if(action == "Explore") UnitAutomation().automatedExplore(this)
}
private fun doPostTurnAction() {

View File

@ -18,7 +18,7 @@ import com.unciv.ui.worldscreen.optionstable.YesNoPopupTable
import java.util.*
import kotlin.math.min
class UnitAction(var name: String, var canAct:Boolean, var action:()->Unit){
class UnitAction(var name: String, var canAct: Boolean, var currentAction: Boolean = false, var title: String = name.tr(), var action: () -> Unit = {}){
var sound="click"
fun sound(soundName:String): UnitAction {sound=soundName; return this}
}
@ -38,26 +38,41 @@ class UnitActions {
}
}
if(unit.canFortify()) {
actionList += UnitAction("Fortify", unit.currentMovement >0)
{ unit.action = "Fortify 0" }.sound("fortify")
if(!unit.isFortified() && (!unit.canFortify() || unit.health<100) && unit.currentMovement >0 && unit.action!="Set Up") {
val sleeping = unit.action == "Sleep"
actionList += UnitAction("Sleep", !sleeping, sleeping) {
unit.action = "Sleep"
}
}
if(!unit.isFortified() && !unit.canFortify() && unit.action!="Sleep") {
actionList += UnitAction("Sleep",unit.currentMovement >0) { unit.action = "Sleep" }
if(unit.canFortify()) {
actionList += UnitAction("Fortify", unit.currentMovement >0) {
unit.action = "Fortify 0"
}.sound("fortify")
} else if (unit.isFortified()) {
actionList += UnitAction(
"Fortify",
false,
currentAction = true,
title = "Fortification".tr() + " " + unit.getFortificationTurns() * 20 + "%"
)
}
if(unit.type == UnitType.Scout){
if(unit.action != "explore")
actionList += UnitAction("Explore",unit.currentMovement >0)
{ UnitAutomation().automatedExplore(unit); unit.action = "explore" }
if(unit.action != "Explore")
actionList += UnitAction("Explore",true) {
UnitAutomation().automatedExplore(unit)
unit.action = "Explore"
}
else
actionList += UnitAction("Stop exploration", true) { unit.action = null }
}
if(!unit.type.isCivilian() && unit.promotions.canBePromoted()) {
actionList += UnitAction("Promote", unit.currentMovement >0)
{ UnCivGame.Current.screen = PromotionPickerScreen(unit) }.sound("promote")
// promotion does not consume movement points, so we can do it always
actionList += UnitAction("Promote", true) {
UnCivGame.Current.screen = PromotionPickerScreen(unit)
}.sound("promote")
}
if(unit.baseUnit().upgradesTo!=null && tile.getOwner()==unit.civInfo) {
@ -104,9 +119,17 @@ class UnitActions {
}
}
if(unit.hasUnique("Must set up to ranged attack") && unit.action != "Set Up" && !unit.isEmbarked())
actionList+=UnitAction("Set up",unit.currentMovement >0)
{unit.action="Set Up"; unit.useMovementPoints(1f)}.sound("setup")
if(unit.hasUnique("Must set up to ranged attack") && !unit.isEmbarked()) {
val setUp = unit.action == "Set Up"
actionList+=UnitAction("Set up", unit.currentMovement >0 && !setUp, currentAction = setUp ) {
unit.action="Set Up"
// setting up uses up all movement points
// this is to avoid problems with the idle state:
// - it should not be idle when setting up right now
// - it should be idle when set up in the past
unit.currentMovement=0f
}.sound("setup")
}
if (unit.hasUnique("Founds a new city") && !unit.isEmbarked()) {
actionList += UnitAction("Found city",
@ -130,7 +153,7 @@ class UnitActions {
) { worldScreen.game.screen = ImprovementPickerScreen(tile) }
if("automation" == unit.action){
actionList += UnitAction("Stop automation",true) {unit.action = null}
actionList += UnitAction("Stop automation", true) {unit.action = null}
}
else {
actionList += UnitAction("Automate", unit.currentMovement >0)
@ -176,7 +199,7 @@ class UnitActions {
if (unit.name == "Great Scientist" && !unit.isEmbarked()) {
actionList += UnitAction( "Discover Technology",unit.currentMovement >0
actionList += UnitAction("Discover Technology", unit.currentMovement >0
) {
unit.civInfo.tech.freeTechs += 1
unit.destroy()
@ -185,7 +208,7 @@ class UnitActions {
}
if (unit.hasUnique("Can start an 8-turn golden age") && !unit.isEmbarked()) {
actionList += UnitAction( "Start Golden Age",unit.currentMovement >0
actionList += UnitAction("Start Golden Age", unit.currentMovement >0
) {
unit.civInfo.goldenAges.enterGoldenAge()
unit.destroy()
@ -193,7 +216,7 @@ class UnitActions {
}
if (unit.name == "Great Engineer" && !unit.isEmbarked()) {
actionList += UnitAction( "Hurry Wonder",
actionList += UnitAction("Hurry Wonder",
unit.currentMovement >0 &&
tile.isCityCenter() &&
tile.getCity()!!.cityConstructions.getCurrentConstruction() is Building &&
@ -218,7 +241,7 @@ class UnitActions {
}.sound("chimes")
}
actionList += UnitAction("Disband unit",unit.currentMovement >0
actionList += UnitAction("Disband unit", unit.currentMovement >0
) {
val disbandText = if(unit.currentTile.getOwner()==unit.civInfo)
"Disband this unit for [${unit.baseUnit.getDisbandGold()}] gold?".tr()

View File

@ -68,7 +68,9 @@ class UnitActionsTable(val worldScreen: WorldScreen) : Table(){
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.tr(),CameraStageBaseScreen.skin).setFontColor(Color.WHITE))
actionButton.add(
Label(unitAction.title,CameraStageBaseScreen.skin)
.setFontColor(if(unitAction.currentAction) Color.YELLOW else Color.WHITE))
.pad(5f)
actionButton.pack()
actionButton.onClick(unitAction.sound) { unitAction.action(); UnCivGame.Current.worldScreen.shouldUpdate=true }

View File

@ -128,13 +128,6 @@ class UnitTable(val worldScreen: WorldScreen) : Table(){
unitDescriptionTable.add(unit.promotions.XP.toString()+"/"+unit.promotions.xpForNextPromotion())
}
if(unit.isFortified() && unit.getFortificationTurns()>0) {
unitDescriptionTable.row()
unitDescriptionTable.add("Fortification")
unitDescriptionTable.add(""+unit.getFortificationTurns() * 20 + "%")
}
unitDescriptionTable.pack()
if(unit.promotions.promotions.size != promotionsTable.children.size) // The unit has been promoted! Reload promotions!
selectedUnitHasChanged = true
}
@ -159,6 +152,7 @@ class UnitTable(val worldScreen: WorldScreen) : Table(){
unitNameLabel.setText("")
unitDescriptionTable.clear()
unitIconHolder.clear()
promotionsTable.clear()
}
if(!selectedUnitHasChanged) return