Added minimap!

Notifications now take up less of the increasingly valuabe screenspace
This commit is contained in:
Yair Morgenstern 2018-06-08 13:18:45 +03:00
parent 7002b8d55e
commit 83c235690a
9 changed files with 107 additions and 10 deletions

View file

@ -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")

View file

@ -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

View file

@ -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?) {

View file

@ -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<TileInfo, Image>()
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
}
}
}

View file

@ -28,7 +28,7 @@ class NotificationsScroll(private val notifications: List<Notification>, 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<Notification>, interna
}
}
notificationsTable.add(minitable).pad(5f)
notificationsTable.add(minitable).pad(3f)
notificationsTable.row()
}
notificationsTable.pack()

View file

@ -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)
}

View file

@ -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

View file

@ -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

View file

@ -32,4 +32,5 @@ class WorldScreenBottomBar(val worldScreen: WorldScreen) : Table(){
if(selectedTile!=null) tileInfoTable.updateTileTable(selectedTile)
pack()
}
}
}