Back to index

supertuxkart  0.5+dfsg1
main_menu.cpp
Go to the documentation of this file.
00001 //  $Id: main_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 "main_menu.hpp"
00023 #include "widget_manager.hpp"
00024 #include "race_manager.hpp"
00025 #include "menu_manager.hpp"
00026 #include "translation.hpp"
00027 #include "user_config.hpp"
00028 #include "unlock_manager.hpp"
00029 
00030 enum WidgetTokens
00031 {
00032     WTOK_SINGLE,
00033     WTOK_MULTI,
00034     WTOK_CHALLENGES,
00035     WTOK_OPTIONS,
00036     WTOK_QUIT,
00037     WTOK_HELP,
00038     WTOK_CREDITS,
00039     WTOK_WARNING
00040 };
00041 
00042 MainMenu::MainMenu()
00043 {
00044     widget_manager->switchOrder();
00045 
00046     const int WIDTH=30;
00047     widget_manager->addTextButtonWgt( WTOK_SINGLE, WIDTH, 7, _("Single Player") );
00048     widget_manager->addTextButtonWgt( WTOK_MULTI, WIDTH, 7, _("Multiplayer") );
00049 
00050     std::vector<const Challenge*> all_challenges=unlock_manager->getActiveChallenges();
00051     if(all_challenges.size()>0)
00052     {
00053         widget_manager->addTextButtonWgt( WTOK_CHALLENGES, WIDTH, 7, _("Challenges") );
00054     }
00055 
00056     widget_manager->addTextButtonWgt( WTOK_OPTIONS, WIDTH, 7, _("Options") );
00057     widget_manager->addTextButtonWgt( WTOK_QUIT, WIDTH, 7, _("Quit") );
00058 
00059     widget_manager->addEmptyWgt( WidgetManager::WGT_NONE, WIDTH, 7 );
00060 
00061     widget_manager->addTextButtonWgt( WTOK_HELP, WIDTH, 7, _("Help") );
00062     widget_manager->setWgtTextSize( WTOK_HELP, WGT_FNT_SML );
00063 
00064     widget_manager->addTextButtonWgt( WTOK_CREDITS, WIDTH, 7, _("Credits") );
00065     widget_manager->setWgtTextSize( WTOK_CREDITS, WGT_FNT_SML );
00066 
00067     if(user_config->getWarning()!="")
00068     {
00069         widget_manager->addTextWgt( WTOK_WARNING, 80, 8, user_config->getWarning().c_str() );
00070         widget_manager->setWgtTextSize( WTOK_WARNING, WGT_FNT_SML );
00071         widget_manager->hideWgtRect(WTOK_WARNING);
00072     }
00073 
00074     widget_manager->layout(WGT_AREA_ALL);
00075 }
00076 
00077 //-----------------------------------------------------------------------------
00078 MainMenu::~MainMenu()
00079 {
00080     widget_manager->reset();
00081     user_config->resetWarning();
00082 }
00083 
00084 //-----------------------------------------------------------------------------
00085 void MainMenu::select()
00086 {
00087     switch ( widget_manager->getSelectedWgt() )
00088     {
00089     case WTOK_SINGLE:
00090         race_manager->setNumPlayers(1);
00091         menu_manager->pushMenu(MENUID_GAMEMODE);
00092         break;
00093     case WTOK_MULTI:
00094         menu_manager->pushMenu(MENUID_NUMPLAYERS);
00095         break;
00096     case WTOK_CHALLENGES:
00097         menu_manager->pushMenu(MENUID_CHALLENGES);
00098         break;
00099     case WTOK_OPTIONS:
00100         menu_manager->pushMenu(MENUID_OPTIONS);
00101         break;
00102 
00103     case WTOK_QUIT:
00104         menu_manager->pushMenu(MENUID_EXITGAME);
00105         break;
00106     case WTOK_HELP:
00107         menu_manager->pushMenu(MENUID_HELP1);
00108         break;
00109     case WTOK_CREDITS:
00110         menu_manager->pushMenu(MENUID_CREDITS);
00111         break;
00112     }
00113 }
00114 
00115 //-----------------------------------------------------------------------------
00116 void MainMenu::handle(GameAction ga, int value)
00117 {
00118     switch ( ga )
00119     {
00120     case GA_LEAVE:
00121         if(!value) break;
00122         menu_manager->pushMenu(MENUID_EXITGAME);
00123         break;
00124 
00125     default:
00126         BaseGUI::handle(ga, value);
00127         break;
00128     }
00129 }
00130 
00131 /* EOF */