mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-14 17:59:11 +07:00
Notifications scroll pane position fix (#8900)
* Notifications scroll pane position fix * Removed an unnecessary var
This commit is contained in:
@ -32,7 +32,6 @@ class NotificationsScroll(
|
|||||||
private var notificationsHash: Int = 0
|
private var notificationsHash: Int = 0
|
||||||
|
|
||||||
private var notificationsTable = Table()
|
private var notificationsTable = Table()
|
||||||
private var endOfTableSpacerCell: Cell<*>? = null
|
|
||||||
|
|
||||||
private val maxEntryWidth = worldScreen.stage.width * maxWidthOfStage * inverseScaleFactor
|
private val maxEntryWidth = worldScreen.stage.width * maxWidthOfStage * inverseScaleFactor
|
||||||
|
|
||||||
@ -50,13 +49,12 @@ class NotificationsScroll(
|
|||||||
*/
|
*/
|
||||||
internal fun update(
|
internal fun update(
|
||||||
notifications: MutableList<Notification>,
|
notifications: MutableList<Notification>,
|
||||||
maxNotificationsHeight: Float,
|
maxNotificationsHeight: Float
|
||||||
tileInfoTableHeight: Float
|
|
||||||
) {
|
) {
|
||||||
val previousScrollY = scrollY
|
val previousScrollY = scrollY
|
||||||
|
|
||||||
updateContent(notifications)
|
updateContent(notifications)
|
||||||
updateLayout(maxNotificationsHeight, tileInfoTableHeight)
|
updateLayout(maxNotificationsHeight)
|
||||||
|
|
||||||
scrollY = previousScrollY
|
scrollY = previousScrollY
|
||||||
updateVisualScroll()
|
updateVisualScroll()
|
||||||
@ -69,7 +67,6 @@ class NotificationsScroll(
|
|||||||
notificationsHash = newHash
|
notificationsHash = newHash
|
||||||
|
|
||||||
notificationsTable.clearChildren()
|
notificationsTable.clearChildren()
|
||||||
endOfTableSpacerCell = null
|
|
||||||
|
|
||||||
val reversedNotifications = notifications.asReversed().toList() // toList to avoid concurrency problems
|
val reversedNotifications = notifications.asReversed().toList() // toList to avoid concurrency problems
|
||||||
for (category in NotificationCategory.values()){
|
for (category in NotificationCategory.values()){
|
||||||
@ -120,29 +117,14 @@ class NotificationsScroll(
|
|||||||
notificationsTable.pack() // needed to get height - prefHeight is set and close but not quite the same value
|
notificationsTable.pack() // needed to get height - prefHeight is set and close but not quite the same value
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateLayout(maxNotificationsHeight: Float, tileInfoTableHeight: Float) {
|
private fun updateLayout(maxNotificationsHeight: Float) {
|
||||||
val newHeight = min(notificationsTable.height, maxNotificationsHeight * inverseScaleFactor)
|
val newHeight = min(notificationsTable.height, maxNotificationsHeight * inverseScaleFactor)
|
||||||
|
|
||||||
sizeScrollingSpacer(tileInfoTableHeight)
|
|
||||||
|
|
||||||
pack()
|
pack()
|
||||||
height = newHeight // after this, maxY is still incorrect until layout()
|
height = newHeight // after this, maxY is still incorrect until layout()
|
||||||
layout()
|
layout()
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Add some empty space that can be scrolled under the TileInfoTable which is covering our lower part */
|
|
||||||
private fun sizeScrollingSpacer(tileInfoTableHeight: Float) {
|
|
||||||
if (endOfTableSpacerCell == null) {
|
|
||||||
endOfTableSpacerCell = notificationsTable.add().pad(5f)
|
|
||||||
notificationsTable.row()
|
|
||||||
}
|
|
||||||
val scaledHeight = tileInfoTableHeight * inverseScaleFactor
|
|
||||||
endOfTableSpacerCell!!.height(scaledHeight)
|
|
||||||
notificationsTable.invalidate() // looks redundant but isn't
|
|
||||||
// (the flags it sets are already on when inspected in debugger, but when omitting it the
|
|
||||||
// ScrollPane will not properly scroll down to the new maxY when TileInfoTable changes to a smaller height)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun setTopRight (right: Float, top: Float) {
|
fun setTopRight (right: Float, top: Float) {
|
||||||
setPosition(right - width * scaleFactor, top - height * scaleFactor)
|
setPosition(right - width * scaleFactor, top - height * scaleFactor)
|
||||||
}
|
}
|
||||||
|
@ -454,8 +454,8 @@ class WorldScreen(
|
|||||||
updateGameplayButtons()
|
updateGameplayButtons()
|
||||||
|
|
||||||
val maxNotificationsHeight = statusButtons.y -
|
val maxNotificationsHeight = statusButtons.y -
|
||||||
(if (game.settings.showMinimap) minimapWrapper.height else 0f) - 5f
|
(if (game.settings.showMinimap) minimapWrapper.height else 0f) - bottomTileInfoTable.height - 5f
|
||||||
notificationsScroll.update(viewingCiv.notifications, maxNotificationsHeight, bottomTileInfoTable.height)
|
notificationsScroll.update(viewingCiv.notifications, maxNotificationsHeight)
|
||||||
notificationsScroll.setTopRight(stage.width - 10f, statusButtons.y - 5f)
|
notificationsScroll.setTopRight(stage.width - 10f, statusButtons.y - 5f)
|
||||||
|
|
||||||
val posZoomFromRight = if (game.settings.showMinimap) minimapWrapper.width
|
val posZoomFromRight = if (game.settings.showMinimap) minimapWrapper.width
|
||||||
|
Reference in New Issue
Block a user