mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-27 05:46:43 -04:00
Redraw TechPickerScreen and PickerScreen, Make map symmetrical if it's not wrapped (#3757)
* Redraw TechPickerScreen and PickerScreen * Make map symmetrical if it's not wrapped
This commit is contained in:
parent
55659657aa
commit
faac24a2a5
@ -120,9 +120,11 @@ class TileGroupMap<T: TileGroup>(tileGroups: Collection<T>, private val leftAndR
|
|||||||
|
|
||||||
// there are tiles "below the zero",
|
// there are tiles "below the zero",
|
||||||
// so we zero out the starting position of the whole board so they will be displayed as well
|
// 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.
|
// 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)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -11,9 +11,8 @@ open class PickerScreen : CameraStageBaseScreen() {
|
|||||||
|
|
||||||
internal var closeButton: TextButton = Constants.close.toTextButton()
|
internal var closeButton: TextButton = Constants.close.toTextButton()
|
||||||
protected var descriptionLabel: Label
|
protected var descriptionLabel: Label
|
||||||
protected var rightSideGroup = VerticalGroup()
|
private var rightSideGroup = VerticalGroup()
|
||||||
protected var rightSideButton: TextButton
|
protected var rightSideButton: TextButton
|
||||||
private var screenSplit = 0.85f
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The table displaying the choices from which to pick (usually).
|
* The table displaying the choices from which to pick (usually).
|
||||||
@ -21,15 +20,15 @@ open class PickerScreen : CameraStageBaseScreen() {
|
|||||||
*/
|
*/
|
||||||
protected var topTable: Table
|
protected var topTable: Table
|
||||||
var bottomTable:Table = Table()
|
var bottomTable:Table = Table()
|
||||||
internal var splitPane: SplitPane
|
|
||||||
protected var scrollPane: ScrollPane
|
protected var scrollPane: ScrollPane
|
||||||
|
|
||||||
init {
|
init {
|
||||||
|
val bottomTableHeight = 150f
|
||||||
bottomTable.add(closeButton).pad(10f)
|
bottomTable.add(closeButton).pad(10f)
|
||||||
|
|
||||||
descriptionLabel = "".toLabel()
|
descriptionLabel = "".toLabel()
|
||||||
descriptionLabel.wrap = true
|
descriptionLabel.wrap = true
|
||||||
val labelScroll = ScrollPane(descriptionLabel,skin)
|
val labelScroll = ScrollPane(descriptionLabel)
|
||||||
bottomTable.add(labelScroll).pad(5f).fill().expand()
|
bottomTable.add(labelScroll).pad(5f).fill().expand()
|
||||||
|
|
||||||
rightSideButton = "".toTextButton()
|
rightSideButton = "".toTextButton()
|
||||||
@ -37,17 +36,16 @@ open class PickerScreen : CameraStageBaseScreen() {
|
|||||||
rightSideGroup.addActor(rightSideButton)
|
rightSideGroup.addActor(rightSideButton)
|
||||||
|
|
||||||
bottomTable.add(rightSideGroup).pad(10f).right()
|
bottomTable.add(rightSideGroup).pad(10f).right()
|
||||||
bottomTable.height = stage.height * (1 - screenSplit)
|
|
||||||
|
|
||||||
topTable = Table()
|
topTable = Table()
|
||||||
scrollPane = ScrollPane(topTable)
|
scrollPane = ScrollPane(topTable)
|
||||||
|
|
||||||
scrollPane.setSize(stage.width, stage.height * screenSplit)
|
val pickerScreenTable = Table()
|
||||||
|
pickerScreenTable.add(scrollPane).height(stage.height - bottomTableHeight - 2f).row()
|
||||||
splitPane = SplitPane(scrollPane, bottomTable, true, skin)
|
pickerScreenTable.addSeparator()
|
||||||
splitPane.splitAmount = screenSplit
|
pickerScreenTable.add(bottomTable).height(bottomTableHeight).fillX().expandX().row()
|
||||||
splitPane.setFillParent(true)
|
pickerScreenTable.setFillParent(true)
|
||||||
stage.addActor(splitPane)
|
stage.addActor(pickerScreenTable)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setDefaultCloseAction(previousScreen: CameraStageBaseScreen?=null) {
|
fun setDefaultCloseAction(previousScreen: CameraStageBaseScreen?=null) {
|
||||||
|
@ -15,6 +15,7 @@ import com.unciv.models.translations.tr
|
|||||||
import com.unciv.ui.utils.*
|
import com.unciv.ui.utils.*
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import kotlin.collections.ArrayList
|
import kotlin.collections.ArrayList
|
||||||
|
import kotlin.math.max
|
||||||
|
|
||||||
|
|
||||||
class TechPickerScreen(internal val civInfo: CivilizationInfo, centerOnTech: Technology? = null) : PickerScreen() {
|
class TechPickerScreen(internal val civInfo: CivilizationInfo, centerOnTech: Technology? = null) : PickerScreen() {
|
||||||
@ -60,7 +61,7 @@ class TechPickerScreen(internal val civInfo: CivilizationInfo, centerOnTech: Tec
|
|||||||
|
|
||||||
createTechTable()
|
createTechTable()
|
||||||
setButtonsInfo()
|
setButtonsInfo()
|
||||||
topTable.add(techTable)
|
topTable.add(techTable).fill().expand()
|
||||||
|
|
||||||
rightSideButton.setText("Pick a tech".tr())
|
rightSideButton.setText("Pick a tech".tr())
|
||||||
rightSideButton.onClick(UncivSound.Paper) {
|
rightSideButton.onClick(UncivSound.Paper) {
|
||||||
@ -95,30 +96,30 @@ class TechPickerScreen(internal val civInfo: CivilizationInfo, centerOnTech: Tec
|
|||||||
val allTechs = civInfo.gameInfo.ruleSet.technologies.values
|
val allTechs = civInfo.gameInfo.ruleSet.technologies.values
|
||||||
if (allTechs.isEmpty()) return
|
if (allTechs.isEmpty()) return
|
||||||
val columns = allTechs.map { it.column!!.columnNumber }.maxOrNull()!! + 1
|
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<Array<Technology?>>(columns) { arrayOfNulls(rows) } // Divided into columns, then rows
|
val techMatrix = Array<Array<Technology?>>(columns) { arrayOfNulls(rows) } // Divided into columns, then rows
|
||||||
|
|
||||||
for (technology in allTechs) {
|
|
||||||
techMatrix[technology.column!!.columnNumber][technology.row - 1] = technology
|
|
||||||
}
|
|
||||||
|
|
||||||
val erasNamesToColumns = LinkedHashMap<String, ArrayList<Int>>()
|
val erasNamesToColumns = LinkedHashMap<String, ArrayList<Int>>()
|
||||||
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()
|
if (!erasNamesToColumns.containsKey(era)) erasNamesToColumns[era] = ArrayList()
|
||||||
val columnNumber = tech.column!!.columnNumber
|
val columnNumber = technology.column!!.columnNumber
|
||||||
if (!erasNamesToColumns[era]!!.contains(columnNumber)) erasNamesToColumns[era]!!.add(columnNumber)
|
if (!erasNamesToColumns[era]!!.contains(columnNumber))
|
||||||
|
erasNamesToColumns[era]!!.add(columnNumber)
|
||||||
}
|
}
|
||||||
var i = 0
|
var i = 0
|
||||||
for ((era, columns) in erasNamesToColumns) {
|
erasNamesToColumns.forEach { (era, columns) ->
|
||||||
val columnSpan = columns.size
|
val columnSpan = columns.size
|
||||||
val color = if (i % 2 == 0) Color.BLUE else Color.FIREBRICK
|
val color = if (i % 2 == 0) Color.BLUE else Color.FIREBRICK
|
||||||
i++
|
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) {
|
for (rowIndex in 0 until rows) {
|
||||||
techTable.row().pad(5f).padRight(40f)
|
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) {
|
for (columnIndex in techMatrix.indices) {
|
||||||
val tech = techMatrix[columnIndex][rowIndex]
|
val tech = techMatrix[columnIndex][rowIndex]
|
||||||
@ -130,7 +131,7 @@ class TechPickerScreen(internal val civInfo: CivilizationInfo, centerOnTech: Tec
|
|||||||
|
|
||||||
techNameToButton[tech.name] = techButton
|
techNameToButton[tech.name] = techButton
|
||||||
techButton.onClick { selectTechnology(tech, false) }
|
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))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,6 +1,5 @@
|
|||||||
package com.unciv.ui.tilegroups
|
package com.unciv.ui.tilegroups
|
||||||
|
|
||||||
import com.badlogic.gdx.graphics.g2d.Batch
|
|
||||||
import com.unciv.UncivGame
|
import com.unciv.UncivGame
|
||||||
import com.unciv.logic.city.CityInfo
|
import com.unciv.logic.city.CityInfo
|
||||||
import com.unciv.logic.civilization.CivilizationInfo
|
import com.unciv.logic.civilization.CivilizationInfo
|
||||||
|
@ -5,7 +5,6 @@ import com.badlogic.gdx.Input
|
|||||||
import com.badlogic.gdx.Screen
|
import com.badlogic.gdx.Screen
|
||||||
import com.badlogic.gdx.graphics.Color
|
import com.badlogic.gdx.graphics.Color
|
||||||
import com.badlogic.gdx.graphics.GL20
|
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.BitmapFont
|
||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||||
import com.badlogic.gdx.graphics.g2d.TextureAtlas
|
import com.badlogic.gdx.graphics.g2d.TextureAtlas
|
||||||
@ -33,10 +32,9 @@ open class CameraStageBaseScreen : Screen {
|
|||||||
|
|
||||||
// An initialized val always turned out to illegally be null...
|
// An initialized val always turned out to illegally be null...
|
||||||
// Remember to always set LOWER CASE chars as the keys!
|
// Remember to always set LOWER CASE chars as the keys!
|
||||||
var keyPressDispatcher: HashMap<Char, (() -> Unit)>
|
var keyPressDispatcher: HashMap<Char, (() -> Unit)> = hashMapOf()
|
||||||
|
|
||||||
init {
|
init {
|
||||||
keyPressDispatcher = hashMapOf()
|
|
||||||
val resolutions: List<Float> = game.settings.resolution.split("x").map { it.toInt().toFloat() }
|
val resolutions: List<Float> = game.settings.resolution.split("x").map { it.toInt().toFloat() }
|
||||||
val width = resolutions[0]
|
val width = resolutions[0]
|
||||||
val height = resolutions[1]
|
val height = resolutions[1]
|
||||||
@ -81,7 +79,7 @@ open class CameraStageBaseScreen : Screen {
|
|||||||
|
|
||||||
override fun hide() {}
|
override fun hide() {}
|
||||||
|
|
||||||
override fun dispose() {}
|
override fun dispose() { stage.dispose() }
|
||||||
|
|
||||||
fun displayTutorial(tutorial: Tutorial, test: (() -> Boolean)? = null) {
|
fun displayTutorial(tutorial: Tutorial, test: (() -> Boolean)? = null) {
|
||||||
if (!game.settings.showTutorials) return
|
if (!game.settings.showTutorials) return
|
||||||
@ -110,7 +108,6 @@ open class CameraStageBaseScreen : Screen {
|
|||||||
skin.get(SelectBox.SelectBoxStyle::class.java).listStyle.font = Fonts.font.apply { data.setScale(20 / ORIGINAL_FONT_SIZE) }
|
skin.get(SelectBox.SelectBoxStyle::class.java).listStyle.font = Fonts.font.apply { data.setScale(20 / ORIGINAL_FONT_SIZE) }
|
||||||
skin
|
skin
|
||||||
}
|
}
|
||||||
internal var batch: Batch = SpriteBatch()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** It returns the assigned [InputListener] */
|
/** It returns the assigned [InputListener] */
|
||||||
@ -210,8 +207,7 @@ fun Table.addSeparator(): Cell<Image> {
|
|||||||
|
|
||||||
fun Table.addSeparatorVertical(): Cell<Image> {
|
fun Table.addSeparatorVertical(): Cell<Image> {
|
||||||
val image = ImageGetter.getWhiteDot()
|
val image = ImageGetter.getWhiteDot()
|
||||||
val cell = add(image).width(2f).fillY()
|
return add(image).width(2f).fillY()
|
||||||
return cell
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun <T : Actor> Table.addCell(actor: T): Table {
|
fun <T : Actor> Table.addCell(actor: T): Table {
|
||||||
|
@ -11,10 +11,6 @@ open class ZoomableScrollPane: ScrollPane(null) {
|
|||||||
var continousScrollingX = false
|
var continousScrollingX = false
|
||||||
|
|
||||||
init{
|
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()
|
addZoomListeners()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -24,7 +20,10 @@ open class ZoomableScrollPane: ScrollPane(null) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun addZoomListeners() {
|
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() {
|
addListener(object : InputListener() {
|
||||||
override fun scrolled(event: InputEvent?, x: Float, y: Float, amountX: Float, amountY: Float): Boolean {
|
override fun scrolled(event: InputEvent?, x: Float, y: Float, amountX: Float, amountY: Float): Boolean {
|
||||||
if (amountX > 0 || amountY > 0) zoom(scaleX * 0.8f)
|
if (amountX > 0 || amountY > 0) zoom(scaleX * 0.8f)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user