Promotion picker keeps vertical scroll pos on promote or resize (#4247)

* Promotion picker keeps vertical scroll pos on promote or resize

* Promotion picker keeps vertical scroll - without parameter
This commit is contained in:
SomeTroglodyte 2021-06-24 20:37:50 +02:00 committed by GitHub
parent af0cd0c9df
commit 06b2e7da2f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -21,7 +21,7 @@ class PromotionPickerScreen(val unit: MapUnit) : PickerScreen() {
unit.promotions.addPromotion(promotion.name)
if (unit.promotions.canBePromoted())
game.setScreen(PromotionPickerScreen(unit))
game.setScreen(PromotionPickerScreen(unit).setScrollY(scrollPane.scrollY))
else
game.setWorldScreen()
dispose()
@ -32,7 +32,6 @@ class PromotionPickerScreen(val unit: MapUnit) : PickerScreen() {
onBackButtonClicked { UncivGame.Current.setWorldScreen() }
setDefaultCloseAction()
rightSideButton.setText("Pick promotion".tr())
rightSideButton.onClick(UncivSound.Promote) {
acceptPromotion(selectedPromotion)
@ -99,4 +98,17 @@ class PromotionPickerScreen(val unit: MapUnit) : PickerScreen() {
displayTutorial(Tutorial.Experience)
}
fun setScrollY(scrollY: Float): PromotionPickerScreen {
splitPane.pack() // otherwise scrollPane.maxY == 0
scrollPane.scrollY = scrollY
scrollPane.updateVisualScroll()
return this
}
override fun resize(width: Int, height: Int) {
if (stage.viewport.screenWidth != width || stage.viewport.screenHeight != height) {
game.setScreen(PromotionPickerScreen(unit).setScrollY(scrollPane.scrollY))
}
}
}