From bc1592bafea7184d166212072bcb1c7d79f2304d Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Thu, 29 Aug 2019 13:18:09 +0300 Subject: [PATCH] Added game ID copy and join, so one person can create a game, send it to someone else, and the other person can join it --- .../unciv/ui/cityscreen/ConstructionsTable.kt | 2 +- .../optionstable/WorldScreenMenuTable.kt | 42 +++++++++++++++++++ .../optionstable/WorldScreenOptionsTable.kt | 1 + 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/core/src/com/unciv/ui/cityscreen/ConstructionsTable.kt b/core/src/com/unciv/ui/cityscreen/ConstructionsTable.kt index 37dd89e6ea..d374d425ba 100644 --- a/core/src/com/unciv/ui/cityscreen/ConstructionsTable.kt +++ b/core/src/com/unciv/ui/cityscreen/ConstructionsTable.kt @@ -150,7 +150,6 @@ class ConstructionsTable(val cityScreen: CityScreen) : Table(CameraStageBaseScre if (construction.canBePurchased()) { val constructionGoldCost = construction.getGoldCost(city.civInfo) purchaseConstructionButton = TextButton("Buy for [$constructionGoldCost] gold".tr(), CameraStageBaseScreen.skin) - purchaseConstructionButton.labelCell.pad(10f) purchaseConstructionButton.onClick("coin") { YesNoPopupTable("Would you like to purchase [${construction.name}] for [$constructionGoldCost] gold?".tr(), { cityConstructions.purchaseConstruction(construction.name) @@ -166,6 +165,7 @@ class ConstructionsTable(val cityScreen: CityScreen) : Table(CameraStageBaseScre purchaseConstructionButton = TextButton("Buy".tr(), CameraStageBaseScreen.skin) purchaseConstructionButton.disable() } + purchaseConstructionButton.labelCell.pad(10f) add(purchaseConstructionButton).pad(10f).row() diff --git a/core/src/com/unciv/ui/worldscreen/optionstable/WorldScreenMenuTable.kt b/core/src/com/unciv/ui/worldscreen/optionstable/WorldScreenMenuTable.kt index 6df8c51f42..9a22801471 100644 --- a/core/src/com/unciv/ui/worldscreen/optionstable/WorldScreenMenuTable.kt +++ b/core/src/com/unciv/ui/worldscreen/optionstable/WorldScreenMenuTable.kt @@ -1,6 +1,7 @@ package com.unciv.ui.worldscreen.optionstable import com.badlogic.gdx.Gdx +import com.badlogic.gdx.graphics.Color import com.unciv.UnCivGame import com.unciv.logic.map.RoadStatus import com.unciv.models.gamebasics.tr @@ -10,7 +11,11 @@ import com.unciv.ui.mapeditor.MapEditorScreen import com.unciv.ui.newgamescreen.NewGameScreen import com.unciv.ui.saves.LoadGameScreen import com.unciv.ui.saves.SaveGameScreen +import com.unciv.ui.utils.setFontColor +import com.unciv.ui.utils.toLabel import com.unciv.ui.worldscreen.WorldScreen +import java.util.* +import kotlin.collections.ArrayList class WorldScreenMenuTable(val worldScreen: WorldScreen) : PopupTable(worldScreen) { @@ -47,6 +52,12 @@ class WorldScreenMenuTable(val worldScreen: WorldScreen) : PopupTable(worldScree addButton("Start new game".tr()){ UnCivGame.Current.screen = NewGameScreen() } + if(worldScreen.gameInfo.gameParameters.isOnlineMultiplayer){ + addButton("Copy game ID to clipboard".tr()){ Gdx.app.clipboard.contents = worldScreen.gameInfo.gameId } + } + +// addJoinMultiplayerButton() + addButton("Victory status".tr()) { UnCivGame.Current.screen = VictoryScreen() } addButton("Options".tr()){ @@ -63,6 +74,37 @@ class WorldScreenMenuTable(val worldScreen: WorldScreen) : PopupTable(worldScree open() } + + private fun addJoinMultiplayerButton() { + addButton("Join multiplayer".tr()) { + close() + val joinMultiplayerPopup = PopupTable(screen) + joinMultiplayerPopup.addGoodSizedLabel("Copy the game ID to your clipboard, and click the Join Game button!").row() + val badGameIdLabel = "".toLabel().setFontColor(Color.RED) + badGameIdLabel.isVisible = false + joinMultiplayerPopup.addButton("Join Game") { + val gameId = Gdx.app.clipboard.contents.trim() + try { + UUID.fromString(gameId) + } catch (ex: Exception) { + badGameIdLabel.setText("Invalid game ID!") + badGameIdLabel.isVisible = true + return@addButton + } + try { + val game = OnlineMultiplayer().tryDownloadGame(gameId) + UnCivGame.Current.loadGame(game) + } catch (ex: Exception) { + badGameIdLabel.setText("Could not download game1!") + badGameIdLabel.isVisible = true + return@addButton + } + }.row() + joinMultiplayerPopup.add(badGameIdLabel).row() + joinMultiplayerPopup.addCloseButton() + joinMultiplayerPopup.open() + } + } } class WorldScreenCommunityTable(val worldScreen: WorldScreen) : PopupTable(worldScreen) { diff --git a/core/src/com/unciv/ui/worldscreen/optionstable/WorldScreenOptionsTable.kt b/core/src/com/unciv/ui/worldscreen/optionstable/WorldScreenOptionsTable.kt index ff5e990b48..b892912a9a 100644 --- a/core/src/com/unciv/ui/worldscreen/optionstable/WorldScreenOptionsTable.kt +++ b/core/src/com/unciv/ui/worldscreen/optionstable/WorldScreenOptionsTable.kt @@ -69,6 +69,7 @@ class WorldScreenOptionsTable(val worldScreen:WorldScreen) : PopupTable(worldScr update() } + innerTable.add("Auto-assign city production".toLabel()) innerTable.addButton(if(settings.autoAssignCityProduction) "Yes".tr() else "No".tr()) { settings.autoAssignCityProduction= !settings.autoAssignCityProduction