diff --git a/android/build.gradle b/android/build.gradle index 38ee34e8a6..37cf80d0e0 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -21,8 +21,8 @@ android { applicationId "com.unciv.app" minSdkVersion 14 targetSdkVersion 28 - versionCode 198 - versionName "2.12.5" + versionCode 199 + versionName "2.13.0" } // Had to add this crap for Travis to build, it wanted to sign the app diff --git a/core/src/com/unciv/GameStarter.kt b/core/src/com/unciv/GameStarter.kt index 898b98e7fe..db2aa052d1 100644 --- a/core/src/com/unciv/GameStarter.kt +++ b/core/src/com/unciv/GameStarter.kt @@ -20,6 +20,7 @@ class GameParameters{ var humanNations=ArrayList().apply { add("Babylon") } var numberOfEnemies=3 var mapType= MapType.Perlin + var mapFileName :String?=null } class GameStarter{ @@ -27,7 +28,7 @@ class GameStarter{ val gameInfo = GameInfo() gameInfo.gameParameters = newGameParameters - gameInfo.tileMap = TileMap(newGameParameters.mapRadius, newGameParameters.mapType) + gameInfo.tileMap = TileMap(newGameParameters) gameInfo.tileMap.gameInfo = gameInfo // need to set this transient before placing units in the map val startingLocations = getStartingLocations( newGameParameters.numberOfEnemies+newGameParameters.numberOfHumanPlayers, gameInfo.tileMap) diff --git a/core/src/com/unciv/logic/GameSaver.kt b/core/src/com/unciv/logic/GameSaver.kt index 927d0d570c..8f6cc87d1e 100644 --- a/core/src/com/unciv/logic/GameSaver.kt +++ b/core/src/com/unciv/logic/GameSaver.kt @@ -22,6 +22,8 @@ class GameSaver { val unzippedJson = Gzip.unzip(gzippedString) return json().fromJson(TileMap::class.java, unzippedJson) } + fun getMaps() = Gdx.files.local(mapsFolder).list().map { it.name() } + fun getSave(GameName: String): FileHandle { return Gdx.files.local("$saveFilesFolder/$GameName") diff --git a/core/src/com/unciv/logic/map/TileMap.kt b/core/src/com/unciv/logic/map/TileMap.kt index 361e97abb4..f67616599c 100644 --- a/core/src/com/unciv/logic/map/TileMap.kt +++ b/core/src/com/unciv/logic/map/TileMap.kt @@ -1,6 +1,7 @@ package com.unciv.logic.map import com.badlogic.gdx.math.Vector2 +import com.unciv.GameParameters import com.unciv.logic.GameInfo import com.unciv.logic.GameSaver import com.unciv.logic.HexMath @@ -31,15 +32,15 @@ class TileMap { get() = tileList - constructor(distance: Int, mapType: MapType) { + constructor(newGameParameters: GameParameters) { val mapValues:Collection - if(mapType == MapType.File) - mapValues = GameSaver().loadMap("Test").values - else if(mapType==MapType.Perlin) - mapValues = PerlinNoiseRandomMapGenerator().generateMap(distance).values + if(newGameParameters.mapType == MapType.File) + mapValues = GameSaver().loadMap(newGameParameters.mapFileName!!).values + else if(newGameParameters.mapType==MapType.Perlin) + mapValues = PerlinNoiseRandomMapGenerator().generateMap(newGameParameters.mapRadius).values else - mapValues = CelluarAutomataRandomMapGenerator(mapType).generateMap(distance).values + mapValues = CelluarAutomataRandomMapGenerator(newGameParameters.mapType).generateMap(newGameParameters.mapRadius).values tileList.addAll(mapValues) // tileList.addAll(AlexanderRandomMapGenerator().generateMap(distance,0.8f).values) diff --git a/core/src/com/unciv/ui/MapEditorScreen.kt b/core/src/com/unciv/ui/MapEditorScreen.kt index 6a47711c8f..e3fbc0a42d 100644 --- a/core/src/com/unciv/ui/MapEditorScreen.kt +++ b/core/src/com/unciv/ui/MapEditorScreen.kt @@ -2,30 +2,31 @@ package com.unciv.ui import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.scenes.scene2d.Actor -import com.badlogic.gdx.scenes.scene2d.ui.Image -import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane -import com.badlogic.gdx.scenes.scene2d.ui.Table -import com.badlogic.gdx.scenes.scene2d.ui.TextButton +import com.badlogic.gdx.scenes.scene2d.ui.* +import com.unciv.GameParameters import com.unciv.UnCivGame import com.unciv.logic.GameSaver -import com.unciv.logic.map.MapType import com.unciv.logic.map.TileMap import com.unciv.models.gamebasics.GameBasics import com.unciv.models.gamebasics.tile.Terrain import com.unciv.models.gamebasics.tile.TerrainType import com.unciv.models.gamebasics.tile.TileResource +import com.unciv.models.gamebasics.tr import com.unciv.ui.tilegroups.TileGroup import com.unciv.ui.utils.CameraStageBaseScreen import com.unciv.ui.utils.ImageGetter import com.unciv.ui.utils.center import com.unciv.ui.utils.onClick import com.unciv.ui.worldscreen.TileGroupMap +import com.unciv.ui.worldscreen.optionstable.PopupTable class MapEditorScreen: CameraStageBaseScreen(){ var clearTerrainFeature=false var selectedTerrain : Terrain?=null var clearResource=false var selectedResource:TileResource?=null + var tileMap = TileMap(GameParameters()) + var mapName = "My first map" fun clearSelection(){ clearTerrainFeature=false @@ -48,7 +49,6 @@ class MapEditorScreen: CameraStageBaseScreen(){ } init{ - val tileMap = TileMap(20, MapType.Default) val scrollPane = getMapHolder(tileMap) stage.addActor(scrollPane) @@ -56,10 +56,10 @@ class MapEditorScreen: CameraStageBaseScreen(){ val scrollTable = getTileEditorOptions() stage.addActor(scrollTable) - val saveMapButton = TextButton("Save map",skin) + + val saveMapButton = TextButton("Options".tr(),skin) saveMapButton.onClick { - GameSaver().saveMap("Test",tileMap) - UnCivGame.Current.setWorldScreen() + mapScreenOptionsTable(this) } stage.addActor(saveMapButton) } @@ -140,4 +140,25 @@ class MapEditorScreen: CameraStageBaseScreen(){ scrollTable.setPosition(0f, stage.height - scrollTable.height) return scrollTable } +} + +class mapScreenOptionsTable(mapEditorScreen: MapEditorScreen):PopupTable(mapEditorScreen){ + init{ + val mapNameEditor = TextField(mapEditorScreen.mapName, CameraStageBaseScreen.skin) + mapNameEditor.addListener{ mapEditorScreen.mapName=mapNameEditor.text; true } + add(mapNameEditor).row() + + val saveMapButton = TextButton("Save".tr(), CameraStageBaseScreen.skin) + saveMapButton.onClick { + GameSaver().saveMap(mapEditorScreen.mapName,mapEditorScreen.tileMap) + UnCivGame.Current.setWorldScreen() + } + add(saveMapButton).row() + + val closeOptionsButtton = TextButton("Close".tr(), CameraStageBaseScreen.skin) + closeOptionsButtton.onClick { remove() } + add(closeOptionsButtton).row() + + open() + } } \ No newline at end of file diff --git a/core/src/com/unciv/ui/NewGameScreen.kt b/core/src/com/unciv/ui/NewGameScreen.kt index a8ae920020..d7f9b171d3 100644 --- a/core/src/com/unciv/ui/NewGameScreen.kt +++ b/core/src/com/unciv/ui/NewGameScreen.kt @@ -2,10 +2,7 @@ package com.unciv.ui import com.badlogic.gdx.Gdx import com.badlogic.gdx.scenes.scene2d.Actor -import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane -import com.badlogic.gdx.scenes.scene2d.ui.SelectBox -import com.badlogic.gdx.scenes.scene2d.ui.Skin -import com.badlogic.gdx.scenes.scene2d.ui.Table +import com.badlogic.gdx.scenes.scene2d.ui.* import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener import com.badlogic.gdx.utils.Array import com.unciv.GameStarter @@ -75,35 +72,46 @@ class NewGameScreen: PickerScreen(){ newGameOptionsTable.add("{Map type}:".tr()) val mapTypes = LinkedHashMap() for (type in MapType.values()) { - if(type==MapType.File && !GameSaver().getMap("Test").exists()) continue + if(type==MapType.File && GameSaver().getMaps().isEmpty()) continue mapTypes[type.toString()] = type } + + val mapFileLabel = Label("{Map file}:".tr(),skin) + val mapFileSelectBox = getMapFileSelectBox() + mapFileLabel.isVisible=false + mapFileSelectBox.isVisible=false + val mapTypeSelectBox = TranslatedSelectBox(mapTypes.keys, newGameParameters.mapType.toString(), skin) + + val worldSizeSelectBox = getWorldSizeSelectBox() + val worldSizeLabel = Label("{World size}:".tr(),skin) + mapTypeSelectBox.addListener(object : ChangeListener() { override fun changed(event: ChangeEvent?, actor: Actor?) { newGameParameters.mapType = mapTypes[mapTypeSelectBox.selected.value]!! + if (newGameParameters.mapType == MapType.File) { + worldSizeSelectBox.isVisible = false + worldSizeLabel.isVisible = false + mapFileSelectBox.isVisible = true + mapFileLabel.isVisible=true + newGameParameters.mapFileName = mapFileSelectBox.selected + } else { + worldSizeSelectBox.isVisible = true + worldSizeLabel.isVisible = true + mapFileSelectBox.isVisible = false + mapFileLabel.isVisible=false + newGameParameters.mapFileName = null + } } }) newGameOptionsTable.add(mapTypeSelectBox).pad(10f).row() - newGameOptionsTable.add("{World size}:".tr()) - val worldSizeToRadius = LinkedHashMap() - worldSizeToRadius["Tiny"] = 10 - worldSizeToRadius["Small"] = 15 - worldSizeToRadius["Medium"] = 20 - worldSizeToRadius["Large"] = 30 - worldSizeToRadius["Huge"] = 40 - val currentWorldSizeName = worldSizeToRadius.entries.first { it.value==newGameParameters.mapRadius }.key - val worldSizeSelectBox = TranslatedSelectBox(worldSizeToRadius.keys, currentWorldSizeName, skin) - - worldSizeSelectBox.addListener(object : ChangeListener() { - override fun changed(event: ChangeEvent?, actor: Actor?) { - newGameParameters.mapRadius = worldSizeToRadius[worldSizeSelectBox.selected.value]!! - } - }) + newGameOptionsTable.add(worldSizeLabel) newGameOptionsTable.add(worldSizeSelectBox).pad(10f).row() + newGameOptionsTable.add(mapFileLabel) + newGameOptionsTable.add(mapFileSelectBox).pad(10f).row() newGameOptionsTable.add("{Number of human players}:".tr()) @@ -168,6 +176,39 @@ class NewGameScreen: PickerScreen(){ return newGameOptionsTable } + private fun getMapFileSelectBox(): SelectBox { + val mapFileSelectBox = SelectBox(skin) + val mapNames = Array() + for (mapName in GameSaver().getMaps()) mapNames.add(mapName) + mapFileSelectBox.items = mapNames + + mapFileSelectBox.addListener(object : ChangeListener() { + override fun changed(event: ChangeEvent?, actor: Actor?) { + newGameParameters.mapFileName = mapFileSelectBox.selected!! + } + }) + return mapFileSelectBox + } + + private fun getWorldSizeSelectBox(): TranslatedSelectBox { + val worldSizeToRadius = LinkedHashMap() + worldSizeToRadius["Tiny"] = 10 + worldSizeToRadius["Small"] = 15 + worldSizeToRadius["Medium"] = 20 + worldSizeToRadius["Large"] = 30 + worldSizeToRadius["Huge"] = 40 + + val currentWorldSizeName = worldSizeToRadius.entries.first { it.value == newGameParameters.mapRadius }.key + val worldSizeSelectBox = TranslatedSelectBox(worldSizeToRadius.keys, currentWorldSizeName, skin) + + worldSizeSelectBox.addListener(object : ChangeListener() { + override fun changed(event: ChangeEvent?, actor: Actor?) { + newGameParameters.mapRadius = worldSizeToRadius[worldSizeSelectBox.selected.value]!! + } + }) + return worldSizeSelectBox + } + var newGame:GameInfo?=null override fun render(delta: Float) { @@ -190,7 +231,8 @@ class TranslatedSelectBox(values : Collection, default:String, skin: Ski val array = Array() values.forEach{array.add(TranslatedString(it))} items = array - selected = array.first { it.value==default } + val defaultItem = array.firstOrNull { it.value==default } + selected = if(defaultItem!=null) defaultItem else array.first() } }