From 6d5cb002715aeb41afec0a79f6b0e2c2e9519547 Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Wed, 7 Apr 2021 19:26:17 +0300 Subject: [PATCH] Revert "Redraw TechPickerScreen and PickerScreen, Make map symmetrical if it's not wrapped (#3757)" This reverts commit faac24a2a5fa923842a8ac19e2b38ca97a52132f. --- core/src/com/unciv/ui/map/TileGroupMap.kt | 6 ++-- .../unciv/ui/pickerscreens/PickerScreen.kt | 20 ++++++----- .../ui/pickerscreens/TechPickerScreen.kt | 34 ++++++++----------- .../com/unciv/ui/tilegroups/WorldTileGroup.kt | 1 + .../unciv/ui/utils/CameraStageBaseScreen.kt | 10 ++++-- .../com/unciv/ui/utils/ZoomableScrollPane.kt | 9 ++--- 6 files changed, 40 insertions(+), 40 deletions(-) diff --git a/core/src/com/unciv/ui/map/TileGroupMap.kt b/core/src/com/unciv/ui/map/TileGroupMap.kt index 4206e3449b..9bdf51e490 100644 --- a/core/src/com/unciv/ui/map/TileGroupMap.kt +++ b/core/src/com/unciv/ui/map/TileGroupMap.kt @@ -120,11 +120,9 @@ 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 - // Map's width is reduced by groupSize if it is wrapped, because wrapped map will miss a tile on the right. + // The width has to be lowered by groupSize because wrapped maps are missing a tile on the right. // This ensures that wrapped maps have a smooth transition. - // 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) + setSize(topX - bottomX + leftAndRightPadding * 2 - groupSize, topY - bottomY + topAndBottomPadding * 2) } /** diff --git a/core/src/com/unciv/ui/pickerscreens/PickerScreen.kt b/core/src/com/unciv/ui/pickerscreens/PickerScreen.kt index 10427ab6ed..aff9468c76 100644 --- a/core/src/com/unciv/ui/pickerscreens/PickerScreen.kt +++ b/core/src/com/unciv/ui/pickerscreens/PickerScreen.kt @@ -11,8 +11,9 @@ open class PickerScreen : CameraStageBaseScreen() { internal var closeButton: TextButton = Constants.close.toTextButton() protected var descriptionLabel: Label - private var rightSideGroup = VerticalGroup() + protected var rightSideGroup = VerticalGroup() protected var rightSideButton: TextButton + private var screenSplit = 0.85f /** * The table displaying the choices from which to pick (usually). @@ -20,15 +21,15 @@ open class PickerScreen : CameraStageBaseScreen() { */ 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) + val labelScroll = ScrollPane(descriptionLabel,skin) bottomTable.add(labelScroll).pad(5f).fill().expand() rightSideButton = "".toTextButton() @@ -36,16 +37,17 @@ open class PickerScreen : CameraStageBaseScreen() { rightSideGroup.addActor(rightSideButton) bottomTable.add(rightSideGroup).pad(10f).right() + bottomTable.height = stage.height * (1 - screenSplit) topTable = Table() scrollPane = ScrollPane(topTable) - 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) + scrollPane.setSize(stage.width, stage.height * screenSplit) + + splitPane = SplitPane(scrollPane, bottomTable, true, skin) + splitPane.splitAmount = screenSplit + splitPane.setFillParent(true) + stage.addActor(splitPane) } 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 73824565ee..ecfab27d4e 100644 --- a/core/src/com/unciv/ui/pickerscreens/TechPickerScreen.kt +++ b/core/src/com/unciv/ui/pickerscreens/TechPickerScreen.kt @@ -15,7 +15,6 @@ 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() { @@ -61,7 +60,7 @@ class TechPickerScreen(internal val civInfo: CivilizationInfo, centerOnTech: Tec createTechTable() setButtonsInfo() - topTable.add(techTable).fill().expand() + topTable.add(techTable) rightSideButton.setText("Pick a tech".tr()) rightSideButton.onClick(UncivSound.Paper) { @@ -96,30 +95,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()!! + val rows = allTechs.map { it.row }.maxOrNull()!! + 1 val techMatrix = Array>(columns) { arrayOfNulls(rows) } // Divided into columns, then rows - val erasNamesToColumns = LinkedHashMap>() - allTechs.forEach { technology -> + for (technology in allTechs) { techMatrix[technology.column!!.columnNumber][technology.row - 1] = technology + } - val era = technology.era() + val erasNamesToColumns = LinkedHashMap>() + for (tech in allTechs) { + val era = tech.era() if (!erasNamesToColumns.containsKey(era)) erasNamesToColumns[era] = ArrayList() - val columnNumber = technology.column!!.columnNumber - if (!erasNamesToColumns[era]!!.contains(columnNumber)) - erasNamesToColumns[era]!!.add(columnNumber) + val columnNumber = tech.column!!.columnNumber + if (!erasNamesToColumns[era]!!.contains(columnNumber)) erasNamesToColumns[era]!!.add(columnNumber) } var i = 0 - erasNamesToColumns.forEach { (era, columns) -> + for ((era, columns) in erasNamesToColumns) { val columnSpan = columns.size val color = if (i % 2 == 0) Color.BLUE else Color.FIREBRICK i++ - techTable.add(era.toLabel().addBorder(2f, color)).fill().expand().colspan(columnSpan) + techTable.add(era.toLabel().addBorder(2f, color)).fill().colspan(columnSpan) } - 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 (rowIndex in 0..rows - 1) { + techTable.row().pad(5f).padRight(40f) for (columnIndex in techMatrix.indices) { val tech = techMatrix[columnIndex][rowIndex] @@ -131,7 +130,7 @@ class TechPickerScreen(internal val civInfo: CivilizationInfo, centerOnTech: Tec techNameToButton[tech.name] = techButton techButton.onClick { selectTechnology(tech, false) } - techTable.add(techButton).height(100f).fillX() + techTable.add(techButton).fillX() } } } @@ -286,9 +285,4 @@ 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/tilegroups/WorldTileGroup.kt b/core/src/com/unciv/ui/tilegroups/WorldTileGroup.kt index 788a6b872b..7ae16da1fa 100644 --- a/core/src/com/unciv/ui/tilegroups/WorldTileGroup.kt +++ b/core/src/com/unciv/ui/tilegroups/WorldTileGroup.kt @@ -1,5 +1,6 @@ package com.unciv.ui.tilegroups +import com.badlogic.gdx.graphics.g2d.Batch import com.unciv.UncivGame import com.unciv.logic.city.CityInfo import com.unciv.logic.civilization.CivilizationInfo diff --git a/core/src/com/unciv/ui/utils/CameraStageBaseScreen.kt b/core/src/com/unciv/ui/utils/CameraStageBaseScreen.kt index 5a497efe74..c0db1d1d21 100644 --- a/core/src/com/unciv/ui/utils/CameraStageBaseScreen.kt +++ b/core/src/com/unciv/ui/utils/CameraStageBaseScreen.kt @@ -5,6 +5,7 @@ import com.badlogic.gdx.Input 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 @@ -32,9 +33,10 @@ open class CameraStageBaseScreen : Screen { // An initialized val always turned out to illegally be null... // Remember to always set LOWER CASE chars as the keys! - var keyPressDispatcher: HashMap Unit)> = hashMapOf() + var keyPressDispatcher: HashMap Unit)> init { + keyPressDispatcher = hashMapOf() val resolutions: List = game.settings.resolution.split("x").map { it.toInt().toFloat() } val width = resolutions[0] val height = resolutions[1] @@ -79,7 +81,7 @@ open class CameraStageBaseScreen : Screen { override fun hide() {} - override fun dispose() { stage.dispose() } + override fun dispose() {} fun displayTutorial(tutorial: Tutorial, test: (() -> Boolean)? = null) { if (!game.settings.showTutorials) return @@ -108,6 +110,7 @@ open class CameraStageBaseScreen : Screen { skin.get(SelectBox.SelectBoxStyle::class.java).listStyle.font = Fonts.font.apply { data.setScale(20 / ORIGINAL_FONT_SIZE) } skin } + internal var batch: Batch = SpriteBatch() } /** It returns the assigned [InputListener] */ @@ -207,7 +210,8 @@ fun Table.addSeparator(): Cell { fun Table.addSeparatorVertical(): Cell { val image = ImageGetter.getWhiteDot() - return add(image).width(2f).fillY() + val cell = add(image).width(2f).fillY() + return cell } fun Table.addCell(actor: T): Table { diff --git a/core/src/com/unciv/ui/utils/ZoomableScrollPane.kt b/core/src/com/unciv/ui/utils/ZoomableScrollPane.kt index 31d8ccbf2a..42858af83b 100644 --- a/core/src/com/unciv/ui/utils/ZoomableScrollPane.kt +++ b/core/src/com/unciv/ui/utils/ZoomableScrollPane.kt @@ -11,6 +11,10 @@ open class ZoomableScrollPane: ScrollPane(null) { var continousScrollingX = 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() } @@ -20,10 +24,7 @@ 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) zoom(scaleX * 0.8f)