mirror of
https://github.com/yairm210/Unciv.git
synced 2025-03-09 20:29:50 +07:00
Map editor save / load / download keys (#4056)
This commit is contained in:
parent
11cbe1c84a
commit
dc8657dc02
@ -33,6 +33,7 @@ class MapDownloadPopup(loadMapScreen: SaveAndLoadMapScreen): Popup(loadMapScreen
|
|||||||
val listener = TextField.TextFieldListener{ textField: TextField, _: Char -> updateList(textField.text) }
|
val listener = TextField.TextFieldListener{ textField: TextField, _: Char -> updateList(textField.text) }
|
||||||
filter.setTextFieldListener(listener)
|
filter.setTextFieldListener(listener)
|
||||||
header.add(filter).row()
|
header.add(filter).row()
|
||||||
|
keyboardFocus = filter
|
||||||
header.addSeparator().row()
|
header.addSeparator().row()
|
||||||
pack()
|
pack()
|
||||||
}
|
}
|
||||||
@ -56,14 +57,18 @@ class MapDownloadPopup(loadMapScreen: SaveAndLoadMapScreen): Popup(loadMapScreen
|
|||||||
}
|
}
|
||||||
scrollableMapTable.add(downloadMapButton).row()
|
scrollableMapTable.add(downloadMapButton).row()
|
||||||
}
|
}
|
||||||
contentTable.add(ScrollPane(scrollableMapTable)).height(screen.stage.height * 2 / 3).row()
|
val scrollPane = ScrollPane(scrollableMapTable)
|
||||||
pack()
|
contentTable.add(scrollPane).height(screen.stage.height * 2 / 3).row()
|
||||||
close()
|
// the list is loaded and ready to be shown - remove "Loading..."
|
||||||
// the list is loaded and ready to be shown
|
innerTable.removeActor(loadingLabel)
|
||||||
removeActor(loadingLabel)
|
|
||||||
// create the header with a filter tool
|
// create the header with a filter tool
|
||||||
createHeader()
|
createHeader()
|
||||||
open()
|
pack()
|
||||||
|
center(screen.stage)
|
||||||
|
// Due to some jokers spamming very long names the content would end up way on the right
|
||||||
|
// scrollPane.scrollPercentX = 0.5f does _not_ work for this! That fun doesn't refer to the center.
|
||||||
|
// This will bounce in with visual effect, if undesired call updateVisualScroll()
|
||||||
|
scrollPane.scrollX = scrollPane.maxX / 2
|
||||||
}
|
}
|
||||||
} catch (ex: Exception) {
|
} catch (ex: Exception) {
|
||||||
Gdx.app.postRunnable { addGoodSizedLabel("Could not get list of maps!").row() }
|
Gdx.app.postRunnable { addGoodSizedLabel("Could not get list of maps!").row() }
|
||||||
|
@ -7,6 +7,7 @@ import com.badlogic.gdx.scenes.scene2d.ui.Table
|
|||||||
import com.badlogic.gdx.scenes.scene2d.ui.TextButton
|
import com.badlogic.gdx.scenes.scene2d.ui.TextButton
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.TextField
|
import com.badlogic.gdx.scenes.scene2d.ui.TextField
|
||||||
import com.badlogic.gdx.utils.Json
|
import com.badlogic.gdx.utils.Json
|
||||||
|
import com.badlogic.gdx.Input
|
||||||
import com.unciv.logic.MapSaver
|
import com.unciv.logic.MapSaver
|
||||||
import com.unciv.logic.map.MapType
|
import com.unciv.logic.map.MapType
|
||||||
import com.unciv.logic.map.TileMap
|
import com.unciv.logic.map.TileMap
|
||||||
@ -19,16 +20,17 @@ import com.unciv.ui.utils.AutoScrollPane as ScrollPane
|
|||||||
|
|
||||||
class SaveAndLoadMapScreen(mapToSave: TileMap?, save:Boolean = false, previousScreen: CameraStageBaseScreen)
|
class SaveAndLoadMapScreen(mapToSave: TileMap?, save:Boolean = false, previousScreen: CameraStageBaseScreen)
|
||||||
: PickerScreen(disableScroll = true) {
|
: PickerScreen(disableScroll = true) {
|
||||||
var chosenMap: FileHandle? = null
|
private var chosenMap: FileHandle? = null
|
||||||
val deleteButton = "Delete map".toTextButton()
|
val deleteButton = "Delete map".toTextButton()
|
||||||
val mapsTable = Table().apply { defaults().pad(10f) }
|
val mapsTable = Table().apply { defaults().pad(10f) }
|
||||||
val mapNameTextField = TextField("", skin).apply { maxLength = 100 }
|
private val mapNameTextField = TextField("", skin).apply { maxLength = 100 }
|
||||||
|
|
||||||
init {
|
init {
|
||||||
|
val rightSideButtonAction: ()->Unit
|
||||||
if (save) {
|
if (save) {
|
||||||
rightSideButton.enable()
|
rightSideButton.enable()
|
||||||
rightSideButton.setText("Save map".tr())
|
rightSideButton.setText("Save map".tr())
|
||||||
rightSideButton.onClick {
|
rightSideButtonAction = {
|
||||||
mapToSave!!.mapParameters.name = mapNameTextField.text
|
mapToSave!!.mapParameters.name = mapNameTextField.text
|
||||||
mapToSave.mapParameters.type = MapType.custom
|
mapToSave.mapParameters.type = MapType.custom
|
||||||
thread(name = "SaveMap") {
|
thread(name = "SaveMap") {
|
||||||
@ -52,7 +54,7 @@ class SaveAndLoadMapScreen(mapToSave: TileMap?, save:Boolean = false, previousSc
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
rightSideButton.setText("Load map".tr())
|
rightSideButton.setText("Load map".tr())
|
||||||
rightSideButton.onClick {
|
rightSideButtonAction = {
|
||||||
thread {
|
thread {
|
||||||
Gdx.app.postRunnable {
|
Gdx.app.postRunnable {
|
||||||
val popup = Popup(this)
|
val popup = Popup(this)
|
||||||
@ -68,6 +70,8 @@ class SaveAndLoadMapScreen(mapToSave: TileMap?, save:Boolean = false, previousSc
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
rightSideButton.onClick(rightSideButtonAction)
|
||||||
|
keyPressDispatcher['\r'] = rightSideButtonAction
|
||||||
|
|
||||||
topTable.add(ScrollPane(mapsTable)).maxWidth(stage.width / 2)
|
topTable.add(ScrollPane(mapsTable)).maxWidth(stage.width / 2)
|
||||||
|
|
||||||
@ -75,13 +79,18 @@ class SaveAndLoadMapScreen(mapToSave: TileMap?, save:Boolean = false, previousSc
|
|||||||
|
|
||||||
if (save) {
|
if (save) {
|
||||||
mapNameTextField.textFieldFilter = TextField.TextFieldFilter { _, char -> char != '\\' && char != '/' }
|
mapNameTextField.textFieldFilter = TextField.TextFieldFilter { _, char -> char != '\\' && char != '/' }
|
||||||
mapNameTextField.text = "My new map"
|
mapNameTextField.text = if (mapToSave == null || mapToSave.mapParameters.name.isEmpty()) "My new map"
|
||||||
|
else mapToSave.mapParameters.name
|
||||||
rightSideTable.add(mapNameTextField).width(300f).pad(10f)
|
rightSideTable.add(mapNameTextField).width(300f).pad(10f)
|
||||||
|
stage.keyboardFocus = mapNameTextField
|
||||||
|
mapNameTextField.selectAll()
|
||||||
} else {
|
} else {
|
||||||
val downloadMapButton = "Download map".toTextButton()
|
val downloadMapButton = "Download map".toTextButton()
|
||||||
downloadMapButton.onClick {
|
val downloadAction = {
|
||||||
MapDownloadPopup(this).open()
|
MapDownloadPopup(this).open()
|
||||||
}
|
}
|
||||||
|
downloadMapButton.onClick(downloadAction)
|
||||||
|
keyPressDispatcher['\u0004'] = downloadAction // Ctrl-D
|
||||||
rightSideTable.add(downloadMapButton).row()
|
rightSideTable.add(downloadMapButton).row()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,16 +98,18 @@ class SaveAndLoadMapScreen(mapToSave: TileMap?, save:Boolean = false, previousSc
|
|||||||
|
|
||||||
if (save) {
|
if (save) {
|
||||||
val copyMapAsTextButton = "Copy to clipboard".toTextButton()
|
val copyMapAsTextButton = "Copy to clipboard".toTextButton()
|
||||||
copyMapAsTextButton.onClick {
|
val copyMapAsTextAction = {
|
||||||
val json = Json().toJson(mapToSave)
|
val json = Json().toJson(mapToSave)
|
||||||
val base64Gzip = Gzip.zip(json)
|
val base64Gzip = Gzip.zip(json)
|
||||||
Gdx.app.clipboard.contents = base64Gzip
|
Gdx.app.clipboard.contents = base64Gzip
|
||||||
}
|
}
|
||||||
|
copyMapAsTextButton.onClick (copyMapAsTextAction)
|
||||||
|
keyPressDispatcher['\u0003'] = copyMapAsTextAction // Ctrl-C
|
||||||
rightSideTable.add(copyMapAsTextButton).row()
|
rightSideTable.add(copyMapAsTextButton).row()
|
||||||
} else {
|
} else {
|
||||||
val loadFromClipboardButton = "Load copied data".toTextButton()
|
val loadFromClipboardButton = "Load copied data".toTextButton()
|
||||||
val couldNotLoadMapLabel = "Could not load map!".toLabel(Color.RED).apply { isVisible = false }
|
val couldNotLoadMapLabel = "Could not load map!".toLabel(Color.RED).apply { isVisible = false }
|
||||||
loadFromClipboardButton.onClick {
|
val loadFromClipboardAction = {
|
||||||
try {
|
try {
|
||||||
val clipboardContentsString = Gdx.app.clipboard.contents.trim()
|
val clipboardContentsString = Gdx.app.clipboard.contents.trim()
|
||||||
val decoded = Gzip.unzip(clipboardContentsString)
|
val decoded = Gzip.unzip(clipboardContentsString)
|
||||||
@ -108,16 +119,20 @@ class SaveAndLoadMapScreen(mapToSave: TileMap?, save:Boolean = false, previousSc
|
|||||||
couldNotLoadMapLabel.isVisible = true
|
couldNotLoadMapLabel.isVisible = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
loadFromClipboardButton.onClick(loadFromClipboardAction)
|
||||||
|
keyPressDispatcher['\u0016'] = loadFromClipboardAction // Ctrl-V
|
||||||
rightSideTable.add(loadFromClipboardButton).row()
|
rightSideTable.add(loadFromClipboardButton).row()
|
||||||
rightSideTable.add(couldNotLoadMapLabel).row()
|
rightSideTable.add(couldNotLoadMapLabel).row()
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteButton.onClick {
|
val deleteAction = {
|
||||||
YesNoPopup("Are you sure you want to delete this map?", {
|
YesNoPopup("Are you sure you want to delete this map?", {
|
||||||
chosenMap!!.delete()
|
chosenMap!!.delete()
|
||||||
game.setScreen(SaveAndLoadMapScreen(mapToSave, save, previousScreen))
|
game.setScreen(SaveAndLoadMapScreen(mapToSave, save, previousScreen))
|
||||||
}, this).open()
|
}, this).open()
|
||||||
}
|
}
|
||||||
|
deleteButton.onClick(deleteAction)
|
||||||
|
keyPressDispatcher['\u007f'] = deleteAction // Input.Keys.DEL but ascii has precedence
|
||||||
rightSideTable.add(deleteButton).row()
|
rightSideTable.add(deleteButton).row()
|
||||||
|
|
||||||
topTable.add(rightSideTable)
|
topTable.add(rightSideTable)
|
||||||
@ -132,22 +147,23 @@ class SaveAndLoadMapScreen(mapToSave: TileMap?, save:Boolean = false, previousSc
|
|||||||
deleteButton.color = Color.RED
|
deleteButton.color = Color.RED
|
||||||
|
|
||||||
deleteButton.setText("Delete map".tr())
|
deleteButton.setText("Delete map".tr())
|
||||||
// rightSideButton.setText("Load map".tr())
|
|
||||||
|
|
||||||
mapsTable.clear()
|
mapsTable.clear()
|
||||||
for (map in MapSaver.getMaps()) {
|
for (map in MapSaver.getMaps()) {
|
||||||
val loadMapButton = TextButton(map.name(), skin)
|
val existingMapButton = TextButton(map.name(), skin)
|
||||||
loadMapButton.onClick {
|
existingMapButton.onClick {
|
||||||
for (cell in mapsTable.cells) cell.actor.color = Color.WHITE
|
for (cell in mapsTable.cells) cell.actor.color = Color.WHITE
|
||||||
loadMapButton.color = Color.BLUE
|
existingMapButton.color = Color.BLUE
|
||||||
|
|
||||||
rightSideButton.enable()
|
rightSideButton.enable()
|
||||||
chosenMap = map
|
chosenMap = map
|
||||||
mapNameTextField.text = map.name()
|
mapNameTextField.text = map.name()
|
||||||
|
mapNameTextField.setSelection(Int.MAX_VALUE,Int.MAX_VALUE) // sets caret to end of text
|
||||||
|
|
||||||
deleteButton.enable()
|
deleteButton.enable()
|
||||||
deleteButton.color = Color.RED
|
deleteButton.color = Color.RED
|
||||||
}
|
}
|
||||||
mapsTable.add(loadMapButton).row()
|
mapsTable.add(existingMapButton).row()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user