2009-10-04 19:59:05 -04:00
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2009 Marianne Gagnon
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
2009-12-22 16:57:15 -05:00
# include <irrlicht.h>
2009-10-04 19:59:05 -04:00
# include "challenges/unlock_manager.hpp"
2010-04-26 10:41:23 -04:00
# include "guiengine/widgets/dynamic_ribbon_widget.hpp"
# include "guiengine/widgets/ribbon_widget.hpp"
# include "guiengine/widgets/spinner_widget.hpp"
2009-10-04 19:59:05 -04:00
# include "io/file_manager.hpp"
# include "race/race_manager.hpp"
2009-12-19 14:25:12 -05:00
# include "states_screens/arenas_screen.hpp"
2009-10-04 19:59:05 -04:00
# include "states_screens/state_manager.hpp"
# include "states_screens/tracks_screen.hpp"
# include "utils/translation.hpp"
2009-12-22 16:57:15 -05:00
# include "states_screens/race_setup_screen.hpp"
2009-10-04 19:59:05 -04:00
using namespace GUIEngine ;
2010-03-18 14:18:19 -04:00
DEFINE_SCREEN_SINGLETON ( RaceSetupScreen ) ;
2009-10-04 19:59:05 -04:00
2010-02-17 20:07:21 -05:00
class GameModeRibbonListener : public DynamicRibbonHoverListener
{
RaceSetupScreen * m_parent ;
public :
GameModeRibbonListener ( RaceSetupScreen * parent )
{
m_parent = parent ;
}
virtual void onSelectionChanged ( DynamicRibbonWidget * theWidget , const std : : string & selectionID ,
const irr : : core : : stringw & selectionText , const int playerID )
{
// game mode changed!!
m_parent - > onGameModeChanged ( ) ;
}
} ;
2010-02-12 19:07:13 -05:00
// -----------------------------------------------------------------------------
2009-10-04 19:59:05 -04:00
RaceSetupScreen : : RaceSetupScreen ( ) : Screen ( " racesetup.stkgui " )
{
}
2010-02-12 19:07:13 -05:00
// -----------------------------------------------------------------------------
2009-10-04 19:59:05 -04:00
2010-05-01 15:16:38 -04:00
void RaceSetupScreen : : loadedFromFile ( )
{
}
// -----------------------------------------------------------------------------
2009-10-28 19:04:38 -04:00
void RaceSetupScreen : : eventCallback ( Widget * widget , const std : : string & name , const int playerID )
2009-10-04 19:59:05 -04:00
{
if ( name = = " difficulty " )
{
RibbonWidget * w = dynamic_cast < RibbonWidget * > ( widget ) ;
assert ( w ! = NULL ) ;
2010-04-08 17:02:40 -04:00
const std : : string & selection = w - > getSelectionIDString ( PLAYER_ID_GAME_MASTER ) ;
2009-10-04 19:59:05 -04:00
if ( selection = = " novice " )
{
UserConfigParams : : m_difficulty = RaceManager : : RD_EASY ;
race_manager - > setDifficulty ( RaceManager : : RD_EASY ) ;
}
else if ( selection = = " intermediate " )
{
UserConfigParams : : m_difficulty = RaceManager : : RD_MEDIUM ;
race_manager - > setDifficulty ( RaceManager : : RD_MEDIUM ) ;
}
else if ( selection = = " expert " )
{
UserConfigParams : : m_difficulty = RaceManager : : RD_HARD ;
race_manager - > setDifficulty ( RaceManager : : RD_HARD ) ;
}
}
else if ( name = = " gamemode " )
{
DynamicRibbonWidget * w = dynamic_cast < DynamicRibbonWidget * > ( widget ) ;
2010-04-08 17:02:40 -04:00
const std : : string selectedMode = w - > getSelectionIDString ( PLAYER_ID_GAME_MASTER ) ;
2009-10-04 19:59:05 -04:00
if ( selectedMode = = " normal " )
{
2009-12-22 16:57:15 -05:00
race_manager - > setMinorMode ( RaceManager : : MINOR_MODE_NORMAL_RACE ) ;
2009-10-04 19:59:05 -04:00
StateManager : : get ( ) - > pushScreen ( TracksScreen : : getInstance ( ) ) ;
}
else if ( selectedMode = = " timetrial " )
{
race_manager - > setMinorMode ( RaceManager : : MINOR_MODE_TIME_TRIAL ) ;
StateManager : : get ( ) - > pushScreen ( TracksScreen : : getInstance ( ) ) ;
}
else if ( selectedMode = = " ftl " )
{
race_manager - > setMinorMode ( RaceManager : : MINOR_MODE_FOLLOW_LEADER ) ;
StateManager : : get ( ) - > pushScreen ( TracksScreen : : getInstance ( ) ) ;
}
else if ( selectedMode = = " 3strikes " )
{
race_manager - > setMinorMode ( RaceManager : : MINOR_MODE_3_STRIKES ) ;
2010-02-17 11:48:12 -05:00
race_manager - > setNumKarts ( race_manager - > getNumPlayers ( ) ) ; // no AI karts;
2009-12-19 14:25:12 -05:00
StateManager : : get ( ) - > pushScreen ( ArenasScreen : : getInstance ( ) ) ;
2009-10-04 19:59:05 -04:00
}
else if ( selectedMode = = " locked " )
{
unlock_manager - > playLockSound ( ) ;
}
}
else if ( name = = " aikartamount " )
{
SpinnerWidget * w = dynamic_cast < SpinnerWidget * > ( widget ) ;
race_manager - > setNumKarts ( race_manager - > getNumPlayers ( ) + w - > getValue ( ) ) ;
}
}
2010-02-12 19:07:13 -05:00
// -----------------------------------------------------------------------------
2010-02-17 20:07:21 -05:00
void RaceSetupScreen : : onGameModeChanged ( )
{
DynamicRibbonWidget * w2 = getWidget < DynamicRibbonWidget > ( " gamemode " ) ;
assert ( w2 ! = NULL ) ;
2010-06-26 15:36:59 -04:00
std : : string gamemode = w2 - > getSelectionIDString ( PLAYER_ID_GAME_MASTER ) ;
2010-02-17 20:07:21 -05:00
// deactivate the AI karts count widget for modes for which we have no AI
//FIXME? Don't hardcode here which modes have an AI and which don't
SpinnerWidget * kartamount = getWidget < SpinnerWidget > ( " aikartamount " ) ;
2010-05-15 14:51:29 -04:00
if ( gamemode = = " 3strikes " )
2010-02-17 20:07:21 -05:00
{
2010-05-15 14:51:29 -04:00
kartamount - > setDeactivated ( ) ;
// dirty trick to hide the number inside the spinner (FIXME)
2010-02-17 20:07:21 -05:00
kartamount - > m_text = L " - " ;
kartamount - > setValue ( kartamount - > getValue ( ) ) ;
}
2010-05-15 14:51:29 -04:00
else
2010-02-17 20:07:21 -05:00
{
2010-05-15 14:51:29 -04:00
kartamount - > setActivated ( ) ;
2010-02-17 20:07:21 -05:00
kartamount - > m_text = L " " ;
kartamount - > setValue ( kartamount - > getValue ( ) ) ;
}
}
// -----------------------------------------------------------------------------
2009-10-04 19:59:05 -04:00
void RaceSetupScreen : : init ( )
{
RibbonWidget * w = getWidget < RibbonWidget > ( " difficulty " ) ;
assert ( w ! = NULL ) ;
2010-04-08 17:02:40 -04:00
w - > setSelection ( race_manager - > getDifficulty ( ) , PLAYER_ID_GAME_MASTER ) ;
2009-10-04 19:59:05 -04:00
SpinnerWidget * kartamount = getWidget < SpinnerWidget > ( " aikartamount " ) ;
2010-02-10 06:40:33 -05:00
kartamount - > setValue ( race_manager - > getNumberOfKarts ( ) - race_manager - > getNumPlayers ( ) ) ;
2009-10-04 19:59:05 -04:00
DynamicRibbonWidget * w2 = getWidget < DynamicRibbonWidget > ( " gamemode " ) ;
assert ( w2 ! = NULL ) ;
2009-12-30 13:17:16 -05:00
w2 - > clearItems ( ) ;
// ---- Add game modes
2010-02-12 19:07:13 -05:00
irr : : core : : stringw name1 = irr : : core : : stringw (
RaceManager : : getNameOf ( RaceManager : : MINOR_MODE_NORMAL_RACE ) ) + L " \n " ;
//FIXME: avoid duplicating descriptions from the help menu!
2009-12-30 13:17:16 -05:00
name1 + = _ ( " All blows allowed, so catch weapons and make clever use of them! " ) ;
2010-03-04 20:28:23 -05:00
w2 - > addItem ( name1 , " normal " , RaceManager : : getIconOf ( RaceManager : : MINOR_MODE_NORMAL_RACE ) ) ;
2009-12-30 13:17:16 -05:00
2010-02-12 19:07:13 -05:00
irr : : core : : stringw name2 = irr : : core : : stringw (
RaceManager : : getNameOf ( RaceManager : : MINOR_MODE_TIME_TRIAL ) ) + L " \n " ;
//FIXME: avoid duplicating descriptions from the help menu!
2009-12-30 13:17:16 -05:00
name2 + = _ ( " Contains no powerups, so only your driving skills matter! " ) ;
2010-03-04 20:28:23 -05:00
w2 - > addItem ( name2 , " timetrial " , RaceManager : : getIconOf ( RaceManager : : MINOR_MODE_TIME_TRIAL ) ) ;
2009-10-04 19:59:05 -04:00
2009-12-30 13:17:16 -05:00
if ( unlock_manager - > isLocked ( " followtheleader " ) )
2009-10-04 19:59:05 -04:00
{
2009-12-30 13:17:16 -05:00
w2 - > addItem ( _ ( " Locked : solve active challenges to gain access to more! " ) ,
2010-03-04 20:28:23 -05:00
" locked " , RaceManager : : getIconOf ( RaceManager : : MINOR_MODE_FOLLOW_LEADER ) , true ) ;
2009-12-30 13:17:16 -05:00
}
else
{
2010-02-12 19:07:13 -05:00
irr : : core : : stringw name3 = irr : : core : : stringw (
RaceManager : : getNameOf ( RaceManager : : MINOR_MODE_FOLLOW_LEADER ) ) + L " \n " ;
//FIXME: avoid duplicating descriptions from the help menu!
2009-12-30 13:17:16 -05:00
name3 + = _ ( " Run for second place, as the last kart will be disqualified every time the counter hits zero. Beware : going in front of the leader will get you eliminated too! " ) ;
2010-03-04 20:28:23 -05:00
w2 - > addItem ( name3 , " ftl " , RaceManager : : getIconOf ( RaceManager : : MINOR_MODE_FOLLOW_LEADER ) , false ) ;
2009-10-04 19:59:05 -04:00
}
2009-12-30 13:17:16 -05:00
if ( race_manager - > getNumPlayers ( ) > 1 )
{
2010-02-12 19:07:13 -05:00
irr : : core : : stringw name4 = irr : : core : : stringw (
RaceManager : : getNameOf ( RaceManager : : MINOR_MODE_3_STRIKES ) ) + L " \n " ;
//FIXME: avoid duplicating descriptions from the help menu!
2009-12-30 13:17:16 -05:00
name4 + = _ ( " Hit others with weapons until they lose all their lives. (Only in multiplayer games) " ) ;
2010-03-04 20:28:23 -05:00
w2 - > addItem ( name4 , " 3strikes " , RaceManager : : getIconOf ( RaceManager : : MINOR_MODE_3_STRIKES ) ) ;
2009-12-30 13:17:16 -05:00
}
2009-10-04 19:59:05 -04:00
w2 - > updateItemDisplay ( ) ;
2010-02-17 20:07:21 -05:00
//FIXME: it's unclear to me whether I must add a listener everytime init is called or not
m_mode_listener = new GameModeRibbonListener ( this ) ;
w2 - > registerHoverListener ( m_mode_listener ) ;
2009-10-04 19:59:05 -04:00
}
2010-02-12 19:07:13 -05:00
// -----------------------------------------------------------------------------
2009-10-04 19:59:05 -04:00
void RaceSetupScreen : : tearDown ( )
{
2010-02-17 20:07:21 -05:00
//delete m_mode_listener;
//m_mode_listener = NULL;
//DynamicRibbonWidget* w2 = getWidget<DynamicRibbonWidget>("gamemode");
//assert( w2 != NULL );
// w2->setListener(NULL);
2009-10-04 19:59:05 -04:00
}
2010-02-12 19:07:13 -05:00
// -----------------------------------------------------------------------------