diff --git a/src/states_screens/help/help_common.cpp b/src/states_screens/help/help_common.cpp new file mode 100644 index 000000000..959cc2b61 --- /dev/null +++ b/src/states_screens/help/help_common.cpp @@ -0,0 +1,44 @@ + // SuperTuxKart - a fun racing game with go-kart +// Copyright (C) 2009-2015 Marianne Gagnon +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 3 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +#include "states_screens/help/help_common.hpp" + +#include "guiengine/screen.hpp" + +namespace HelpCommon +{ + void switchTab(std::string selected_tab) + { + GUIEngine::Screen *screen = NULL; + if (selected_tab == "page1") + screen = HelpScreen1::getInstance(); + else if (selected_tab == "page2") + screen = HelpScreen2::getInstance(); + else if (selected_tab == "page3") + screen = HelpScreen3::getInstance(); + else if (selected_tab == "page4") + screen = HelpScreen4::getInstance(); + else if (selected_tab == "page5") + screen = HelpScreen5::getInstance(); + else if (selected_tab == "page6") + screen = HelpScreen6::getInstance(); + else if (selected_tab == "page7") + screen = HelpScreen7::getInstance(); + if(screen) + StateManager::get()->replaceTopMostScreen(screen); + } +} \ No newline at end of file diff --git a/src/states_screens/help/help_common.hpp b/src/states_screens/help/help_common.hpp new file mode 100644 index 000000000..4366081fb --- /dev/null +++ b/src/states_screens/help/help_common.hpp @@ -0,0 +1,45 @@ + // SuperTuxKart - a fun racing game with go-kart +// Copyright (C) 2009-2015 Marianne Gagnon +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 3 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +#ifndef __HEADER_HELP_COMMON_HPP__ +#define __HEADER_HELP_COMMON_HPP__ + +// This file contains include headers that are used by all or most help screens. +// It also contains a standalone function to switch between the help screens. +// This simplifies maintenance. + +// Frequent widgets used by multiple option screens +#include "guiengine/widgets/ribbon_widget.hpp" + +// Other help screens, for navigation between them +#include "states_screens/help/help_screen_1.hpp" +#include "states_screens/help/help_screen_2.hpp" +#include "states_screens/help/help_screen_3.hpp" +#include "states_screens/help/help_screen_4.hpp" +#include "states_screens/help/help_screen_5.hpp" +#include "states_screens/help/help_screen_6.hpp" +#include "states_screens/help/help_screen_7.hpp" + +// GUI management +#include "states_screens/state_manager.hpp" + +namespace HelpCommon +{ + void switchTab(std::string selected_tab); +} + +#endif \ No newline at end of file diff --git a/src/states_screens/help/help_screen_1.cpp b/src/states_screens/help/help_screen_1.cpp index 651025c29..18d8e5ecf 100644 --- a/src/states_screens/help/help_screen_1.cpp +++ b/src/states_screens/help/help_screen_1.cpp @@ -15,33 +15,19 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -#include "states_screens/help/help_screen_1.hpp" +// Manages includes common to all help screens +#include "states_screens/help/help_common.hpp" -#include "challenges/unlock_manager.hpp" #include "config/player_manager.hpp" #include "config/user_config.hpp" -#include "guiengine/widget.hpp" #include "guiengine/widgets/button_widget.hpp" -#include "guiengine/widgets/list_widget.hpp" -#include "guiengine/widgets/ribbon_widget.hpp" #include "input/device_manager.hpp" #include "input/input_manager.hpp" -#include "input/keyboard_device.hpp" #include "karts/kart_properties_manager.hpp" #include "race/race_manager.hpp" -#include "states_screens/help/help_screen_2.hpp" -#include "states_screens/help/help_screen_3.hpp" -#include "states_screens/help/help_screen_4.hpp" -#include "states_screens/help/help_screen_5.hpp" -#include "states_screens/help/help_screen_6.hpp" -#include "states_screens/help/help_screen_7.hpp" -#include "states_screens/state_manager.hpp" using namespace GUIEngine; -// FIXME : it's hugely repetitive to have one class per help screen when -// THEY ALL DO THE SAME THING -// (the specialized test of this first screen is a tiny exception) // ----------------------------------------------------------------------------- HelpScreen1::HelpScreen1() : Screen("help/help1.stkgui") @@ -97,23 +83,8 @@ void HelpScreen1::eventCallback(Widget* widget, const std::string& name, const i { std::string selection = ((RibbonWidget*)widget)->getSelectionIDString(PLAYER_ID_GAME_MASTER); - Screen *screen = NULL; - //if (selection == "page1") - // screen = HelpScreen1::getInstance(); - if (selection == "page2") - screen = HelpScreen2::getInstance(); - else if (selection == "page3") - screen = HelpScreen3::getInstance(); - else if (selection == "page4") - screen = HelpScreen4::getInstance(); - else if (selection == "page5") - screen = HelpScreen5::getInstance(); - else if (selection == "page6") - screen = HelpScreen6::getInstance(); - else if (selection == "page7") - screen = HelpScreen7::getInstance(); - if(screen) - StateManager::get()->replaceTopMostScreen(screen); + if (selection != "page1") + HelpCommon::switchTab(selection); } else if (name == "back") { diff --git a/src/states_screens/help/help_screen_2.cpp b/src/states_screens/help/help_screen_2.cpp index ea2d7f849..b06b6cfd7 100644 --- a/src/states_screens/help/help_screen_2.cpp +++ b/src/states_screens/help/help_screen_2.cpp @@ -15,17 +15,8 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -#include "states_screens/help/help_screen_2.hpp" - -#include "guiengine/widget.hpp" -#include "guiengine/widgets/ribbon_widget.hpp" -#include "states_screens/help/help_screen_1.hpp" -#include "states_screens/help/help_screen_3.hpp" -#include "states_screens/help/help_screen_4.hpp" -#include "states_screens/help/help_screen_5.hpp" -#include "states_screens/help/help_screen_6.hpp" -#include "states_screens/help/help_screen_7.hpp" -#include "states_screens/state_manager.hpp" +// Manages includes common to all help screens +#include "states_screens/help/help_common.hpp" using namespace GUIEngine; @@ -49,23 +40,8 @@ void HelpScreen2::eventCallback(Widget* widget, const std::string& name, const i { std::string selection = ((RibbonWidget*)widget)->getSelectionIDString(PLAYER_ID_GAME_MASTER); - Screen *screen = NULL; - if (selection == "page1") - screen = HelpScreen1::getInstance(); - //else if (selection == "page2") - // screen = HelpScreen2::getInstance(); - else if (selection == "page3") - screen = HelpScreen3::getInstance(); - else if (selection == "page4") - screen = HelpScreen4::getInstance(); - else if (selection == "page5") - screen = HelpScreen5::getInstance(); - else if (selection == "page6") - screen = HelpScreen6::getInstance(); - else if (selection == "page7") - screen = HelpScreen7::getInstance(); - if(screen) - StateManager::get()->replaceTopMostScreen(screen); + if (selection != "page2") + HelpCommon::switchTab(selection); } else if (name == "back") { diff --git a/src/states_screens/help/help_screen_3.cpp b/src/states_screens/help/help_screen_3.cpp index a9074e2e2..c6b608b4a 100644 --- a/src/states_screens/help/help_screen_3.cpp +++ b/src/states_screens/help/help_screen_3.cpp @@ -15,18 +15,8 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -#include "states_screens/help/help_screen_3.hpp" - -#include "guiengine/widget.hpp" -#include "guiengine/widgets/ribbon_widget.hpp" -#include "modes/world.hpp" -#include "states_screens/help/help_screen_1.hpp" -#include "states_screens/help/help_screen_2.hpp" -#include "states_screens/help/help_screen_4.hpp" -#include "states_screens/help/help_screen_5.hpp" -#include "states_screens/help/help_screen_6.hpp" -#include "states_screens/help/help_screen_7.hpp" -#include "states_screens/state_manager.hpp" +// Manages includes common to all help screens +#include "states_screens/help/help_common.hpp" using namespace GUIEngine; @@ -51,23 +41,8 @@ void HelpScreen3::eventCallback(Widget* widget, const std::string& name, const i std::string selection = ((RibbonWidget*)widget)->getSelectionIDString(PLAYER_ID_GAME_MASTER); - Screen *screen = NULL; - if (selection == "page1") - screen = HelpScreen1::getInstance(); - else if (selection == "page2") - screen = HelpScreen2::getInstance(); - //else if (selection == "page3") - // screen = HelpScreen3::getInstance(); - else if (selection == "page4") - screen = HelpScreen4::getInstance(); - else if (selection == "page5") - screen = HelpScreen5::getInstance(); - else if (selection == "page6") - screen = HelpScreen6::getInstance(); - else if (selection == "page7") - screen = HelpScreen7::getInstance(); - if(screen) - StateManager::get()->replaceTopMostScreen(screen); + if (selection != "page3") + HelpCommon::switchTab(selection); } else if (name == "back") { diff --git a/src/states_screens/help/help_screen_4.cpp b/src/states_screens/help/help_screen_4.cpp index 6eca44a0c..c300b2185 100644 --- a/src/states_screens/help/help_screen_4.cpp +++ b/src/states_screens/help/help_screen_4.cpp @@ -15,18 +15,8 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -#include "states_screens/help/help_screen_4.hpp" - -#include "guiengine/widget.hpp" -#include "guiengine/widgets/ribbon_widget.hpp" -#include "modes/world.hpp" -#include "states_screens/help/help_screen_1.hpp" -#include "states_screens/help/help_screen_2.hpp" -#include "states_screens/help/help_screen_3.hpp" -#include "states_screens/help/help_screen_5.hpp" -#include "states_screens/help/help_screen_6.hpp" -#include "states_screens/help/help_screen_7.hpp" -#include "states_screens/state_manager.hpp" +// Manages includes common to all help screens +#include "states_screens/help/help_common.hpp" using namespace GUIEngine; @@ -51,23 +41,8 @@ void HelpScreen4::eventCallback(Widget* widget, const std::string& name, const i std::string selection = ((RibbonWidget*)widget)->getSelectionIDString(PLAYER_ID_GAME_MASTER); - Screen *screen = NULL; - if (selection == "page1") - screen = HelpScreen1::getInstance(); - else if (selection == "page2") - screen = HelpScreen2::getInstance(); - else if (selection == "page3") - screen = HelpScreen3::getInstance(); - //else if (selection == "page4") - // screen = HelpScreen4::getInstance(); - else if (selection == "page5") - screen = HelpScreen5::getInstance(); - else if (selection == "page6") - screen = HelpScreen6::getInstance(); - else if (selection == "page7") - screen = HelpScreen7::getInstance(); - if(screen) - StateManager::get()->replaceTopMostScreen(screen); + if (selection != "page4") + HelpCommon::switchTab(selection); } else if (name == "back") { diff --git a/src/states_screens/help/help_screen_5.cpp b/src/states_screens/help/help_screen_5.cpp index 4533ba661..c13bc2014 100644 --- a/src/states_screens/help/help_screen_5.cpp +++ b/src/states_screens/help/help_screen_5.cpp @@ -15,17 +15,8 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -#include "states_screens/help/help_screen_5.hpp" - -#include "guiengine/widget.hpp" -#include "guiengine/widgets/ribbon_widget.hpp" -#include "states_screens/help/help_screen_1.hpp" -#include "states_screens/help/help_screen_2.hpp" -#include "states_screens/help/help_screen_3.hpp" -#include "states_screens/help/help_screen_4.hpp" -#include "states_screens/help/help_screen_6.hpp" -#include "states_screens/help/help_screen_7.hpp" -#include "states_screens/state_manager.hpp" +// Manages includes common to all help screens +#include "states_screens/help/help_common.hpp" using namespace GUIEngine; @@ -50,23 +41,8 @@ void HelpScreen5::eventCallback(Widget* widget, const std::string& name, const i std::string selection = ((RibbonWidget*)widget)->getSelectionIDString(PLAYER_ID_GAME_MASTER); - Screen *screen = NULL; - if (selection == "page1") - screen = HelpScreen1::getInstance(); - else if (selection == "page2") - screen = HelpScreen2::getInstance(); - else if (selection == "page3") - screen = HelpScreen3::getInstance(); - else if (selection == "page4") - screen = HelpScreen4::getInstance(); - //else if (selection == "page5") - // screen = HelpScreen5::getInstance(); - else if (selection == "page6") - screen = HelpScreen6::getInstance(); - else if (selection == "page7") - screen = HelpScreen7::getInstance(); - if(screen) - StateManager::get()->replaceTopMostScreen(screen); + if (selection != "page5") + HelpCommon::switchTab(selection); } else if (name == "back") { diff --git a/src/states_screens/help/help_screen_6.cpp b/src/states_screens/help/help_screen_6.cpp index ec729c654..0264f4102 100644 --- a/src/states_screens/help/help_screen_6.cpp +++ b/src/states_screens/help/help_screen_6.cpp @@ -15,17 +15,8 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -#include "states_screens/help/help_screen_6.hpp" - -#include "guiengine/widget.hpp" -#include "guiengine/widgets/ribbon_widget.hpp" -#include "states_screens/help/help_screen_1.hpp" -#include "states_screens/help/help_screen_2.hpp" -#include "states_screens/help/help_screen_3.hpp" -#include "states_screens/help/help_screen_4.hpp" -#include "states_screens/help/help_screen_5.hpp" -#include "states_screens/help/help_screen_7.hpp" -#include "states_screens/state_manager.hpp" +// Manages includes common to all help screens +#include "states_screens/help/help_common.hpp" using namespace GUIEngine; @@ -50,23 +41,8 @@ void HelpScreen6::eventCallback(Widget* widget, const std::string& name, const i std::string selection = ((RibbonWidget*)widget)->getSelectionIDString(PLAYER_ID_GAME_MASTER); - Screen *screen = NULL; - if (selection == "page1") - screen = HelpScreen1::getInstance(); - else if (selection == "page2") - screen = HelpScreen2::getInstance(); - else if (selection == "page3") - screen = HelpScreen3::getInstance(); - else if (selection == "page4") - screen = HelpScreen4::getInstance(); - else if (selection == "page5") - screen = HelpScreen5::getInstance(); - //else if (selection == "page6") - // screen = HelpScreen6::getInstance(); - else if (selection == "page7") - screen = HelpScreen7::getInstance(); - if(screen) - StateManager::get()->replaceTopMostScreen(screen); + if (selection != "page6") + HelpCommon::switchTab(selection); } else if (name == "back") { diff --git a/src/states_screens/help/help_screen_7.cpp b/src/states_screens/help/help_screen_7.cpp index 128811b4c..a3695280a 100644 --- a/src/states_screens/help/help_screen_7.cpp +++ b/src/states_screens/help/help_screen_7.cpp @@ -15,17 +15,8 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -#include "states_screens/help/help_screen_7.hpp" - -#include "guiengine/widget.hpp" -#include "guiengine/widgets/ribbon_widget.hpp" -#include "states_screens/help/help_screen_1.hpp" -#include "states_screens/help/help_screen_2.hpp" -#include "states_screens/help/help_screen_3.hpp" -#include "states_screens/help/help_screen_4.hpp" -#include "states_screens/help/help_screen_5.hpp" -#include "states_screens/help/help_screen_6.hpp" -#include "states_screens/state_manager.hpp" +// Manages includes common to all help screens +#include "states_screens/help/help_common.hpp" using namespace GUIEngine; @@ -50,23 +41,8 @@ void HelpScreen7::eventCallback(Widget* widget, const std::string& name, const i std::string selection = ((RibbonWidget*)widget)->getSelectionIDString(PLAYER_ID_GAME_MASTER); - Screen *screen = NULL; - if (selection == "page1") - screen = HelpScreen1::getInstance(); - else if (selection == "page2") - screen = HelpScreen2::getInstance(); - else if (selection == "page3") - screen = HelpScreen3::getInstance(); - else if (selection == "page4") - screen = HelpScreen4::getInstance(); - else if (selection == "page5") - screen = HelpScreen5::getInstance(); - else if (selection == "page6") - screen = HelpScreen6::getInstance(); - //else if (selection == "page7") - // screen = HelpScreen7::getInstance(); - if(screen) - StateManager::get()->replaceTopMostScreen(screen); + if (selection != "page7") + HelpCommon::switchTab(selection); } else if (name == "back") {