Autoplay menu cleanup (#11115)

* Minor linting and fix folder-package mismatch

* Actually make AnimatedMenuPopup stay inside the stage in all directions (was done for bottom left only before)

* Proper keyboard bindings for AutoPlay and -menu

* Testing translations

* AutoPlay as widely used term
This commit is contained in:
SomeTroglodyte 2024-02-13 22:27:18 +01:00 committed by GitHub
parent 9f53b7e1ee
commit eb8fee8edd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 47 additions and 34 deletions

View File

@ -2568,6 +2568,7 @@ You returned captured units to us = Vous nous avez rendu des unités capturées
Main Menu = Menu principal
World Screen = Écran de jeu
AutoPlay menu = Menu Jeu Auto
Map Panning = Défilement de la carte
Unit Actions = Actions des unités
City Screen = Écran de la ville
@ -2576,6 +2577,7 @@ Popups = Fenêtres
Menu = Menu
Next Turn = Tour suivant
Next Turn Alternate = Tour suivant (alt.)
Open AutoPlay menu = Ouvrir le menu Jeu Auto
Empire Overview = Vue d'ensemble
Music Player = Lecteur de musique
Developer Console = Console Développeur
@ -6750,4 +6752,3 @@ Reveal known resources on world screen = Révéler les ressources connues sur l'
In the Resources overview, click on a resource icon to center the world screen on tiles already discovered and providing this resource. = Dans la Vue d'ensemble des Ressources, cliquez sur une icône de ressource pour centrer la carte sur les cases déjà découvertes et fournissant cette ressource.
Alternatively, click on the "Unimproved" number to center the world screen only on owned tiles where the resource is not improved. = Il est également possible de cliquer sur la valeur "Non-Aménagées" pour centrer la carte uniquement sur les cases de votre empire où la ressource n'est pas aménagée.
If more than one tile is available, click repeatedly on the notification to cycle through all of them. = Si plus d'une case est disponible, cliquez plusieurs fois sur la notification afin de les parcourir en boucle.

View File

@ -39,6 +39,8 @@ enum class KeyboardBinding(
Menu(Category.WorldScreen, KeyCharAndCode.TAB),
NextTurn(Category.WorldScreen),
NextTurnAlternate(Category.WorldScreen, KeyCharAndCode.SPACE),
AutoPlayMenu(Category.WorldScreen, "Open AutoPlay menu", KeyCharAndCode.UNKNOWN), // 'a' is already assigned to map panning
AutoPlay(Category.WorldScreen, "Start AutoPlay", KeyCharAndCode.ctrl('a')),
EmpireOverview(Category.WorldScreen),
MusicPlayer(Category.WorldScreen, KeyCharAndCode.ctrl('m')),
DeveloperConsole(Category.WorldScreen, '`'),
@ -134,6 +136,12 @@ enum class KeyboardBinding(
HideAdditionalActions(Category.UnitActions,"Back", Input.Keys.PAGE_UP),
AddInCapital(Category.UnitActions, "Add in capital", 'g'),
// The AutoPlayMenu reuses the AutoPlay binding, under Worldscreen above - otherwise clear labeling would be tricky
AutoPlayMenuEndTurn(Category.AutoPlayMenu, "AutoPlay End Turn", 't'),
AutoPlayMenuMilitary(Category.AutoPlayMenu, "AutoPlay Military Once", 'm'),
AutoPlayMenuCivilians(Category.AutoPlayMenu, "AutoPlay Civilians Once", 'c'),
AutoPlayMenuEconomy(Category.AutoPlayMenu, "AutoPlay Economy Once", 'e'),
// City Screen
AddConstruction(Category.CityScreen, "Add to or remove from queue", KeyCharAndCode.RETURN),
RaisePriority(Category.CityScreen, "Raise queue priority", Input.Keys.UP),
@ -206,6 +214,9 @@ enum class KeyboardBinding(
// Conflict checking within group plus keys assigned to UnitActions are a problem
override fun checkConflictsIn() = sequenceOf(this, MapPanning, UnitActions)
},
AutoPlayMenu {
override val label = "AutoPlay menu" // adapt to existing usage
},
MapPanning {
override fun checkConflictsIn() = sequenceOf(this, WorldScreen)
},
@ -218,7 +229,7 @@ enum class KeyboardBinding(
Civilopedia,
Popups
;
val label = unCamelCase(name)
open val label = unCamelCase(name)
open fun checkConflictsIn() = sequenceOf(this)
}

View File

@ -98,11 +98,17 @@ open class AnimatedMenuPopup(
container.setScale(0.05f)
container.color.a = 0f
open(true) // this only does the screen-covering "click-behind" portion
open(true) // this only does the screen-covering "click-behind" portion - and ensures this.stage is set
// Note that coerceIn throws if min>max, so we defend against newInnerTable being bigger than the stage,
// and padding helps the rounded edges to look more natural:
val paddedHalfWidth = newInnerTable.width / 2 + 2f
val paddedHalfHeight = newInnerTable.height / 2 + 2f
container.setPosition(
position.x.coerceAtMost(stage.width - newInnerTable.width / 2),
position.y.coerceAtLeast(newInnerTable.height / 2)
if (paddedHalfWidth * 2 > stage.width) stage.width / 2
else position.x.coerceIn(paddedHalfWidth, stage.width - paddedHalfWidth),
if (paddedHalfHeight * 2 > stage.height) stage.height / 2
else position.y.coerceIn(paddedHalfHeight, stage.height - paddedHalfHeight)
)
super.addActor(container)

View File

@ -1,4 +1,4 @@
package com.unciv.ui.popups
package com.unciv.ui.screens.worldscreen.status
import com.badlogic.gdx.scenes.scene2d.Actor
import com.badlogic.gdx.scenes.scene2d.Stage
@ -8,14 +8,11 @@ import com.unciv.logic.automation.civilization.NextTurnAutomation
import com.unciv.logic.automation.unit.UnitAutomation
import com.unciv.logic.civilization.managers.TurnManager
import com.unciv.ui.components.input.KeyboardBinding
import com.unciv.ui.popups.AnimatedMenuPopup
import com.unciv.ui.screens.worldscreen.WorldScreen
import com.unciv.ui.screens.worldscreen.status.NextTurnButton
//todo Check move/top/end for "place one improvement" buildings
//todo Check add/remove-all for "place one improvement" buildings
/**
* Adds a number of options
* The "context" menu for the AutoPlay button
*/
class AutoPlayMenu(
stage: Stage,
@ -25,23 +22,19 @@ class AutoPlayMenu(
) : AnimatedMenuPopup(stage, getActorTopRight(positionNextTo)) {
private val settings = GUI.getSettings()
init {
closeListeners.add {
}
}
override fun createContentTable(): Table? {
override fun createContentTable(): Table {
val table = super.createContentTable()!!
// Using the same keyboard binding for bypassing this menu and the default option
if (!worldScreen.gameInfo.gameParameters.isOnlineMultiplayer)
table.add(getButton("Start AutoPlay", KeyboardBinding.RaisePriority, ::autoPlay)).row()
table.add(getButton("AutoPlay End Turn", KeyboardBinding.RaisePriority, ::autoPlayEndTurn)).row()
table.add(getButton("AutoPlay Military Once", KeyboardBinding.RaisePriority, ::autoPlayMilitary)).row()
table.add(getButton("AutoPlay Civilians Once", KeyboardBinding.RaisePriority, ::autoPlayCivilian)).row()
table.add(getButton("AutoPlay Economy Once", KeyboardBinding.RaisePriority, ::autoPlayEconomy)).row()
table.add(getButton("Start AutoPlay", KeyboardBinding.AutoPlay, ::autoPlay)).row()
table.add(getButton("AutoPlay End Turn", KeyboardBinding.AutoPlayMenuEndTurn, ::autoPlayEndTurn)).row()
table.add(getButton("AutoPlay Military Once", KeyboardBinding.AutoPlayMenuMilitary, ::autoPlayMilitary)).row()
table.add(getButton("AutoPlay Civilians Once", KeyboardBinding.AutoPlayMenuCivilians, ::autoPlayCivilian)).row()
table.add(getButton("AutoPlay Economy Once", KeyboardBinding.AutoPlayMenuEconomy, ::autoPlayEconomy)).row()
return table.takeUnless { it.cells.isEmpty }
return table
}
private fun autoPlayEndTurn() {
TurnManager(worldScreen.viewingCiv).automateTurn()
worldScreen.nextTurn()
@ -51,7 +44,7 @@ class AutoPlayMenu(
settings.autoPlay.startAutoPlay()
nextTurnButton.update()
}
private fun autoPlayMilitary() {
val civInfo = worldScreen.viewingCiv
val isAtWar = civInfo.isAtWar()
@ -71,7 +64,7 @@ class AutoPlayMenu(
worldScreen.shouldUpdate = true
worldScreen.render(0f)
}
private fun autoPlayEconomy() {
val civInfo = worldScreen.viewingCiv
NextTurnAutomation.automateCities(civInfo)

View File

@ -6,10 +6,11 @@ import com.badlogic.gdx.scenes.scene2d.ui.Stack
import com.badlogic.gdx.utils.Disposable
import com.unciv.GUI
import com.unciv.ui.components.extensions.setSize
import com.unciv.ui.components.input.onClick
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.ImageGetter
import com.unciv.ui.popups.AutoPlayMenu
import com.unciv.ui.screens.basescreen.BaseScreen
import com.unciv.ui.screens.worldscreen.WorldScreen
@ -18,24 +19,26 @@ class AutoPlayStatusButton(
nextTurnButton: NextTurnButton
) : Button(BaseScreen.skin), Disposable {
private val autoPlayImage = createAutoplayImage()
init {
add(Stack(autoPlayImage)).pad(5f)
val settings = GUI.getSettings()
onClick {
onActivation(binding = KeyboardBinding.AutoPlayMenu) {
if (settings.autoPlay.isAutoPlaying())
settings.autoPlay.stopAutoPlay()
else if (worldScreen.viewingCiv == worldScreen.gameInfo.currentPlayerCiv)
AutoPlayMenu(stage,this, nextTurnButton, worldScreen)
}
onRightClick {
if (!worldScreen.gameInfo.gameParameters.isOnlineMultiplayer
val directAutoPlay = {
if (!worldScreen.gameInfo.gameParameters.isOnlineMultiplayer
&& worldScreen.viewingCiv == worldScreen.gameInfo.currentPlayerCiv) {
settings.autoPlay.startAutoPlay()
nextTurnButton.update()
}
}
onRightClick(action = directAutoPlay)
keyShortcuts.add(KeyboardBinding.AutoPlay, action = directAutoPlay)
}
private fun createAutoplayImage(): Image {
@ -43,7 +46,7 @@ class AutoPlayStatusButton(
img.setSize(40f)
return img
}
override fun dispose() {
val settings = GUI.getSettings()
if (isPressed && settings.autoPlay.isAutoPlaying()) {
@ -51,4 +54,3 @@ class AutoPlayStatusButton(
}
}
}