made on-map windows touchable, so you can't "touch through" them on the map

This commit is contained in:
martin 2019-05-14 08:33:32 +02:00 committed by Yair Morgenstern
parent 48af218795
commit 462dc26460
5 changed files with 26 additions and 15 deletions

View File

@ -1,10 +1,10 @@
package com.unciv.ui.worldscreen
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.scenes.scene2d.Touchable
import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane
import com.badlogic.gdx.scenes.scene2d.ui.Table
import com.unciv.logic.civilization.Notification
import com.unciv.models.gamebasics.tr
import com.unciv.ui.utils.*
import kotlin.math.min
@ -12,7 +12,8 @@ class NotificationsScroll(internal val worldScreen: WorldScreen) : ScrollPane(nu
private var notificationsTable = Table()
init {
widget = notificationsTable
actor = notificationsTable.right()
touchable = Touchable.childrenOnly
}
internal fun update(notifications: MutableList<Notification>) {
@ -20,21 +21,24 @@ class NotificationsScroll(internal val worldScreen: WorldScreen) : ScrollPane(nu
for (notification in notifications.toList()) { // tolist to avoid concurrecy problems
val label = notification.text.toLabel().setFontColor(Color.BLACK)
.setFontSize(14)
val minitable = Table()
val listItem = Table()
minitable.add(ImageGetter.getCircle()
listItem.add(ImageGetter.getCircle()
.apply { color=notification.color }).size(10f).pad(5f)
minitable.background(ImageGetter.getDrawable("OtherIcons/civTableBackground.png"))
minitable.add(label).pad(5f).padRight(10f)
listItem.background(ImageGetter.getDrawable("OtherIcons/civTableBackground.png"))
listItem.add(label).pad(5f).padRight(10f)
if (notification.location != null) {
minitable.onClick {
worldScreen.tileMapHolder.setCenterPosition(notification.location!!)
// using a larger click area to avoid miss-clicking in between the messages on the map
val clickArea = Table().apply {
add(listItem).pad(3f)
touchable = Touchable.enabled
onClick {
if (notification.location != null)
worldScreen.tileMapHolder.setCenterPosition(notification.location!!)
}
}
notificationsTable.add(minitable).pad(3f)
notificationsTable.row()
notificationsTable.add(clickArea).right().row()
}
notificationsTable.pack()
pack()

View File

@ -49,7 +49,8 @@ class WorldScreen : CameraStageBaseScreen() {
topBar.width = stage.width
notificationsScroll = NotificationsScroll(this)
notificationsScroll.width = stage.width/3
// notifications are right-aligned, they take up only as much space as necessary.
notificationsScroll.width = stage.width/2
minimapWrapper.x = stage.width - minimapWrapper.width
@ -150,7 +151,7 @@ class WorldScreen : CameraStageBaseScreen() {
minimapWrapper.y = bottomBar.height // couldn't be bothered to create a separate val for minimap wrapper
unitActionsTable.update(bottomBar.unitTable.selectedUnit)
unitActionsTable.y = bottomBar.height
unitActionsTable.y = bottomBar.unitTable.height
// if we use the clone, then when we update viewable tiles
// it doesn't update the explored tiles of the civ... need to think about that harder
@ -159,7 +160,6 @@ class WorldScreen : CameraStageBaseScreen() {
topBar.update(cloneCivilization)
notificationsScroll.update(currentPlayerCiv.notifications)
notificationsScroll.width = stage.width/3
notificationsScroll.setPosition(stage.width - notificationsScroll.width - 5f,
nextTurnButton.y - notificationsScroll.height - 5f)

View File

@ -1,6 +1,7 @@
package com.unciv.ui.worldscreen.bottombar
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.scenes.scene2d.Touchable
import com.badlogic.gdx.scenes.scene2d.actions.Actions
import com.badlogic.gdx.scenes.scene2d.actions.RepeatAction
import com.badlogic.gdx.scenes.scene2d.ui.Image
@ -24,6 +25,7 @@ class BattleTable(val worldScreen: WorldScreen): Table() {
skin = CameraStageBaseScreen.skin
background = ImageGetter.getBackground(ImageGetter.getBlue())
pad(5f)
touchable = Touchable.enabled
}
fun hide(){

View File

@ -2,6 +2,7 @@ package com.unciv.ui.worldscreen.unit
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.scenes.scene2d.Actor
import com.badlogic.gdx.scenes.scene2d.Touchable
import com.badlogic.gdx.scenes.scene2d.ui.Button
import com.badlogic.gdx.scenes.scene2d.ui.Label
import com.badlogic.gdx.scenes.scene2d.ui.Table
@ -14,6 +15,10 @@ import com.unciv.ui.worldscreen.WorldScreen
class UnitActionsTable(val worldScreen: WorldScreen) : Table(){
init {
touchable = Touchable.enabled
}
fun getIconForUnitAction(unitAction:String): Actor {
if(unitAction.startsWith("Upgrade to")){
// Regexplaination: start with a [, take as many non-] chars as you can, until you reach a ].

View File

@ -34,7 +34,7 @@ class UnitTable(val worldScreen: WorldScreen) : Table(){
init {
pad(5f)
touchable = Touchable.enabled
background = ImageGetter.getBackground(ImageGetter.getBlue().lerp(Color.BLACK, 0.5f))
add(VerticalGroup().apply {