mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-22 13:49:54 +07:00
idle unit buttons: set due=false and select the right unit in case of 2 units per tile
This commit is contained in:
@ -301,6 +301,8 @@ class CivilizationInfo {
|
|||||||
units=newList
|
units=newList
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getIdleUnits() = getCivUnits().filter { it.isIdle() }
|
||||||
|
|
||||||
fun getDueUnits() = getCivUnits().filter { it.due && it.isIdle() }
|
fun getDueUnits() = getCivUnits().filter { it.due && it.isIdle() }
|
||||||
|
|
||||||
fun shouldOpenTechPicker() = tech.freeTechs != 0
|
fun shouldOpenTechPicker() = tech.freeTechs != 0
|
||||||
@ -309,11 +311,10 @@ class CivilizationInfo {
|
|||||||
fun shouldGoToDueUnit() = UnCivGame.Current.settings.checkForDueUnits && getDueUnits().isNotEmpty()
|
fun shouldGoToDueUnit() = UnCivGame.Current.settings.checkForDueUnits && getDueUnits().isNotEmpty()
|
||||||
|
|
||||||
fun getNextDueUnit(selectedUnit: MapUnit?): MapUnit? {
|
fun getNextDueUnit(selectedUnit: MapUnit?): MapUnit? {
|
||||||
|
selectedUnit?.due = false
|
||||||
val dueUnits = getDueUnits()
|
val dueUnits = getDueUnits()
|
||||||
if(dueUnits.isNotEmpty()) {
|
if(dueUnits.isNotEmpty()) {
|
||||||
var index = dueUnits.indexOf(selectedUnit)
|
val unit = dueUnits[0]
|
||||||
index = ++index % dueUnits.size // for looping
|
|
||||||
val unit = dueUnits[index]
|
|
||||||
unit.due = false
|
unit.due = false
|
||||||
return unit
|
return unit
|
||||||
}
|
}
|
||||||
|
@ -4,19 +4,21 @@ import com.badlogic.gdx.graphics.Color
|
|||||||
import com.badlogic.gdx.scenes.scene2d.Touchable
|
import com.badlogic.gdx.scenes.scene2d.Touchable
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
||||||
import com.badlogic.gdx.utils.Align
|
import com.badlogic.gdx.utils.Align
|
||||||
|
import com.unciv.logic.map.MapUnit
|
||||||
import com.unciv.logic.map.TileInfo
|
import com.unciv.logic.map.TileInfo
|
||||||
import com.unciv.ui.utils.ImageGetter
|
import com.unciv.ui.utils.ImageGetter
|
||||||
import com.unciv.ui.utils.onClick
|
import com.unciv.ui.utils.onClick
|
||||||
import com.unciv.ui.worldscreen.TileMapHolder
|
import com.unciv.ui.worldscreen.TileMapHolder
|
||||||
|
|
||||||
class IdleUnitButton (internal val unitTable: UnitTable,
|
class IdleUnitButton (
|
||||||
val tileMapHolder: TileMapHolder, val previous:Boolean)
|
internal val unitTable: UnitTable,
|
||||||
: Table() {
|
val tileMapHolder: TileMapHolder,
|
||||||
|
val previous:Boolean
|
||||||
|
) : Table() {
|
||||||
|
|
||||||
val image = ImageGetter.getImage("OtherIcons/BackArrow")
|
val image = ImageGetter.getImage("OtherIcons/BackArrow")
|
||||||
|
|
||||||
fun getTilesWithIdleUnits() = tileMapHolder.tileMap.values
|
fun hasIdleUnits() = unitTable.worldScreen.currentPlayerCiv.getIdleUnits().isNotEmpty()
|
||||||
.filter { it.hasIdleUnit() && it.getUnits().first().owner == unitTable.worldScreen.currentPlayerCiv.civName }
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
val imageSize = 25f
|
val imageSize = 25f
|
||||||
@ -28,20 +30,26 @@ class IdleUnitButton (internal val unitTable: UnitTable,
|
|||||||
add(image).size(imageSize).pad(10f,20f,10f,20f)
|
add(image).size(imageSize).pad(10f,20f,10f,20f)
|
||||||
enable()
|
enable()
|
||||||
onClick {
|
onClick {
|
||||||
val tilesWithIdleUnits = getTilesWithIdleUnits()
|
|
||||||
if(tilesWithIdleUnits.isEmpty()) return@onClick
|
val idleUnits = unitTable.worldScreen.currentPlayerCiv.getIdleUnits()
|
||||||
val tileToSelect: TileInfo
|
if(idleUnits.isEmpty()) return@onClick
|
||||||
if (unitTable.selectedUnit==null || !tilesWithIdleUnits.contains(unitTable.selectedUnit!!.getTile()))
|
|
||||||
tileToSelect = tilesWithIdleUnits[0]
|
val unitToSelect: MapUnit
|
||||||
|
if (unitTable.selectedUnit==null || !idleUnits.contains(unitTable.selectedUnit!!))
|
||||||
|
unitToSelect = idleUnits[0]
|
||||||
else {
|
else {
|
||||||
var index = tilesWithIdleUnits.indexOf(unitTable.selectedUnit!!.getTile())
|
var index = idleUnits.indexOf(unitTable.selectedUnit!!)
|
||||||
if(previous) index-- else index++
|
if(previous) index-- else index++
|
||||||
index += tilesWithIdleUnits.size
|
index += idleUnits.size
|
||||||
index %= tilesWithIdleUnits.size // for looping
|
index %= idleUnits.size // for looping
|
||||||
tileToSelect = tilesWithIdleUnits[index]
|
unitToSelect = idleUnits[index]
|
||||||
}
|
}
|
||||||
tileMapHolder.setCenterPosition(tileToSelect.position)
|
|
||||||
|
unitToSelect.due = false
|
||||||
|
tileMapHolder.setCenterPosition(unitToSelect.currentTile.position)
|
||||||
|
unitTable.selectedUnit = unitToSelect
|
||||||
unitTable.worldScreen.shouldUpdate=true
|
unitTable.worldScreen.shouldUpdate=true
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,7 +92,7 @@ class UnitTable(val worldScreen: WorldScreen) : Table(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(prevIdleUnitButton.getTilesWithIdleUnits().isNotEmpty()) { // more efficient to do this check once for both
|
if(prevIdleUnitButton.hasIdleUnits()) { // more efficient to do this check once for both
|
||||||
prevIdleUnitButton.enable()
|
prevIdleUnitButton.enable()
|
||||||
nextIdleUnitButton.enable()
|
nextIdleUnitButton.enable()
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user