From 01204f5aeebca6fda21f70bc547443f345fda653 Mon Sep 17 00:00:00 2001 From: vegeta1k95 <32207817+vegeta1k95@users.noreply.github.com> Date: Fri, 17 Feb 2023 01:12:32 +0100 Subject: [PATCH] Desktop: world camera autoscroll, selectable window mode (#8679) * Desktop: world camera autoscroll, selectable window mode * Map auto-scroll is optional * Fix option update, more scroll speed * Fix translation --------- Co-authored-by: vegeta1k95 --- .../jsons/translations/template.properties | 4 +++ core/src/com/unciv/UncivGame.kt | 1 + .../com/unciv/models/metadata/GameSettings.kt | 26 +++++++++++++++++ core/src/com/unciv/ui/options/DisplayTab.kt | 22 +++++++++++++++ .../com/unciv/ui/utils/ZoomableScrollPane.kt | 28 ++++++++++++++++++- .../com/unciv/ui/worldscreen/WorldScreen.kt | 3 ++ 6 files changed, 83 insertions(+), 1 deletion(-) diff --git a/android/assets/jsons/translations/template.properties b/android/assets/jsons/translations/template.properties index bbc191d7b7..bd7883bb6a 100644 --- a/android/assets/jsons/translations/template.properties +++ b/android/assets/jsons/translations/template.properties @@ -722,6 +722,7 @@ Automated workers replace improvements = Automated units move on turn start = Minimap size = off = +Map mouse auto-scroll = Show pixel units = Show pixel improvements = Enable Nuclear Weapons = @@ -1395,6 +1396,9 @@ Movement cost = for = Missing translations: = Screen Size = +Screen Window = +Windowed = +Fullscreen = Tileset = Unitset = UI Skin = diff --git a/core/src/com/unciv/UncivGame.kt b/core/src/com/unciv/UncivGame.kt index de1636e4c9..1d30482cd4 100644 --- a/core/src/com/unciv/UncivGame.kt +++ b/core/src/com/unciv/UncivGame.kt @@ -117,6 +117,7 @@ class UncivGame(parameters: UncivGameParameters) : Game() { * - Font (hence Fonts.resetFont() inside setSkin()) */ settings = files.getGeneralSettings() // needed for the screen + settings.refreshScreenMode() setAsRootScreen(GameStartScreen()) // NOT dependent on any atlas or skin GameSounds.init() diff --git a/core/src/com/unciv/models/metadata/GameSettings.kt b/core/src/com/unciv/models/metadata/GameSettings.kt index 4aca63f4fd..93a227691d 100644 --- a/core/src/com/unciv/models/metadata/GameSettings.kt +++ b/core/src/com/unciv/models/metadata/GameSettings.kt @@ -23,7 +23,14 @@ enum class ScreenSize(val virtualWidth:Float, val virtualHeight:Float){ Huge(1500f,1000f) } +enum class ScreenWindow { + Windowed, + Fullscreen +} + class GameSettings { + + var mapAutoScroll: Boolean = false var showWorkedTiles: Boolean = false var showResourcesAndImprovements: Boolean = true var showTileYields: Boolean = false @@ -38,6 +45,7 @@ class GameSettings { @Deprecated("Since 4.3.6 - replaces with screenSize") var resolution: String = "900x600" var screenSize:ScreenSize = ScreenSize.Small + var screenWindow: ScreenWindow = ScreenWindow.Windowed var tutorialsShown = HashSet() var tutorialTasksCompleted = HashSet() @@ -140,6 +148,24 @@ class GameSettings { fun getCollatorFromLocale(): Collator { return Collator.getInstance(getCurrentLocale()) } + + fun refreshScreenMode() { + + if (Gdx.app.type != Application.ApplicationType.Desktop) + return + + when (screenWindow) { + ScreenWindow.Windowed -> { + val mode = Gdx.graphics.displayMode + Gdx.graphics.setUndecorated(false) + Gdx.graphics.setWindowedMode(mode.width, mode.height) + } + + ScreenWindow.Fullscreen -> { + Gdx.graphics.setFullscreenMode(Gdx.graphics.displayMode) + } + } + } } enum class LocaleCode(var language: String, var country: String) { diff --git a/core/src/com/unciv/ui/options/DisplayTab.kt b/core/src/com/unciv/ui/options/DisplayTab.kt index 088c21d997..392ab629df 100644 --- a/core/src/com/unciv/ui/options/DisplayTab.kt +++ b/core/src/com/unciv/ui/options/DisplayTab.kt @@ -1,5 +1,6 @@ package com.unciv.ui.options +import com.badlogic.gdx.Application import com.badlogic.gdx.Gdx import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.scenes.scene2d.ui.SelectBox @@ -8,6 +9,7 @@ import com.badlogic.gdx.utils.Array import com.unciv.UncivGame import com.unciv.models.metadata.GameSettings import com.unciv.models.metadata.ScreenSize +import com.unciv.models.metadata.ScreenWindow import com.unciv.models.skins.SkinCache import com.unciv.models.tilesets.TileSetCache import com.unciv.models.translations.tr @@ -34,6 +36,14 @@ fun displayTab( val settings = optionsPopup.settings + if (Gdx.app.type == Application.ApplicationType.Desktop) { + addFullscreenSelectBox(this, settings, optionsPopup.selectBoxMinWidth) + optionsPopup.addCheckbox(this, "Map mouse auto-scroll", settings.mapAutoScroll, true) { + UncivGame.Current.worldScreen?.mapHolder?.isAutoScrollEnabled = it + settings.mapAutoScroll = it + } + } + optionsPopup.addCheckbox(this, "Show unit movement arrows", settings.showUnitMovements, true) { settings.showUnitMovements = it } optionsPopup.addCheckbox(this, "Show tile yields", settings.showTileYields, true) { settings.showTileYields = it } // JN optionsPopup.addCheckbox(this, "Show worked tiles", settings.showWorkedTiles, true) { settings.showWorkedTiles = it } @@ -128,6 +138,18 @@ private fun addUnitIconAlphaSlider(table: Table, settings: GameSettings, selectB table.add(unitIconAlphaSlider).minWidth(selectBoxMinWidth).pad(10f).row() } +private fun addFullscreenSelectBox(table: Table, settings: GameSettings, selectBoxMinWidth: Float) { + table.add("Screen Window".toLabel()).left().fillX() + + val screenSizeSelectBox = TranslatedSelectBox(ScreenWindow.values().map { it.name }, settings.screenWindow.name,table.skin) + table.add(screenSizeSelectBox).minWidth(selectBoxMinWidth).pad(10f).row() + + screenSizeSelectBox.onChange { + settings.screenWindow = ScreenWindow.valueOf(screenSizeSelectBox.selected.value) + settings.refreshScreenMode() + } +} + private fun addScreenSizeSelectBox(table: Table, settings: GameSettings, selectBoxMinWidth: Float, onResolutionChange: () -> Unit) { table.add("Screen Size".toLabel()).left().fillX() diff --git a/core/src/com/unciv/ui/utils/ZoomableScrollPane.kt b/core/src/com/unciv/ui/utils/ZoomableScrollPane.kt index 0c56bd317f..2203134b91 100644 --- a/core/src/com/unciv/ui/utils/ZoomableScrollPane.kt +++ b/core/src/com/unciv/ui/utils/ZoomableScrollPane.kt @@ -1,5 +1,7 @@ package com.unciv.ui.utils +import com.badlogic.gdx.Gdx +import com.badlogic.gdx.graphics.g2d.Batch import com.badlogic.gdx.math.Interpolation import com.badlogic.gdx.math.MathUtils import com.badlogic.gdx.math.Rectangle @@ -37,6 +39,8 @@ open class ZoomableScrollPane( private val horizontalPadding get() = width / 2 private val verticalPadding get() = height / 2 + var isAutoScrollEnabled = false + init { this.addListener(zoomListener) } @@ -266,6 +270,29 @@ open class ZoomableScrollPane( } } + override fun draw(batch: Batch?, parentAlpha: Float) { + if (isAutoScrollEnabled && !Gdx.input.isTouched) { + + val posX = Gdx.input.x + val posY = Gdx.input.y + + if (posX <= 2f) { + scrollX -= 3f + } else if (posX >= stage.viewport.screenWidth - 2f) { + scrollX += 3f + } + + if (posY <= 6f) { + scrollY -= 3f + } else if (posY >= stage.viewport.screenHeight - 6f) { + scrollY += 3f + } + + updateVisualScroll() + } + super.draw(batch, parentAlpha) + } + inner class FlickScrollListener : ActorGestureListener() { private var isPanning = false override fun pan(event: InputEvent, x: Float, y: Float, deltaX: Float, deltaY: Float) { @@ -277,7 +304,6 @@ open class ZoomableScrollPane( scrollX -= deltaX scrollY += deltaY - //this is the new feature to fake an infinite scroll when { continuousScrollingX && scrollPercentX >= 1 && deltaX < 0 -> { scrollPercentX = 0f diff --git a/core/src/com/unciv/ui/worldscreen/WorldScreen.kt b/core/src/com/unciv/ui/worldscreen/WorldScreen.kt index 6a8ea50a38..d4efd9e9ab 100644 --- a/core/src/com/unciv/ui/worldscreen/WorldScreen.kt +++ b/core/src/com/unciv/ui/worldscreen/WorldScreen.kt @@ -1,5 +1,6 @@ package com.unciv.ui.worldscreen +import com.badlogic.gdx.Application import com.badlogic.gdx.Gdx import com.badlogic.gdx.Input import com.badlogic.gdx.graphics.Color @@ -178,6 +179,8 @@ class WorldScreen( else -> Vector2.Zero } + mapHolder.isAutoScrollEnabled = Gdx.app.type == Application.ApplicationType.Desktop && game.settings.mapAutoScroll + // Don't select unit and change selectedCiv when centering as spectator if (viewingCiv.isSpectator()) mapHolder.setCenterPosition(tileToCenterOn, immediately = true, selectUnit = false)