Back to index

supertuxkart  0.5+dfsg1
race_menu.cpp
Go to the documentation of this file.
00001 //  $Id: race_menu.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 <SDL/SDL.h>
00021 
00022 #include "widget_manager.hpp"
00023 #include "user_config.hpp"
00024 #include "race_menu.hpp"
00025 #include "world.hpp"
00026 
00027 #include "menu_manager.hpp"
00028 #include "race_manager.hpp"
00029 #include "sound_manager.hpp"
00030 #include "translation.hpp"
00031 
00032 enum WidgetTokens
00033 {
00034     WTOK_PAUSE,
00035     WTOK_RETURN_RACE,
00036     WTOK_OPTIONS,
00037     WTOK_HELP,
00038     WTOK_RESTART_RACE,
00039     WTOK_SETUP_NEW_RACE,
00040     WTOK_QUIT,
00041 };
00042 
00043 RaceMenu::RaceMenu()
00044 {
00045     widget_manager->switchOrder();
00046 
00047     widget_manager->addTitleWgt( WTOK_PAUSE, 50, 7, _("Paused") );
00048 
00049     widget_manager->addTextButtonWgt( WTOK_RETURN_RACE, 50, 7, _("Return To Race"));
00050     widget_manager->addTextButtonWgt( WTOK_OPTIONS, 50, 7, _("Options") );
00051     widget_manager->addTextButtonWgt( WTOK_HELP, 50, 7, _("Help") );
00052     widget_manager->addTextButtonWgt( WTOK_RESTART_RACE, 50, 7, _("Restart Race") );
00053 
00054     if(race_manager->getRaceMode()==RaceManager::RM_QUICK_RACE)
00055     {
00056         widget_manager->addTextButtonWgt( WTOK_SETUP_NEW_RACE, 50, 7,
00057             _("Setup New Race") );
00058     }
00059 
00060     widget_manager->addTextButtonWgt( WTOK_QUIT, 50, 7, _("Exit Race") );
00061 
00062     widget_manager->layout(WGT_AREA_ALL);
00063     if(user_config->m_fullscreen) SDL_ShowCursor(SDL_ENABLE);
00064 }
00065 
00066 //-----------------------------------------------------------------------------
00067 RaceMenu::~RaceMenu()
00068 {
00069     widget_manager->reset();
00070 }
00071 
00072 
00073 //-----------------------------------------------------------------------------
00074 void RaceMenu::select()
00075 {
00076     int clicked_token = widget_manager->getSelectedWgt();
00077 
00078     switch (clicked_token)
00079     {
00080     case WTOK_RETURN_RACE:
00081         world->unpause();
00082         menu_manager->popMenu();
00083         if(user_config->m_fullscreen) SDL_ShowCursor(SDL_DISABLE);
00084         break;
00085 
00086     case WTOK_SETUP_NEW_RACE:
00087         world->unpause();
00088         race_manager->exit_race();
00089         menu_manager->pushMenu(MENUID_CHARSEL_P1);
00090         break;
00091 
00092     case WTOK_RESTART_RACE:
00093         menu_manager->popMenu();
00094         if(user_config->m_fullscreen) SDL_ShowCursor(SDL_DISABLE);
00095         world->restartRace();
00096         break;
00097 
00098     case WTOK_OPTIONS:
00099         menu_manager->pushMenu(MENUID_OPTIONS);
00100         break;
00101 
00102     case WTOK_HELP:
00103         menu_manager->pushMenu(MENUID_HELP1);
00104         break;
00105 
00106     case WTOK_QUIT:
00107         world->unpause();
00108         race_manager->exit_race();
00109         break;
00110 
00111     default:
00112         break;
00113     }
00114 }
00115 
00116 //-----------------------------------------------------------------------------
00117 void RaceMenu::handle(GameAction ga, int value)
00118 {
00119     switch ( ga )
00120     {
00121     case GA_LEAVE:
00122         if (value)
00123             break;
00124               
00125         world->unpause();
00126         menu_manager->popMenu();
00127         break;
00128 
00129     default:
00130         BaseGUI::handle(ga, value);
00131         break;
00132     }
00133 }
00134 
00135