Unified Menu Popups (#4113)

This commit is contained in:
Federico Luongo 2021-06-13 20:56:32 +02:00 committed by GitHub
parent 0d79326869
commit ea852f9fa0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 34 deletions

View File

@ -86,8 +86,8 @@ class MainMenuScreen: CameraStageBaseScreen() {
} }
} }
val column1 = Table().apply { defaults().pad(10f) } val column1 = Table().apply { defaults().pad(10f).fillX() }
val column2 = if(singleColumn) column1 else Table().apply { defaults().pad(10f) } val column2 = if(singleColumn) column1 else Table().apply { defaults().pad(10f).fillX() }
val autosaveGame = GameSaver.getSave(autosave, false) val autosaveGame = GameSaver.getSave(autosave, false)
if (autosaveGame.exists()) { if (autosaveGame.exists()) {

View File

@ -11,6 +11,7 @@ import com.unciv.ui.utils.*
class MapEditorMenuPopup(var mapEditorScreen: MapEditorScreen): Popup(mapEditorScreen) { class MapEditorMenuPopup(var mapEditorScreen: MapEditorScreen): Popup(mapEditorScreen) {
init { init {
defaults().fillX()
addButton("New map", 'n') { UncivGame.Current.setScreen(NewMapScreen(mapEditorScreen.tileMap.mapParameters)) } addButton("New map", 'n') { UncivGame.Current.setScreen(NewMapScreen(mapEditorScreen.tileMap.mapParameters)) }
addButton("Save map", 's') { mapEditorScreen.game.setScreen(SaveAndLoadMapScreen(mapEditorScreen.tileMap, true, mapEditorScreen)); this.close() } addButton("Save map", 's') { mapEditorScreen.game.setScreen(SaveAndLoadMapScreen(mapEditorScreen.tileMap, true, mapEditorScreen)); this.close() }
addButton("Load map", 'l') { mapEditorScreen.game.setScreen(SaveAndLoadMapScreen(mapEditorScreen.tileMap, false, mapEditorScreen)); this.close() } addButton("Load map", 'l') { mapEditorScreen.game.setScreen(SaveAndLoadMapScreen(mapEditorScreen.tileMap, false, mapEditorScreen)); this.close() }

View File

@ -73,6 +73,7 @@ open class Popup(val screen: CameraStageBaseScreen): Table(CameraStageBaseScreen
/* All additions to the popup are to the inner table - we shouldn't care that there's an inner table at all */ /* All additions to the popup are to the inner table - we shouldn't care that there's an inner table at all */
final override fun <T : Actor?> add(actor: T): Cell<T> = innerTable.add(actor) final override fun <T : Actor?> add(actor: T): Cell<T> = innerTable.add(actor)
override fun row(): Cell<Actor> = innerTable.row() override fun row(): Cell<Actor> = innerTable.row()
override fun defaults(): Cell<Actor> = innerTable.defaults()
fun addSeparator() = innerTable.addSeparator() fun addSeparator() = innerTable.addSeparator()
/** /**

View File

@ -19,50 +19,31 @@ import com.unciv.ui.victoryscreen.VictoryScreen
import com.unciv.ui.worldscreen.WorldScreen import com.unciv.ui.worldscreen.WorldScreen
class WorldScreenMenuPopup(val worldScreen: WorldScreen) : Popup(worldScreen) { class WorldScreenMenuPopup(val worldScreen: WorldScreen) : Popup(worldScreen) {
val buttonWidth = 200f
val buttonHeight = 30f
init { init {
addMenuButton("Main menu") { worldScreen.game.setScreen(MainMenuScreen()) } defaults().fillX()
addMenuButton("Civilopedia") { worldScreen.game.setScreen(CivilopediaScreen(worldScreen.gameInfo.ruleSet)) } addButton("Main menu") { worldScreen.game.setScreen(MainMenuScreen()) }
addMenuButton("Save game") { worldScreen.game.setScreen(SaveGameScreen(worldScreen.gameInfo)) } addButton("Civilopedia") { worldScreen.game.setScreen(CivilopediaScreen(worldScreen.gameInfo.ruleSet)) }
addMenuButton("Load game") { worldScreen.game.setScreen(LoadGameScreen(worldScreen)) } addButton("Save game") { worldScreen.game.setScreen(SaveGameScreen(worldScreen.gameInfo)) }
addButton("Load game") { worldScreen.game.setScreen(LoadGameScreen(worldScreen)) }
addMenuButton("Start new game") { addButton("Start new game") {
val newGameScreen = NewGameScreen(worldScreen, GameSetupInfo(worldScreen.gameInfo)) val newGameScreen = NewGameScreen(worldScreen, GameSetupInfo(worldScreen.gameInfo))
worldScreen.game.setScreen(newGameScreen) worldScreen.game.setScreen(newGameScreen)
} }
addMenuButton("Victory status") { worldScreen.game.setScreen(VictoryScreen(worldScreen)) } addButton("Victory status") { worldScreen.game.setScreen(VictoryScreen(worldScreen)) }
addMenuButton("Options") { worldScreen.openOptionsPopup() } addButton("Options") { worldScreen.openOptionsPopup() }
addMenuButton("Community") { WorldScreenCommunityPopup(worldScreen).open(force = true) } addButton("Community") {
addSquareButton(Constants.close) {
close() close()
}.size(buttonWidth, buttonHeight) WorldScreenCommunityPopup(worldScreen).open(force = true) }
} addCloseButton()
pack()
fun addMenuButton(text: String, action: () -> Unit) {
addSquareButton(text) {
action()
close()
}.size(buttonWidth, buttonHeight)
innerTable.addSeparator()
}
fun addSquareButton(text: String, action: () -> Unit): Cell<Table> {
val button = Table()
button.add(text.toLabel())
button.onClick(action)
button.touchable = Touchable.enabled
return add(button).apply { row() }
} }
} }
class WorldScreenCommunityPopup(val worldScreen: WorldScreen) : Popup(worldScreen) { class WorldScreenCommunityPopup(val worldScreen: WorldScreen) : Popup(worldScreen) {
init { init {
defaults().fillX()
addButton("Discord") { addButton("Discord") {
Gdx.net.openURI("https://discord.gg/bjrB4Xw") Gdx.net.openURI("https://discord.gg/bjrB4Xw")
close() close()