Add dialog asking to select challenge difficulty. Crashes for now so don't report bugs yet

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@10736 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria
2012-01-28 02:06:44 +00:00
parent 0bf039c09e
commit 708d79b2f4
6 changed files with 191 additions and 48 deletions

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,26 @@
<stkgui>
<div x="5%" y="5%" width="90%" height="90%" layout="vertical-row" >
<header width="80%" text="Race Setup" align="center" text_align="center" />
<spacer height="2%" width="1"/>
<icon-button id="novice" icon="gui/difficulty_easy.png"
I18N="Difficulty" text="Novice" proportion="1"/>
<spacer height="8%" width="1"/>
<icon-button id="intermediate" icon="gui/difficulty_medium.png"
I18N="Difficulty" text="Intermediate" proportion="1"/>
<spacer height="8%" width="1"/>
<icon-button id="expert" icon="gui/difficulty_hard.png"
I18N="Difficulty" text="Expert" proportion="1"/>
<spacer height="8%" width="1"/>
</div>
</stkgui>

View File

@@ -61,6 +61,7 @@
9542FC7712D3BDB000C00366 /* particle_emitter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9542FC7512D3BDB000C00366 /* particle_emitter.cpp */; };
9542FD4C12D3E0D700C00366 /* particle_kind.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9542FD4A12D3E0D700C00366 /* particle_kind.cpp */; };
9543D58F14D36EE3000B0888 /* kart_gfx.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9543D58D14D36EE3000B0888 /* kart_gfx.cpp */; };
9543D59E14D38831000B0888 /* select_challenge.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9543D59D14D38831000B0888 /* select_challenge.cpp */; };
95453ACA11808B8700A155B9 /* emergency_animation.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 95453AC811808B8700A155B9 /* emergency_animation.cpp */; };
9545ABCA11E3E38300D3C37A /* progress_bar_widget.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9545ABC811E3E38300D3C37A /* progress_bar_widget.cpp */; };
954E486A11B19C4100B1DF63 /* fribidi.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 954E486911B19C4100B1DF63 /* fribidi.framework */; };
@@ -510,6 +511,8 @@
9542FD4B12D3E0D700C00366 /* particle_kind.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = particle_kind.hpp; path = ../../graphics/particle_kind.hpp; sourceTree = SOURCE_ROOT; };
9543D58D14D36EE3000B0888 /* kart_gfx.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = kart_gfx.cpp; path = ../../karts/kart_gfx.cpp; sourceTree = SOURCE_ROOT; };
9543D58E14D36EE3000B0888 /* kart_gfx.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = kart_gfx.hpp; path = ../../karts/kart_gfx.hpp; sourceTree = SOURCE_ROOT; };
9543D59D14D38831000B0888 /* select_challenge.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = select_challenge.cpp; path = ../../states_screens/dialogs/select_challenge.cpp; sourceTree = SOURCE_ROOT; };
9543D5A514D3885F000B0888 /* select_challenge.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = select_challenge.hpp; path = ../../states_screens/dialogs/select_challenge.hpp; sourceTree = SOURCE_ROOT; };
95453AC811808B8700A155B9 /* emergency_animation.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = emergency_animation.cpp; path = ../../karts/emergency_animation.cpp; sourceTree = SOURCE_ROOT; };
95453AC911808B8700A155B9 /* emergency_animation.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = emergency_animation.hpp; path = ../../karts/emergency_animation.hpp; sourceTree = SOURCE_ROOT; };
9545ABC811E3E38300D3C37A /* progress_bar_widget.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = progress_bar_widget.cpp; path = ../../guiengine/widgets/progress_bar_widget.cpp; sourceTree = SOURCE_ROOT; };
@@ -2311,6 +2314,8 @@
9551DB32104CABFC001C53E5 /* race_over_dialog.hpp */,
958D8C53104F523000A81934 /* race_paused_dialog.cpp */,
958D8C52104F523000A81934 /* race_paused_dialog.hpp */,
9543D59D14D38831000B0888 /* select_challenge.cpp */,
9543D5A514D3885F000B0888 /* select_challenge.hpp */,
95E5C333148C19F500AD3FCC /* story_mode_new.cpp */,
95E5C334148C19F500AD3FCC /* story_mode_new.hpp */,
9583323D101243ED00C5137E /* track_info_dialog.cpp */,
@@ -3219,6 +3224,7 @@
957957A214A3CA3900E72497 /* custom_video_settings.cpp in Sources */,
95EF178E14AFBC91005FFEEB /* race_gui_overworld.cpp in Sources */,
9543D58F14D36EE3000B0888 /* kart_gfx.cpp in Sources */,
9543D59E14D38831000B0888 /* select_challenge.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

View File

@@ -22,6 +22,7 @@
#include "karts/kart.hpp"
#include "modes/overworld.hpp"
#include "network/network_manager.hpp"
#include "states_screens/dialogs/select_challenge.hpp"
#include "states_screens/race_gui_overworld.hpp"
#include "tracks/track.hpp"
@@ -91,53 +92,7 @@ void OverWorld::onFirePressed(Controller* who)
if ((kart_xyz - Vec3(challenges[n].m_position)).length2_2d() < CHALLENGE_DISTANCE_SQUARED)
{
core::rect<s32> pos(15,
10,
15 + UserConfigParams::m_width/2,
10 + GUIEngine::getTitleFontHeight());
const ChallengeData* challenge = unlock_manager->getChallenge(challenges[n].m_challenge_id);
if (challenge == NULL)
{
fprintf(stderr, "[RaceGUIOverworld] ERROR: Cannot find challenge <%s>\n",
challenges[n].m_challenge_id.c_str());
break;
}
race_manager->exitRace();
//StateManager::get()->resetActivePlayers();
// Use latest used device
InputDevice* device = input_manager->getDeviceList()->getLatestUsedDevice();
assert(device != NULL);
// Set up race manager appropriately
race_manager->setNumLocalPlayers(1);
race_manager->setLocalKartInfo(0, UserConfigParams::m_default_kart);
//int id = StateManager::get()->createActivePlayer( unlock_manager->getCurrentPlayer(), device );
input_manager->getDeviceList()->setSinglePlayer( StateManager::get()->getActivePlayer(0) );
// ASSIGN should make sure that only input from assigned devices is read.
input_manager->getDeviceList()->setAssignMode(ASSIGN);
// Go straight to the race
StateManager::get()->enterGameState();
// Initialise global data - necessary even in local games to avoid
// many if tests in other places (e.g. if network_game call
// network_manager else call race_manager).
network_manager->initCharacterDataStructures();
// TODO: allow user to select difficulty
// Launch challenge
challenge->setRace(RaceManager::RD_HARD);
// Sets up kart info, including random list of kart for AI
network_manager->setupPlayerKartInfo();
race_manager->startNew();
return;
new SelectChallengeDialog(0.8f, 0.8f, challenges[n].m_challenge_id);
} // end if
} // end for
}

View File

@@ -0,0 +1,115 @@
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2012 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.
#include "challenges/unlock_manager.hpp"
#include "config/user_config.hpp"
#include "guiengine/engine.hpp"
#include "input/device_manager.hpp"
#include "input/input_manager.hpp"
#include "network/network_manager.hpp"
#include "race/race_manager.hpp"
#include "states_screens/dialogs/select_challenge.hpp"
SelectChallengeDialog::SelectChallengeDialog(const float percentWidth,
const float percentHeight,
std::string challenge_id) :
ModalDialog(percentWidth, percentHeight)
{
loadFromFile("select_challenge.stkgui");
m_challenge_id = challenge_id;
}
SelectChallengeDialog::~SelectChallengeDialog()
{
}
GUIEngine::EventPropagation SelectChallengeDialog::processEvent(const std::string& eventSource)
{
if (eventSource == "novice" || eventSource == "intermediate" ||
eventSource == "expert")
{
ModalDialog::dismiss();
core::rect<s32> pos(15,
10,
15 + UserConfigParams::m_width/2,
10 + GUIEngine::getTitleFontHeight());
const ChallengeData* challenge = unlock_manager->getChallenge(m_challenge_id);
if (challenge == NULL)
{
fprintf(stderr, "[RaceGUIOverworld] ERROR: Cannot find challenge <%s>\n",
m_challenge_id.c_str());
return GUIEngine::EVENT_LET;
}
race_manager->exitRace();
//StateManager::get()->resetActivePlayers();
// Use latest used device
InputDevice* device = input_manager->getDeviceList()->getLatestUsedDevice();
assert(device != NULL);
// Set up race manager appropriately
race_manager->setNumLocalPlayers(1);
race_manager->setLocalKartInfo(0, UserConfigParams::m_default_kart);
//int id = StateManager::get()->createActivePlayer( unlock_manager->getCurrentPlayer(), device );
input_manager->getDeviceList()->setSinglePlayer( StateManager::get()->getActivePlayer(0) );
// ASSIGN should make sure that only input from assigned devices is read.
input_manager->getDeviceList()->setAssignMode(ASSIGN);
// Go straight to the race
StateManager::get()->enterGameState();
// Initialise global data - necessary even in local games to avoid
// many if tests in other places (e.g. if network_game call
// network_manager else call race_manager).
network_manager->initCharacterDataStructures();
// Launch challenge
if (eventSource == "novice")
{
challenge->setRace(RaceManager::RD_EASY);
}
else if (eventSource == "intermediate")
{
challenge->setRace(RaceManager::RD_MEDIUM);
}
else if (eventSource == "expert")
{
challenge->setRace(RaceManager::RD_HARD);
}
else
{
fprintf(stderr, "ERROR: unknown widget <%s>\n", eventSource.c_str());
//assert(false);
return GUIEngine::EVENT_LET;
}
// Sets up kart info, including random list of kart for AI
network_manager->setupPlayerKartInfo();
race_manager->startNew();
}
return GUIEngine::EVENT_LET;
}

View File

@@ -0,0 +1,41 @@
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2012 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.
#ifndef SELECT_CHALLENGE_HPP
#define SELECT_CHALLENGE_HPP
#include "guiengine/event_handler.hpp"
#include "guiengine/modaldialog.hpp"
/**
* \brief Dialog shown when starting a challenge
* \ingroup states_screens
*/
class SelectChallengeDialog : public GUIEngine::ModalDialog
{
std::string m_challenge_id;
public:
SelectChallengeDialog(const float percentWidth, const float percentHeight,
std::string challenge_id);
virtual ~SelectChallengeDialog();
virtual GUIEngine::EventPropagation processEvent(const std::string& eventSource);
};
#endif