Notificiations tab scroll fix in empire overview (#7536)

* Update NotificationsOverviewTable.kt

* Update EmpireOverviewCategories.kt

* Update NotificationsOverviewTable.kt
This commit is contained in:
MindaugasRumsa51 2022-08-13 22:43:42 +03:00 committed by GitHub
parent 9967642573
commit 89979748a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 4 deletions

View File

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

View File

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