Add optional on-screen buttons to zoom in and out (#6933)

This commit is contained in:
alexban011 2022-05-29 16:32:36 +03:00 committed by GitHub
parent 57c027dca5
commit ea31bd164f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 53 additions and 2 deletions

View File

@ -654,6 +654,7 @@ Show pixel units =
Show pixel improvements =
Enable Nuclear Weapons =
Experimental Demographics scoreboard =
Show zoom buttons in world screen =
Show tile yields =
Show unit movement arrows =
Continuous rendering =

View File

@ -50,6 +50,7 @@ class GameSettings {
var isFreshlyCreated = false
var visualMods = HashSet<String>()
var useDemographics: Boolean = false
var showZoomButtons: Boolean = false
var multiplayer = GameSettingsMultiplayer()

View File

@ -16,6 +16,7 @@ import com.unciv.ui.popup.ToastPopup
import com.unciv.ui.popup.YesNoPopup
import com.unciv.ui.tilegroups.TileGroup
import com.unciv.ui.utils.*
import com.unciv.ui.worldscreen.ZoomButtonPair
//todo normalize properly
@ -65,6 +66,7 @@ class MapEditorScreen(map: TileMap? = null): BaseScreen() {
var mapHolder: EditorMapHolder
val tabs: MapEditorMainTabs
var tileClickHandler: ((tile: TileInfo)->Unit)? = null
private var zoomController: ZoomButtonPair? = null
private val highlightedTileGroups = mutableListOf<TileGroup>()
@ -139,6 +141,13 @@ class MapEditorScreen(map: TileMap? = null): BaseScreen() {
modsTabNeedsRefresh = true
editTabsNeedRefresh = true
naturalWondersNeedRefresh = true
if (UncivGame.Current.settings.showZoomButtons) {
zoomController = ZoomButtonPair(result)
zoomController!!.setPosition(10f, 10f)
stage.addActor(zoomController)
}
return result
}

View File

@ -34,6 +34,7 @@ fun displayTab(
optionsPopup.addCheckbox(this, "Show pixel units", settings.showPixelUnits, true) { settings.showPixelUnits = it }
optionsPopup.addCheckbox(this, "Show pixel improvements", settings.showPixelImprovements, true) { settings.showPixelImprovements = it }
optionsPopup.addCheckbox(this, "Experimental Demographics scoreboard", settings.useDemographics, true) { settings.useDemographics = it }
optionsPopup.addCheckbox(this, "Show zoom buttons in world screen", settings.showZoomButtons, true) { settings.showZoomButtons = it }
addMinimapSizeSlider(this, settings, optionsPopup.screen, optionsPopup.selectBoxMinWidth)

View File

@ -89,7 +89,7 @@ import java.util.*
* @property isPlayersTurn (readonly) Indicates it's the player's ([viewingCiv]) turn
* @property selectedCiv Selected civilization, used in spectator and replay mode, equals viewingCiv in ordinary games
* @property canChangeState (readonly) `true` when it's the player's turn unless he is a spectator
* @property mapHolder A [MinimapHolder] instance
* @property mapHolder A [WorldMapHolder] instance
* @property bottomUnitTable Bottom left widget holding information about a selected unit or city
*/
class WorldScreen(val gameInfo: GameInfo, val viewingCiv:CivilizationInfo) : BaseScreen() {
@ -125,6 +125,8 @@ class WorldScreen(val gameInfo: GameInfo, val viewingCiv:CivilizationInfo) : Bas
private val notificationsScroll: NotificationsScroll
var shouldUpdate = false
private val zoomController = ZoomButtonPair(mapHolder)
private var nextTurnUpdateJob: Job? = null
private val events = EventBus.EventReceiver()
@ -178,6 +180,9 @@ class WorldScreen(val gameInfo: GameInfo, val viewingCiv:CivilizationInfo) : Bas
stage.addActor(techPolicyAndVictoryHolder)
stage.addActor(tutorialTaskTable)
if (UncivGame.Current.settings.showZoomButtons) {
stage.addActor(zoomController)
}
diplomacyButtonHolder.defaults().pad(5f)
stage.addActor(fogOfWarButton)
@ -499,6 +504,10 @@ class WorldScreen(val gameInfo: GameInfo, val viewingCiv:CivilizationInfo) : Bas
updateGameplayButtons()
notificationsScroll.update(viewingCiv.notifications, bottomTileInfoTable.height)
notificationsScroll.setTopRight(stage.width - 10f, statusButtons.y - 5f)
val posZoomFromRight = if (game.settings.showMinimap) minimapWrapper.width
else bottomTileInfoTable.width
zoomController.setPosition(stage.width - posZoomFromRight - 10f, 10f, Align.bottomRight)
}
private fun getCurrentTutorialTask(): String {

View File

@ -0,0 +1,30 @@
package com.unciv.ui.worldscreen
import com.badlogic.gdx.scenes.scene2d.ui.Cell
import com.badlogic.gdx.scenes.scene2d.ui.Table
import com.badlogic.gdx.scenes.scene2d.ui.TextButton
import com.badlogic.gdx.utils.Align
import com.unciv.ui.utils.BaseScreen
import com.unciv.ui.utils.ZoomableScrollPane
import com.unciv.ui.utils.onClick
import com.unciv.ui.utils.setFontSize
class ZoomButtonPair(private val mapHolder: ZoomableScrollPane) : Table(BaseScreen.skin) {
init {
addButton("+") {
mapHolder.zoomIn()
}.padRight(10f)
addButton("") { // figure dash U+2013, not minus, looks better
mapHolder.zoomOut()
}
pack()
}
private fun addButton(text: String, action: () -> Unit): Cell<TextButton> {
val button = TextButton(text, skin)
button.label.setFontSize(30)
button.label.setAlignment(Align.center)
button.onClick(action)
return add(button)
}
}