From 5b427d76c61beb88c821fbaeb0a57b28d9ecb372 Mon Sep 17 00:00:00 2001 From: Benau Date: Sun, 26 Jul 2020 01:05:38 +0800 Subject: [PATCH] Remember language selection position after changed --- src/guiengine/widgets/CGUISTKListBox.hpp | 1 + src/states_screens/options/options_screen_language.cpp | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/src/guiengine/widgets/CGUISTKListBox.hpp b/src/guiengine/widgets/CGUISTKListBox.hpp index 7eaa147a8..5e98a022f 100644 --- a/src/guiengine/widgets/CGUISTKListBox.hpp +++ b/src/guiengine/widgets/CGUISTKListBox.hpp @@ -171,6 +171,7 @@ namespace irr virtual void setDrawBackground(bool draw); void setAlternatingDarkness(bool val) { m_alternating_darkness = val; } + gui::IGUIScrollBar* getScrollBar() const { return ScrollBar; } private: void recalculateItemHeight(); diff --git a/src/states_screens/options/options_screen_language.cpp b/src/states_screens/options/options_screen_language.cpp index c2c5a0f89..067cc3514 100644 --- a/src/states_screens/options/options_screen_language.cpp +++ b/src/states_screens/options/options_screen_language.cpp @@ -155,6 +155,9 @@ void OptionsScreenLanguage::eventCallback(Widget* widget, const std::string& nam else if (name == "language") { ListWidget* list_widget = getWidget("language"); + irr::gui::CGUISTKListBox* box = + list_widget->getIrrlichtElement(); + int old_pos = box->getScrollBar()->getPos(); std::string selection = list_widget->getSelectionInternalName(); delete translations; @@ -190,6 +193,11 @@ void OptionsScreenLanguage::eventCallback(Widget* widget, const std::string& nam user_config->saveConfig(); OptionsScreenLanguage::getInstance()->push(); + // Menu is deleted so we need a new screen instance + OptionsScreenLanguage* os = OptionsScreenLanguage::getInstance(); + list_widget = os->getWidget("language"); + box = list_widget->getIrrlichtElement(); + box->getScrollBar()->setPos(old_pos); // Update tips for new translation TipsManager::destroy(); TipsManager::create();