mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-29 23:10:39 -04:00
Cleaned up map editor
This commit is contained in:
parent
3d8e7fa99d
commit
5bac35d36d
@ -27,11 +27,9 @@ class MapEditorMenuPopup(var mapEditorScreen: MapEditorScreen): Popup(mapEditorS
|
|||||||
mapEditorScreen.stage.keyboardFocus = mapNameEditor
|
mapEditorScreen.stage.keyboardFocus = mapNameEditor
|
||||||
|
|
||||||
addNewMapButton()
|
addNewMapButton()
|
||||||
addClearCurrentMapButton()
|
|
||||||
addSaveMapButton()
|
addSaveMapButton()
|
||||||
addCopyMapAsTextButton()
|
addCopyMapAsTextButton()
|
||||||
addLoadMapButton()
|
addLoadMapButton()
|
||||||
// addUploadMapButton()
|
|
||||||
addExitMapEditorButton()
|
addExitMapEditorButton()
|
||||||
addCloseOptionsButton()
|
addCloseOptionsButton()
|
||||||
}
|
}
|
||||||
@ -44,33 +42,6 @@ class MapEditorMenuPopup(var mapEditorScreen: MapEditorScreen): Popup(mapEditorS
|
|||||||
add(newMapButton).row()
|
add(newMapButton).row()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun Popup.addClearCurrentMapButton() {
|
|
||||||
val clearCurrentMapButton = "Clear current map".toTextButton()
|
|
||||||
|
|
||||||
clearCurrentMapButton.onClick {
|
|
||||||
YesNoPopup("Are you sure you want to clear the entire map?", {
|
|
||||||
for (tileGroup in mapEditorScreen.mapHolder.tileGroups.values) {
|
|
||||||
val tile = tileGroup.tileInfo
|
|
||||||
tile.baseTerrain = Constants.ocean
|
|
||||||
tile.terrainFeature = null
|
|
||||||
tile.naturalWonder = null
|
|
||||||
tile.hasBottomRiver = false
|
|
||||||
tile.hasBottomLeftRiver = false
|
|
||||||
tile.hasBottomRightRiver = false
|
|
||||||
tile.resource = null
|
|
||||||
tile.improvement = null
|
|
||||||
tile.improvementInProgress = null
|
|
||||||
tile.roadStatus = RoadStatus.None
|
|
||||||
|
|
||||||
tile.setTransients()
|
|
||||||
|
|
||||||
tileGroup.update()
|
|
||||||
}
|
|
||||||
}, mapEditorScreen).open(true)
|
|
||||||
}
|
|
||||||
add(clearCurrentMapButton).row()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun Popup.addSaveMapButton() {
|
private fun Popup.addSaveMapButton() {
|
||||||
val saveMapButton = "Save map".toTextButton()
|
val saveMapButton = "Save map".toTextButton()
|
||||||
saveMapButton.onClick {
|
saveMapButton.onClick {
|
||||||
@ -122,35 +93,6 @@ class MapEditorMenuPopup(var mapEditorScreen: MapEditorScreen): Popup(mapEditorS
|
|||||||
add(loadMapButton).row()
|
add(loadMapButton).row()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun Popup.addUploadMapButton() {
|
|
||||||
val uploadMapButton = "Upload map".toTextButton()
|
|
||||||
uploadMapButton.onClick {
|
|
||||||
thread(name = "MapUpload") {
|
|
||||||
try {
|
|
||||||
val gzippedMap = Gzip.zip(Json().toJson(mapEditorScreen.tileMap))
|
|
||||||
DropBox.uploadFile("/Maps/" + mapEditorScreen.mapName, gzippedMap)
|
|
||||||
|
|
||||||
remove()
|
|
||||||
Gdx.app.postRunnable {
|
|
||||||
val uploadedSuccessfully = Popup(screen)
|
|
||||||
uploadedSuccessfully.addGoodSizedLabel("Map uploaded successfully!").row()
|
|
||||||
uploadedSuccessfully.addCloseButton()
|
|
||||||
uploadedSuccessfully.open()
|
|
||||||
}
|
|
||||||
} catch (ex: Exception) {
|
|
||||||
remove()
|
|
||||||
Gdx.app.postRunnable {
|
|
||||||
val couldNotUpload = Popup(screen)
|
|
||||||
couldNotUpload.addGoodSizedLabel("Could not upload map!").row()
|
|
||||||
couldNotUpload.addCloseButton()
|
|
||||||
couldNotUpload.open()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
add(uploadMapButton).row()
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private fun Popup.addExitMapEditorButton() {
|
private fun Popup.addExitMapEditorButton() {
|
||||||
val exitMapEditorButton = "Exit map editor".toTextButton()
|
val exitMapEditorButton = "Exit map editor".toTextButton()
|
||||||
|
@ -14,7 +14,6 @@ import com.unciv.logic.map.TileInfo
|
|||||||
import com.unciv.logic.map.TileMap
|
import com.unciv.logic.map.TileMap
|
||||||
import com.unciv.models.metadata.Player
|
import com.unciv.models.metadata.Player
|
||||||
import com.unciv.models.ruleset.Nation
|
import com.unciv.models.ruleset.Nation
|
||||||
import com.unciv.models.ruleset.tile.ResourceType
|
|
||||||
import com.unciv.models.ruleset.tile.TerrainType
|
import com.unciv.models.ruleset.tile.TerrainType
|
||||||
import com.unciv.models.translations.tr
|
import com.unciv.models.translations.tr
|
||||||
import com.unciv.ui.tilegroups.TileGroup
|
import com.unciv.ui.tilegroups.TileGroup
|
||||||
@ -83,7 +82,7 @@ class TileEditorOptionsTable(val mapEditorScreen: MapEditorScreen): Table(Camera
|
|||||||
val baseTerrainTable = Table().apply { defaults().pad(20f) }
|
val baseTerrainTable = Table().apply { defaults().pad(20f) }
|
||||||
val terrainFeaturesTable = Table().apply { defaults().pad(20f) }
|
val terrainFeaturesTable = Table().apply { defaults().pad(20f) }
|
||||||
|
|
||||||
terrainFeaturesTable.add(getHex(Color.WHITE, getRedCross(50f, 0.6f)).apply {
|
terrainFeaturesTable.add(getHex(getRedCross(50f, 0.6f)).apply {
|
||||||
onClick {
|
onClick {
|
||||||
tileAction = {
|
tileAction = {
|
||||||
it.terrainFeature = null
|
it.terrainFeature = null
|
||||||
@ -92,7 +91,7 @@ class TileEditorOptionsTable(val mapEditorScreen: MapEditorScreen): Table(Camera
|
|||||||
it.hasBottomLeftRiver = false
|
it.hasBottomLeftRiver = false
|
||||||
it.hasBottomRightRiver = false
|
it.hasBottomRightRiver = false
|
||||||
}
|
}
|
||||||
setCurrentHex(getHex(Color.WHITE, getRedCross(40f, 0.6f)), "Clear terrain features")
|
setCurrentHex(getHex(getRedCross(40f, 0.6f)), "Clear terrain features")
|
||||||
}
|
}
|
||||||
}).row()
|
}).row()
|
||||||
|
|
||||||
@ -126,17 +125,17 @@ class TileEditorOptionsTable(val mapEditorScreen: MapEditorScreen): Table(Camera
|
|||||||
editorPickTable.clear()
|
editorPickTable.clear()
|
||||||
|
|
||||||
val improvementsTable = Table()
|
val improvementsTable = Table()
|
||||||
improvementsTable.add(getHex(Color.WHITE, getRedCross(40f, 0.6f)).apply {
|
improvementsTable.add(getHex(getRedCross(40f, 0.6f)).apply {
|
||||||
onClick {
|
onClick {
|
||||||
tileAction = { it.improvement = null }
|
tileAction = { it.improvement = null }
|
||||||
setCurrentHex(getHex(Color.WHITE, getRedCross(40f, 0.6f)), "Clear improvements")
|
setCurrentHex(getHex(getRedCross(40f, 0.6f)), "Clear improvements")
|
||||||
}
|
}
|
||||||
}).row()
|
}).row()
|
||||||
|
|
||||||
for (improvement in ruleset.tileImprovements.values) {
|
for (improvement in ruleset.tileImprovements.values) {
|
||||||
if (improvement.name.startsWith("Remove")) continue
|
if (improvement.name.startsWith("Remove")) continue
|
||||||
if (improvement.name == Constants.cancelImprovementOrder) continue
|
if (improvement.name == Constants.cancelImprovementOrder) continue
|
||||||
val improvementImage = getHex(Color.WHITE, ImageGetter.getImprovementIcon(improvement.name, 40f))
|
val improvementImage = getHex(ImageGetter.getImprovementIcon(improvement.name, 40f))
|
||||||
improvementImage.onClick {
|
improvementImage.onClick {
|
||||||
tileAction = {
|
tileAction = {
|
||||||
when (improvement.name) {
|
when (improvement.name) {
|
||||||
@ -145,7 +144,7 @@ class TileEditorOptionsTable(val mapEditorScreen: MapEditorScreen): Table(Camera
|
|||||||
else -> it.improvement = improvement.name
|
else -> it.improvement = improvement.name
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val improvementIcon = getHex(Color.WHITE, ImageGetter.getImprovementIcon(improvement.name, 40f))
|
val improvementIcon = getHex(ImageGetter.getImprovementIcon(improvement.name, 40f))
|
||||||
setCurrentHex(improvementIcon, improvement.name.tr() + "\n" + improvement.clone().toString())
|
setCurrentHex(improvementIcon, improvement.name.tr() + "\n" + improvement.clone().toString())
|
||||||
}
|
}
|
||||||
improvementsTable.add(improvementImage).row()
|
improvementsTable.add(improvementImage).row()
|
||||||
@ -159,7 +158,7 @@ class TileEditorOptionsTable(val mapEditorScreen: MapEditorScreen): Table(Camera
|
|||||||
for (nation in ruleset.nations.values) {
|
for (nation in ruleset.nations.values) {
|
||||||
if (nation.isSpectator()) continue // no improvements for spectator
|
if (nation.isSpectator()) continue // no improvements for spectator
|
||||||
|
|
||||||
val nationImage = getHex(Color.WHITE, ImageGetter.getNationIndicator(nation, 40f))
|
val nationImage = getHex(ImageGetter.getNationIndicator(nation, 40f))
|
||||||
nationImage.onClick {
|
nationImage.onClick {
|
||||||
val improvementName = "StartingLocation " + nation.name
|
val improvementName = "StartingLocation " + nation.name
|
||||||
tileAction = {
|
tileAction = {
|
||||||
@ -173,7 +172,7 @@ class TileEditorOptionsTable(val mapEditorScreen: MapEditorScreen): Table(Camera
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val nationIcon = getHex(Color.WHITE, ImageGetter.getNationIndicator(nation, 40f))
|
val nationIcon = getHex(ImageGetter.getNationIndicator(nation, 40f))
|
||||||
setCurrentHex(nationIcon, "[${nation.name}] starting location")
|
setCurrentHex(nationIcon, "[${nation.name}] starting location")
|
||||||
}
|
}
|
||||||
nationTable.add(nationImage).row()
|
nationTable.add(nationImage).row()
|
||||||
@ -214,12 +213,8 @@ class TileEditorOptionsTable(val mapEditorScreen: MapEditorScreen): Table(Camera
|
|||||||
it.airUnits.add(unit)
|
it.airUnits.add(unit)
|
||||||
if (!it.isCityCenter()) unit.isTransported = true // if not city - air unit enters carrier
|
if (!it.isCityCenter()) unit.isTransported = true // if not city - air unit enters carrier
|
||||||
}
|
}
|
||||||
unit.type.isCivilian() -> {
|
unit.type.isCivilian() -> it.civilianUnit = unit
|
||||||
it.civilianUnit = unit
|
else -> it.militaryUnit = unit
|
||||||
}
|
|
||||||
else -> {
|
|
||||||
it.militaryUnit = unit
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
unit.currentTile = it // needed for unit icon - unit needs to know if it's embarked or not...
|
unit.currentTile = it // needed for unit icon - unit needs to know if it's embarked or not...
|
||||||
}
|
}
|
||||||
@ -309,16 +304,16 @@ class TileEditorOptionsTable(val mapEditorScreen: MapEditorScreen): Table(Camera
|
|||||||
|
|
||||||
private fun getResourceActors(): ArrayList<Actor> {
|
private fun getResourceActors(): ArrayList<Actor> {
|
||||||
val resources = ArrayList<Actor>()
|
val resources = ArrayList<Actor>()
|
||||||
resources.add(getHex(Color.WHITE, getCrossedResource()).apply {
|
resources.add(getHex(getCrossedResource()).apply {
|
||||||
onClick {
|
onClick {
|
||||||
tileAction = { it.resource = null }
|
tileAction = { it.resource = null }
|
||||||
setCurrentHex(getHex(Color.WHITE, getCrossedResource()), "Clear resource")
|
setCurrentHex(getHex(getCrossedResource()), "Clear resource")
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
for (resource in ruleset.tileResources.values) {
|
for (resource in ruleset.tileResources.values) {
|
||||||
if (resource.terrainsCanBeFoundOn.none { ruleset.terrains.containsKey(it) }) continue // This resource can't be placed
|
if (resource.terrainsCanBeFoundOn.none { ruleset.terrains.containsKey(it) }) continue // This resource can't be placed
|
||||||
val resourceHex = getHex(Color.WHITE, ImageGetter.getResourceImage(resource.name, 40f))
|
val resourceHex = getHex(ImageGetter.getResourceImage(resource.name, 40f))
|
||||||
resourceHex.onClick {
|
resourceHex.onClick {
|
||||||
tileAction = { it.resource = resource.name }
|
tileAction = { it.resource = resource.name }
|
||||||
|
|
||||||
@ -427,9 +422,9 @@ class TileEditorOptionsTable(val mapEditorScreen: MapEditorScreen): Table(Camera
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun getHex(color: Color, image: Actor? = null): Group {
|
private fun getHex(image: Actor? = null): Group {
|
||||||
val hex = ImageGetter.getImage(tileSetLocation + "Hexagon")
|
val hex = ImageGetter.getImage(tileSetLocation + "Hexagon")
|
||||||
hex.color = color
|
hex.color = Color.WHITE
|
||||||
hex.width *= 0.3f
|
hex.width *= 0.3f
|
||||||
hex.height *= 0.3f
|
hex.height *= 0.3f
|
||||||
val group = Group()
|
val group = Group()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user