tile groups moved to tile map holder, as they should be
This commit is contained in:
parent
064aee2f07
commit
146c4111fd
3 changed files with 23 additions and 22 deletions
|
@ -44,31 +44,32 @@ class TileInfoTable(private val worldScreen: WorldScreen, internal val civInfo:
|
|||
|
||||
|
||||
if (tile.unit != null) {
|
||||
var moveUnitButton = TextButton("Move to", skin)
|
||||
if (worldScreen.tileMapHolder.unitTile == tile) moveUnitButton = TextButton("Stop movement", skin)
|
||||
val tileMapHolder = worldScreen.tileMapHolder
|
||||
val buttonText = if (tileMapHolder.unitTile == tile)"Stop movement" else "Move to"
|
||||
var moveUnitButton = TextButton(buttonText, skin)
|
||||
moveUnitButton.label.setFontScale(worldScreen.buttonScale)
|
||||
if (tile.unit!!.currentMovement == 0f) {
|
||||
moveUnitButton.color = Color.GRAY
|
||||
moveUnitButton.touchable = Touchable.disabled
|
||||
}
|
||||
moveUnitButton.addClickListener {
|
||||
if (worldScreen.tileMapHolder.unitTile != null) {
|
||||
worldScreen.tileMapHolder.unitTile = null
|
||||
worldScreen.update()
|
||||
if (tileMapHolder.unitTile != null) {
|
||||
tileMapHolder.unitTile = null
|
||||
tileMapHolder.updateTiles()
|
||||
return@addClickListener
|
||||
}
|
||||
worldScreen.tileMapHolder.unitTile = tile
|
||||
tileMapHolder.unitTile = tile
|
||||
|
||||
// Set all tiles transparent except those in unit range
|
||||
for (TG in worldScreen.tileGroups.linqValues()) TG.setColor(0f, 0f, 0f, 0.3f)
|
||||
for (TG in tileMapHolder.tileGroups.linqValues()) TG.setColor(0f, 0f, 0f, 0.3f)
|
||||
|
||||
val distanceToTiles = civInfo.gameInfo.tileMap.getDistanceToTilesWithinTurn(
|
||||
worldScreen.tileMapHolder.unitTile!!.position,
|
||||
worldScreen.tileMapHolder.unitTile!!.unit!!.currentMovement,
|
||||
tileMapHolder.unitTile!!.position,
|
||||
tileMapHolder.unitTile!!.unit!!.currentMovement,
|
||||
civInfo.tech.isResearched("Machinery"))
|
||||
|
||||
for (tile in distanceToTiles.keys) {
|
||||
worldScreen.tileGroups[tile.position.toString()]!!.color = Color.WHITE
|
||||
tileMapHolder.tileGroups[tile.position.toString()]!!.color = Color.WHITE
|
||||
}
|
||||
|
||||
worldScreen.update()
|
||||
|
|
|
@ -9,6 +9,7 @@ import com.unciv.logic.civilization.CivilizationInfo
|
|||
import com.unciv.logic.map.TileInfo
|
||||
import com.unciv.logic.map.TileMap
|
||||
import com.unciv.models.linq.Linq
|
||||
import com.unciv.models.linq.LinqHashMap
|
||||
import com.unciv.ui.cityscreen.addClickListener
|
||||
import com.unciv.ui.tilegroups.WorldTileGroup
|
||||
import com.unciv.ui.utils.HexMath
|
||||
|
@ -17,6 +18,7 @@ import java.util.*
|
|||
class TileMapHolder(internal val worldScreen: WorldScreen, internal val tileMap: TileMap, internal val civInfo: CivilizationInfo) : ScrollPane(null) {
|
||||
internal var selectedTile: TileInfo? = null
|
||||
internal var unitTile: TileInfo? = null
|
||||
val tileGroups = LinqHashMap<String, WorldTileGroup>()
|
||||
|
||||
internal fun addTiles() {
|
||||
val allTiles = Group()
|
||||
|
@ -59,7 +61,7 @@ class TileMapHolder(internal val worldScreen: WorldScreen, internal val tileMap:
|
|||
val groupSize = 50
|
||||
group.setPosition(worldScreen.stage.width / 2 + positionalVector.x * 0.8f * groupSize.toFloat(),
|
||||
worldScreen.stage.height / 2 + positionalVector.y * 0.8f * groupSize.toFloat())
|
||||
worldScreen.tileGroups[tileInfo.position.toString()] = group
|
||||
tileGroups[tileInfo.position.toString()] = group
|
||||
allTiles.addActor(group)
|
||||
topX = Math.max(topX, group.x + groupSize)
|
||||
topY = Math.max(topY, group.y + groupSize)
|
||||
|
@ -67,7 +69,7 @@ class TileMapHolder(internal val worldScreen: WorldScreen, internal val tileMap:
|
|||
bottomY = Math.min(bottomY, group.y)
|
||||
}
|
||||
|
||||
for (group in worldScreen.tileGroups.linqValues()) {
|
||||
for (group in tileGroups.linqValues()) {
|
||||
group.moveBy(-bottomX + 50, -bottomY + 50)
|
||||
}
|
||||
|
||||
|
@ -98,7 +100,7 @@ class TileMapHolder(internal val worldScreen: WorldScreen, internal val tileMap:
|
|||
}
|
||||
|
||||
internal fun updateTiles() {
|
||||
for (WG in worldScreen.tileGroups.linqValues()) WG.update(worldScreen)
|
||||
for (WG in tileGroups.linqValues()) WG.update(worldScreen)
|
||||
|
||||
if (unitTile != null)
|
||||
return // While we're in "unit move" mode, no tiles but the tiles the unit can move to will be "visible"
|
||||
|
@ -106,7 +108,7 @@ class TileMapHolder(internal val worldScreen: WorldScreen, internal val tileMap:
|
|||
// YES A TRIPLE FOR, GOT PROBLEMS WITH THAT?
|
||||
// Seriously though, there is probably a more efficient way of doing this, probably?
|
||||
// The original implementation caused serious lag on android, so efficiency is key, here
|
||||
for (WG in worldScreen.tileGroups.linqValues()) WG.setIsViewable(false)
|
||||
for (WG in tileGroups.linqValues()) WG.setIsViewable(false)
|
||||
val veiwableVectorStrings = HashSet<String>()
|
||||
|
||||
// tiles adjacent to city tiles
|
||||
|
@ -122,19 +124,19 @@ class TileMapHolder(internal val worldScreen: WorldScreen, internal val tileMap:
|
|||
veiwableVectorStrings.add(tileInfo.position.toString())
|
||||
|
||||
for (string in veiwableVectorStrings)
|
||||
if (worldScreen.tileGroups.containsKey(string))
|
||||
worldScreen.tileGroups[string]!!.setIsViewable(true)
|
||||
if (tileGroups.containsKey(string))
|
||||
tileGroups[string]!!.setIsViewable(true)
|
||||
}
|
||||
|
||||
|
||||
fun setCenterPosition(vector: Vector2) {
|
||||
val TG = worldScreen.tileGroups.linqValues().first { arg0 -> arg0.tileInfo.position == vector }
|
||||
val tileGroup = tileGroups.linqValues().first { it.tileInfo.position == vector }
|
||||
layout() // Fit the scroll pane to the contents - otherwise, setScroll won't work!
|
||||
// We want to center on the middle of TG (TG.getX()+TG.getWidth()/2)
|
||||
// and so the scroll position (== where the screen starts) needs to be half a screen away
|
||||
scrollX = TG!!.x + TG.width / 2 - worldScreen.stage.width / 2
|
||||
scrollX = tileGroup!!.x + tileGroup.width / 2 - worldScreen.stage.width / 2
|
||||
// Here it's the same, only the Y axis is inverted - when at 0 we're at the top, not bottom - so we invert it back.
|
||||
scrollY = maxY - (TG.y + TG.width / 2 - worldScreen.stage.height / 2)
|
||||
scrollY = maxY - (tileGroup.y + tileGroup.width / 2 - worldScreen.stage.height / 2)
|
||||
updateVisualScroll()
|
||||
}
|
||||
|
||||
|
|
|
@ -5,11 +5,9 @@ import com.badlogic.gdx.scenes.scene2d.ui.Label
|
|||
import com.badlogic.gdx.scenes.scene2d.ui.TextButton
|
||||
import com.unciv.logic.civilization.CivilizationInfo
|
||||
import com.unciv.models.linq.Linq
|
||||
import com.unciv.models.linq.LinqHashMap
|
||||
import com.unciv.ui.cityscreen.addClickListener
|
||||
import com.unciv.ui.pickerscreens.PolicyPickerScreen
|
||||
import com.unciv.ui.pickerscreens.TechPickerScreen
|
||||
import com.unciv.ui.tilegroups.WorldTileGroup
|
||||
import com.unciv.ui.utils.CameraStageBaseScreen
|
||||
import com.unciv.ui.utils.GameSaver
|
||||
|
||||
|
@ -22,7 +20,7 @@ class WorldScreen : CameraStageBaseScreen() {
|
|||
private val tileInfoTable: TileInfoTable
|
||||
private val civTable = CivStatsTable()
|
||||
private val techButton = TextButton("", CameraStageBaseScreen.skin)
|
||||
val tileGroups = LinqHashMap<String, WorldTileGroup>()
|
||||
|
||||
|
||||
internal val optionsTable: WorldScreenOptionsTable
|
||||
private val notificationsScroll: NotificationsScroll
|
||||
|
|
Loading…
Reference in a new issue