Back to index

supertuxkart  0.5+dfsg1
challenges_menu.cpp
Go to the documentation of this file.
00001 //  $Id: challenges_menu.cpp 1305 2007-11-26 14:28:15Z hiker $
00002 //
00003 //  SuperTuxKart - a fun racing game with go-kart
00004 //  Copyright (C) 2008 Joerg Henrichs
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 "gui/challenges_menu.hpp"
00021 #include "widget_manager.hpp"
00022 #include "menu_manager.hpp"
00023 #include "unlock_manager.hpp"
00024 #include "translation.hpp"
00025 
00026 enum WidgetTokens
00027 {
00028     WTOK_TITLE,
00029     WTOK_BACK,
00030     WTOK_DESCRIPTION,
00031     WTOK_CHALLENGES
00032 };
00033 
00034 ChallengesMenu::ChallengesMenu()
00035 {
00036     widget_manager->addTitleWgt( WTOK_TITLE, 60, 10, _("Active Challenges"));
00037     widget_manager->breakLine();
00038 
00039     m_all_challenges=unlock_manager->getActiveChallenges();
00040     for(int i=0; i<(int)m_all_challenges.size(); i++)
00041     {
00042         widget_manager->addTextButtonWgt(WTOK_CHALLENGES+i, 60, 10,
00043             _(m_all_challenges[i]->getName().c_str()) );
00044         widget_manager->breakLine();
00045     }
00046 
00047     widget_manager->addTextButtonWgt( WTOK_DESCRIPTION, 60, 30, "");
00048     widget_manager->breakLine();
00049 
00050     widget_manager->addTextButtonWgt(WTOK_BACK, 50, 7,
00051         _("Go back to the main menu"));
00052 
00053     widget_manager->layout(WGT_AREA_ALL);
00054 }   // ChallengesMenu
00055 
00056 //-----------------------------------------------------------------------------
00057 ChallengesMenu::~ChallengesMenu()
00058 {
00059     widget_manager->reset();
00060 }   // ~ChallengesMenu
00061 
00062 //-----------------------------------------------------------------------------
00063 void ChallengesMenu::update(float dt)
00064 {
00065     const int challenge= widget_manager->getSelectedWgt() - WTOK_CHALLENGES;
00066     if(challenge>=0 && challenge<(int)m_all_challenges.size())
00067     {
00068         widget_manager->setWgtText(WTOK_DESCRIPTION,
00069             m_all_challenges[challenge]->getChallengeDescription());
00070     }
00071     widget_manager->update(dt);
00072 }   // update
00073 
00074 //-----------------------------------------------------------------------------
00075 void ChallengesMenu::select()
00076 {
00077     if(widget_manager->getSelectedWgt()==WTOK_BACK)
00078     {
00079         menu_manager->popMenu();
00080         return;
00081     }
00082     int n=widget_manager->getSelectedWgt()-WTOK_CHALLENGES;
00083     if(n>=0 && n<(int)m_all_challenges.size())
00084     {
00085         m_all_challenges[n]->setRace();
00086         menu_manager->pushMenu(MENUID_START_RACE_FEEDBACK);
00087     }
00088 }   // select