Remove code duplication in the options screens
Use a new standalone 'switchTab' function to centralize the activation of the screen matching the selected tab
This commit is contained in:
parent
2fc05e94fc
commit
ad02608744
46
src/states_screens/options/options_common.cpp
Normal file
46
src/states_screens/options/options_common.cpp
Normal file
@ -0,0 +1,46 @@
|
||||
// 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/options/options_common.hpp"
|
||||
|
||||
#include "guiengine/screen.hpp"
|
||||
|
||||
namespace OptionsCommon
|
||||
{
|
||||
void switchTab(std::string selected_tab)
|
||||
{
|
||||
GUIEngine::Screen *screen = NULL;
|
||||
if (selected_tab == "tab_audio")
|
||||
screen = OptionsScreenAudio::getInstance();
|
||||
else if (selected_tab == "tab_display")
|
||||
screen = OptionsScreenDisplay::getInstance();
|
||||
else if (selected_tab == "tab_video")
|
||||
screen = OptionsScreenVideo::getInstance();
|
||||
else if (selected_tab == "tab_players")
|
||||
screen = TabbedUserScreen::getInstance();
|
||||
else if (selected_tab == "tab_controls")
|
||||
screen = OptionsScreenInput::getInstance();
|
||||
else if (selected_tab == "tab_ui")
|
||||
screen = OptionsScreenUI::getInstance();
|
||||
else if (selected_tab == "tab_general")
|
||||
screen = OptionsScreenGeneral::getInstance();
|
||||
else if (selected_tab == "tab_language")
|
||||
screen = OptionsScreenLanguage::getInstance();
|
||||
if(screen)
|
||||
StateManager::get()->replaceTopMostScreen(screen);
|
||||
}
|
||||
}
|
@ -15,11 +15,12 @@
|
||||
// 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_OPTIONS_INCLUDE_HEADERS_HPP__
|
||||
#define __HEADER_OPTIONS_INCLUDE_HEADERS_HPP__
|
||||
#ifndef __HEADER_OPTIONS_COMMON_HPP__
|
||||
#define __HEADER_OPTIONS_COMMON_HPP__
|
||||
|
||||
// This file only contains include headers that are used by all or most
|
||||
// options screens. This simplifies maintenance.
|
||||
// This file contains include headers that are used by all or most options screens.
|
||||
// It also contains a standalone function to switch between the options screens.
|
||||
// This simplifies maintenance.
|
||||
|
||||
// Config to read and save settings
|
||||
#include "config/user_config.hpp"
|
||||
@ -47,4 +48,9 @@
|
||||
#include "utils/string_utils.hpp"
|
||||
#include "utils/translation.hpp"
|
||||
|
||||
namespace OptionsCommon
|
||||
{
|
||||
void switchTab(std::string selected_tab);
|
||||
}
|
||||
|
||||
#endif
|
@ -90,25 +90,8 @@ void OptionsScreenAudio::eventCallback(Widget* widget, const std::string& name,
|
||||
{
|
||||
std::string selection = ((RibbonWidget*)widget)->getSelectionIDString(PLAYER_ID_GAME_MASTER);
|
||||
|
||||
Screen *screen = NULL;
|
||||
//if (selection == "tab_audio")
|
||||
// screen = OptionsScreenAudio::getInstance();
|
||||
if (selection == "tab_display")
|
||||
screen = OptionsScreenDisplay::getInstance();
|
||||
else if (selection == "tab_video")
|
||||
screen = OptionsScreenVideo::getInstance();
|
||||
else if (selection == "tab_players")
|
||||
screen = TabbedUserScreen::getInstance();
|
||||
else if (selection == "tab_controls")
|
||||
screen = OptionsScreenInput::getInstance();
|
||||
else if (selection == "tab_ui")
|
||||
screen = OptionsScreenUI::getInstance();
|
||||
else if (selection == "tab_general")
|
||||
screen = OptionsScreenGeneral::getInstance();
|
||||
else if (selection == "tab_language")
|
||||
screen = OptionsScreenLanguage::getInstance();
|
||||
if(screen)
|
||||
StateManager::get()->replaceTopMostScreen(screen);
|
||||
if (selection != "tab_audio")
|
||||
OptionsCommon::switchTab(selection);
|
||||
}
|
||||
else if(name == "back")
|
||||
{
|
||||
|
@ -520,25 +520,8 @@ void OptionsScreenDevice::eventCallback(Widget* widget,
|
||||
{
|
||||
std::string selection = ((RibbonWidget*)widget)->getSelectionIDString(PLAYER_ID_GAME_MASTER);
|
||||
|
||||
Screen *screen = NULL;
|
||||
if (selection == "tab_audio")
|
||||
screen = OptionsScreenAudio::getInstance();
|
||||
else if (selection == "tab_display")
|
||||
screen = OptionsScreenDisplay::getInstance();
|
||||
else if (selection == "tab_video")
|
||||
screen = OptionsScreenVideo::getInstance();
|
||||
else if (selection == "tab_players")
|
||||
screen = TabbedUserScreen::getInstance();
|
||||
//else if (selection == "tab_controls")
|
||||
// screen = OptionsScreenInput::getInstance();
|
||||
else if (selection == "tab_ui")
|
||||
screen = OptionsScreenUI::getInstance();
|
||||
else if (selection == "tab_general")
|
||||
screen = OptionsScreenGeneral::getInstance();
|
||||
else if (selection == "tab_language")
|
||||
screen = OptionsScreenLanguage::getInstance();
|
||||
if(screen)
|
||||
StateManager::get()->replaceTopMostScreen(screen);
|
||||
if (selection != "tab_controls")
|
||||
OptionsCommon::switchTab(selection);
|
||||
}
|
||||
else if (name == "back_to_device_list")
|
||||
{
|
||||
|
@ -324,25 +324,8 @@ void OptionsScreenDisplay::eventCallback(Widget* widget, const std::string& name
|
||||
{
|
||||
std::string selection = ((RibbonWidget*)widget)->getSelectionIDString(PLAYER_ID_GAME_MASTER);
|
||||
|
||||
Screen *screen = NULL;
|
||||
if (selection == "tab_audio")
|
||||
screen = OptionsScreenAudio::getInstance();
|
||||
//else if (selection == "tab_display")
|
||||
// screen = OptionsScreenDisplay::getInstance();
|
||||
else if (selection == "tab_video")
|
||||
screen = OptionsScreenVideo::getInstance();
|
||||
else if (selection == "tab_players")
|
||||
screen = TabbedUserScreen::getInstance();
|
||||
else if (selection == "tab_controls")
|
||||
screen = OptionsScreenInput::getInstance();
|
||||
else if (selection == "tab_ui")
|
||||
screen = OptionsScreenUI::getInstance();
|
||||
else if (selection == "tab_general")
|
||||
screen = OptionsScreenGeneral::getInstance();
|
||||
else if (selection == "tab_language")
|
||||
screen = OptionsScreenLanguage::getInstance();
|
||||
if(screen)
|
||||
StateManager::get()->replaceTopMostScreen(screen);
|
||||
if (selection != "tab_display")
|
||||
OptionsCommon::switchTab(selection);
|
||||
}
|
||||
else if(name == "back")
|
||||
{
|
||||
|
@ -103,25 +103,8 @@ void OptionsScreenGeneral::eventCallback(Widget* widget, const std::string& name
|
||||
{
|
||||
std::string selection = ((RibbonWidget*)widget)->getSelectionIDString(PLAYER_ID_GAME_MASTER);
|
||||
|
||||
Screen *screen = NULL;
|
||||
if (selection == "tab_audio")
|
||||
screen = OptionsScreenAudio::getInstance();
|
||||
else if (selection == "tab_display")
|
||||
screen = OptionsScreenDisplay::getInstance();
|
||||
else if (selection == "tab_video")
|
||||
screen = OptionsScreenVideo::getInstance();
|
||||
else if (selection == "tab_players")
|
||||
screen = TabbedUserScreen::getInstance();
|
||||
else if (selection == "tab_controls")
|
||||
screen = OptionsScreenInput::getInstance();
|
||||
else if (selection == "tab_ui")
|
||||
screen = OptionsScreenUI::getInstance();
|
||||
//else if (selection == "tab_general")
|
||||
// screen = OptionsScreenGeneral::getInstance();
|
||||
else if (selection == "tab_language")
|
||||
screen = OptionsScreenLanguage::getInstance();
|
||||
if(screen)
|
||||
StateManager::get()->replaceTopMostScreen(screen);
|
||||
if (selection != "tab_general")
|
||||
OptionsCommon::switchTab(selection);
|
||||
}
|
||||
else if(name == "back")
|
||||
{
|
||||
|
@ -226,25 +226,8 @@ void OptionsScreenInput::eventCallback(Widget* widget, const std::string& name,
|
||||
{
|
||||
std::string selection = ((RibbonWidget*)widget)->getSelectionIDString(PLAYER_ID_GAME_MASTER);
|
||||
|
||||
Screen *screen = NULL;
|
||||
if (selection == "tab_audio")
|
||||
screen = OptionsScreenAudio::getInstance();
|
||||
else if (selection == "tab_display")
|
||||
screen = OptionsScreenDisplay::getInstance();
|
||||
else if (selection == "tab_video")
|
||||
screen = OptionsScreenVideo::getInstance();
|
||||
else if (selection == "tab_players")
|
||||
screen = TabbedUserScreen::getInstance();
|
||||
//else if (selection == "tab_controls")
|
||||
// screen = OptionsScreenInput::getInstance();
|
||||
else if (selection == "tab_ui")
|
||||
screen = OptionsScreenUI::getInstance();
|
||||
else if (selection == "tab_general")
|
||||
screen = OptionsScreenGeneral::getInstance();
|
||||
else if (selection == "tab_language")
|
||||
screen = OptionsScreenLanguage::getInstance();
|
||||
if(screen)
|
||||
StateManager::get()->replaceTopMostScreen(screen);
|
||||
if (selection != "tab_controls")
|
||||
OptionsCommon::switchTab(selection);
|
||||
}
|
||||
else if (name == "add_device")
|
||||
{
|
||||
|
@ -107,25 +107,8 @@ void OptionsScreenLanguage::eventCallback(Widget* widget, const std::string& nam
|
||||
{
|
||||
std::string selection = ((RibbonWidget*)widget)->getSelectionIDString(PLAYER_ID_GAME_MASTER);
|
||||
|
||||
Screen *screen = NULL;
|
||||
if (selection == "tab_audio")
|
||||
screen = OptionsScreenAudio::getInstance();
|
||||
else if (selection == "tab_display")
|
||||
screen = OptionsScreenDisplay::getInstance();
|
||||
else if (selection == "tab_video")
|
||||
screen = OptionsScreenVideo::getInstance();
|
||||
else if (selection == "tab_players")
|
||||
screen = TabbedUserScreen::getInstance();
|
||||
else if (selection == "tab_controls")
|
||||
screen = OptionsScreenInput::getInstance();
|
||||
else if (selection == "tab_ui")
|
||||
screen = OptionsScreenUI::getInstance();
|
||||
else if (selection == "tab_general")
|
||||
screen = OptionsScreenGeneral::getInstance();
|
||||
//else if (selection == "tab_language")
|
||||
// screen = OptionsScreenLanguage::getInstance();
|
||||
if(screen)
|
||||
StateManager::get()->replaceTopMostScreen(screen);
|
||||
if (selection != "tab_language")
|
||||
OptionsCommon::switchTab(selection);
|
||||
}
|
||||
else if(name == "back")
|
||||
{
|
||||
|
@ -360,25 +360,8 @@ void OptionsScreenUI::eventCallback(Widget* widget, const std::string& name, con
|
||||
{
|
||||
std::string selection = ((RibbonWidget*)widget)->getSelectionIDString(PLAYER_ID_GAME_MASTER);
|
||||
|
||||
Screen *screen = NULL;
|
||||
if (selection == "tab_audio")
|
||||
screen = OptionsScreenAudio::getInstance();
|
||||
else if (selection == "tab_display")
|
||||
screen = OptionsScreenDisplay::getInstance();
|
||||
else if (selection == "tab_video")
|
||||
screen = OptionsScreenVideo::getInstance();
|
||||
else if (selection == "tab_players")
|
||||
screen = TabbedUserScreen::getInstance();
|
||||
else if (selection == "tab_controls")
|
||||
screen = OptionsScreenInput::getInstance();
|
||||
//else if (selection == "tab_ui")
|
||||
// screen = OptionsScreenUI::getInstance();
|
||||
else if (selection == "tab_general")
|
||||
screen = OptionsScreenGeneral::getInstance();
|
||||
else if (selection == "tab_language")
|
||||
screen = OptionsScreenLanguage::getInstance();
|
||||
if(screen)
|
||||
StateManager::get()->replaceTopMostScreen(screen);
|
||||
if (selection != "tab_ui")
|
||||
OptionsCommon::switchTab(selection);
|
||||
}
|
||||
else if(name == "back")
|
||||
{
|
||||
|
@ -516,25 +516,8 @@ void OptionsScreenVideo::eventCallback(Widget* widget, const std::string& name,
|
||||
{
|
||||
std::string selection = ((RibbonWidget*)widget)->getSelectionIDString(PLAYER_ID_GAME_MASTER);
|
||||
|
||||
Screen *screen = NULL;
|
||||
if (selection == "tab_audio")
|
||||
screen = OptionsScreenAudio::getInstance();
|
||||
else if (selection == "tab_display")
|
||||
screen = OptionsScreenDisplay::getInstance();
|
||||
//else if (selection == "tab_video")
|
||||
// screen = OptionsScreenVideo::getInstance();
|
||||
else if (selection == "tab_players")
|
||||
screen = TabbedUserScreen::getInstance();
|
||||
else if (selection == "tab_controls")
|
||||
screen = OptionsScreenInput::getInstance();
|
||||
else if (selection == "tab_ui")
|
||||
screen = OptionsScreenUI::getInstance();
|
||||
else if (selection == "tab_general")
|
||||
screen = OptionsScreenGeneral::getInstance();
|
||||
else if (selection == "tab_language")
|
||||
screen = OptionsScreenLanguage::getInstance();
|
||||
if(screen)
|
||||
StateManager::get()->replaceTopMostScreen(screen);
|
||||
if (selection != "tab_video")
|
||||
OptionsCommon::switchTab(selection);
|
||||
}
|
||||
else if(name == "back")
|
||||
{
|
||||
|
@ -706,8 +706,6 @@ void BaseUserScreen::unloaded()
|
||||
{
|
||||
} // unloaded
|
||||
|
||||
|
||||
|
||||
// ============================================================================
|
||||
/** In the tab version, make sure the right tab is selected.
|
||||
*/
|
||||
@ -731,25 +729,8 @@ void TabbedUserScreen::eventCallback(GUIEngine::Widget* widget,
|
||||
{
|
||||
std::string selection = ((RibbonWidget*)widget)->getSelectionIDString(PLAYER_ID_GAME_MASTER);
|
||||
|
||||
Screen *screen = NULL;
|
||||
if (selection == "tab_audio")
|
||||
screen = OptionsScreenAudio::getInstance();
|
||||
else if (selection == "tab_display")
|
||||
screen = OptionsScreenDisplay::getInstance();
|
||||
else if (selection == "tab_video")
|
||||
screen = OptionsScreenVideo::getInstance();
|
||||
//else if (selection == "tab_players")
|
||||
// screen = TabbedUserScreen::getInstance();
|
||||
else if (selection == "tab_controls")
|
||||
screen = OptionsScreenInput::getInstance();
|
||||
else if (selection == "tab_ui")
|
||||
screen = OptionsScreenUI::getInstance();
|
||||
else if (selection == "tab_general")
|
||||
screen = OptionsScreenGeneral::getInstance();
|
||||
else if (selection == "tab_language")
|
||||
screen = OptionsScreenLanguage::getInstance();
|
||||
if(screen)
|
||||
StateManager::get()->replaceTopMostScreen(screen);
|
||||
if (selection != "tab_players")
|
||||
OptionsCommon::switchTab(selection);
|
||||
}
|
||||
else
|
||||
BaseUserScreen::eventCallback(widget, name, player_id);
|
||||
|
Loading…
Reference in New Issue
Block a user