2009-10-20 16:52:52 -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.
|
|
|
|
|
|
|
|
|
|
|
|
#include "states_screens/challenges.hpp"
|
|
|
|
|
2010-02-27 19:52:41 -05:00
|
|
|
|
2009-10-20 16:52:52 -04:00
|
|
|
#include "challenges/unlock_manager.hpp"
|
2010-02-27 19:52:41 -05:00
|
|
|
#include "config/user_config.hpp"
|
|
|
|
#include "guiengine/engine.hpp"
|
|
|
|
#include "input/device_manager.hpp"
|
|
|
|
#include "input/input_manager.hpp"
|
|
|
|
#include "io/file_manager.hpp"
|
|
|
|
#include "network/network_manager.hpp"
|
|
|
|
#include "race/race_manager.hpp"
|
2009-10-20 16:52:52 -04:00
|
|
|
#include "states_screens/state_manager.hpp"
|
2009-10-21 18:51:23 -04:00
|
|
|
#include "utils/translation.hpp"
|
2009-10-20 16:52:52 -04:00
|
|
|
|
|
|
|
#include <fstream>
|
|
|
|
|
|
|
|
#include "irrString.h"
|
|
|
|
using irr::core::stringw;
|
|
|
|
using irr::core::stringc;
|
|
|
|
|
2010-03-18 14:18:19 -04:00
|
|
|
using namespace GUIEngine;
|
|
|
|
|
|
|
|
DEFINE_SCREEN_SINGLETON( ChallengesScreen );
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
ChallengesScreen::ChallengesScreen() : Screen("challenges.stkgui")
|
2009-10-20 16:52:52 -04:00
|
|
|
{
|
2010-03-18 14:18:19 -04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void ChallengesScreen::onUpdate(float elapsed_time, irr::video::IVideoDriver*)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void ChallengesScreen::init()
|
|
|
|
{
|
|
|
|
DynamicRibbonWidget* w = this->getWidget<DynamicRibbonWidget>("challenges");
|
|
|
|
assert( w != NULL );
|
|
|
|
|
|
|
|
// Re-build track list everytime (accounts for locking changes, etc.)
|
|
|
|
w->clearItems();
|
2009-10-20 16:52:52 -04:00
|
|
|
|
2010-03-18 14:18:19 -04:00
|
|
|
const std::vector<const Challenge*>& activeChallenges = unlock_manager->getActiveChallenges();
|
|
|
|
const std::vector<const Challenge*>& solvedChallenges = unlock_manager->getUnlockedFeatures();
|
|
|
|
const std::vector<const Challenge*>& lockedChallenges = unlock_manager->getLockedChallenges();
|
|
|
|
|
|
|
|
const int activeChallengeAmount = activeChallenges.size();
|
|
|
|
const int solvedChallengeAmount = solvedChallenges.size();
|
|
|
|
const int lockedChallengeAmount = lockedChallenges.size();
|
|
|
|
|
|
|
|
for (int n=0; n<activeChallengeAmount; n++)
|
2009-10-20 16:52:52 -04:00
|
|
|
{
|
2010-03-18 14:18:19 -04:00
|
|
|
w->addItem(activeChallenges[n]->getName() + L"\n" + activeChallenges[n]->getChallengeDescription(),
|
|
|
|
activeChallenges[n]->getId(), "/gui/challenge.png");
|
|
|
|
}
|
|
|
|
for (int n=0; n<solvedChallengeAmount; n++)
|
|
|
|
{
|
|
|
|
// TODO : add bronze/silver/gold difficulties to challenges
|
|
|
|
w->addItem(solvedChallenges[n]->getName() + L"\n" + solvedChallenges[n]->getChallengeDescription(),
|
|
|
|
solvedChallenges[n]->getId(), "/textures/cup_gold.png");
|
|
|
|
}
|
|
|
|
for (int n=0; n<lockedChallengeAmount; n++)
|
|
|
|
{
|
|
|
|
w->addItem( _("Locked : solve active challenges to gain access to more!"), "locked",
|
|
|
|
"/gui/challenge.png", true);
|
2009-10-20 16:52:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-18 14:18:19 -04:00
|
|
|
|
|
|
|
w->updateItemDisplay();
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void ChallengesScreen::tearDown()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void ChallengesScreen::eventCallback(GUIEngine::Widget* widget, const std::string& name, const int playerID)
|
|
|
|
{
|
|
|
|
if (name == "back")
|
2009-10-20 16:52:52 -04:00
|
|
|
{
|
2010-03-18 14:18:19 -04:00
|
|
|
StateManager::get()->escapePressed();
|
2009-10-20 16:52:52 -04:00
|
|
|
}
|
2010-03-18 14:18:19 -04:00
|
|
|
else if (name == "challenges")
|
2009-10-20 16:52:52 -04:00
|
|
|
{
|
|
|
|
DynamicRibbonWidget* w = this->getWidget<DynamicRibbonWidget>("challenges");
|
|
|
|
assert( w != NULL );
|
|
|
|
|
2010-04-08 17:02:40 -04:00
|
|
|
// only player 0 can start a challenge (i.e. we have no multiplayer challenges)
|
|
|
|
std::string selection = w->getSelectionIDString( PLAYER_ID_GAME_MASTER );
|
2009-10-20 16:52:52 -04:00
|
|
|
|
2010-03-18 14:18:19 -04:00
|
|
|
if (selection == "locked")
|
2009-10-20 16:52:52 -04:00
|
|
|
{
|
2010-03-18 14:18:19 -04:00
|
|
|
unlock_manager->playLockSound();
|
2009-10-20 16:52:52 -04:00
|
|
|
}
|
2010-03-18 14:18:19 -04:00
|
|
|
else if (!selection.empty())
|
2009-10-21 18:51:23 -04:00
|
|
|
{
|
2010-03-18 14:18:19 -04:00
|
|
|
//FIXME: simplify and centralize race start sequence!!
|
|
|
|
|
|
|
|
// Use latest used device
|
|
|
|
InputDevice* device = input_manager->getDeviceList()->getLatestUsedDevice();
|
|
|
|
|
|
|
|
// Create player and associate player with device (FIXME: ask for player ident)
|
|
|
|
StateManager::get()->createActivePlayer( UserConfigParams::m_all_players.get(0), device );
|
2009-10-21 19:00:12 -04:00
|
|
|
|
2010-03-18 14:18:19 -04:00
|
|
|
// Set up race manager appropriately
|
|
|
|
race_manager->setNumLocalPlayers(1);
|
|
|
|
race_manager->setLocalKartInfo(0, UserConfigParams::m_default_kart);
|
2009-10-21 19:00:12 -04:00
|
|
|
|
2010-03-18 14:18:19 -04:00
|
|
|
// 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();
|
|
|
|
|
|
|
|
//FIXME: why do we need to invoke the network manager for local games??
|
|
|
|
network_manager->initCharacterDataStructures();
|
|
|
|
network_manager->setupPlayerKartInfo();
|
|
|
|
|
|
|
|
// Launch challenge
|
|
|
|
unlock_manager->getChallenge(selection)->setRace();
|
|
|
|
race_manager->startNew();
|
2009-10-21 18:51:23 -04:00
|
|
|
}
|
2009-10-20 16:52:52 -04:00
|
|
|
}
|
2010-03-18 14:18:19 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------------
|
|
|
|
|