From 298693ab03eba3ea5fc4d7d88fa15c97d140c432 Mon Sep 17 00:00:00 2001 From: lishaoxia1985 <49801619+lishaoxia1985@users.noreply.github.com> Date: Wed, 9 Jun 2021 13:38:20 -0500 Subject: [PATCH] Revert "Revert "Redraw TechPickerScreen and PickerScreen, Make map symmetrical if it's not wrapped (#3757)"" (#3991) This reverts commit 6d5cb002715aeb41afec0a79f6b0e2c2e9519547. --- core/src/com/unciv/ui/LanguagePickerScreen.kt | 2 +- core/src/com/unciv/ui/map/TileGroupMap.kt | 6 ++- .../ui/mapeditor/GameParametersScreen.kt | 2 +- .../ui/mapeditor/SaveAndLoadMapScreen.kt | 2 +- .../multiplayer/AddMultiplayerGameScreen.kt | 2 +- .../EditMultiplayerGameInfoScreen.kt | 2 +- .../unciv/ui/newgamescreen/NewGameScreen.kt | 2 +- .../ui/pickerscreens/ModManagementScreen.kt | 2 +- .../unciv/ui/pickerscreens/PickerScreen.kt | 23 +++++------ .../ui/pickerscreens/TechPickerScreen.kt | 38 +++++++++++-------- core/src/com/unciv/ui/saves/LoadGameScreen.kt | 2 +- core/src/com/unciv/ui/saves/SaveGameScreen.kt | 2 +- .../unciv/ui/utils/CameraStageBaseScreen.kt | 2 - .../com/unciv/ui/utils/ZoomableScrollPane.kt | 9 ++--- 14 files changed, 49 insertions(+), 47 deletions(-) diff --git a/core/src/com/unciv/ui/LanguagePickerScreen.kt b/core/src/com/unciv/ui/LanguagePickerScreen.kt index f821bf8952..64e404871f 100644 --- a/core/src/com/unciv/ui/LanguagePickerScreen.kt +++ b/core/src/com/unciv/ui/LanguagePickerScreen.kt @@ -34,7 +34,7 @@ class LanguageTable(val language:String, val percentComplete: Int):Table(){ } -class LanguagePickerScreen : PickerScreen(){ +class LanguagePickerScreen : PickerScreen() { var chosenLanguage = "English" private val languageTables = ArrayList() diff --git a/core/src/com/unciv/ui/map/TileGroupMap.kt b/core/src/com/unciv/ui/map/TileGroupMap.kt index 9bdf51e490..4206e3449b 100644 --- a/core/src/com/unciv/ui/map/TileGroupMap.kt +++ b/core/src/com/unciv/ui/map/TileGroupMap.kt @@ -120,9 +120,11 @@ class TileGroupMap(tileGroups: Collection, private val leftAndR // there are tiles "below the zero", // so we zero out the starting position of the whole board so they will be displayed as well - // The width has to be lowered by groupSize because wrapped maps are missing a tile on the right. + // Map's width is reduced by groupSize if it is wrapped, because wrapped map will miss a tile on the right. // This ensures that wrapped maps have a smooth transition. - setSize(topX - bottomX + leftAndRightPadding * 2 - groupSize, topY - bottomY + topAndBottomPadding * 2) + // If map is not wrapped, Map's width doesn't need to be reduce by groupSize + if (worldWrap) setSize(topX - bottomX + leftAndRightPadding * 2 - groupSize, topY - bottomY + topAndBottomPadding * 2) + else setSize(topX - bottomX + leftAndRightPadding * 2, topY - bottomY + topAndBottomPadding * 2) } /** diff --git a/core/src/com/unciv/ui/mapeditor/GameParametersScreen.kt b/core/src/com/unciv/ui/mapeditor/GameParametersScreen.kt index 2e76c6d164..9ab067b037 100644 --- a/core/src/com/unciv/ui/mapeditor/GameParametersScreen.kt +++ b/core/src/com/unciv/ui/mapeditor/GameParametersScreen.kt @@ -16,7 +16,7 @@ import com.unciv.ui.utils.* * updates [mapEditorScreen] and switches to it. * @param [mapEditorScreen] previous screen from map editor. */ -class GameParametersScreen(var mapEditorScreen: MapEditorScreen): IPreviousScreen, PickerScreen(disableScroll = true) { +class GameParametersScreen(var mapEditorScreen: MapEditorScreen): IPreviousScreen, PickerScreen() { override var gameSetupInfo = mapEditorScreen.gameSetupInfo.clone() override var ruleset = RulesetCache.getComplexRuleset(gameSetupInfo.gameParameters.mods) var playerPickerTable = PlayerPickerTable(this, gameSetupInfo.gameParameters) diff --git a/core/src/com/unciv/ui/mapeditor/SaveAndLoadMapScreen.kt b/core/src/com/unciv/ui/mapeditor/SaveAndLoadMapScreen.kt index 35353d505e..7bb0cd1f37 100644 --- a/core/src/com/unciv/ui/mapeditor/SaveAndLoadMapScreen.kt +++ b/core/src/com/unciv/ui/mapeditor/SaveAndLoadMapScreen.kt @@ -18,7 +18,7 @@ import kotlin.concurrent.thread import com.unciv.ui.utils.AutoScrollPane as ScrollPane class SaveAndLoadMapScreen(mapToSave: TileMap?, save:Boolean = false, previousScreen: CameraStageBaseScreen) - : PickerScreen(disableScroll = true) { + : PickerScreen() { private var chosenMap: FileHandle? = null val deleteButton = "Delete map".toTextButton() val mapsTable = Table().apply { defaults().pad(10f) } diff --git a/core/src/com/unciv/ui/multiplayer/AddMultiplayerGameScreen.kt b/core/src/com/unciv/ui/multiplayer/AddMultiplayerGameScreen.kt index f7e692bf28..5993a23af1 100644 --- a/core/src/com/unciv/ui/multiplayer/AddMultiplayerGameScreen.kt +++ b/core/src/com/unciv/ui/multiplayer/AddMultiplayerGameScreen.kt @@ -13,7 +13,7 @@ import com.unciv.ui.utils.onClick import com.unciv.ui.utils.toLabel import java.util.* -class AddMultiplayerGameScreen(backScreen: MultiplayerScreen) : PickerScreen(){ +class AddMultiplayerGameScreen(backScreen: MultiplayerScreen) : PickerScreen() { init { val gameNameTextField = TextField("", skin) val gameIDTextField = TextField("", skin) diff --git a/core/src/com/unciv/ui/multiplayer/EditMultiplayerGameInfoScreen.kt b/core/src/com/unciv/ui/multiplayer/EditMultiplayerGameInfoScreen.kt index 50a02a1421..58e4c1081a 100644 --- a/core/src/com/unciv/ui/multiplayer/EditMultiplayerGameInfoScreen.kt +++ b/core/src/com/unciv/ui/multiplayer/EditMultiplayerGameInfoScreen.kt @@ -14,7 +14,7 @@ import kotlin.concurrent.thread /** Subscreen of MultiplayerScreen to edit and delete saves * backScreen is used for getting back to the MultiplayerScreen so it doesn't have to be created over and over again */ -class EditMultiplayerGameInfoScreen(game: GameInfo?, gameName: String, backScreen: MultiplayerScreen): PickerScreen(){ +class EditMultiplayerGameInfoScreen(game: GameInfo?, gameName: String, backScreen: MultiplayerScreen): PickerScreen() { init { val textField = TextField(gameName, skin) diff --git a/core/src/com/unciv/ui/newgamescreen/NewGameScreen.kt b/core/src/com/unciv/ui/newgamescreen/NewGameScreen.kt index c98ab45ac1..be61294fd1 100644 --- a/core/src/com/unciv/ui/newgamescreen/NewGameScreen.kt +++ b/core/src/com/unciv/ui/newgamescreen/NewGameScreen.kt @@ -37,7 +37,7 @@ class GameSetupInfo(var gameId:String, var gameParameters: GameParameters, var m } } -class NewGameScreen(private val previousScreen: CameraStageBaseScreen, _gameSetupInfo: GameSetupInfo?=null): IPreviousScreen, PickerScreen(disableScroll = true) { +class NewGameScreen(private val previousScreen: CameraStageBaseScreen, _gameSetupInfo: GameSetupInfo?=null): IPreviousScreen, PickerScreen() { override val gameSetupInfo = _gameSetupInfo ?: GameSetupInfo() override var ruleset = RulesetCache.getComplexRuleset(gameSetupInfo.gameParameters.mods) // needs to be set because the GameOptionsTable etc. depend on this var newGameOptionsTable = GameOptionsTable(this) { desiredCiv: String -> playerPickerTable.update(desiredCiv) } diff --git a/core/src/com/unciv/ui/pickerscreens/ModManagementScreen.kt b/core/src/com/unciv/ui/pickerscreens/ModManagementScreen.kt index 9eb31a5719..780f1ed375 100644 --- a/core/src/com/unciv/ui/pickerscreens/ModManagementScreen.kt +++ b/core/src/com/unciv/ui/pickerscreens/ModManagementScreen.kt @@ -26,7 +26,7 @@ import kotlin.concurrent.thread */ // All picker screens auto-wrap the top table in a ScrollPane. // Since we want the different parts to scroll separately, we disable the default ScrollPane, which would scroll everything at once. -class ModManagementScreen: PickerScreen(disableScroll = true) { +class ModManagementScreen: PickerScreen() { private val modTable = Table().apply { defaults().pad(10f) } private val scrollInstalledMods = ScrollPane(modTable) diff --git a/core/src/com/unciv/ui/pickerscreens/PickerScreen.kt b/core/src/com/unciv/ui/pickerscreens/PickerScreen.kt index 50071b4039..0556dbcbec 100644 --- a/core/src/com/unciv/ui/pickerscreens/PickerScreen.kt +++ b/core/src/com/unciv/ui/pickerscreens/PickerScreen.kt @@ -6,13 +6,12 @@ import com.unciv.UncivGame import com.unciv.ui.utils.* import com.unciv.ui.utils.AutoScrollPane as ScrollPane -open class PickerScreen(val disableScroll: Boolean = false) : CameraStageBaseScreen() { +open class PickerScreen : CameraStageBaseScreen() { internal var closeButton: TextButton = Constants.close.toTextButton() protected var descriptionLabel: Label - protected var rightSideGroup = VerticalGroup() + private var rightSideGroup = VerticalGroup() protected var rightSideButton: TextButton - private var screenSplit = 0.85f /** * The table displaying the choices from which to pick (usually). @@ -20,15 +19,15 @@ open class PickerScreen(val disableScroll: Boolean = false) : CameraStageBaseScr */ protected var topTable: Table var bottomTable:Table = Table() - internal var splitPane: SplitPane protected var scrollPane: ScrollPane init { + val bottomTableHeight = 150f bottomTable.add(closeButton).pad(10f) descriptionLabel = "".toLabel() descriptionLabel.wrap = true - val labelScroll = ScrollPane(descriptionLabel,skin) + val labelScroll = ScrollPane(descriptionLabel) bottomTable.add(labelScroll).pad(5f).fill().expand() rightSideButton = "".toTextButton() @@ -36,18 +35,16 @@ open class PickerScreen(val disableScroll: Boolean = false) : CameraStageBaseScr rightSideGroup.addActor(rightSideButton) bottomTable.add(rightSideGroup).pad(10f).right() - bottomTable.height = stage.height * (1 - screenSplit) topTable = Table() scrollPane = ScrollPane(topTable) - scrollPane.setScrollingDisabled(disableScroll, disableScroll) - scrollPane.setSize(stage.width, stage.height * screenSplit) - - splitPane = SplitPane(scrollPane, bottomTable, true, skin) - splitPane.splitAmount = screenSplit - splitPane.setFillParent(true) - stage.addActor(splitPane) + val pickerScreenTable = Table() + pickerScreenTable.add(scrollPane).height(stage.height - bottomTableHeight - 2f).row() + pickerScreenTable.addSeparator() + pickerScreenTable.add(bottomTable).height(bottomTableHeight).fillX().expandX().row() + pickerScreenTable.setFillParent(true) + stage.addActor(pickerScreenTable) } fun setDefaultCloseAction(previousScreen: CameraStageBaseScreen?=null) { diff --git a/core/src/com/unciv/ui/pickerscreens/TechPickerScreen.kt b/core/src/com/unciv/ui/pickerscreens/TechPickerScreen.kt index ecfab27d4e..73824565ee 100644 --- a/core/src/com/unciv/ui/pickerscreens/TechPickerScreen.kt +++ b/core/src/com/unciv/ui/pickerscreens/TechPickerScreen.kt @@ -15,6 +15,7 @@ import com.unciv.models.translations.tr import com.unciv.ui.utils.* import java.util.* import kotlin.collections.ArrayList +import kotlin.math.max class TechPickerScreen(internal val civInfo: CivilizationInfo, centerOnTech: Technology? = null) : PickerScreen() { @@ -60,7 +61,7 @@ class TechPickerScreen(internal val civInfo: CivilizationInfo, centerOnTech: Tec createTechTable() setButtonsInfo() - topTable.add(techTable) + topTable.add(techTable).fill().expand() rightSideButton.setText("Pick a tech".tr()) rightSideButton.onClick(UncivSound.Paper) { @@ -95,30 +96,30 @@ class TechPickerScreen(internal val civInfo: CivilizationInfo, centerOnTech: Tec val allTechs = civInfo.gameInfo.ruleSet.technologies.values if (allTechs.isEmpty()) return val columns = allTechs.map { it.column!!.columnNumber }.maxOrNull()!! + 1 - val rows = allTechs.map { it.row }.maxOrNull()!! + 1 + val rows = allTechs.map { it.row }.maxOrNull()!! val techMatrix = Array>(columns) { arrayOfNulls(rows) } // Divided into columns, then rows - - for (technology in allTechs) { - techMatrix[technology.column!!.columnNumber][technology.row - 1] = technology - } - val erasNamesToColumns = LinkedHashMap>() - for (tech in allTechs) { - val era = tech.era() + + allTechs.forEach { technology -> + techMatrix[technology.column!!.columnNumber][technology.row - 1] = technology + + val era = technology.era() if (!erasNamesToColumns.containsKey(era)) erasNamesToColumns[era] = ArrayList() - val columnNumber = tech.column!!.columnNumber - if (!erasNamesToColumns[era]!!.contains(columnNumber)) erasNamesToColumns[era]!!.add(columnNumber) + val columnNumber = technology.column!!.columnNumber + if (!erasNamesToColumns[era]!!.contains(columnNumber)) + erasNamesToColumns[era]!!.add(columnNumber) } var i = 0 - for ((era, columns) in erasNamesToColumns) { + erasNamesToColumns.forEach { (era, columns) -> val columnSpan = columns.size val color = if (i % 2 == 0) Color.BLUE else Color.FIREBRICK i++ - techTable.add(era.toLabel().addBorder(2f, color)).fill().colspan(columnSpan) + techTable.add(era.toLabel().addBorder(2f, color)).fill().expand().colspan(columnSpan) } - for (rowIndex in 0..rows - 1) { - techTable.row().pad(5f).padRight(40f) + for (rowIndex in 0 until rows) { + val rowPadding = max(5f,(stage.height - 40 - 150 - 2 - 100 * rows) / (2 * rows)) + techTable.row().pad(rowPadding).padLeft(20f).padRight(20f) for (columnIndex in techMatrix.indices) { val tech = techMatrix[columnIndex][rowIndex] @@ -130,7 +131,7 @@ class TechPickerScreen(internal val civInfo: CivilizationInfo, centerOnTech: Tec techNameToButton[tech.name] = techButton techButton.onClick { selectTechnology(tech, false) } - techTable.add(techButton).fillX() + techTable.add(techButton).height(100f).fillX() } } } @@ -285,4 +286,9 @@ class TechPickerScreen(internal val civInfo: CivilizationInfo, centerOnTech: Tec } } + override fun resize(width: Int, height: Int) { + if (stage.viewport.screenWidth != width || stage.viewport.screenHeight != height) { + game.setScreen(TechPickerScreen(civInfo)) + } + } } \ No newline at end of file diff --git a/core/src/com/unciv/ui/saves/LoadGameScreen.kt b/core/src/com/unciv/ui/saves/LoadGameScreen.kt index 1c78d5b4ae..1521a8df64 100644 --- a/core/src/com/unciv/ui/saves/LoadGameScreen.kt +++ b/core/src/com/unciv/ui/saves/LoadGameScreen.kt @@ -20,7 +20,7 @@ import java.util.concurrent.CancellationException import kotlin.concurrent.thread import com.unciv.ui.utils.AutoScrollPane as ScrollPane -class LoadGameScreen(previousScreen:CameraStageBaseScreen) : PickerScreen(disableScroll = true) { +class LoadGameScreen(previousScreen:CameraStageBaseScreen) : PickerScreen() { lateinit var selectedSave: String private val copySavedGameToClipboardButton = "Copy saved game to clipboard".toTextButton() private val saveTable = Table() diff --git a/core/src/com/unciv/ui/saves/SaveGameScreen.kt b/core/src/com/unciv/ui/saves/SaveGameScreen.kt index e4c4029aa0..931c1a5867 100644 --- a/core/src/com/unciv/ui/saves/SaveGameScreen.kt +++ b/core/src/com/unciv/ui/saves/SaveGameScreen.kt @@ -17,7 +17,7 @@ import kotlin.concurrent.thread import com.unciv.ui.utils.AutoScrollPane as ScrollPane -class SaveGameScreen(val gameInfo: GameInfo) : PickerScreen(disableScroll = true) { +class SaveGameScreen(val gameInfo: GameInfo) : PickerScreen() { private val gameNameTextField = TextField("", skin) val currentSaves = Table() diff --git a/core/src/com/unciv/ui/utils/CameraStageBaseScreen.kt b/core/src/com/unciv/ui/utils/CameraStageBaseScreen.kt index 23e5e30f79..134e26a800 100644 --- a/core/src/com/unciv/ui/utils/CameraStageBaseScreen.kt +++ b/core/src/com/unciv/ui/utils/CameraStageBaseScreen.kt @@ -4,7 +4,6 @@ import com.badlogic.gdx.Gdx import com.badlogic.gdx.Screen import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.GL20 -import com.badlogic.gdx.graphics.g2d.Batch import com.badlogic.gdx.graphics.g2d.BitmapFont import com.badlogic.gdx.graphics.g2d.SpriteBatch import com.badlogic.gdx.graphics.g2d.TextureAtlas @@ -90,7 +89,6 @@ open class CameraStageBaseScreen : Screen { skin.get(SelectBox.SelectBoxStyle::class.java).listStyle.font = Fonts.font.apply { data.setScale(20 / Fonts.ORIGINAL_FONT_SIZE) } skin } - internal var batch: Batch = SpriteBatch() } fun onBackButtonClicked(action: () -> Unit) { diff --git a/core/src/com/unciv/ui/utils/ZoomableScrollPane.kt b/core/src/com/unciv/ui/utils/ZoomableScrollPane.kt index b47bf5eb76..baafc76e61 100644 --- a/core/src/com/unciv/ui/utils/ZoomableScrollPane.kt +++ b/core/src/com/unciv/ui/utils/ZoomableScrollPane.kt @@ -11,10 +11,6 @@ open class ZoomableScrollPane: ScrollPane(null) { var continuousScrollingX = false init{ - // Remove the existing inputListener - // which defines that mouse scroll = vertical movement - val zoomListener = listeners.last { it is InputListener && it !in captureListeners } - removeListener(zoomListener) addZoomListeners() } @@ -30,7 +26,10 @@ open class ZoomableScrollPane: ScrollPane(null) { } private fun addZoomListeners() { - + // At first, Remove the existing inputListener + // which defines that mouse scroll = vertical movement + val zoomListener = listeners.last { it is InputListener && it !in captureListeners } + removeListener(zoomListener) addListener(object : InputListener() { override fun scrolled(event: InputEvent?, x: Float, y: Float, amountX: Float, amountY: Float): Boolean { if (amountX > 0 || amountY > 0) zoomOut()