From 28e0e7ee2ccc1b2ea9cc81adc2540dd2a4f9a85b Mon Sep 17 00:00:00 2001 From: Oskar Niesen Date: Tue, 5 Mar 2024 15:06:13 -0600 Subject: [PATCH] Skip next unit button (#11244) * Added a next turn menu to skip all the next unit actions * Added a move automated units button * Added whitespace * Added unique NextTurnMenu KeyboardBindings --- .../ui/components/input/KeyboardBinding.kt | 7 +++++ .../worldscreen/status/NextTurnButton.kt | 2 ++ .../worldscreen/status/NextTurnMenu.kt | 29 +++++++++++++++++++ 3 files changed, 38 insertions(+) create mode 100644 core/src/com/unciv/ui/screens/worldscreen/status/NextTurnMenu.kt diff --git a/core/src/com/unciv/ui/components/input/KeyboardBinding.kt b/core/src/com/unciv/ui/components/input/KeyboardBinding.kt index 70e872b1d3..7e39f4a7fc 100644 --- a/core/src/com/unciv/ui/components/input/KeyboardBinding.kt +++ b/core/src/com/unciv/ui/components/input/KeyboardBinding.kt @@ -142,6 +142,10 @@ enum class KeyboardBinding( AutoPlayMenuCivilians(Category.AutoPlayMenu, "AutoPlay Civilians Once", 'c'), AutoPlayMenuEconomy(Category.AutoPlayMenu, "AutoPlay Economy Once", 'e'), + // NextTurnMenu + NextTurnMenuNextTurn(Category.NextTurnMenu, "Next Turn", 'n'), + NextTurnMenuMoveAutomatedUnits(Category.NextTurnMenu, "Move Automated Units", 'm'), + // City Screen AddConstruction(Category.CityScreen, "Add to or remove from queue", KeyCharAndCode.RETURN), RaisePriority(Category.CityScreen, "Raise queue priority", Input.Keys.UP), @@ -217,6 +221,9 @@ enum class KeyboardBinding( AutoPlayMenu { override val label = "AutoPlay menu" // adapt to existing usage }, + NextTurnMenu { + override val label = "NextTurn menu" // adapt to existing usage + }, MapPanning { override fun checkConflictsIn() = sequenceOf(this, WorldScreen) }, diff --git a/core/src/com/unciv/ui/screens/worldscreen/status/NextTurnButton.kt b/core/src/com/unciv/ui/screens/worldscreen/status/NextTurnButton.kt index e6f400ab6f..a60f8385cc 100644 --- a/core/src/com/unciv/ui/screens/worldscreen/status/NextTurnButton.kt +++ b/core/src/com/unciv/ui/screens/worldscreen/status/NextTurnButton.kt @@ -9,6 +9,7 @@ import com.unciv.ui.components.extensions.setSize import com.unciv.ui.components.input.KeyboardBinding import com.unciv.ui.components.input.keyShortcuts import com.unciv.ui.components.input.onActivation +import com.unciv.ui.components.input.onRightClick import com.unciv.ui.images.IconTextButton import com.unciv.ui.images.ImageGetter import com.unciv.ui.popups.hasOpenPopups @@ -22,6 +23,7 @@ class NextTurnButton( // label.setFontSize(30) labelCell.pad(10f) onActivation { nextTurnAction.action(worldScreen) } + onRightClick { NextTurnMenu(stage, this, this, worldScreen) } keyShortcuts.add(KeyboardBinding.NextTurn) keyShortcuts.add(KeyboardBinding.NextTurnAlternate) // Let unit actions override this for command "Wait". diff --git a/core/src/com/unciv/ui/screens/worldscreen/status/NextTurnMenu.kt b/core/src/com/unciv/ui/screens/worldscreen/status/NextTurnMenu.kt new file mode 100644 index 0000000000..b400fc34e3 --- /dev/null +++ b/core/src/com/unciv/ui/screens/worldscreen/status/NextTurnMenu.kt @@ -0,0 +1,29 @@ +package com.unciv.ui.screens.worldscreen.status + +import com.badlogic.gdx.scenes.scene2d.Actor +import com.badlogic.gdx.scenes.scene2d.Stage +import com.badlogic.gdx.scenes.scene2d.ui.Table +import com.unciv.ui.components.input.KeyboardBinding +import com.unciv.ui.popups.AnimatedMenuPopup +import com.unciv.ui.screens.worldscreen.WorldScreen + +class NextTurnMenu( + stage: Stage, + positionNextTo: Actor, + private val nextTurnButton: NextTurnButton, + private val worldScreen: WorldScreen +) : AnimatedMenuPopup(stage, getActorTopRight(positionNextTo)) { + override fun createContentTable(): Table { + val table = super.createContentTable()!! + table.add(getButton("Next Turn", KeyboardBinding.NextTurnMenuNextTurn) { + worldScreen.nextTurn() + }).row() + val automateUnitsAction = NextTurnAction.MoveAutomatedUnits + if (automateUnitsAction.isChoice(worldScreen)) + table.add(getButton("Move automated units", KeyboardBinding.NextTurnMenuMoveAutomatedUnits) { + automateUnitsAction.action(worldScreen) + }).row() + return table + } +} +