From ad18d9299d69dc40d4f57d5f378d0ee2532b239f Mon Sep 17 00:00:00 2001 From: hilnius Date: Mon, 29 Jul 2013 12:42:21 +0000 Subject: [PATCH] fixing last issues with the inherited kart selection screen : the screen is now deleted when back is pressed, and re-instantiated when it's loaded again. If not, there was a problem with two screens instantiating the same '.stkgui' file. The screen is not deleted when the user clicks a kart (eg when starting normal game) to allow a working popScreen() git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/hilnius@13378 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- src/guiengine/engine.cpp | 21 ++++++++++++++++- src/guiengine/engine.hpp | 2 ++ src/states_screens/kart_selection.cpp | 8 +++++-- src/states_screens/kart_selection.hpp | 6 +++++ src/states_screens/main_menu_screen.cpp | 3 ++- src/states_screens/network_kart_selection.cpp | 23 ++++++++++++++++++- src/states_screens/network_kart_selection.hpp | 1 + src/states_screens/race_setup_screen.cpp | 10 ++++---- 8 files changed, 64 insertions(+), 10 deletions(-) diff --git a/src/guiengine/engine.cpp b/src/guiengine/engine.cpp index cdbefe733..83235ad63 100644 --- a/src/guiengine/engine.cpp +++ b/src/guiengine/engine.cpp @@ -485,7 +485,7 @@ namespace GUIEngine Used on divs, indicate by how many pixels to pad contents - + \n
\section code Using the engine in code @@ -904,6 +904,25 @@ namespace GUIEngine g_loaded_screens.push_back(cutscene); } // addScreenToList + // ------------------------------------------------------------------------ + + void removeScreen(const char* name) + { + const int screen_amount = g_loaded_screens.size(); + for(int n=0; nunload(); + delete g_current_screen; + g_current_screen = NULL; + g_loaded_screens.remove(n); + break; + } + } + } + // ------------------------------------------------------------------------ void reshowCurrentScreen() { diff --git a/src/guiengine/engine.hpp b/src/guiengine/engine.hpp index 9a91cdd84..d4916d533 100644 --- a/src/guiengine/engine.hpp +++ b/src/guiengine/engine.hpp @@ -195,6 +195,8 @@ namespace GUIEngine /** \brief Add a screen to the list of screens known by the gui engine */ void addScreenToList(Screen* screen); + /** \brief Remove a screen from the list of screens known by the gui engine */ + void removeScreen(const char* name); /** \brief Low-level mean to change current screen. * \note Do not use directly. Use a state manager instead to get higher-level functionnality. diff --git a/src/states_screens/kart_selection.cpp b/src/states_screens/kart_selection.cpp index a5508bab0..96b9fb194 100644 --- a/src/states_screens/kart_selection.cpp +++ b/src/states_screens/kart_selection.cpp @@ -974,6 +974,7 @@ void KartSelectionScreen::beforeAddingWidget() void KartSelectionScreen::init() { Screen::init(); + m_must_delete_on_back = false; RibbonWidget* tabs = getWidget("kartgroups"); assert( tabs != NULL ); @@ -1083,6 +1084,9 @@ void KartSelectionScreen::tearDown() Screen::tearDown(); m_kart_widgets.clearAndDeleteAll(); + + if (m_must_delete_on_back) + GUIEngine::removeScreen(this->getName().c_str()); } // tearDown // ---------------------------------------------------------------------------- @@ -1567,7 +1571,7 @@ void KartSelectionScreen::eventCallback(Widget* widget, else if (name == "back") { m_go_to_overworld_next = false; // valid once - + m_must_delete_on_back = true; if (m_from_overworld) { m_from_overworld = false; // valid once @@ -1606,7 +1610,7 @@ void KartSelectionScreen::setMultiplayer(bool multiplayer) bool KartSelectionScreen::onEscapePressed() { m_go_to_overworld_next = false; // valid once - + m_must_delete_on_back = true; // delete the screen if (m_from_overworld) { m_from_overworld = false; // valid once diff --git a/src/states_screens/kart_selection.hpp b/src/states_screens/kart_selection.hpp index e7ddf2e61..a7ed47198 100644 --- a/src/states_screens/kart_selection.hpp +++ b/src/states_screens/kart_selection.hpp @@ -16,6 +16,9 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +#ifndef KART_SELECTION_INCLUDED +#define KART_SELECTION_INCLUDED + #include #include "guiengine/screen.hpp" #include "guiengine/widgets/dynamic_ribbon_widget.hpp" @@ -61,6 +64,7 @@ protected: bool m_go_to_overworld_next; + bool m_must_delete_on_back; //!< To delete the screen if back is pressed KartSelectionScreen(); @@ -350,3 +354,5 @@ public: const irr::core::stringw& selectionText, const int playerID); }; // KartHoverListener + +#endif diff --git a/src/states_screens/main_menu_screen.cpp b/src/states_screens/main_menu_screen.cpp index 04246253c..a32836c6f 100644 --- a/src/states_screens/main_menu_screen.cpp +++ b/src/states_screens/main_menu_screen.cpp @@ -42,6 +42,7 @@ #include "states_screens/credits.hpp" #include "states_screens/help_screen_1.hpp" #include "states_screens/offline_kart_selection.hpp" +#include "states_screens/network_kart_selection.hpp" // FIXME : remove when not testing #include "states_screens/options_screen_video.hpp" #include "states_screens/state_manager.hpp" @@ -271,7 +272,7 @@ void MainMenuScreen::eventCallback(Widget* widget, const std::string& name, #endif if (selection == "new") { - KartSelectionScreen* s = OfflineKartSelectionScreen::getInstance(); + KartSelectionScreen* s = OfflineKartSelectionScreen::getInstance(); //FIXME : that was for tests s->setMultiplayer(false); s->setFromOverworld(false); StateManager::get()->pushScreen( s ); diff --git a/src/states_screens/network_kart_selection.cpp b/src/states_screens/network_kart_selection.cpp index f9e239430..0df55bf6e 100644 --- a/src/states_screens/network_kart_selection.cpp +++ b/src/states_screens/network_kart_selection.cpp @@ -13,11 +13,32 @@ NetworkKartSelectionScreen::~NetworkKartSelectionScreen() { } +void NetworkKartSelectionScreen::init() +{ + KartSelectionScreen::init(); + + RibbonWidget* tabs = getWidget("kartgroups"); + assert( tabs != NULL ); + tabs->setVisible(false); + tabs->select( "standard", PLAYER_ID_GAME_MASTER); // select standard kart group + + // change the back button image (because it makes the game quit) + IconButtonWidget* back_button = getWidget("back"); + back_button->setImage("gui/main_quit.png"); +} + /** * Callback handling events from the kart selection menu */ void NetworkKartSelectionScreen::eventCallback(GUIEngine::Widget* widget, const std::string& name, const int playerID) { - Log::info("NetworkKartSelectionScreen", "Fuck events !"); + if (name != "karts") + { + KartSelectionScreen::eventCallback(widget, name, playerID); + } + else // name = karts + { + // must quit the server here + } } // eventCallback diff --git a/src/states_screens/network_kart_selection.hpp b/src/states_screens/network_kart_selection.hpp index 86debbfca..48cf0a9c2 100644 --- a/src/states_screens/network_kart_selection.hpp +++ b/src/states_screens/network_kart_selection.hpp @@ -12,6 +12,7 @@ protected: virtual ~NetworkKartSelectionScreen(); public: + virtual void init(); virtual void eventCallback(GUIEngine::Widget* widget, const std::string& name, const int playerID) OVERRIDE; }; diff --git a/src/states_screens/race_setup_screen.cpp b/src/states_screens/race_setup_screen.cpp index b143cfbfd..0af3dd4d5 100644 --- a/src/states_screens/race_setup_screen.cpp +++ b/src/states_screens/race_setup_screen.cpp @@ -180,7 +180,7 @@ void RaceSetupScreen::eventCallback(Widget* widget, const std::string& name, con { StateManager::get()->escapePressed(); } - + } // eventCallback // ----------------------------------------------------------------------------- @@ -225,7 +225,7 @@ void RaceSetupScreen::init() { w->setSelection( UserConfigParams::m_difficulty, PLAYER_ID_GAME_MASTER ); } - + SpinnerWidget* kartamount = getWidget("aikartamount"); kartamount->setActivated(); @@ -327,13 +327,13 @@ void RaceSetupScreen::init() m_mode_listener = new GameModeRibbonListener(this); w2->registerHoverListener(m_mode_listener); - - + + if (unlock_manager->getCurrentSlot()->isLocked("difficulty_best")) { RibbonWidget* w = getWidget("difficulty"); assert(w != NULL); - + int index = w->findItemNamed("best"); Widget* hardestWidget = &w->getChildren()[index]; hardestWidget->setBadge(LOCKED_BADGE);