From d8c779fd9b98590d2054d643d1f52399479918da Mon Sep 17 00:00:00 2001 From: yairm210 Date: Mon, 1 Sep 2025 10:38:58 +0300 Subject: [PATCH] Notification categories can me minimized by clicking on the title --- .../worldscreen/NotificationsScroll.kt | 40 ++++++++++++++----- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/core/src/com/unciv/ui/screens/worldscreen/NotificationsScroll.kt b/core/src/com/unciv/ui/screens/worldscreen/NotificationsScroll.kt index 3f346a68b8..cd4c213cb6 100644 --- a/core/src/com/unciv/ui/screens/worldscreen/NotificationsScroll.kt +++ b/core/src/com/unciv/ui/screens/worldscreen/NotificationsScroll.kt @@ -256,19 +256,41 @@ class NotificationsScroll( .groupBy { it.category } .toSortedMap() // This sorts by Category ordinal, so far intentional - the order of the grouped lists are unaffected for ((category, categoryNotifications) in orderedNotifications) { - if (category == NotificationCategory.General) - notificationsTable.add().padTop(categoryTopPad).row() // Make sure category w/o header gets same spacing + val header: CategoryHeader? + if (category == NotificationCategory.General) { + notificationsTable.add().padTop(categoryTopPad) + .row() // Make sure category w/o header gets same spacing + header = null + } else { - val header = CategoryHeader(category, backgroundDrawable) + header = CategoryHeader(category, backgroundDrawable) categoryHeaders.add(header) notificationsTable.add(header).right().row() } - for (notification in categoryNotifications) { - val item = ListItem(notification, backgroundDrawable) - itemWidths.add(item.itemWidth) - val itemCell = notificationsTable.add(item) - if (notification == highlightNotification) selectedCell = itemCell - itemCell.right().row() + + val notificationCategoryTable = Table() + + fun fillNotificationCategoryTable() { + for (notification in categoryNotifications) { + val item = ListItem(notification, backgroundDrawable) + itemWidths.add(item.itemWidth) + val itemCell = notificationCategoryTable.add(item) + if (notification == highlightNotification) selectedCell = itemCell + itemCell.right().row() + } + } + + fillNotificationCategoryTable() + notificationsTable.add(notificationCategoryTable).right().row() + + header?.onClick { + if (notificationCategoryTable.hasChildren()) { + notificationCategoryTable.clear() + notificationCategoryTable.pack() + } else { + fillNotificationCategoryTable() + notificationCategoryTable.pack() + } } }