Back to index

supertuxkart  0.5+dfsg1
help_page_one.cpp
Go to the documentation of this file.
00001 //  $Id: help_menu.cpp 812 2006-10-07 11:43:57Z hiker $
00002 //
00003 //  SuperTuxKart - a fun racing game with go-kart
00004 //  Copyright (C) 2006 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 "help_page_one.hpp"
00021 #include "widget_manager.hpp"
00022 #include "race_manager.hpp"
00023 #include "menu_manager.hpp"
00024 #include "user_config.hpp"
00025 #include "player.hpp"
00026 #include "collectable_manager.hpp"
00027 #include "material.hpp"
00028 #include "translation.hpp"
00029 
00030 enum WidgetTokens
00031 {
00032     WTOK_MSG1,
00033     WTOK_MSG2,
00034     WTOK_MSG3,
00035     WTOK_MSG4,
00036     WTOK_MSG5,
00037     WTOK_MSG6,
00038     WTOK_MSG7,
00039 
00040     WTOK_LOCK,
00041 
00042     WTOK_SECOND_PAGE,
00043     WTOK_QUIT
00044 };
00045 
00046 HelpPageOne::HelpPageOne()
00047 {
00048     //The ssgContext constructor calls makeCurrent(), it has to be restored
00049     ssgContext* oldContext = ssgGetCurrentContext();
00050     m_context = new ssgContext;
00051     oldContext->makeCurrent();
00052 
00053     m_box = 0;
00054     m_silver_coin = 0;
00055     m_gold_coin = 0;
00056     m_banana = 0;
00057 
00058        m_clock = 0;
00059 
00060     //FIXME: instead of using setInitialTextState, the gui & widget manager macros should improve it's design
00061     widget_manager->setInitialTextState
00062     (
00063         false,
00064         "",
00065         WGT_FNT_SML,
00066         WGT_FONT_GUI,
00067         WGT_WHITE,
00068         true
00069     );
00070     widget_manager->addTextWgt( WTOK_MSG1, 50, 7,
00071         _("Force your rivals bite *your* dust!") );
00072     widget_manager->breakLine();
00073 
00074     widget_manager->addTextWgt( WTOK_MSG2, 60, 7,
00075         _("Grab blue boxes and coins") );
00076     widget_manager->addTextWgt( WTOK_MSG3, 30, 7, _("Avoid bananas") );
00077     widget_manager->breakLine();
00078 
00079     /*Rotating 3D models*/
00080        ssgEntity* hm = herring_manager->getHerringModel(HE_RED);
00081     ssgDeRefDelete(m_box);
00082     m_box = new ssgTransform;
00083     m_box->ref();
00084     m_box->addKid(hm);
00085 
00086     hm = herring_manager->getHerringModel(HE_SILVER);
00087     ssgDeRefDelete(m_silver_coin);
00088     m_silver_coin = new ssgTransform;
00089     m_silver_coin->ref();
00090     m_silver_coin->addKid(hm);
00091 
00092     hm = herring_manager->getHerringModel(HE_GOLD);
00093     ssgDeRefDelete(m_gold_coin);
00094     m_gold_coin = new ssgTransform;
00095     m_gold_coin->ref();
00096     m_gold_coin->addKid(hm);
00097 
00098     hm = herring_manager->getHerringModel(HE_GREEN);
00099     ssgDeRefDelete(m_banana);
00100     m_banana = new ssgTransform;
00101     m_banana->ref();
00102     m_banana->addKid(hm);
00103 
00104     /*Empty widget to cover the space for the 3D models*/
00105     widget_manager->addEmptyWgt( WidgetManager::WGT_NONE, 100, 15);
00106     widget_manager->breakLine();
00107 
00108     widget_manager->addTextWgt(WTOK_MSG4, 100, 13,
00109 //Next line starts at column 0 to avoid spaces in the GUI
00110 _("At high speeds wheelies drive you faster, but you can't steer. If you\n\
00111 get stuck or fall too far, use the rescue button to get back on track."));
00112     widget_manager->setWgtResizeToText( WTOK_MSG4, false );
00113     widget_manager->breakLine();
00114 
00115     widget_manager->addEmptyWgt( WidgetManager::WGT_NONE, 100, 1);
00116     widget_manager->breakLine();
00117 
00118     widget_manager->addTextWgt(WTOK_MSG5, 80, 10,
00119         _("The current key bindings can be seen/changed in the\nOptions->Player Config menu."));
00120     widget_manager->breakLine();
00121     widget_manager->addEmptyWgt( WidgetManager::WGT_NONE, 100, 1);
00122     widget_manager->breakLine();
00123 
00124     widget_manager->addTextWgt(WTOK_MSG6, 100, 17,
00125 _("Collecting coins increases the number of collectables you receive.\n\
00126 After 5 silver coins, each blue box will yield 2 collectables,\nafter 10,\
00127  3 collectables and so on.\nEach gold coin is worth 3 silver coins, \
00128 so look out for them!"));
00129     widget_manager->setWgtResizeToText( WTOK_MSG6, false);
00130     widget_manager->breakLine();
00131     widget_manager->addEmptyWgt( WidgetManager::WGT_NONE, 100, 1);
00132     widget_manager->breakLine();
00133 
00134     widget_manager->addTextWgt(WTOK_MSG7, 87, 8,
00135 _("If you see a button with a lock like the one to the right,\n\
00136 you need to complete a challenge to unlock it."));
00137 
00138     widget_manager->addImgWgt(WTOK_LOCK, 6, 8, 0);
00139     widget_manager->setWgtTexture(WTOK_LOCK, "gui_help_lock.rgb", false);
00140     widget_manager->breakLine();
00141 
00142     widget_manager->addEmptyWgt( WidgetManager::WGT_NONE, 100, 1);
00143     widget_manager->breakLine();
00144 
00145     /*Buttons at the bottom*/
00146     widget_manager->addTextButtonWgt(WTOK_SECOND_PAGE, 20, 7,
00147         _("Next help screen"));
00148     widget_manager->breakLine();
00149 
00150     widget_manager->addTextButtonWgt(WTOK_QUIT, 40, 7,
00151         _("Go back to the menu"));
00152 
00153     widget_manager->layout( WGT_AREA_TOP );
00154 }   // HelpPageOne
00155 
00156 //-----------------------------------------------------------------------------
00157 HelpPageOne::~HelpPageOne()
00158 {
00159     widget_manager->reset();
00160 
00161        if (m_box != NULL && m_silver_coin != NULL && m_gold_coin != NULL
00162         && m_banana != NULL )
00163        {
00164               ssgDeRefDelete(m_box);
00165               ssgDeRefDelete(m_silver_coin);
00166               ssgDeRefDelete(m_gold_coin);
00167               ssgDeRefDelete(m_banana);
00168        }
00169 
00170     delete m_context;
00171 
00172 }   // ~HelpPageOne
00173 
00174 //-----------------------------------------------------------------------------
00175 void HelpPageOne::update(float dt)
00176 {
00177     m_clock += dt * 40.0f;
00178 
00179     if (m_box != NULL && m_silver_coin != NULL && m_gold_coin != NULL
00180         && m_banana != NULL )
00181     {
00182         ssgContext* oldContext = ssgGetCurrentContext();
00183         m_context -> makeCurrent();
00184 
00185         glClear(GL_DEPTH_BUFFER_BIT);
00186 
00187         sgCoord cam_pos;
00188         sgSetCoord(&cam_pos, 0, 0, 0, 0, 0, 0);
00189         m_context -> setCamera ( &cam_pos ) ;
00190 
00191         glEnable (GL_DEPTH_TEST);
00192         sgCoord trans;
00193         sgSetCoord(&trans, -4, 10, 1.85f, m_clock, 0, 0);
00194         m_box->setTransform (&trans);
00195 
00196         sgSetCoord(&trans, -2, 8, 1.5f, m_clock, 0, 0);
00197         m_silver_coin->setTransform (&trans);
00198 
00199         sgSetCoord(&trans, -1, 8, 1.5f, m_clock, 0, 0);
00200         m_gold_coin->setTransform (&trans);
00201 
00202         sgSetCoord(&trans, 5, 15, 3, m_clock, 0, 0);
00203         m_banana->setTransform (&trans);
00204 
00205         //glShadeModel(GL_SMOOTH);
00206         ssgCullAndDraw ( m_box ) ;
00207         ssgCullAndDraw ( m_silver_coin ) ;
00208         ssgCullAndDraw ( m_gold_coin ) ;
00209         ssgCullAndDraw ( m_banana ) ;
00210         glViewport ( 0, 0, user_config->m_width, user_config->m_height ) ;
00211 
00212         glDisable (GL_DEPTH_TEST);
00213         oldContext->makeCurrent();
00214     }
00215 
00216     widget_manager->update(dt);
00217 }
00218 
00219 //-----------------------------------------------------------------------------
00220 void HelpPageOne::select()
00221 {
00222     switch ( widget_manager->getSelectedWgt() )
00223     {
00224         case WTOK_SECOND_PAGE:
00225             //This switches the first page with the second page, so they
00226             //are not stacked by the menu manager, and the menu that called
00227             //this help is the one that gets called back when the next page
00228             //is popped.
00229             menu_manager->popMenu();
00230             menu_manager->pushMenu(MENUID_HELP2);
00231             break;
00232 
00233         case WTOK_QUIT:
00234             menu_manager->popMenu();
00235             break;
00236     }
00237 }   // select
00238 
00239 /* EOF */