diff --git a/src/guiengine/modaldialog.cpp b/src/guiengine/modaldialog.cpp index 60f25b2fe..8467109f1 100644 --- a/src/guiengine/modaldialog.cpp +++ b/src/guiengine/modaldialog.cpp @@ -187,6 +187,7 @@ void ModalDialog::dismiss() { if(modalWindow != NULL) delete modalWindow; modalWindow = NULL; + GUIEngine::getCurrentScreen()->onDialogClose(); } // ---------------------------------------------------------------------------- diff --git a/src/guiengine/screen.hpp b/src/guiengine/screen.hpp index b6271c0c1..017c84b31 100644 --- a/src/guiengine/screen.hpp +++ b/src/guiengine/screen.hpp @@ -302,6 +302,10 @@ namespace GUIEngine int axisDir, int value) {} + /** Callback that gets called when a dialog is closed. + * Can be used to set focus for instance. + */ + virtual void onDialogClose() {} }; } diff --git a/src/guiengine/widgets/ribbon_widget.cpp b/src/guiengine/widgets/ribbon_widget.cpp index fcd2323f5..4bd2a491a 100644 --- a/src/guiengine/widgets/ribbon_widget.cpp +++ b/src/guiengine/widgets/ribbon_widget.cpp @@ -471,7 +471,6 @@ void RibbonWidget::select(std::string item, const int mousePlayerID) // ---------------------------------------------------------------------------- EventPropagation RibbonWidget::rightPressed(const int playerID) { - Log::info("RibbonWidget", "Right Pressed"); if (m_deactivated) return EVENT_LET; // empty ribbon, or only one item (can't move right) if (m_active_children.size() < 2) return EVENT_LET; diff --git a/src/states_screens/dialogs/login_dialog.cpp b/src/states_screens/dialogs/login_dialog.cpp index 82856c202..b8afdaec4 100644 --- a/src/states_screens/dialogs/login_dialog.cpp +++ b/src/states_screens/dialogs/login_dialog.cpp @@ -40,7 +40,6 @@ LoginDialog::LoginDialog(const Message message_type) : { m_self_destroy = false; m_open_registration_dialog = false; - m_reshow_current_screen = false; loadFromFile("online/login_dialog.stkgui"); m_info_widget = getWidget("info"); @@ -105,7 +104,6 @@ GUIEngine::EventPropagation LoginDialog::processEvent(const std::string& eventSo stringw info = ""; if(CurrentOnlineUser::get()->signIn(username,password,info)) { - m_reshow_current_screen = true; m_self_destroy = true; } else @@ -128,7 +126,7 @@ GUIEngine::EventPropagation LoginDialog::processEvent(const std::string& eventSo void LoginDialog::onEnterPressedInternal() { - //If enter was pressed while "cancel" nor "signup" was selected, then interpret as "signin" press. + //If enter was pressed while none of the other widgets are focused, then interpret as "signin" press. const int playerID = PLAYER_ID_GAME_MASTER; if (!GUIEngine::isFocusedForPlayer(m_recovery_widget, playerID) && !GUIEngine::isFocusedForPlayer(m_register_widget, playerID) && @@ -150,14 +148,6 @@ void LoginDialog::onUpdate(float dt) if (m_self_destroy) { ModalDialog::dismiss(); - if (m_reshow_current_screen) - /*Replaced to online state screen. Not 100% how I will handle this. - * Thee options : - * - Listener - * - Directly calling GUIEngine::reshowCurrentScreen(); (old option) - * - Underlying stateschreen is responsible for polling changed state (current option) - */ - true;//GUIEngine::reshowCurrentScreen(); if (m_open_registration_dialog) new RegistrationDialog(0.8f, 0.9f); diff --git a/src/states_screens/dialogs/login_dialog.hpp b/src/states_screens/dialogs/login_dialog.hpp index cbcf6e70f..37a2cc918 100644 --- a/src/states_screens/dialogs/login_dialog.hpp +++ b/src/states_screens/dialogs/login_dialog.hpp @@ -37,7 +37,6 @@ private: bool m_self_destroy; bool m_open_registration_dialog; - bool m_reshow_current_screen; GUIEngine::LabelWidget * m_info_widget; GUIEngine::TextBoxWidget * m_username_widget; diff --git a/src/states_screens/online_screen.cpp b/src/states_screens/online_screen.cpp index 35ceb0d47..800eeafee 100644 --- a/src/states_screens/online_screen.cpp +++ b/src/states_screens/online_screen.cpp @@ -32,8 +32,8 @@ #include "main_loop.hpp" #include "states_screens/online_screen.hpp" #include "states_screens/state_manager.hpp" -#include "states_screens/dialogs/login_dialog.hpp" #include "states_screens/dialogs/message_dialog.hpp" +#include "states_screens/dialogs/login_dialog.hpp" #include "states_screens/dialogs/registration_dialog.hpp" #include "modes/demo_world.hpp" #include "utils/translation.hpp" @@ -133,12 +133,8 @@ void OnlineScreen::beforeAddingWidget() void OnlineScreen::init() { Screen::init(); - if(m_recorded_state == Not) - m_bottom_menu_widget->setFocusForPlayer(PLAYER_ID_GAME_MASTER); - else - m_top_menu_widget->setFocusForPlayer(PLAYER_ID_GAME_MASTER); - - DemoWorld::resetIdleTime(); + setInitialFocus(); + DemoWorld::resetIdleTime(); //FIXME : what's this? m_online_status_widget->setText(irr::core::stringw(_("Signed in as : ")) + CurrentOnlineUser::get()->getUserName() + ".", false); } // init @@ -205,7 +201,6 @@ void OnlineScreen::tearDown() } // tearDown // ---------------------------------------------------------------------------- - void OnlineScreen::onDisabledItemClicked(const std::string& item) { if (item == "find_server" || item =="create_server") @@ -217,3 +212,21 @@ void OnlineScreen::onDisabledItemClicked(const std::string& item) new LoginDialog(LoginDialog::Signing_In_Required); } } // onDisabledItemClicked + +// ---------------------------------------------------------------------------- +void OnlineScreen::setInitialFocus() +{ + if(m_recorded_state == Not) + m_bottom_menu_widget->setFocusForPlayer(PLAYER_ID_GAME_MASTER); + else + m_top_menu_widget->setFocusForPlayer(PLAYER_ID_GAME_MASTER); +} // setInitialFocus + +// ---------------------------------------------------------------------------- +void OnlineScreen::onDialogClose() +{ + if (hasStateChanged()) + GUIEngine::reshowCurrentScreen(); + else + setInitialFocus(); +} // onLoginDialogClose() diff --git a/src/states_screens/online_screen.hpp b/src/states_screens/online_screen.hpp index f5fc0c7d9..055c5b092 100644 --- a/src/states_screens/online_screen.hpp +++ b/src/states_screens/online_screen.hpp @@ -29,7 +29,8 @@ namespace GUIEngine { class Widget; class ListWidget; } * \brief Handles the main menu * \ingroup states_screens */ -class OnlineScreen : public GUIEngine::Screen, public GUIEngine::ScreenSingleton +class OnlineScreen : public GUIEngine::Screen, + public GUIEngine::ScreenSingleton { private: friend class GUIEngine::ScreenSingleton; @@ -59,6 +60,8 @@ private: /** \brief Checks if the recorded state differs from the actual state and sets it. */ bool hasStateChanged(); + /** \brief Sets which widget has to be focused. Depends on the user state. */ + void setInitialFocus(); public: @@ -82,6 +85,9 @@ public: /** \brief implement callback from parent class GUIEngine::Screen */ virtual void onDisabledItemClicked(const std::string& item) OVERRIDE; + + /** \brief Implements the callback when a dialog gets closed. */ + virtual void onDialogClose() OVERRIDE; }; #endif