mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-22 19:08:48 -04:00
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 <vfylfhby>
This commit is contained in:
parent
7114a67d2c
commit
01204f5aee
@ -722,6 +722,7 @@ Automated workers replace improvements =
|
|||||||
Automated units move on turn start =
|
Automated units move on turn start =
|
||||||
Minimap size =
|
Minimap size =
|
||||||
off =
|
off =
|
||||||
|
Map mouse auto-scroll =
|
||||||
Show pixel units =
|
Show pixel units =
|
||||||
Show pixel improvements =
|
Show pixel improvements =
|
||||||
Enable Nuclear Weapons =
|
Enable Nuclear Weapons =
|
||||||
@ -1395,6 +1396,9 @@ Movement cost =
|
|||||||
for =
|
for =
|
||||||
Missing translations: =
|
Missing translations: =
|
||||||
Screen Size =
|
Screen Size =
|
||||||
|
Screen Window =
|
||||||
|
Windowed =
|
||||||
|
Fullscreen =
|
||||||
Tileset =
|
Tileset =
|
||||||
Unitset =
|
Unitset =
|
||||||
UI Skin =
|
UI Skin =
|
||||||
|
@ -117,6 +117,7 @@ class UncivGame(parameters: UncivGameParameters) : Game() {
|
|||||||
* - Font (hence Fonts.resetFont() inside setSkin())
|
* - Font (hence Fonts.resetFont() inside setSkin())
|
||||||
*/
|
*/
|
||||||
settings = files.getGeneralSettings() // needed for the screen
|
settings = files.getGeneralSettings() // needed for the screen
|
||||||
|
settings.refreshScreenMode()
|
||||||
setAsRootScreen(GameStartScreen()) // NOT dependent on any atlas or skin
|
setAsRootScreen(GameStartScreen()) // NOT dependent on any atlas or skin
|
||||||
GameSounds.init()
|
GameSounds.init()
|
||||||
|
|
||||||
|
@ -23,7 +23,14 @@ enum class ScreenSize(val virtualWidth:Float, val virtualHeight:Float){
|
|||||||
Huge(1500f,1000f)
|
Huge(1500f,1000f)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum class ScreenWindow {
|
||||||
|
Windowed,
|
||||||
|
Fullscreen
|
||||||
|
}
|
||||||
|
|
||||||
class GameSettings {
|
class GameSettings {
|
||||||
|
|
||||||
|
var mapAutoScroll: Boolean = false
|
||||||
var showWorkedTiles: Boolean = false
|
var showWorkedTiles: Boolean = false
|
||||||
var showResourcesAndImprovements: Boolean = true
|
var showResourcesAndImprovements: Boolean = true
|
||||||
var showTileYields: Boolean = false
|
var showTileYields: Boolean = false
|
||||||
@ -38,6 +45,7 @@ class GameSettings {
|
|||||||
@Deprecated("Since 4.3.6 - replaces with screenSize")
|
@Deprecated("Since 4.3.6 - replaces with screenSize")
|
||||||
var resolution: String = "900x600"
|
var resolution: String = "900x600"
|
||||||
var screenSize:ScreenSize = ScreenSize.Small
|
var screenSize:ScreenSize = ScreenSize.Small
|
||||||
|
var screenWindow: ScreenWindow = ScreenWindow.Windowed
|
||||||
var tutorialsShown = HashSet<String>()
|
var tutorialsShown = HashSet<String>()
|
||||||
var tutorialTasksCompleted = HashSet<String>()
|
var tutorialTasksCompleted = HashSet<String>()
|
||||||
|
|
||||||
@ -140,6 +148,24 @@ class GameSettings {
|
|||||||
fun getCollatorFromLocale(): Collator {
|
fun getCollatorFromLocale(): Collator {
|
||||||
return Collator.getInstance(getCurrentLocale())
|
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) {
|
enum class LocaleCode(var language: String, var country: String) {
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.unciv.ui.options
|
package com.unciv.ui.options
|
||||||
|
|
||||||
|
import com.badlogic.gdx.Application
|
||||||
import com.badlogic.gdx.Gdx
|
import com.badlogic.gdx.Gdx
|
||||||
import com.badlogic.gdx.graphics.Color
|
import com.badlogic.gdx.graphics.Color
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.SelectBox
|
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.UncivGame
|
||||||
import com.unciv.models.metadata.GameSettings
|
import com.unciv.models.metadata.GameSettings
|
||||||
import com.unciv.models.metadata.ScreenSize
|
import com.unciv.models.metadata.ScreenSize
|
||||||
|
import com.unciv.models.metadata.ScreenWindow
|
||||||
import com.unciv.models.skins.SkinCache
|
import com.unciv.models.skins.SkinCache
|
||||||
import com.unciv.models.tilesets.TileSetCache
|
import com.unciv.models.tilesets.TileSetCache
|
||||||
import com.unciv.models.translations.tr
|
import com.unciv.models.translations.tr
|
||||||
@ -34,6 +36,14 @@ fun displayTab(
|
|||||||
|
|
||||||
val settings = optionsPopup.settings
|
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 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 tile yields", settings.showTileYields, true) { settings.showTileYields = it } // JN
|
||||||
optionsPopup.addCheckbox(this, "Show worked tiles", settings.showWorkedTiles, true) { settings.showWorkedTiles = it }
|
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()
|
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) {
|
private fun addScreenSizeSelectBox(table: Table, settings: GameSettings, selectBoxMinWidth: Float, onResolutionChange: () -> Unit) {
|
||||||
table.add("Screen Size".toLabel()).left().fillX()
|
table.add("Screen Size".toLabel()).left().fillX()
|
||||||
|
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package com.unciv.ui.utils
|
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.Interpolation
|
||||||
import com.badlogic.gdx.math.MathUtils
|
import com.badlogic.gdx.math.MathUtils
|
||||||
import com.badlogic.gdx.math.Rectangle
|
import com.badlogic.gdx.math.Rectangle
|
||||||
@ -37,6 +39,8 @@ open class ZoomableScrollPane(
|
|||||||
private val horizontalPadding get() = width / 2
|
private val horizontalPadding get() = width / 2
|
||||||
private val verticalPadding get() = height / 2
|
private val verticalPadding get() = height / 2
|
||||||
|
|
||||||
|
var isAutoScrollEnabled = false
|
||||||
|
|
||||||
init {
|
init {
|
||||||
this.addListener(zoomListener)
|
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() {
|
inner class FlickScrollListener : ActorGestureListener() {
|
||||||
private var isPanning = false
|
private var isPanning = false
|
||||||
override fun pan(event: InputEvent, x: Float, y: Float, deltaX: Float, deltaY: Float) {
|
override fun pan(event: InputEvent, x: Float, y: Float, deltaX: Float, deltaY: Float) {
|
||||||
@ -277,7 +304,6 @@ open class ZoomableScrollPane(
|
|||||||
scrollX -= deltaX
|
scrollX -= deltaX
|
||||||
scrollY += deltaY
|
scrollY += deltaY
|
||||||
|
|
||||||
//this is the new feature to fake an infinite scroll
|
|
||||||
when {
|
when {
|
||||||
continuousScrollingX && scrollPercentX >= 1 && deltaX < 0 -> {
|
continuousScrollingX && scrollPercentX >= 1 && deltaX < 0 -> {
|
||||||
scrollPercentX = 0f
|
scrollPercentX = 0f
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.unciv.ui.worldscreen
|
package com.unciv.ui.worldscreen
|
||||||
|
|
||||||
|
import com.badlogic.gdx.Application
|
||||||
import com.badlogic.gdx.Gdx
|
import com.badlogic.gdx.Gdx
|
||||||
import com.badlogic.gdx.Input
|
import com.badlogic.gdx.Input
|
||||||
import com.badlogic.gdx.graphics.Color
|
import com.badlogic.gdx.graphics.Color
|
||||||
@ -178,6 +179,8 @@ class WorldScreen(
|
|||||||
else -> Vector2.Zero
|
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
|
// Don't select unit and change selectedCiv when centering as spectator
|
||||||
if (viewingCiv.isSpectator())
|
if (viewingCiv.isSpectator())
|
||||||
mapHolder.setCenterPosition(tileToCenterOn, immediately = true, selectUnit = false)
|
mapHolder.setCenterPosition(tileToCenterOn, immediately = true, selectUnit = false)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user