mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-27 05:46:43 -04:00
Resolved #3289 - can place unbuildable improvements that can exist on tiles
This commit is contained in:
parent
f57955c8d5
commit
c1a717e4f8
@ -299,7 +299,7 @@ open class TileInfo {
|
||||
}
|
||||
}
|
||||
|
||||
/** Without regards to what civinfo it is, a lot of the checks are ust for the improvement on the tile.
|
||||
/** Without regards to what civinfo it is, a lot of the checks are just for the improvement on the tile.
|
||||
* Doubles as a check for the map editor.
|
||||
*/
|
||||
fun canImprovementBeBuiltHere(improvement: TileImprovement, resourceIsVisible:Boolean = resource!=null): Boolean {
|
||||
|
@ -21,10 +21,10 @@ import com.unciv.ui.tilegroups.TileGroup
|
||||
import com.unciv.ui.tilegroups.TileSetStrings
|
||||
import com.unciv.ui.utils.*
|
||||
|
||||
class TileEditorOptionsTable(val mapEditorScreen: MapEditorScreen): Table(CameraStageBaseScreen.skin){
|
||||
private val tileSetLocation = "TileSets/"+ UncivGame.Current.settings.tileSet +"/"
|
||||
class TileEditorOptionsTable(val mapEditorScreen: MapEditorScreen): Table(CameraStageBaseScreen.skin) {
|
||||
private val tileSetLocation = "TileSets/" + UncivGame.Current.settings.tileSet + "/"
|
||||
|
||||
var tileAction:(TileInfo)->Unit = {}
|
||||
var tileAction: (TileInfo) -> Unit = {}
|
||||
|
||||
private val editorPickTable = Table()
|
||||
|
||||
@ -34,16 +34,16 @@ class TileEditorOptionsTable(val mapEditorScreen: MapEditorScreen): Table(Camera
|
||||
private val ruleset = mapEditorScreen.ruleset
|
||||
private val gameParameters = mapEditorScreen.gameSetupInfo.gameParameters
|
||||
|
||||
private val scrollPanelHeight = mapEditorScreen.stage.height*0.7f - 100f // -100 reserved for currentHex table
|
||||
private val scrollPanelHeight = mapEditorScreen.stage.height * 0.7f - 100f // -100 reserved for currentHex table
|
||||
|
||||
init{
|
||||
init {
|
||||
update()
|
||||
}
|
||||
|
||||
fun update() {
|
||||
clear()
|
||||
height = mapEditorScreen.stage.height
|
||||
width = mapEditorScreen.stage.width/3
|
||||
width = mapEditorScreen.stage.width / 3
|
||||
|
||||
setTerrainsAndResources()
|
||||
|
||||
@ -79,12 +79,12 @@ class TileEditorOptionsTable(val mapEditorScreen: MapEditorScreen): Table(Camera
|
||||
sliderTab.add(slider)
|
||||
|
||||
add(sliderTab).row()
|
||||
add(AutoScrollPane(tabPickerTable).apply { this.width= mapEditorScreen.stage.width/3}).row()
|
||||
add(AutoScrollPane(tabPickerTable).apply { this.width = mapEditorScreen.stage.width / 3 }).row()
|
||||
|
||||
add(editorPickTable).row()
|
||||
}
|
||||
|
||||
private fun setTerrainsAndResources(){
|
||||
private fun setTerrainsAndResources() {
|
||||
|
||||
val baseTerrainTable = Table().apply { defaults().pad(20f) }
|
||||
val terrainFeaturesTable = Table().apply { defaults().pad(20f) }
|
||||
@ -92,11 +92,11 @@ class TileEditorOptionsTable(val mapEditorScreen: MapEditorScreen): Table(Camera
|
||||
terrainFeaturesTable.add(getHex(Color.WHITE, getRedCross(50f, 0.6f)).apply {
|
||||
onClick {
|
||||
tileAction = {
|
||||
it.terrainFeature=null
|
||||
it.terrainFeature = null
|
||||
it.naturalWonder = null
|
||||
it.hasBottomRiver=false
|
||||
it.hasBottomLeftRiver=false
|
||||
it.hasBottomRightRiver=false
|
||||
it.hasBottomRiver = false
|
||||
it.hasBottomLeftRiver = false
|
||||
it.hasBottomRightRiver = false
|
||||
}
|
||||
setCurrentHex(getHex(Color.WHITE, getRedCross(40f, 0.6f)), "Clear terrain features")
|
||||
}
|
||||
@ -112,14 +112,14 @@ class TileEditorOptionsTable(val mapEditorScreen: MapEditorScreen): Table(Camera
|
||||
background = ImageGetter.getBackground(Color.GRAY.cpy().apply { a = 0.7f })
|
||||
|
||||
val terrainsAndResourcesTable = Table()
|
||||
terrainsAndResourcesTable.add(AutoScrollPane(baseTerrainTable).apply { setScrollingDisabled(true,false) }).height(scrollPanelHeight)
|
||||
terrainsAndResourcesTable.add(AutoScrollPane(baseTerrainTable).apply { setScrollingDisabled(true, false) }).height(scrollPanelHeight)
|
||||
|
||||
terrainsAndResourcesTable.add(AutoScrollPane(terrainFeaturesTable).apply { setScrollingDisabled(true,false) }).height(scrollPanelHeight)
|
||||
terrainsAndResourcesTable.add(AutoScrollPane(terrainFeaturesTable).apply { setScrollingDisabled(true, false) }).height(scrollPanelHeight)
|
||||
|
||||
val resourcesTable = Table()
|
||||
for(resource in resources) resourcesTable.add(resource).row()
|
||||
for (resource in resources) resourcesTable.add(resource).row()
|
||||
resourcesTable.pack()
|
||||
terrainsAndResourcesTable.add(AutoScrollPane(resourcesTable).apply { setScrollingDisabled(true,false) }).height(scrollPanelHeight).row()
|
||||
terrainsAndResourcesTable.add(AutoScrollPane(resourcesTable).apply { setScrollingDisabled(true, false) }).height(scrollPanelHeight).row()
|
||||
|
||||
terrainsAndResourcesTable.pack()
|
||||
|
||||
@ -134,12 +134,12 @@ class TileEditorOptionsTable(val mapEditorScreen: MapEditorScreen): Table(Camera
|
||||
val improvementsTable = Table()
|
||||
improvementsTable.add(getHex(Color.WHITE, getRedCross(40f, 0.6f)).apply {
|
||||
onClick {
|
||||
tileAction = {it.improvement=null}
|
||||
tileAction = { it.improvement = null }
|
||||
setCurrentHex(getHex(Color.WHITE, getRedCross(40f, 0.6f)), "Clear improvements")
|
||||
}
|
||||
}).row()
|
||||
|
||||
for(improvement in ruleset.tileImprovements.values){
|
||||
for (improvement in ruleset.tileImprovements.values) {
|
||||
if (improvement.name.startsWith("Remove")) continue
|
||||
if (improvement.name == Constants.cancelImprovementOrder) continue
|
||||
val improvementImage = getHex(Color.WHITE, ImageGetter.getImprovementIcon(improvement.name, 40f))
|
||||
@ -152,11 +152,11 @@ class TileEditorOptionsTable(val mapEditorScreen: MapEditorScreen): Table(Camera
|
||||
}
|
||||
}
|
||||
val improvementIcon = getHex(Color.WHITE, 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()
|
||||
}
|
||||
editorPickTable.add(AutoScrollPane(improvementsTable).apply { setScrollingDisabled(true,false) }).height(scrollPanelHeight)
|
||||
editorPickTable.add(AutoScrollPane(improvementsTable).apply { setScrollingDisabled(true, false) }).height(scrollPanelHeight)
|
||||
|
||||
val nationTable = Table()
|
||||
|
||||
@ -184,19 +184,19 @@ class TileEditorOptionsTable(val mapEditorScreen: MapEditorScreen): Table(Camera
|
||||
}
|
||||
|
||||
val nationIcon = getHex(Color.WHITE, ImageGetter.getNationIndicator(nation, 40f))
|
||||
setCurrentHex(nationIcon,"Player [$playerIndex] starting location")
|
||||
setCurrentHex(nationIcon, "Player [$playerIndex] starting location")
|
||||
}
|
||||
nationTable.add(nationImage).row()
|
||||
}
|
||||
} else {
|
||||
/** old way improvements for all civs
|
||||
* */
|
||||
for(nation in ruleset.nations.values){
|
||||
for (nation in ruleset.nations.values) {
|
||||
if (nation.isSpectator()) continue // no improvements for spectator
|
||||
|
||||
val nationImage = getHex(Color.WHITE, ImageGetter.getNationIndicator(nation, 40f))
|
||||
nationImage.onClick {
|
||||
val improvementName = "StartingLocation "+nation.name
|
||||
val improvementName = "StartingLocation " + nation.name
|
||||
tileAction = {
|
||||
it.improvement = improvementName
|
||||
for (tileGroup in mapEditorScreen.mapHolder.tileGroups.values) {
|
||||
@ -215,34 +215,34 @@ class TileEditorOptionsTable(val mapEditorScreen: MapEditorScreen): Table(Camera
|
||||
}
|
||||
}
|
||||
|
||||
editorPickTable.add(AutoScrollPane(nationTable).apply { setScrollingDisabled(true,false) }).height(scrollPanelHeight)
|
||||
editorPickTable.add(AutoScrollPane(nationTable).apply { setScrollingDisabled(true, false) }).height(scrollPanelHeight)
|
||||
}
|
||||
|
||||
fun setUnits(){
|
||||
fun setUnits() {
|
||||
editorPickTable.clear()
|
||||
|
||||
val nationsTable = Table()
|
||||
|
||||
// default player - first MajorCiv player
|
||||
val defaultPlayer = gameParameters.players.first{
|
||||
val defaultPlayer = gameParameters.players.first {
|
||||
it.chosenCiv != Constants.spectator && it.chosenCiv != Constants.random
|
||||
}
|
||||
var currentPlayer = getPlayerIndexString(defaultPlayer)
|
||||
var currentNation: Nation = ruleset.nations[defaultPlayer.chosenCiv]!!
|
||||
var currentUnit = ruleset.units.values.first()
|
||||
|
||||
fun setUnitTileAction(){
|
||||
fun setUnitTileAction() {
|
||||
val unitImage = ImageGetter.getUnitIcon(currentUnit.name, currentNation.getInnerColor())
|
||||
.surroundWithCircle(40f*0.9f).apply { circle.color=currentNation.getOuterColor() }
|
||||
.surroundWithCircle(40f, false).apply { circle.color=currentNation.getInnerColor() }
|
||||
.surroundWithCircle(40f * 0.9f).apply { circle.color = currentNation.getOuterColor() }
|
||||
.surroundWithCircle(40f, false).apply { circle.color = currentNation.getInnerColor() }
|
||||
|
||||
setCurrentHex(unitImage, currentUnit.name.tr()+ " - $currentPlayer ("+currentNation.name.tr()+")")
|
||||
setCurrentHex(unitImage, currentUnit.name.tr() + " - $currentPlayer (" + currentNation.name.tr() + ")")
|
||||
tileAction = {
|
||||
val unit = MapUnit()
|
||||
unit.baseUnit = currentUnit
|
||||
unit.name = currentUnit.name
|
||||
unit.owner = currentNation.name
|
||||
unit.civInfo = CivilizationInfo(currentNation.name).apply { nation=currentNation } // needed for the unit icon to render correctly
|
||||
unit.civInfo = CivilizationInfo(currentNation.name).apply { nation = currentNation } // needed for the unit icon to render correctly
|
||||
unit.updateUniques()
|
||||
if (unit.movement.canMoveTo(it)) {
|
||||
when {
|
||||
@ -250,10 +250,14 @@ class TileEditorOptionsTable(val mapEditorScreen: MapEditorScreen): Table(Camera
|
||||
it.airUnits.add(unit)
|
||||
if (!it.isCityCenter()) unit.isTransported = true // if not city - air unit enters carrier
|
||||
}
|
||||
unit.type.isCivilian() -> { it.civilianUnit = unit }
|
||||
else -> { it.militaryUnit = unit }
|
||||
unit.type.isCivilian() -> {
|
||||
it.civilianUnit = unit
|
||||
}
|
||||
unit.currentTile=it // needed for unit icon - unit needs to know if it's embarked or not...
|
||||
else -> {
|
||||
it.militaryUnit = unit
|
||||
}
|
||||
}
|
||||
unit.currentTile = it // needed for unit icon - unit needs to know if it's embarked or not...
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -274,12 +278,13 @@ class TileEditorOptionsTable(val mapEditorScreen: MapEditorScreen): Table(Camera
|
||||
nationImage.onClick {
|
||||
currentNation = nation;
|
||||
currentPlayer = getPlayerIndexString(player)
|
||||
setUnitTileAction() }
|
||||
setUnitTileAction()
|
||||
}
|
||||
}
|
||||
|
||||
// barbarians icon
|
||||
if (!gameParameters.noBarbarians) {
|
||||
val barbarians = ruleset.nations.values.filter { it.isBarbarian()}
|
||||
val barbarians = ruleset.nations.values.filter { it.isBarbarian() }
|
||||
for (nation in barbarians) {
|
||||
val nationImage = ImageGetter.getNationIndicator(nation, 40f)
|
||||
nationsTable.add(nationImage).row()
|
||||
@ -294,7 +299,7 @@ class TileEditorOptionsTable(val mapEditorScreen: MapEditorScreen): Table(Camera
|
||||
editorPickTable.add(AutoScrollPane(nationsTable)).height(scrollPanelHeight)
|
||||
|
||||
val unitsTable = Table()
|
||||
for(unit in ruleset.units.values){
|
||||
for (unit in ruleset.units.values) {
|
||||
val unitImage = ImageGetter.getUnitIcon(unit.name).surroundWithCircle(40f)
|
||||
unitsTable.add(unitImage).row()
|
||||
unitImage.onClick { currentUnit = unit; setUnitTileAction() }
|
||||
@ -326,12 +331,12 @@ class TileEditorOptionsTable(val mapEditorScreen: MapEditorScreen): Table(Camera
|
||||
|
||||
private fun getRedCross(size: Float, alpha: Float): Actor {
|
||||
val redCross = ImageGetter.getImage("OtherIcons/Close")
|
||||
redCross.setSize( size, size)
|
||||
redCross.setSize(size, size)
|
||||
redCross.color = Color.RED.cpy().apply { a = alpha }
|
||||
return redCross
|
||||
}
|
||||
|
||||
private fun getCrossedResource() : Actor {
|
||||
private fun getCrossedResource(): Actor {
|
||||
val redCross = getRedCross(45f, 0.5f)
|
||||
val group = IconCircleGroup(40f, redCross, false)
|
||||
group.circle.color = ImageGetter.foodCircleColor
|
||||
@ -416,7 +421,7 @@ class TileEditorOptionsTable(val mapEditorScreen: MapEditorScreen): Table(Camera
|
||||
tileInfoBottomRightRiver.hasBottomRightRiver = true
|
||||
val tileGroupBottomRightRiver = makeTileGroup(tileInfoBottomRightRiver)
|
||||
tileGroupBottomRightRiver.onClick {
|
||||
tileAction = {it.hasBottomRightRiver = !it.hasBottomRightRiver}
|
||||
tileAction = { it.hasBottomRightRiver = !it.hasBottomRightRiver }
|
||||
|
||||
setCurrentHex(tileInfoBottomRightRiver, "Bottom right river")
|
||||
}
|
||||
@ -428,7 +433,7 @@ class TileEditorOptionsTable(val mapEditorScreen: MapEditorScreen): Table(Camera
|
||||
tileInfoBottomRiver.hasBottomRiver = true
|
||||
val tileGroupBottomRiver = makeTileGroup(tileInfoBottomRiver)
|
||||
tileGroupBottomRiver.onClick {
|
||||
tileAction = {it.hasBottomRiver = !it.hasBottomRiver}
|
||||
tileAction = { it.hasBottomRiver = !it.hasBottomRiver }
|
||||
setCurrentHex(tileInfoBottomRiver, "Bottom river")
|
||||
}
|
||||
baseTerrainTable.add(tileGroupBottomRiver).row()
|
||||
@ -439,7 +444,7 @@ class TileEditorOptionsTable(val mapEditorScreen: MapEditorScreen): Table(Camera
|
||||
tileInfoBottomLeftRiver.baseTerrain = Constants.plains
|
||||
val tileGroupBottomLeftRiver = makeTileGroup(tileInfoBottomLeftRiver)
|
||||
tileGroupBottomLeftRiver.onClick {
|
||||
tileAction = {it.hasBottomLeftRiver = !it.hasBottomLeftRiver}
|
||||
tileAction = { it.hasBottomLeftRiver = !it.hasBottomLeftRiver }
|
||||
setCurrentHex(tileInfoBottomLeftRiver, "Bottom left river")
|
||||
}
|
||||
baseTerrainTable.add(tileGroupBottomLeftRiver).row()
|
||||
@ -458,17 +463,17 @@ class TileEditorOptionsTable(val mapEditorScreen: MapEditorScreen): Table(Camera
|
||||
}
|
||||
|
||||
|
||||
private fun getHex(color: Color, image: Actor?=null): Group {
|
||||
private fun getHex(color: Color, image: Actor? = null): Group {
|
||||
val hex = ImageGetter.getImage(tileSetLocation + "Hexagon")
|
||||
hex.color = color
|
||||
hex.width*=0.3f
|
||||
hex.height*=0.3f
|
||||
hex.width *= 0.3f
|
||||
hex.height *= 0.3f
|
||||
val group = Group()
|
||||
group.setSize(hex.width,hex.height)
|
||||
group.setSize(hex.width, hex.height)
|
||||
hex.center(group)
|
||||
group.addActor(hex)
|
||||
|
||||
if(image!=null) {
|
||||
if (image != null) {
|
||||
image.setSize(40f, 40f)
|
||||
image.center(group)
|
||||
group.addActor(image)
|
||||
@ -482,7 +487,7 @@ class TileEditorOptionsTable(val mapEditorScreen: MapEditorScreen): Table(Camera
|
||||
normalizeTile(tileInfo)
|
||||
}
|
||||
|
||||
fun normalizeTile(tileInfo: TileInfo){
|
||||
fun normalizeTile(tileInfo: TileInfo) {
|
||||
/*Natural Wonder superpowers! */
|
||||
if (tileInfo.naturalWonder != null) {
|
||||
val naturalWonder = tileInfo.getNaturalWonder()
|
||||
@ -494,19 +499,19 @@ class TileEditorOptionsTable(val mapEditorScreen: MapEditorScreen): Table(Camera
|
||||
|
||||
if (tileInfo.terrainFeature != null) {
|
||||
val terrainFeature = tileInfo.getTerrainFeature()
|
||||
if (terrainFeature==null || terrainFeature.occursOn.isNotEmpty() && !terrainFeature.occursOn.contains(tileInfo.baseTerrain))
|
||||
if (terrainFeature == null || terrainFeature.occursOn.isNotEmpty() && !terrainFeature.occursOn.contains(tileInfo.baseTerrain))
|
||||
tileInfo.terrainFeature = null
|
||||
}
|
||||
if (tileInfo.resource != null) {
|
||||
val resource = tileInfo.getTileResource()
|
||||
if(resource.terrainsCanBeFoundOn.none { it==tileInfo.baseTerrain || it==tileInfo.terrainFeature })
|
||||
tileInfo.resource=null
|
||||
if (resource.terrainsCanBeFoundOn.none { it == tileInfo.baseTerrain || it == tileInfo.terrainFeature })
|
||||
tileInfo.resource = null
|
||||
}
|
||||
if (tileInfo.improvement!=null) {
|
||||
if (tileInfo.improvement != null) {
|
||||
normalizeTileImprovement(tileInfo)
|
||||
}
|
||||
if (tileInfo.isWater || tileInfo.isImpassible())
|
||||
tileInfo.roadStatus= RoadStatus.None
|
||||
tileInfo.roadStatus = RoadStatus.None
|
||||
}
|
||||
|
||||
private fun normalizeTileImprovement(tileInfo: TileInfo) {
|
||||
@ -518,29 +523,32 @@ class TileEditorOptionsTable(val mapEditorScreen: MapEditorScreen): Table(Camera
|
||||
}
|
||||
val improvement = tileInfo.getTileImprovement()!!
|
||||
tileInfo.improvement = null // Unset, and check if it can be reset. If so, do it, if not, invalid.
|
||||
if (tileInfo.canImprovementBeBuiltHere(improvement))
|
||||
if (tileInfo.canImprovementBeBuiltHere(improvement)
|
||||
// Allow building 'other' improvements like city ruins, barb encampments, Great Improvements etc
|
||||
|| (improvement.terrainsCanBeBuiltOn.isEmpty() && ruleset.tileResources.values.none { it.improvement==improvement.name }
|
||||
&& !tileInfo.isImpassible() && tileInfo.isLand))
|
||||
tileInfo.improvement = improvement.name
|
||||
}
|
||||
|
||||
private fun setCurrentHex(tileInfo: TileInfo, text:String){
|
||||
private fun setCurrentHex(tileInfo: TileInfo, text: String) {
|
||||
val tileGroup = TileGroup(tileInfo, TileSetStrings())
|
||||
.apply {
|
||||
showEntireMap=true
|
||||
forMapEditorIcon=true
|
||||
showEntireMap = true
|
||||
forMapEditorIcon = true
|
||||
update()
|
||||
}
|
||||
tileGroup.baseLayerGroup.moveBy(-10f, 10f)
|
||||
setCurrentHex(tileGroup,text)
|
||||
setCurrentHex(tileGroup, text)
|
||||
}
|
||||
|
||||
private fun setCurrentHex(actor: Actor, text:String){
|
||||
private fun setCurrentHex(actor: Actor, text: String) {
|
||||
currentHex.remove()
|
||||
val currentHexTable = Table()
|
||||
currentHexTable.add(text.toLabel()).padRight(30f)
|
||||
currentHexTable.add(actor)
|
||||
currentHexTable.pack()
|
||||
currentHex=currentHexTable
|
||||
currentHex.setPosition(stage.width - currentHex.width-10, 10f)
|
||||
currentHex = currentHexTable
|
||||
currentHex.setPosition(stage.width - currentHex.width - 10, 10f)
|
||||
stage.addActor(currentHex)
|
||||
}
|
||||
|
||||
|
@ -85,9 +85,4 @@ class BasicTests {
|
||||
Assert.assertTrue(modCheck == "")
|
||||
}
|
||||
|
||||
|
||||
// @Test // This should NOT run as part of the test suite!
|
||||
// fun tryGetGithubTopicInfo(){
|
||||
// println(Github.tryGetGithubReposWithTopic())
|
||||
// }
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user