mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-15 02:09:21 +07:00
Map name field adjusted, map saving exceptions shouldn't crash, threaded (#2393)
* Map name field adjusted, map saving exceptions shouldn't crash, threaded * Map save: Deal with empty map name, name defaults to blank
This commit is contained in:
@ -12,6 +12,8 @@ import com.unciv.logic.map.RoadStatus
|
|||||||
import com.unciv.models.translations.tr
|
import com.unciv.models.translations.tr
|
||||||
import com.unciv.ui.saves.Gzip
|
import com.unciv.ui.saves.Gzip
|
||||||
import com.unciv.ui.utils.Popup
|
import com.unciv.ui.utils.Popup
|
||||||
|
import com.unciv.ui.utils.enable
|
||||||
|
import com.unciv.ui.utils.isEnabled
|
||||||
import com.unciv.ui.utils.onClick
|
import com.unciv.ui.utils.onClick
|
||||||
import com.unciv.ui.worldscreen.mainmenu.DropBox
|
import com.unciv.ui.worldscreen.mainmenu.DropBox
|
||||||
import kotlin.concurrent.thread
|
import kotlin.concurrent.thread
|
||||||
@ -19,8 +21,10 @@ import kotlin.concurrent.thread
|
|||||||
class MapEditorMenuPopup(mapEditorScreen: MapEditorScreen): Popup(mapEditorScreen){
|
class MapEditorMenuPopup(mapEditorScreen: MapEditorScreen): Popup(mapEditorScreen){
|
||||||
init{
|
init{
|
||||||
val mapNameEditor = TextField(mapEditorScreen.mapName, skin)
|
val mapNameEditor = TextField(mapEditorScreen.mapName, skin)
|
||||||
mapNameEditor.addListener{ mapEditorScreen.mapName=mapNameEditor.text; true }
|
add(mapNameEditor).fillX().row()
|
||||||
add(mapNameEditor).row()
|
mapNameEditor.selectAll()
|
||||||
|
mapNameEditor.maxLength = 240 // A few under max for most filesystems
|
||||||
|
mapEditorScreen.stage.keyboardFocus = mapNameEditor
|
||||||
|
|
||||||
val newMapButton = TextButton("New map".tr(),skin)
|
val newMapButton = TextButton("New map".tr(),skin)
|
||||||
newMapButton.onClick {
|
newMapButton.onClick {
|
||||||
@ -51,10 +55,28 @@ class MapEditorMenuPopup(mapEditorScreen: MapEditorScreen): Popup(mapEditorScree
|
|||||||
saveMapButton.onClick {
|
saveMapButton.onClick {
|
||||||
mapEditorScreen.tileMap.mapParameters.name=mapEditorScreen.mapName
|
mapEditorScreen.tileMap.mapParameters.name=mapEditorScreen.mapName
|
||||||
mapEditorScreen.tileMap.mapParameters.type=MapType.custom
|
mapEditorScreen.tileMap.mapParameters.type=MapType.custom
|
||||||
MapSaver.saveMap(mapEditorScreen.mapName,mapEditorScreen.tileMap)
|
thread ( name = "SaveMap" ) {
|
||||||
|
try {
|
||||||
|
MapSaver.saveMap(mapEditorScreen.mapName, mapEditorScreen.tileMap)
|
||||||
UncivGame.Current.setWorldScreen()
|
UncivGame.Current.setWorldScreen()
|
||||||
|
} catch (ex: Exception) {
|
||||||
|
ex.printStackTrace()
|
||||||
|
Gdx.app.postRunnable {
|
||||||
|
val cantLoadGamePopup = Popup(mapEditorScreen)
|
||||||
|
cantLoadGamePopup.addGoodSizedLabel("It looks like your map can't be saved!").row()
|
||||||
|
cantLoadGamePopup.addCloseButton()
|
||||||
|
cantLoadGamePopup.open(force = true)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
saveMapButton.isEnabled = mapNameEditor.text.isNotEmpty()
|
||||||
add(saveMapButton).row()
|
add(saveMapButton).row()
|
||||||
|
mapNameEditor.addListener {
|
||||||
|
mapEditorScreen.mapName = mapNameEditor.text
|
||||||
|
saveMapButton.isEnabled = mapNameEditor.text.isNotEmpty()
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
val copyMapAsTextButton = TextButton("Copy to clipboard".tr(), skin)
|
val copyMapAsTextButton = TextButton("Copy to clipboard".tr(), skin)
|
||||||
copyMapAsTextButton.onClick {
|
copyMapAsTextButton.onClick {
|
||||||
|
@ -18,7 +18,7 @@ import com.unciv.ui.utils.setFontSize
|
|||||||
|
|
||||||
class MapEditorScreen(): CameraStageBaseScreen() {
|
class MapEditorScreen(): CameraStageBaseScreen() {
|
||||||
val ruleset = RulesetCache.getBaseRuleset()
|
val ruleset = RulesetCache.getBaseRuleset()
|
||||||
var mapName = "My first map"
|
var mapName = ""
|
||||||
|
|
||||||
var tileMap = TileMap()
|
var tileMap = TileMap()
|
||||||
lateinit var mapHolder: EditorMapHolder
|
lateinit var mapHolder: EditorMapHolder
|
||||||
|
@ -113,7 +113,10 @@ fun Button.enable() {
|
|||||||
color = Color.WHITE
|
color = Color.WHITE
|
||||||
touchable = Touchable.enabled
|
touchable = Touchable.enabled
|
||||||
}
|
}
|
||||||
|
var Button.isEnabled: Boolean
|
||||||
|
//Todo: Use in PromotionPickerScreen, TradeTable, WorldScreen.updateNextTurnButton
|
||||||
|
get() = touchable == Touchable.enabled
|
||||||
|
set(value) = if (value) enable() else disable()
|
||||||
|
|
||||||
fun colorFromRGB(r: Int, g: Int, b: Int): Color {
|
fun colorFromRGB(r: Int, g: Int, b: Int): Color {
|
||||||
return Color(r/255f, g/255f, b/255f, 1f)
|
return Color(r/255f, g/255f, b/255f, 1f)
|
||||||
|
Reference in New Issue
Block a user