diff --git a/core/src/com/unciv/ui/cityscreen/CityTileGroup.kt b/core/src/com/unciv/ui/cityscreen/CityTileGroup.kt index 61dae6db..3915d354 100644 --- a/core/src/com/unciv/ui/cityscreen/CityTileGroup.kt +++ b/core/src/com/unciv/ui/cityscreen/CityTileGroup.kt @@ -10,10 +10,8 @@ import com.unciv.ui.utils.centerX class CityTileGroup(private val city: CityInfo, tileInfo: TileInfo) : TileGroup(tileInfo) { - var yieldGroup: YieldGroup init { - this.yieldGroup = YieldGroup() addActor(yieldGroup) if (city.location == tileInfo.position) { populationImage = ImageGetter.getImage("StatIcons/City_Center_(Civ6).png") diff --git a/core/src/com/unciv/ui/tilegroups/TileGroup.kt b/core/src/com/unciv/ui/tilegroups/TileGroup.kt index 28c00a0c..ded6e499 100644 --- a/core/src/com/unciv/ui/tilegroups/TileGroup.kt +++ b/core/src/com/unciv/ui/tilegroups/TileGroup.kt @@ -9,6 +9,7 @@ import com.unciv.logic.HexMath import com.unciv.logic.map.MapUnit import com.unciv.logic.map.RoadStatus import com.unciv.logic.map.TileInfo +import com.unciv.ui.cityscreen.YieldGroup import com.unciv.ui.utils.ImageGetter import com.unciv.ui.utils.center import com.unciv.ui.utils.colorFromRGB @@ -33,6 +34,7 @@ open class TileGroup(var tileInfo: TileInfo) : Group() { protected var militaryUnitImage: Group? = null private val circleImage = ImageGetter.getImage("OtherIcons/Circle.png") // for blue and red circles on the tile private val fogImage = ImageGetter.getImage("TerrainIcons/Fog.png") + var yieldGroup = YieldGroup() init { val groupSize = 54f diff --git a/core/src/com/unciv/ui/tilegroups/WorldTileGroup.kt b/core/src/com/unciv/ui/tilegroups/WorldTileGroup.kt index 4db69c92..a191e922 100644 --- a/core/src/com/unciv/ui/tilegroups/WorldTileGroup.kt +++ b/core/src/com/unciv/ui/tilegroups/WorldTileGroup.kt @@ -32,6 +32,11 @@ class WorldTileGroup(tileInfo: TileInfo) : TileGroup(tileInfo) { whiteHalo.toBack() } + init{ + yieldGroup.center(this) + yieldGroup.moveBy(-22f,0f) + } + override fun update(isViewable: Boolean) { @@ -46,6 +51,10 @@ class WorldTileGroup(tileInfo: TileInfo) : TileGroup(tileInfo) { || viewEntireMapForDebug) updateCityButton(city) // needs to be before the update so the units will be above the city button super.update(isViewable) + + yieldGroup.isVisible = !UnCivGame.Current.settings.showResourcesAndImprovements + if(yieldGroup.isVisible) + yieldGroup.setStats(tileInfo.getTileStats(UnCivGame.Current.gameInfo.getPlayerCivilization())) } private fun updateCityButton(city: CityInfo?) { diff --git a/core/src/com/unciv/ui/worldscreen/Minimap.kt b/core/src/com/unciv/ui/worldscreen/Minimap.kt new file mode 100644 index 00000000..d14bc0ef --- /dev/null +++ b/core/src/com/unciv/ui/worldscreen/Minimap.kt @@ -0,0 +1,83 @@ +package com.unciv.ui.worldscreen + +import com.badlogic.gdx.graphics.Color +import com.badlogic.gdx.scenes.scene2d.Event +import com.badlogic.gdx.scenes.scene2d.Group +import com.badlogic.gdx.scenes.scene2d.InputListener +import com.badlogic.gdx.scenes.scene2d.ui.Image +import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane +import com.unciv.logic.HexMath +import com.unciv.logic.map.TileInfo +import com.unciv.ui.cityscreen.addClickListener +import com.unciv.ui.utils.ImageGetter +import com.unciv.ui.utils.colorFromRGB + +class Minimap(val tileMapHolder: TileMapHolder) : ScrollPane(null){ + val allTiles = Group() + val tileImages = HashMap() + + + fun setScrollToTileMapHolder(){ + scrollPercentX = tileMapHolder.scrollPercentX + scrollPercentY = tileMapHolder.scrollPercentY + } + + init{ + var topX = 0f + var topY = 0f + var bottomX = 0f + var bottomY = 0f + + for (tileInfo in tileMapHolder.tileMap.values) { + val hex = ImageGetter.getImage("TerrainIcons/Hexagon.png") + + val positionalVector = HexMath().Hex2WorldCoords(tileInfo.position) + val groupSize = 10f + hex.setSize(groupSize,groupSize) + hex.setPosition(positionalVector.x * 0.5f * groupSize, + positionalVector.y * 0.5f * groupSize) + hex.addClickListener { + tileMapHolder.setCenterPosition(tileInfo.position); + setScrollToTileMapHolder() + } + allTiles.addActor(hex) + tileImages.put(tileInfo,hex) + + topX = Math.max(topX, hex.x + groupSize) + topY = Math.max(topY, hex.y + groupSize) + bottomX = Math.min(bottomX, hex.x) + bottomY = Math.min(bottomY, hex.y) + } + + for (group in allTiles.children) { + group.moveBy(-bottomX, -bottomY) + } + + // there are tiles "below the zero", + // so we zero out the starting position of the whole board so they will be displayed as well + allTiles.setSize(10 + topX - bottomX, 10 + topY - bottomY) + + widget = allTiles + layout() + updateVisualScroll() + tileMapHolder.addListener(object : InputListener(){ + override fun handle(e: Event?): Boolean { + setScrollToTileMapHolder() + return true + } + }) + update() + } + + fun update(){ + val exploredTiles = tileMapHolder.worldScreen.civInfo.exploredTiles + for(tileInfo in tileMapHolder.tileMap.values) { + val RGB = tileInfo.getBaseTerrain().RGB!! + val hex = tileImages[tileInfo]!! + if (!exploredTiles.contains(tileInfo.position)) hex.color = Color.BLACK + else if (tileInfo.isCityCenter()) hex.color = Color.WHITE + else if (tileInfo.getCity() != null) hex.color = tileInfo.getOwner()!!.getCivilization().getColor() + else hex.color = colorFromRGB(RGB[0], RGB[1], RGB[2]).lerp(Color.GRAY, 0.5f) // Todo add to baseterrain as function + } + } +} \ No newline at end of file diff --git a/core/src/com/unciv/ui/worldscreen/NotificationsScroll.kt b/core/src/com/unciv/ui/worldscreen/NotificationsScroll.kt index 73b96272..59b2b8af 100644 --- a/core/src/com/unciv/ui/worldscreen/NotificationsScroll.kt +++ b/core/src/com/unciv/ui/worldscreen/NotificationsScroll.kt @@ -28,7 +28,7 @@ class NotificationsScroll(private val notifications: List, interna minitable.add(ImageGetter.getImage("OtherIcons/Circle.png") .apply { color=notification.color }).size(10f).pad(5f) minitable.background(ImageGetter.getDrawable("skin/civTableBackground.png")) - minitable.add(label).pad(5f).padRight(10f) + minitable.add(label).pad(3f).padRight(10f) if (notification.location != null) { minitable.addClickListener { @@ -36,7 +36,7 @@ class NotificationsScroll(private val notifications: List, interna } } - notificationsTable.add(minitable).pad(5f) + notificationsTable.add(minitable).pad(3f) notificationsTable.row() } notificationsTable.pack() diff --git a/core/src/com/unciv/ui/worldscreen/TileInfoTable.kt b/core/src/com/unciv/ui/worldscreen/TileInfoTable.kt index 28a1c40b..ae5201ea 100644 --- a/core/src/com/unciv/ui/worldscreen/TileInfoTable.kt +++ b/core/src/com/unciv/ui/worldscreen/TileInfoTable.kt @@ -15,11 +15,10 @@ class TileInfoTable(private val worldScreen: WorldScreen) : Table() { internal fun updateTileTable(tile: TileInfo) { clearChildren() val civInfo = worldScreen.civInfo - pad(20f) columnDefaults(0).padRight(10f) if (civInfo.exploredTiles.contains(tile.position)) { - add(getStatsTable(tile)).pad(20f) + add(getStatsTable(tile)).pad(10f) add(Label(tile.toString(), skin)).colspan(2) } diff --git a/core/src/com/unciv/ui/worldscreen/TileMapHolder.kt b/core/src/com/unciv/ui/worldscreen/TileMapHolder.kt index 71bbb7b5..ae83b436 100644 --- a/core/src/com/unciv/ui/worldscreen/TileMapHolder.kt +++ b/core/src/com/unciv/ui/worldscreen/TileMapHolder.kt @@ -82,6 +82,7 @@ class TileMapHolder(internal val worldScreen: WorldScreen, internal val tileMap: } }) + layout() // Fit the scroll pane to the contents - otherwise, setScroll won't work! } internal fun updateTiles() { @@ -124,7 +125,6 @@ class TileMapHolder(internal val worldScreen: WorldScreen, internal val tileMap: val tileGroup = tileGroups.values.first { it.tileInfo.position == vector } selectedTile = tileGroup.tileInfo worldScreen.bottomBar.unitTable.tileSelected(selectedTile!!) - 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 (== filter the screen starts) needs to be half a screen away scrollX = tileGroup.x + tileGroup.width / 2 - worldScreen.stage.width / 2 diff --git a/core/src/com/unciv/ui/worldscreen/WorldScreen.kt b/core/src/com/unciv/ui/worldscreen/WorldScreen.kt index 02218d5c..7e18eec4 100644 --- a/core/src/com/unciv/ui/worldscreen/WorldScreen.kt +++ b/core/src/com/unciv/ui/worldscreen/WorldScreen.kt @@ -13,7 +13,6 @@ import com.unciv.ui.pickerscreens.TechPickerScreen import com.unciv.ui.utils.CameraStageBaseScreen import com.unciv.ui.utils.disable import com.unciv.ui.utils.enable -import com.unciv.ui.utils.tr import com.unciv.ui.worldscreen.unit.UnitActionsTable class WorldScreen : CameraStageBaseScreen() { @@ -21,6 +20,7 @@ class WorldScreen : CameraStageBaseScreen() { internal val civInfo: CivilizationInfo = gameInfo.getPlayerCivilization() val tileMapHolder: TileMapHolder = TileMapHolder(this, gameInfo.tileMap, civInfo) + val minimap = Minimap(tileMapHolder) internal var buttonScale = 0.9f private val topBar = WorldScreenTopBar(this) @@ -40,12 +40,15 @@ class WorldScreen : CameraStageBaseScreen() { topBar.y - nextTurnButton.height - 10f) notificationsScroll = NotificationsScroll(gameInfo.notifications, this) notificationsScroll.width = stage.width/3 + notificationsScroll.height = stage.height/3 Label("", skin).style.font.data.setScale(1.5f) - + minimap.setSize(stage.width/5,stage.height/5) + minimap.x = stage.width - minimap.width tileMapHolder.addTiles() stage.addActor(tileMapHolder) + stage.addActor(minimap) stage.addActor(topBar) stage.addActor(nextTurnButton) stage.addActor(techButton) @@ -70,6 +73,8 @@ class WorldScreen : CameraStageBaseScreen() { updateTechButton() bottomBar.update(tileMapHolder.selectedTile) // has to come before tilemapholder update because the tilemapholder actions depend on the selected unit! + minimap.update() + minimap.y = bottomBar.height unitActionsTable.update(bottomBar.unitTable.selectedUnit) unitActionsTable.y = bottomBar.height diff --git a/core/src/com/unciv/ui/worldscreen/WorldScreenBottomBar.kt b/core/src/com/unciv/ui/worldscreen/WorldScreenBottomBar.kt index e73d64e7..36845160 100644 --- a/core/src/com/unciv/ui/worldscreen/WorldScreenBottomBar.kt +++ b/core/src/com/unciv/ui/worldscreen/WorldScreenBottomBar.kt @@ -32,4 +32,5 @@ class WorldScreenBottomBar(val worldScreen: WorldScreen) : Table(){ if(selectedTile!=null) tileInfoTable.updateTileTable(selectedTile) pack() } -} \ No newline at end of file +} +