Back to index

supertuxkart  0.5+dfsg1
options.cpp
Go to the documentation of this file.
00001 //  $Id: options.cpp 2111 2008-05-31 07:04:30Z cosmosninja $
00002 //
00003 //  SuperTuxKart - a fun racing game with go-kart
00004 //  Copyright (C) 2006 SuperTuxKart-Team
00005 //
00006 //  This program is free software; you can redistribute it and/or
00007 //  modify it under the terms of the GNU General Public License
00008 //  as published by the Free Software Foundation; either version 2
00009 //  of the License, or (at your option) any later version.
00010 //
00011 //  This program is distributed in the hope that it will be useful,
00012 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //  GNU General Public License for more details.
00015 //
00016 //  You should have received a copy of the GNU General Public License
00017 //  along with this program; if not, write to the Free Software
00018 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00019 
00020 #include "options.hpp"
00021 #include "widget_manager.hpp"
00022 #include "menu_manager.hpp"
00023 #include "translation.hpp"
00024 #include "user_config.hpp"
00025 
00026 enum WidgetTokens
00027 {
00028     WTOK_TITLE,
00029 
00030     WTOK_CONTROLS,
00031     WTOK_DISPLAY,
00032     WTOK_SOUND,
00033 
00034     WTOK_QUIT
00035 };
00036 
00037 Options::Options()
00038 {
00039     widget_manager->switchOrder();
00040     widget_manager->addTitleWgt( WTOK_TITLE, 45, 7, _("Options") );
00041     widget_manager->addTextButtonWgt( WTOK_CONTROLS, 45, 7, _("Player Config") );
00042 
00043     // Don't display the fullscreen menu when called from within the race.
00044     // The fullscreen mode will reload all textures, reload the models,
00045     // ... basically creating a big mess!!  (and all of this only thanks
00046     // to windows, who discards all textures, ...)
00047     if(!menu_manager->isSomewhereOnStack( MENUID_RACE ))
00048     {
00049         widget_manager->addTextButtonWgt( WTOK_DISPLAY, 45, 7, _("Display") );
00050     }
00051 
00052     widget_manager->addTextButtonWgt( WTOK_SOUND, 45, 7, _("Sound") );
00053 
00054     widget_manager->addEmptyWgt( WidgetManager::WGT_NONE, 1, 7 );
00055 
00056     widget_manager->addTextButtonWgt( WTOK_QUIT, 45, 7,
00057         _("Press <ESC> to go back") );
00058     widget_manager->setWgtTextSize( WTOK_QUIT, WGT_FNT_SML );
00059 
00060     widget_manager->layout(WGT_AREA_ALL);
00061 }
00062 
00063 // -----------------------------------------------------------------------------
00064 Options::~Options()
00065 {
00066     widget_manager->reset() ;
00067 }
00068 
00069 // -----------------------------------------------------------------------------
00070 void Options::select()
00071 {
00072     switch ( widget_manager->getSelectedWgt() )
00073     {
00074     case WTOK_CONTROLS:
00075         menu_manager->pushMenu(MENUID_CONFIG_CONTROLS);
00076         break;
00077     case WTOK_DISPLAY:
00078         menu_manager->pushMenu(MENUID_CONFIG_DISPLAY);
00079         break;
00080     case WTOK_SOUND:
00081         menu_manager->pushMenu(MENUID_CONFIG_SOUND);
00082         break;
00083     case WTOK_QUIT:
00084         //FIXME: this shouldn't be in this screen
00085               // Make config changes permanent.
00086               user_config->saveConfig();
00087 
00088         menu_manager->popMenu();
00089         break;
00090     default:
00091         break;
00092     }  // switch
00093 }
00094 
00095 void Options::handle(GameAction action, int value)
00096 {
00097        // Save config on leave.
00098        if (!value && action == GA_LEAVE)
00099               user_config->saveConfig();
00100 
00101        BaseGUI::handle(action, value);
00102 }