Added Undo button for unit moves!

This commit is contained in:
Yair Morgenstern 2023-02-19 10:50:08 +02:00
parent 119f9715a8
commit 336e6362ce
4 changed files with 59 additions and 30 deletions

View File

@ -414,7 +414,7 @@ class UncivFiles(
}
// keep auto-saves for the last 10 turns for debugging purposes
if(nextTurn) {
if (nextTurn) {
val newAutosaveFilename =
SAVE_FILES_FOLDER + File.separator + AUTOSAVE_FILE_NAME + "-${gameInfo.currentPlayer}-${gameInfo.turns}"
val file =

View File

@ -7,17 +7,18 @@ import com.badlogic.gdx.scenes.scene2d.ui.Container
import com.badlogic.gdx.scenes.scene2d.ui.Table
import com.unciv.models.UncivSound
import com.unciv.models.translations.tr
import com.unciv.ui.images.ImageGetter
import com.unciv.ui.screens.overviewscreen.EspionageOverviewScreen
import com.unciv.ui.screens.pickerscreens.PolicyPickerScreen
import com.unciv.ui.screens.pickerscreens.TechButton
import com.unciv.ui.screens.pickerscreens.TechPickerScreen
import com.unciv.ui.screens.diplomacyscreen.DiplomacyScreen
import com.unciv.ui.components.BaseScreen
import com.unciv.ui.components.Fonts
import com.unciv.ui.components.extensions.colorFromRGB
import com.unciv.ui.components.extensions.onClick
import com.unciv.ui.components.extensions.toLabel
import com.unciv.ui.images.ImageGetter
import com.unciv.ui.screens.diplomacyscreen.DiplomacyScreen
import com.unciv.ui.screens.overviewscreen.EspionageOverviewScreen
import com.unciv.ui.screens.pickerscreens.PolicyPickerScreen
import com.unciv.ui.screens.pickerscreens.TechButton
import com.unciv.ui.screens.pickerscreens.TechPickerScreen
import com.unciv.utils.concurrency.Concurrency
/** A holder for Tech, Policies and Diplomacy buttons going in the top left of the WorldScreen just under WorldScreenTopBar */
@ -30,6 +31,8 @@ class TechPolicyDiplomacyButtons(val worldScreen: WorldScreen) : Table(BaseScree
private val policyScreenButton = Button(skin)
private val diplomacyButtonHolder = Container<Button?>()
private val diplomacyButton = Button(skin)
private val undoButtonHolder = Container<Button?>()
private val undoButton = Button(skin)
private val espionageButtonHolder = Container<Button?>()
private val espionageButton = Button(skin)
@ -39,6 +42,7 @@ class TechPolicyDiplomacyButtons(val worldScreen: WorldScreen) : Table(BaseScree
init {
defaults().left()
add(techButtonHolder).colspan(4).row()
add(undoButtonHolder).padTop(10f).padRight(10f)
add(policyButtonHolder).padTop(10f).padRight(10f)
add(diplomacyButtonHolder).padTop(10f).padRight(10f)
add(espionageButtonHolder).padTop(10f)
@ -51,6 +55,15 @@ class TechPolicyDiplomacyButtons(val worldScreen: WorldScreen) : Table(BaseScree
game.pushScreen(TechPickerScreen(viewingCiv))
}
undoButton.add(ImageGetter.getImage("OtherIcons/Resume")).size(30f).pad(15f)
undoButton.onClick {
Concurrency.run {
// Most of the time we won't load this, so we only set transients once we see it's relevant
worldScreen.preActionGameInfo.setTransients()
game.loadGame(worldScreen.preActionGameInfo)
}
}
policyScreenButton.add(ImageGetter.getImage("PolicyIcons/Constitution")).size(30f).pad(15f)
policyButtonHolder.onClick {
game.pushScreen(PolicyPickerScreen(worldScreen))
@ -69,6 +82,7 @@ class TechPolicyDiplomacyButtons(val worldScreen: WorldScreen) : Table(BaseScree
}
fun update(): Boolean {
updateUndoButton()
updateTechButton()
updatePolicyButton()
val result = updateDiplomacyButton()
@ -103,6 +117,17 @@ class TechPolicyDiplomacyButtons(val worldScreen: WorldScreen) : Table(BaseScree
}
}
private fun updateUndoButton() {
// Don't show policies until they become relevant
if (worldScreen.gameInfo != worldScreen.preActionGameInfo) {
undoButtonHolder.touchable = Touchable.enabled
undoButtonHolder.actor = undoButton
} else {
undoButtonHolder.touchable = Touchable.disabled
undoButtonHolder.actor = null
}
}
private fun updatePolicyButton() {
// Don't show policies until they become relevant
if (viewingCiv.policies.adoptedPolicies.isNotEmpty() || viewingCiv.policies.canAdoptPolicy()) {

View File

@ -17,27 +17,21 @@ import com.badlogic.gdx.scenes.scene2d.utils.ClickListener
import com.badlogic.gdx.utils.Align
import com.unciv.Constants
import com.unciv.UncivGame
import com.unciv.logic.automation.unit.AttackableTile
import com.unciv.logic.automation.unit.BattleHelper
import com.unciv.logic.automation.unit.UnitAutomation
import com.unciv.logic.battle.Battle
import com.unciv.logic.battle.MapUnitCombatant
import com.unciv.logic.city.City
import com.unciv.logic.civilization.Civilization
import com.unciv.logic.map.TileMap
import com.unciv.logic.map.mapunit.MapUnit
import com.unciv.logic.map.tile.Tile
import com.unciv.logic.map.TileMap
import com.unciv.logic.automation.unit.AttackableTile
import com.unciv.models.UncivSound
import com.unciv.models.helpers.MapArrowType
import com.unciv.models.helpers.MiscArrowTypes
import com.unciv.models.ruleset.unique.UniqueType
import com.unciv.ui.screens.basescreen.UncivStage
import com.unciv.ui.audio.SoundPlayer
import com.unciv.ui.images.ImageGetter
import com.unciv.ui.components.tilegroups.TileGroupMap
import com.unciv.ui.components.tilegroups.TileGroup
import com.unciv.ui.components.tilegroups.TileSetStrings
import com.unciv.ui.components.tilegroups.WorldTileGroup
import com.unciv.ui.components.BaseScreen
import com.unciv.ui.components.KeyCharAndCode
import com.unciv.ui.components.UnitGroup
@ -50,6 +44,12 @@ import com.unciv.ui.components.extensions.onActivation
import com.unciv.ui.components.extensions.onClick
import com.unciv.ui.components.extensions.surroundWithCircle
import com.unciv.ui.components.extensions.toLabel
import com.unciv.ui.components.tilegroups.TileGroup
import com.unciv.ui.components.tilegroups.TileGroupMap
import com.unciv.ui.components.tilegroups.TileSetStrings
import com.unciv.ui.components.tilegroups.WorldTileGroup
import com.unciv.ui.images.ImageGetter
import com.unciv.ui.screens.basescreen.UncivStage
import com.unciv.utils.Log
import com.unciv.utils.concurrency.Concurrency
import com.unciv.utils.concurrency.launchOnGLThread
@ -257,6 +257,8 @@ class WorldMapHolder(
return@run
} // can't move here
worldScreen.preActionGameInfo = worldScreen.gameInfo.clone()
launchOnGLThread {
try {
// Because this is darned concurrent (as it MUST be to avoid ANRs),

View File

@ -13,7 +13,6 @@ import com.badlogic.gdx.scenes.scene2d.ui.TextButton
import com.badlogic.gdx.scenes.scene2d.ui.TextField
import com.badlogic.gdx.utils.Align
import com.unciv.Constants
import com.unciv.ui.screens.mainmenuscreen.MainMenuScreen
import com.unciv.UncivGame
import com.unciv.logic.GameInfo
import com.unciv.logic.UncivShowableException
@ -27,20 +26,6 @@ import com.unciv.logic.trade.TradeEvaluation
import com.unciv.models.TutorialTrigger
import com.unciv.models.ruleset.tile.ResourceType
import com.unciv.models.ruleset.unique.UniqueType
import com.unciv.ui.screens.cityscreen.CityScreen
import com.unciv.ui.screens.civilopediascreen.CivilopediaScreen
import com.unciv.ui.images.ImageGetter
import com.unciv.ui.screens.overviewscreen.EmpireOverviewScreen
import com.unciv.ui.screens.pickerscreens.DiplomaticVoteResultScreen
import com.unciv.ui.screens.pickerscreens.GreatPersonPickerScreen
import com.unciv.ui.screens.pickerscreens.PolicyPickerScreen
import com.unciv.ui.screens.pickerscreens.TechPickerScreen
import com.unciv.ui.popups.Popup
import com.unciv.ui.popups.ToastPopup
import com.unciv.ui.popups.hasOpenPopups
import com.unciv.ui.screens.savescreens.LoadGameScreen
import com.unciv.ui.screens.savescreens.QuickSave
import com.unciv.ui.screens.savescreens.SaveGameScreen
import com.unciv.ui.components.BaseScreen
import com.unciv.ui.components.KeyCharAndCode
import com.unciv.ui.components.extensions.centerX
@ -50,6 +35,21 @@ import com.unciv.ui.components.extensions.onClick
import com.unciv.ui.components.extensions.setFontSize
import com.unciv.ui.components.extensions.toLabel
import com.unciv.ui.components.extensions.toTextButton
import com.unciv.ui.images.ImageGetter
import com.unciv.ui.popups.Popup
import com.unciv.ui.popups.ToastPopup
import com.unciv.ui.popups.hasOpenPopups
import com.unciv.ui.screens.cityscreen.CityScreen
import com.unciv.ui.screens.civilopediascreen.CivilopediaScreen
import com.unciv.ui.screens.mainmenuscreen.MainMenuScreen
import com.unciv.ui.screens.overviewscreen.EmpireOverviewScreen
import com.unciv.ui.screens.pickerscreens.DiplomaticVoteResultScreen
import com.unciv.ui.screens.pickerscreens.GreatPersonPickerScreen
import com.unciv.ui.screens.pickerscreens.PolicyPickerScreen
import com.unciv.ui.screens.pickerscreens.TechPickerScreen
import com.unciv.ui.screens.savescreens.LoadGameScreen
import com.unciv.ui.screens.savescreens.QuickSave
import com.unciv.ui.screens.savescreens.SaveGameScreen
import com.unciv.ui.screens.victoryscreen.VictoryScreen
import com.unciv.ui.screens.worldscreen.bottombar.BattleTable
import com.unciv.ui.screens.worldscreen.bottombar.TileInfoTable
@ -126,6 +126,8 @@ class WorldScreen(
var uiEnabled = true
var preActionGameInfo = gameInfo
init {
// notifications are right-aligned, they take up only as much space as necessary.