From 89979748a12cf5238a1a79e957894cebbf453392 Mon Sep 17 00:00:00 2001 From: MindaugasRumsa51 <107413099+MindaugasRumsa51@users.noreply.github.com> Date: Sat, 13 Aug 2022 22:43:42 +0300 Subject: [PATCH] Notificiations tab scroll fix in empire overview (#7536) * Update NotificationsOverviewTable.kt * Update EmpireOverviewCategories.kt * Update NotificationsOverviewTable.kt --- .../overviewscreen/EmpireOverviewCategories.kt | 8 +++++--- .../NotificationsOverviewTable.kt | 18 +++++++++++++++++- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/core/src/com/unciv/ui/overviewscreen/EmpireOverviewCategories.kt b/core/src/com/unciv/ui/overviewscreen/EmpireOverviewCategories.kt index 8b0d4b8fa7..055c853b8f 100644 --- a/core/src/com/unciv/ui/overviewscreen/EmpireOverviewCategories.kt +++ b/core/src/com/unciv/ui/overviewscreen/EmpireOverviewCategories.kt @@ -61,9 +61,11 @@ enum class EmpireOverviewCategories( = WonderOverviewTab(viewingPlayer, overviewScreen), fun (viewingPlayer: CivilizationInfo) = (viewingPlayer.naturalWonders.isEmpty() && viewingPlayer.cities.isEmpty()).toState()), Notifications("OtherIcons/Notifications", 'N', Align.top, - fun (viewingPlayer: CivilizationInfo, overviewScreen: EmpireOverviewScreen, _: EmpireOverviewTabPersistableData?) - = NotificationsOverviewTable(worldScreen = UncivGame.Current.worldScreen!!, viewingPlayer, overviewScreen), - fun (_: CivilizationInfo) = EmpireOverviewTabState.Normal); + fun (viewingPlayer: CivilizationInfo, overviewScreen: EmpireOverviewScreen, persistedData: EmpireOverviewTabPersistableData?) + = NotificationsOverviewTable(worldScreen = UncivGame.Current.worldScreen!!, viewingPlayer, overviewScreen, persistedData), + fun (_: CivilizationInfo) = EmpireOverviewTabState.Normal) + + ; //must be here constructor(iconName: String, shortcutChar: Char, scrollAlign: Int, factory: FactoryType, stateTester: StateTesterType = { _ -> EmpireOverviewTabState.Normal }) : this(iconName, KeyCharAndCode(shortcutChar), scrollAlign, factory, stateTester) diff --git a/core/src/com/unciv/ui/overviewscreen/NotificationsOverviewTable.kt b/core/src/com/unciv/ui/overviewscreen/NotificationsOverviewTable.kt index c910afabcc..2e5522c60f 100644 --- a/core/src/com/unciv/ui/overviewscreen/NotificationsOverviewTable.kt +++ b/core/src/com/unciv/ui/overviewscreen/NotificationsOverviewTable.kt @@ -9,6 +9,7 @@ import com.unciv.logic.civilization.Notification import com.unciv.ui.images.ImageGetter import com.unciv.ui.utils.BaseScreen import com.unciv.ui.utils.WrappableLabel +import com.unciv.ui.utils.TabbedPager import com.unciv.ui.utils.extensions.onClick import com.unciv.ui.utils.extensions.toLabel import com.unciv.ui.worldscreen.WorldScreen @@ -16,8 +17,23 @@ import com.unciv.ui.worldscreen.WorldScreen class NotificationsOverviewTable( val worldScreen: WorldScreen, viewingPlayer: CivilizationInfo, - overviewScreen: EmpireOverviewScreen + overviewScreen: EmpireOverviewScreen, + persistedData: EmpireOverviewTabPersistableData? = null ) : EmpireOverviewTab(viewingPlayer, overviewScreen) { + class NotificationsTabPersistableData( + var scrollY: Float? = null + ) : EmpireOverviewTabPersistableData() { + override fun isEmpty() = scrollY == null + } + override val persistableData = (persistedData as? NotificationsTabPersistableData) ?: NotificationsTabPersistableData() + override fun activated(index: Int, caption: String, pager: TabbedPager) { + if (persistableData.scrollY != null) + pager.setPageScrollY(index, persistableData.scrollY!!) + super.activated(index, caption, pager) + } + override fun deactivated(index: Int, caption: String, pager: TabbedPager) { + persistableData.scrollY = pager.getPageScrollY(index) + } val notificationLog = viewingPlayer.notificationsLog