mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-27 05:46:43 -04:00
Make max Zoom out a setting and fix a merge mistake (#6420)
This commit is contained in:
parent
f9b34fd40d
commit
e8ab73df98
@ -70,6 +70,9 @@ class GameSettings {
|
|||||||
|
|
||||||
var fontFamily: String = Fonts.DEFAULT_FONT_FAMILY
|
var fontFamily: String = Fonts.DEFAULT_FONT_FAMILY
|
||||||
|
|
||||||
|
/** Maximum zoom-out of the map - performance heavy */
|
||||||
|
var maxWorldZoomOut = 2f
|
||||||
|
|
||||||
init {
|
init {
|
||||||
// 26 = Android Oreo. Versions below may display permanent icon in notification bar.
|
// 26 = Android Oreo. Versions below may display permanent icon in notification bar.
|
||||||
if (Gdx.app?.type == Application.ApplicationType.Android && Gdx.app.version < 26) {
|
if (Gdx.app?.type == Application.ApplicationType.Android && Gdx.app.version < 26) {
|
||||||
@ -115,9 +118,9 @@ class GameSettings {
|
|||||||
*
|
*
|
||||||
* @param base Path to the directory where the file should be - if not set, the OS current directory is used (which is "/" on Android)
|
* @param base Path to the directory where the file should be - if not set, the OS current directory is used (which is "/" on Android)
|
||||||
*/
|
*/
|
||||||
fun getSettingsForPlatformLaunchers(base: String = ""): GameSettings {
|
fun getSettingsForPlatformLaunchers(base: String = "."): GameSettings {
|
||||||
// FileHandle is Gdx, but the class and JsonParser are not dependent on app initialization
|
// FileHandle is Gdx, but the class and JsonParser are not dependent on app initialization
|
||||||
// If fact, at this point Gdx.app or Gdx.files are null but this still works.
|
// In fact, at this point Gdx.app or Gdx.files are null but this still works.
|
||||||
val file = FileHandle(base + File.separator + GameSaver.settingsFileName)
|
val file = FileHandle(base + File.separator + GameSaver.settingsFileName)
|
||||||
return if (file.exists())
|
return if (file.exists())
|
||||||
JsonParser().getFromJson(
|
JsonParser().getFromJson(
|
||||||
|
@ -15,7 +15,7 @@ open class ZoomableScrollPane: ScrollPane(null) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
open fun zoom(zoomScale: Float) {
|
open fun zoom(zoomScale: Float) {
|
||||||
if (zoomScale < 0.25f || zoomScale > 2f) return
|
if (zoomScale < 0.5f || zoomScale > 2f) return
|
||||||
setScale(zoomScale)
|
setScale(zoomScale)
|
||||||
}
|
}
|
||||||
fun zoomIn() {
|
fun zoomIn() {
|
||||||
|
@ -30,8 +30,6 @@ import com.unciv.ui.tilegroups.TileGroup
|
|||||||
import com.unciv.ui.tilegroups.TileSetStrings
|
import com.unciv.ui.tilegroups.TileSetStrings
|
||||||
import com.unciv.ui.tilegroups.WorldTileGroup
|
import com.unciv.ui.tilegroups.WorldTileGroup
|
||||||
import com.unciv.ui.utils.*
|
import com.unciv.ui.utils.*
|
||||||
//import com.unciv.ui.worldscreen.unit.UnitMovementsOverlayGroup
|
|
||||||
import kotlin.concurrent.thread
|
|
||||||
|
|
||||||
|
|
||||||
class WorldMapHolder(internal val worldScreen: WorldScreen, internal val tileMap: TileMap): ZoomableScrollPane() {
|
class WorldMapHolder(internal val worldScreen: WorldScreen, internal val tileMap: TileMap): ZoomableScrollPane() {
|
||||||
@ -47,9 +45,19 @@ class WorldMapHolder(internal val worldScreen: WorldScreen, internal val tileMap
|
|||||||
|
|
||||||
private val unitMovementPaths: HashMap<MapUnit, ArrayList<TileInfo>> = HashMap()
|
private val unitMovementPaths: HashMap<MapUnit, ArrayList<TileInfo>> = HashMap()
|
||||||
|
|
||||||
|
private var maxWorldZoomOut = 2f
|
||||||
|
private var minZoomScale = 0.5f
|
||||||
|
|
||||||
init {
|
init {
|
||||||
if (Gdx.app.type == Application.ApplicationType.Desktop) this.setFlingTime(0f)
|
if (Gdx.app.type == Application.ApplicationType.Desktop) this.setFlingTime(0f)
|
||||||
continuousScrollingX = tileMap.mapParameters.worldWrap
|
continuousScrollingX = tileMap.mapParameters.worldWrap
|
||||||
|
reloadMaxZoom()
|
||||||
|
}
|
||||||
|
|
||||||
|
internal fun reloadMaxZoom() {
|
||||||
|
maxWorldZoomOut = UncivGame.Current.settings.maxWorldZoomOut
|
||||||
|
minZoomScale = 1f / maxWorldZoomOut
|
||||||
|
if (scaleX < minZoomScale) zoom(1f) // since normally min isn't reached exactly, only powers of 0.8
|
||||||
}
|
}
|
||||||
|
|
||||||
// Interface for classes that contain the data required to draw a button
|
// Interface for classes that contain the data required to draw a button
|
||||||
@ -62,7 +70,11 @@ class WorldMapHolder(internal val worldScreen: WorldScreen, internal val tileMap
|
|||||||
internal fun addTiles() {
|
internal fun addTiles() {
|
||||||
val tileSetStrings = TileSetStrings()
|
val tileSetStrings = TileSetStrings()
|
||||||
val daTileGroups = tileMap.values.map { WorldTileGroup(worldScreen, it, tileSetStrings) }
|
val daTileGroups = tileMap.values.map { WorldTileGroup(worldScreen, it, tileSetStrings) }
|
||||||
val tileGroupMap = TileGroupMap(daTileGroups, worldScreen.stage.width, worldScreen.stage.height, continuousScrollingX)
|
val tileGroupMap = TileGroupMap(
|
||||||
|
daTileGroups,
|
||||||
|
worldScreen.stage.width * maxWorldZoomOut / 2,
|
||||||
|
worldScreen.stage.height * maxWorldZoomOut / 2,
|
||||||
|
continuousScrollingX)
|
||||||
val mirrorTileGroups = tileGroupMap.getMirrorTiles()
|
val mirrorTileGroups = tileGroupMap.getMirrorTiles()
|
||||||
|
|
||||||
for (tileGroup in daTileGroups) {
|
for (tileGroup in daTileGroups) {
|
||||||
@ -130,7 +142,7 @@ class WorldMapHolder(internal val worldScreen: WorldScreen, internal val tileMap
|
|||||||
|
|
||||||
actor = tileGroupMap
|
actor = tileGroupMap
|
||||||
|
|
||||||
setSize(worldScreen.stage.width * 2, worldScreen.stage.height * 2)
|
setSize(worldScreen.stage.width * maxWorldZoomOut, worldScreen.stage.height * maxWorldZoomOut)
|
||||||
setOrigin(width / 2, height / 2)
|
setOrigin(width / 2, height / 2)
|
||||||
center(worldScreen.stage)
|
center(worldScreen.stage)
|
||||||
|
|
||||||
@ -702,12 +714,13 @@ class WorldMapHolder(internal val worldScreen: WorldScreen, internal val tileMap
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun zoom(zoomScale: Float) {
|
override fun zoom(zoomScale: Float) {
|
||||||
super.zoom(zoomScale)
|
if (zoomScale < minZoomScale || zoomScale > 2f) return
|
||||||
|
setScale(zoomScale)
|
||||||
val scale = 1 / scaleX // don't use zoomScale itself, in case it was out of bounds and not applied
|
val scale = 1 / scaleX // don't use zoomScale itself, in case it was out of bounds and not applied
|
||||||
if (scale >= 1)
|
if (scale >= 1)
|
||||||
for (tileGroup in allWorldTileGroups)
|
for (tileGroup in allWorldTileGroups)
|
||||||
tileGroup.cityButtonLayerGroup.isTransform = false // to save on rendering time to improve framerate
|
tileGroup.cityButtonLayerGroup.isTransform = false // to save on rendering time to improve framerate
|
||||||
if (scale < 1 && scale > 0.5f)
|
if (scale < 1 && scale >= minZoomScale)
|
||||||
for (tileGroup in allWorldTileGroups) {
|
for (tileGroup in allWorldTileGroups) {
|
||||||
// ONLY set those groups that have active city buttons as transformable!
|
// ONLY set those groups that have active city buttons as transformable!
|
||||||
// This is massively framerate-improving!
|
// This is massively framerate-improving!
|
||||||
|
@ -713,6 +713,7 @@ class WorldScreen(val gameInfo: GameInfo, val viewingCiv:CivilizationInfo) : Bas
|
|||||||
* to re-enable the next turn button within its Close button action
|
* to re-enable the next turn button within its Close button action
|
||||||
*/
|
*/
|
||||||
fun enableNextTurnButtonAfterOptions() {
|
fun enableNextTurnButtonAfterOptions() {
|
||||||
|
mapHolder.reloadMaxZoom()
|
||||||
nextTurnButton.isEnabled = isPlayersTurn && !waitingForAutosave
|
nextTurnButton.isEnabled = isPlayersTurn && !waitingForAutosave
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,7 +4,6 @@ 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.Net
|
import com.badlogic.gdx.Net
|
||||||
import com.badlogic.gdx.Net.HttpResponseListener
|
|
||||||
import com.badlogic.gdx.graphics.Color
|
import com.badlogic.gdx.graphics.Color
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.Label
|
import com.badlogic.gdx.scenes.scene2d.ui.Label
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.SelectBox
|
import com.badlogic.gdx.scenes.scene2d.ui.SelectBox
|
||||||
@ -16,7 +15,6 @@ import com.unciv.MainMenuScreen
|
|||||||
import com.unciv.UncivGame
|
import com.unciv.UncivGame
|
||||||
import com.unciv.logic.MapSaver
|
import com.unciv.logic.MapSaver
|
||||||
import com.unciv.logic.civilization.PlayerType
|
import com.unciv.logic.civilization.PlayerType
|
||||||
import com.unciv.logic.multiplayer.FileStorageConflictException
|
|
||||||
import com.unciv.models.UncivSound
|
import com.unciv.models.UncivSound
|
||||||
import com.unciv.models.ruleset.Ruleset
|
import com.unciv.models.ruleset.Ruleset
|
||||||
import com.unciv.models.ruleset.Ruleset.RulesetError
|
import com.unciv.models.ruleset.Ruleset.RulesetError
|
||||||
@ -38,7 +36,6 @@ import com.unciv.ui.utils.UncivTooltip.Companion.addTooltip
|
|||||||
import com.unciv.ui.worldscreen.WorldScreen
|
import com.unciv.ui.worldscreen.WorldScreen
|
||||||
import java.io.BufferedReader
|
import java.io.BufferedReader
|
||||||
import java.io.DataOutputStream
|
import java.io.DataOutputStream
|
||||||
import java.io.FileNotFoundException
|
|
||||||
import java.io.InputStreamReader
|
import java.io.InputStreamReader
|
||||||
import java.net.DatagramSocket
|
import java.net.DatagramSocket
|
||||||
import java.net.HttpURLConnection
|
import java.net.HttpURLConnection
|
||||||
@ -62,6 +59,7 @@ class OptionsPopup(val previousScreen: BaseScreen) : Popup(previousScreen) {
|
|||||||
private var modCheckBaseSelect: TranslatedSelectBox? = null
|
private var modCheckBaseSelect: TranslatedSelectBox? = null
|
||||||
private val modCheckResultTable = Table()
|
private val modCheckResultTable = Table()
|
||||||
private val selectBoxMinWidth: Float
|
private val selectBoxMinWidth: Float
|
||||||
|
private val previousMaxWorldZoom = settings.maxWorldZoomOut
|
||||||
|
|
||||||
//endregion
|
//endregion
|
||||||
|
|
||||||
@ -306,7 +304,7 @@ class OptionsPopup(val previousScreen: BaseScreen) : Popup(previousScreen) {
|
|||||||
fun getIpAddress(): String? {
|
fun getIpAddress(): String? {
|
||||||
DatagramSocket().use { socket ->
|
DatagramSocket().use { socket ->
|
||||||
socket.connect(InetAddress.getByName("8.8.8.8"), 10002)
|
socket.connect(InetAddress.getByName("8.8.8.8"), 10002)
|
||||||
return socket.getLocalAddress().getHostAddress()
|
return socket.localAddress.hostAddress
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -322,7 +320,7 @@ class OptionsPopup(val previousScreen: BaseScreen) : Popup(previousScreen) {
|
|||||||
doOutput = true
|
doOutput = true
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (content != "") {
|
if (content.isNotEmpty()) {
|
||||||
// StandardCharsets.UTF_8 requires API 19
|
// StandardCharsets.UTF_8 requires API 19
|
||||||
val postData: ByteArray = content.toByteArray(Charset.forName("UTF-8"))
|
val postData: ByteArray = content.toByteArray(Charset.forName("UTF-8"))
|
||||||
val outputStream = DataOutputStream(outputStream)
|
val outputStream = DataOutputStream(outputStream)
|
||||||
@ -345,7 +343,7 @@ class OptionsPopup(val previousScreen: BaseScreen) : Popup(previousScreen) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun successfullyConnectedToServer(action: (Boolean, String)->Unit){
|
private fun successfullyConnectedToServer(action: (Boolean, String)->Unit){
|
||||||
SimpleHttp.sendGetRequest( "http://"+ settings.multiplayerServer+":8080/isalive", action)
|
SimpleHttp.sendGetRequest( "http://"+ settings.multiplayerServer+":8080/isalive", action)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -360,6 +358,8 @@ class OptionsPopup(val previousScreen: BaseScreen) : Popup(previousScreen) {
|
|||||||
settings.showExperimentalWorldWrap = it
|
settings.showExperimentalWorldWrap = it
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addMaxZoomSlider()
|
||||||
|
|
||||||
if (previousScreen.game.limitOrientationsHelper != null) {
|
if (previousScreen.game.limitOrientationsHelper != null) {
|
||||||
addCheckbox("Enable portrait orientation", settings.allowAndroidPortrait) {
|
addCheckbox("Enable portrait orientation", settings.allowAndroidPortrait) {
|
||||||
settings.allowAndroidPortrait = it
|
settings.allowAndroidPortrait = it
|
||||||
@ -881,6 +881,17 @@ class OptionsPopup(val previousScreen: BaseScreen) : Popup(previousScreen) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun Table.addMaxZoomSlider() {
|
||||||
|
add("Max zoom out".tr()).left().fillX()
|
||||||
|
val maxZoomSlider = UncivSlider(2f, 6f, 1f,
|
||||||
|
initial = settings.maxWorldZoomOut
|
||||||
|
) {
|
||||||
|
settings.maxWorldZoomOut = it
|
||||||
|
settings.save()
|
||||||
|
}
|
||||||
|
add(maxZoomSlider).pad(5f).row()
|
||||||
|
}
|
||||||
|
|
||||||
private fun Table.addFontFamilySelect(fonts: Collection<FontData>) {
|
private fun Table.addFontFamilySelect(fonts: Collection<FontData>) {
|
||||||
if (fonts.isEmpty()) return
|
if (fonts.isEmpty()) return
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user