Remove code duplication in the help screens
Same approach as with the options screen: managing all the generic includes needed by all help screens in one place and adding a new standalone 'switchTab function
This commit is contained in:
parent
fa421b43c7
commit
785915770a
44
src/states_screens/help/help_common.cpp
Normal file
44
src/states_screens/help/help_common.cpp
Normal file
@ -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);
|
||||
}
|
||||
}
|
45
src/states_screens/help/help_common.hpp
Normal file
45
src/states_screens/help/help_common.hpp
Normal file
@ -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
|
@ -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")
|
||||
{
|
||||
|
@ -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")
|
||||
{
|
||||
|
@ -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")
|
||||
{
|
||||
|
@ -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")
|
||||
{
|
||||
|
@ -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")
|
||||
{
|
||||
|
@ -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")
|
||||
{
|
||||
|
@ -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")
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user