mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-21 21:30:20 +07: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:
@ -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 =
|
||||
|
@ -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()
|
||||
|
||||
|
@ -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<String>()
|
||||
var tutorialTasksCompleted = HashSet<String>()
|
||||
|
||||
@ -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) {
|
||||
|
@ -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()
|
||||
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
Reference in New Issue
Block a user