mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-28 22:37:02 -04:00
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:
parent
1c3b44af16
commit
c11915c978
@ -26,7 +26,7 @@ class SpecificUnitAutomation{
|
|||||||
val createImprovementAction = UnitActions().getUnitActions(unit, UnCivGame.Current.worldScreen)
|
val createImprovementAction = UnitActions().getUnitActions(unit, UnCivGame.Current.worldScreen)
|
||||||
.firstOrNull { it.name.startsWith("Create") } // could be either fishing boats or oil well
|
.firstOrNull { it.name.startsWith("Create") } // could be either fishing boats or oil well
|
||||||
if (createImprovementAction != null)
|
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())
|
else UnitAutomation().explore(unit, unit.getDistanceToTiles())
|
||||||
|
@ -117,7 +117,7 @@ class MapUnit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun isFortified(): Boolean {
|
fun isFortified(): Boolean {
|
||||||
return action!=null && action!!.startsWith("Fortify")
|
return action?.startsWith("Fortify") == true
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getFortificationTurns(): Int {
|
fun getFortificationTurns(): Int {
|
||||||
@ -311,7 +311,7 @@ class MapUnit {
|
|||||||
|
|
||||||
if (action == "automation") WorkerAutomation(this).automateWorkerAction()
|
if (action == "automation") WorkerAutomation(this).automateWorkerAction()
|
||||||
|
|
||||||
if(action == "explore") UnitAutomation().automatedExplore(this)
|
if(action == "Explore") UnitAutomation().automatedExplore(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun doPostTurnAction() {
|
private fun doPostTurnAction() {
|
||||||
|
@ -18,7 +18,7 @@ import com.unciv.ui.worldscreen.optionstable.YesNoPopupTable
|
|||||||
import java.util.*
|
import java.util.*
|
||||||
import kotlin.math.min
|
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"
|
var sound="click"
|
||||||
fun sound(soundName:String): UnitAction {sound=soundName; return this}
|
fun sound(soundName:String): UnitAction {sound=soundName; return this}
|
||||||
}
|
}
|
||||||
@ -38,26 +38,41 @@ class UnitActions {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(unit.canFortify()) {
|
if(!unit.isFortified() && (!unit.canFortify() || unit.health<100) && unit.currentMovement >0 && unit.action!="Set Up") {
|
||||||
actionList += UnitAction("Fortify", unit.currentMovement >0)
|
val sleeping = unit.action == "Sleep"
|
||||||
{ unit.action = "Fortify 0" }.sound("fortify")
|
actionList += UnitAction("Sleep", !sleeping, sleeping) {
|
||||||
|
unit.action = "Sleep"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!unit.isFortified() && !unit.canFortify() && unit.action!="Sleep") {
|
if(unit.canFortify()) {
|
||||||
actionList += UnitAction("Sleep",unit.currentMovement >0) { unit.action = "Sleep" }
|
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.type == UnitType.Scout){
|
||||||
if(unit.action != "explore")
|
if(unit.action != "Explore")
|
||||||
actionList += UnitAction("Explore",unit.currentMovement >0)
|
actionList += UnitAction("Explore",true) {
|
||||||
{ UnitAutomation().automatedExplore(unit); unit.action = "explore" }
|
UnitAutomation().automatedExplore(unit)
|
||||||
|
unit.action = "Explore"
|
||||||
|
}
|
||||||
else
|
else
|
||||||
actionList += UnitAction("Stop exploration", true) { unit.action = null }
|
actionList += UnitAction("Stop exploration", true) { unit.action = null }
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!unit.type.isCivilian() && unit.promotions.canBePromoted()) {
|
if(!unit.type.isCivilian() && unit.promotions.canBePromoted()) {
|
||||||
actionList += UnitAction("Promote", unit.currentMovement >0)
|
// promotion does not consume movement points, so we can do it always
|
||||||
{ UnCivGame.Current.screen = PromotionPickerScreen(unit) }.sound("promote")
|
actionList += UnitAction("Promote", true) {
|
||||||
|
UnCivGame.Current.screen = PromotionPickerScreen(unit)
|
||||||
|
}.sound("promote")
|
||||||
}
|
}
|
||||||
|
|
||||||
if(unit.baseUnit().upgradesTo!=null && tile.getOwner()==unit.civInfo) {
|
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())
|
if(unit.hasUnique("Must set up to ranged attack") && !unit.isEmbarked()) {
|
||||||
actionList+=UnitAction("Set up",unit.currentMovement >0)
|
val setUp = unit.action == "Set Up"
|
||||||
{unit.action="Set Up"; unit.useMovementPoints(1f)}.sound("setup")
|
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()) {
|
if (unit.hasUnique("Founds a new city") && !unit.isEmbarked()) {
|
||||||
actionList += UnitAction("Found city",
|
actionList += UnitAction("Found city",
|
||||||
@ -130,7 +153,7 @@ class UnitActions {
|
|||||||
) { worldScreen.game.screen = ImprovementPickerScreen(tile) }
|
) { worldScreen.game.screen = ImprovementPickerScreen(tile) }
|
||||||
|
|
||||||
if("automation" == unit.action){
|
if("automation" == unit.action){
|
||||||
actionList += UnitAction("Stop automation",true) {unit.action = null}
|
actionList += UnitAction("Stop automation", true) {unit.action = null}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
actionList += UnitAction("Automate", unit.currentMovement >0)
|
actionList += UnitAction("Automate", unit.currentMovement >0)
|
||||||
@ -176,7 +199,7 @@ class UnitActions {
|
|||||||
|
|
||||||
|
|
||||||
if (unit.name == "Great Scientist" && !unit.isEmbarked()) {
|
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.civInfo.tech.freeTechs += 1
|
||||||
unit.destroy()
|
unit.destroy()
|
||||||
@ -185,7 +208,7 @@ class UnitActions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (unit.hasUnique("Can start an 8-turn golden age") && !unit.isEmbarked()) {
|
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.civInfo.goldenAges.enterGoldenAge()
|
||||||
unit.destroy()
|
unit.destroy()
|
||||||
@ -193,7 +216,7 @@ class UnitActions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (unit.name == "Great Engineer" && !unit.isEmbarked()) {
|
if (unit.name == "Great Engineer" && !unit.isEmbarked()) {
|
||||||
actionList += UnitAction( "Hurry Wonder",
|
actionList += UnitAction("Hurry Wonder",
|
||||||
unit.currentMovement >0 &&
|
unit.currentMovement >0 &&
|
||||||
tile.isCityCenter() &&
|
tile.isCityCenter() &&
|
||||||
tile.getCity()!!.cityConstructions.getCurrentConstruction() is Building &&
|
tile.getCity()!!.cityConstructions.getCurrentConstruction() is Building &&
|
||||||
@ -218,7 +241,7 @@ class UnitActions {
|
|||||||
}.sound("chimes")
|
}.sound("chimes")
|
||||||
}
|
}
|
||||||
|
|
||||||
actionList += UnitAction("Disband unit",unit.currentMovement >0
|
actionList += UnitAction("Disband unit", unit.currentMovement >0
|
||||||
) {
|
) {
|
||||||
val disbandText = if(unit.currentTile.getOwner()==unit.civInfo)
|
val disbandText = if(unit.currentTile.getOwner()==unit.civInfo)
|
||||||
"Disband this unit for [${unit.baseUnit.getDisbandGold()}] gold?".tr()
|
"Disband this unit for [${unit.baseUnit.getDisbandGold()}] gold?".tr()
|
||||||
|
@ -68,7 +68,9 @@ class UnitActionsTable(val worldScreen: WorldScreen) : Table(){
|
|||||||
private fun getUnitActionButton(unitAction: UnitAction): Button {
|
private fun getUnitActionButton(unitAction: UnitAction): Button {
|
||||||
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.tr(),CameraStageBaseScreen.skin).setFontColor(Color.WHITE))
|
actionButton.add(
|
||||||
|
Label(unitAction.title,CameraStageBaseScreen.skin)
|
||||||
|
.setFontColor(if(unitAction.currentAction) Color.YELLOW else Color.WHITE))
|
||||||
.pad(5f)
|
.pad(5f)
|
||||||
actionButton.pack()
|
actionButton.pack()
|
||||||
actionButton.onClick(unitAction.sound) { unitAction.action(); UnCivGame.Current.worldScreen.shouldUpdate=true }
|
actionButton.onClick(unitAction.sound) { unitAction.action(); UnCivGame.Current.worldScreen.shouldUpdate=true }
|
||||||
|
@ -128,13 +128,6 @@ class UnitTable(val worldScreen: WorldScreen) : Table(){
|
|||||||
unitDescriptionTable.add(unit.promotions.XP.toString()+"/"+unit.promotions.xpForNextPromotion())
|
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!
|
if(unit.promotions.promotions.size != promotionsTable.children.size) // The unit has been promoted! Reload promotions!
|
||||||
selectedUnitHasChanged = true
|
selectedUnitHasChanged = true
|
||||||
}
|
}
|
||||||
@ -159,6 +152,7 @@ class UnitTable(val worldScreen: WorldScreen) : Table(){
|
|||||||
unitNameLabel.setText("")
|
unitNameLabel.setText("")
|
||||||
unitDescriptionTable.clear()
|
unitDescriptionTable.clear()
|
||||||
unitIconHolder.clear()
|
unitIconHolder.clear()
|
||||||
|
promotionsTable.clear()
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!selectedUnitHasChanged) return
|
if(!selectedUnitHasChanged) return
|
||||||
|
Loading…
x
Reference in New Issue
Block a user