Yay for another mammoth commitsvn rm src/states_screens/options_screen.hpp Major cleanup in screens event handling, so that I can look at my code without being ashamed ;)

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@4077 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria
2009-10-04 23:59:05 +00:00
parent 0166b4365b
commit 1292e2a37f
40 changed files with 2034 additions and 1241 deletions

View File

@@ -36,7 +36,6 @@
#include "modes/world.hpp"
#include "network/network_manager.hpp"
#include "race/race_manager.hpp"
#include "states_screens/options_screen.hpp"
#include "states_screens/kart_selection.hpp"
#include "states_screens/credits.hpp"
#include "utils/translation.hpp"
@@ -44,16 +43,6 @@
using namespace GUIEngine;
/**
* Name of the event sent when constructing a menu
*/
const std::string g_init_event = "init";
/**
* Name of the event sent when destructing a menu
*/
const std::string g_teardown_event = "tearDown";
AbstractStateManager::AbstractStateManager()
{
m_game_mode = MENU;
@@ -99,7 +88,7 @@ void AbstractStateManager::pushMenu(std::string name)
assert(m_game_mode != INGAME_MENU);
// Send tear-down event to previous menu
if (m_menu_stack.size() > 0 && m_game_mode != GAME) eventCallback(NULL, g_teardown_event);
if (m_menu_stack.size() > 0 && m_game_mode != GAME) getCurrentScreen()->tearDown();
input_manager->setMode(InputManager::MENU);
m_menu_stack.push_back(name);
@@ -113,39 +102,54 @@ void AbstractStateManager::pushMenu(std::string name)
m_game_mode = MENU;
}
switchToScreen(name.c_str());
// Send init event to new menu
eventCallback(NULL, g_init_event);
}
void AbstractStateManager::pushCutScene(std::string name)
{
// Send tear-down event to previous menu
if (m_menu_stack.size() > 0 && m_game_mode != GAME) eventCallback(NULL, g_teardown_event);
if (m_menu_stack.size() > 0 && m_game_mode != GAME) getCurrentScreen()->tearDown();
input_manager->setMode(InputManager::MENU);
m_menu_stack.push_back(name);
m_game_mode = CUTSCENE;
GUIEngine::switchToScreen(name.c_str());
// Send init event to new cutscene
eventCallback(NULL, g_init_event);
}
void AbstractStateManager::replaceTopMostMenu(std::string name)
void AbstractStateManager::pushScreen(Screen* screen)
{
if (screen->getScreenType() == SCREEN_TYPE_MENU)
{
pushMenu(screen->getName());
}
else if(screen->getScreenType() == SCREEN_TYPE_CUTSCENE)
{
pushCutScene(screen->getName());
}
else
{
assert(false);
}
screen->init();
}
void AbstractStateManager::replaceTopMostScreen(Screen* screen)
{
assert(m_game_mode != GAME);
// FIXME : handle cutscenes ?
std::string name = screen->getName();
// Send tear-down event to previous menu
if (m_menu_stack.size() > 0) eventCallback(NULL, g_teardown_event);
if (m_menu_stack.size() > 0) getCurrentScreen()->tearDown();
input_manager->setMode(InputManager::MENU);
m_menu_stack[m_menu_stack.size()-1] = name;
switchToScreen(name.c_str());
// Send init event to new menu
eventCallback(NULL, g_init_event);
getCurrentScreen()->init();
}
void AbstractStateManager::reshowTopMostMenu()
@@ -153,12 +157,12 @@ void AbstractStateManager::reshowTopMostMenu()
assert(m_game_mode != GAME);
// Send tear-down event to previous menu
if (m_menu_stack.size() > 0) eventCallback(NULL, g_teardown_event);
if (m_menu_stack.size() > 0) getCurrentScreen()->tearDown();
switchToScreen( m_menu_stack[m_menu_stack.size()-1].c_str() );
// Send init event to new menu
eventCallback(NULL, g_init_event);
getCurrentScreen()->init();
}
void AbstractStateManager::popMenu()
@@ -166,8 +170,7 @@ void AbstractStateManager::popMenu()
assert(m_game_mode != GAME);
// Send tear-down event to menu
if (m_game_mode == CUTSCENE) ((CutScene*)GUIEngine::getCurrentScreen())->terminate();
else eventCallback(NULL, g_teardown_event);
getCurrentScreen()->tearDown();
m_menu_stack.pop_back();
if (m_menu_stack.size() == 0)
@@ -194,12 +197,16 @@ void AbstractStateManager::popMenu()
m_game_mode = MENU;
switchToScreen(m_menu_stack[m_menu_stack.size()-1].c_str());
input_manager->getDeviceList()->setAssignMode(NO_ASSIGN); // No assign mode on menus by default
eventCallback(NULL, g_init_event);
getCurrentScreen()->init();
}
}
void AbstractStateManager::resetAndGoToMenu(std::string name)
void AbstractStateManager::resetAndGoToScreen(Screen* screen)
{
std::string name = screen->getName();
// FIXME: handle cutscenes ?
race_manager->exitRace();
input_manager->setMode(InputManager::MENU);
m_menu_stack.clear();
@@ -207,6 +214,6 @@ void AbstractStateManager::resetAndGoToMenu(std::string name)
m_game_mode = MENU;
sound_manager->positionListener( Vec3(0,0,0), Vec3(0,1,0) );
switchToScreen(name.c_str());
eventCallback(NULL, g_init_event);
getCurrentScreen()->init();
}

View File

@@ -7,6 +7,7 @@
namespace GUIEngine
{
class Widget;
class Screen;
enum GameState
{
@@ -32,16 +33,18 @@ protected:
*/
std::vector<std::string> m_menu_stack;
void pushMenu(std::string name);
void pushCutScene(std::string name);
public:
AbstractStateManager();
virtual ~AbstractStateManager() { }
void pushMenu(std::string name);
void pushCutScene(std::string name);
void replaceTopMostMenu(std::string name);
void pushScreen(Screen* screen);
void replaceTopMostScreen(Screen* screen);
void popMenu();
void resetAndGoToMenu(std::string name);
void resetAndGoToScreen(Screen* screen);
void enterGameState();
GameState getGameState();
@@ -56,20 +59,7 @@ public:
* callback called whenever escape was pressed (or any similar cancel operation)
*/
virtual void escapePressed() = 0;
/**
* Called every frame, to allow updating animations if there is any need.
*/
virtual void onUpdate(float elpased_time) = 0;
/**
* will be called everytime sometimes happens.
* Events are generally a widget state change. In this case, a pointer to the said widget is passed along its
* name, so you get its new state and/or act. There are two special events, passed with a NULL widget, and which
* bear the anmes "init" and "tearDown", called respectively when a screen is being made visible and when it's
* being left, allowing for setup/clean-up.
*/
virtual void eventCallback(Widget* widget, const std::string& name) = 0;
};
}

View File

@@ -36,8 +36,7 @@ public:
CutScene(const char* name);
virtual void onUpdate(float dt, irr::video::IVideoDriver*)=0;
virtual void terminate()=0;
virtual ScreenType getScreenType() { return SCREEN_TYPE_CUTSCENE; }
};
}

View File

@@ -115,9 +115,11 @@ void switchToScreen(const char* screen_name)
// screen not found in list of existing ones, so let's create it
if (g_current_screen == NULL)
{
GUIEngine::Screen* new_screen = new GUIEngine::Screen(screen_name);
g_loaded_screens.push_back(new_screen);
g_current_screen = new_screen;
assert(false);
return;
//GUIEngine::Screen* new_screen = new GUIEngine::Screen(screen_name);
//g_loaded_screens.push_back(new_screen);
//g_current_screen = new_screen;
}
@@ -125,7 +127,7 @@ void switchToScreen(const char* screen_name)
g_current_screen->addWidgets();
}
// -----------------------------------------------------------------------------
void addCutScene(CutScene* cutscene)
void addScreenToList(Screen* cutscene)
{
g_loaded_screens.push_back(cutscene);
}
@@ -189,7 +191,7 @@ void init(IrrlichtDevice* device_a, IVideoDriver* driver_a, AbstractStateManager
void transmitEvent(Widget* widget, std::string& name)
{
assert(g_state_manager != NULL);
g_state_manager->eventCallback(widget, name);
getCurrentScreen()->eventCallback(widget, name);
}
// -----------------------------------------------------------------------------
@@ -221,17 +223,7 @@ void render(float elapsed_time)
g_env->drawAll();
// ---- some menus may need updating
if (gamestate != GAME)
{
g_state_manager->onUpdate(elapsed_time);
if (gamestate == CUTSCENE)
{
((CutScene*)getCurrentScreen())->onUpdate(elapsed_time, g_driver);
}
}
getCurrentScreen()->onUpdate(elapsed_time, g_driver);
}
// -----------------------------------------------------------------------------
Widget* getWidget(const char* name)

View File

@@ -229,7 +229,7 @@ namespace GUIEngine
float getLatestDt();
/** Add a cutscene to the list of screens known by the gui engine */
void addCutScene(CutScene* cutscene);
void addScreenToList(Screen* screen);
// Widgets that need to be notified at every frame can add themselves there
extern ptr_vector<Widget, REF> needsUpdate;

View File

@@ -24,10 +24,12 @@
#include "irrlicht.h"
#include "guiengine/engine.hpp"
#include "guiengine/widget.hpp"
#include "input/input.hpp"
#include "utils/ptr_vector.hpp"
// FIXME : don't use 'using namespace' in header!!!!
using namespace irr;
using namespace core;
using namespace scene;
@@ -39,8 +41,33 @@ using namespace gui;
namespace GUIEngine
{
template<typename SCREEN>
class ScreenSingleton
{
public:
static SCREEN* getInstance()
{
static SCREEN* singleton = NULL;
if (singleton == NULL)
{
singleton = new SCREEN();
GUIEngine::addScreenToList(singleton);
}
return singleton;
}
};
void parseScreenFileDiv(irr::io::IrrXMLReader* xml, ptr_vector<Widget>& append_to);
enum ScreenType
{
SCREEN_TYPE_MENU,
SCREEN_TYPE_CUTSCENE
};
/**
* Represents a single screen. Mainly responsible of its children widgets; Screen lays them
* out, asks them to add themselves, asks them to remove themselves, etc.
@@ -57,6 +84,7 @@ namespace GUIEngine
static void addWidgetsRecursively(ptr_vector<Widget>& widgets, Widget* parent=NULL);
void calculateLayout(ptr_vector<Widget>& widgets, Widget* parent=NULL);
public:
ptr_vector<Widget, HOLD> m_widgets;
@@ -91,12 +119,29 @@ namespace GUIEngine
virtual void addWidgets();
virtual void calculateLayout();
virtual ScreenType getScreenType() { return SCREEN_TYPE_MENU; }
void manualAddWidget(Widget* w);
void manualRemoveWidget(Widget* w);
const std::string& getName() const { return m_filename; }
void elementsWereDeleted(ptr_vector<Widget>* within_vector = NULL);
virtual void init() = 0;
virtual void tearDown() = 0;
/**
* will be called everytime sometimes happens.
* Events are generally a widget state change. In this case, a pointer to the said widget is passed along its
* name, so you get its new state and/or act. There are two special events, passed with a NULL widget, and which
* bear the anmes "init" and "tearDown", called respectively when a screen is being made visible and when it's
* being left, allowing for setup/clean-up.
*/
virtual void eventCallback(Widget* widget, const std::string& name) = 0;
virtual void onUpdate(float dt, irr::video::IVideoDriver*) { };
};
}

View File

@@ -22,6 +22,15 @@
9507E9D20FC1CDCE00BD2B92 /* OpenAL.framework in Copy frameworks */ = {isa = PBXBuildFile; fileRef = 9551C7FA0FC1B63C00DB481B /* OpenAL.framework */; };
9507E9DB0FC1CDD500BD2B92 /* Vorbis.framework in Copy frameworks */ = {isa = PBXBuildFile; fileRef = 9551C7FB0FC1B63C00DB481B /* Vorbis.framework */; };
951BC65E0FFAF290006B5FF1 /* ipo.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 951BC65C0FFAF290006B5FF1 /* ipo.cpp */; };
9522F125107948AD0067ECF5 /* main_menu_screen.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9522F124107948AD0067ECF5 /* main_menu_screen.cpp */; };
9522F15B107949780067ECF5 /* race_setup_screen.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9522F15A107949780067ECF5 /* race_setup_screen.cpp */; };
9522F15E10794A350067ECF5 /* tracks_screen.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9522F15C10794A350067ECF5 /* tracks_screen.cpp */; };
9522F1E010795E8A0067ECF5 /* help_screen_1.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9522F1DE10795E8A0067ECF5 /* help_screen_1.cpp */; };
9522F1E510795EFF0067ECF5 /* help_screen_2.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9522F1E210795EFF0067ECF5 /* help_screen_2.cpp */; };
9522F1E610795EFF0067ECF5 /* help_screen_3.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9522F1E410795EFF0067ECF5 /* help_screen_3.cpp */; };
9522F1EF107961560067ECF5 /* options_screen_av.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9522F1E9107961560067ECF5 /* options_screen_av.cpp */; };
9522F1F0107961560067ECF5 /* options_screen_input.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9522F1EB107961560067ECF5 /* options_screen_input.cpp */; };
9522F1F1107961560067ECF5 /* options_screen_players.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9522F1ED107961560067ECF5 /* options_screen_players.cpp */; };
9524739610497C75000C197E /* dynamic_ribbon_widget.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9524739510497C75000C197E /* dynamic_ribbon_widget.cpp */; };
95263DEC0FD7471900CF5F92 /* grand_prix_data.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 95263DE00FD7471900CF5F92 /* grand_prix_data.cpp */; };
95263DED0FD7471900CF5F92 /* grand_prix_manager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 95263DE20FD7471900CF5F92 /* grand_prix_manager.cpp */; };
@@ -245,7 +254,6 @@
958330D310122B4A00C5137E /* widget.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 958330BF10122B4A00C5137E /* widget.cpp */; };
958330D410122B4A00C5137E /* credits.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 958330C210122B4A00C5137E /* credits.cpp */; };
958330D510122B4A00C5137E /* kart_selection.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 958330C410122B4A00C5137E /* kart_selection.cpp */; };
958330D610122B4A00C5137E /* options_screen.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 958330C610122B4A00C5137E /* options_screen.cpp */; };
958330D710122B4A00C5137E /* race_gui.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 958330C810122B4A00C5137E /* race_gui.cpp */; };
958330D810122B4A00C5137E /* state_manager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 958330CA10122B4A00C5137E /* state_manager.cpp */; };
9583319910123B0200C5137E /* abstract_state_manager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9583319810123B0200C5137E /* abstract_state_manager.cpp */; };
@@ -327,6 +335,24 @@
951C357E0FC05BF400A48379 /* quad_set.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = quad_set.cpp; path = ../../tracks/quad_set.cpp; sourceTree = SOURCE_ROOT; };
951C357F0FC05BF400A48379 /* quad_graph.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = quad_graph.hpp; path = ../../tracks/quad_graph.hpp; sourceTree = SOURCE_ROOT; };
951C35800FC05BF400A48379 /* quad_graph.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = quad_graph.cpp; path = ../../tracks/quad_graph.cpp; sourceTree = SOURCE_ROOT; };
9522F123107948AD0067ECF5 /* main_menu_screen.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = main_menu_screen.hpp; path = ../../states_screens/main_menu_screen.hpp; sourceTree = SOURCE_ROOT; };
9522F124107948AD0067ECF5 /* main_menu_screen.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = main_menu_screen.cpp; path = ../../states_screens/main_menu_screen.cpp; sourceTree = SOURCE_ROOT; };
9522F159107949780067ECF5 /* race_setup_screen.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = race_setup_screen.hpp; path = games/supertuxkart/src/states_screens/race_setup_screen.hpp; sourceTree = SYSTEM_DEVELOPER_DIR; };
9522F15A107949780067ECF5 /* race_setup_screen.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = race_setup_screen.cpp; path = games/supertuxkart/src/states_screens/race_setup_screen.cpp; sourceTree = SYSTEM_DEVELOPER_DIR; };
9522F15C10794A350067ECF5 /* tracks_screen.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = tracks_screen.cpp; path = ../../states_screens/tracks_screen.cpp; sourceTree = SOURCE_ROOT; };
9522F15D10794A350067ECF5 /* tracks_screen.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = tracks_screen.hpp; path = ../../states_screens/tracks_screen.hpp; sourceTree = SOURCE_ROOT; };
9522F1DE10795E8A0067ECF5 /* help_screen_1.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = help_screen_1.cpp; path = ../../states_screens/help_screen_1.cpp; sourceTree = SOURCE_ROOT; };
9522F1DF10795E8A0067ECF5 /* help_screen_1.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = help_screen_1.hpp; path = ../../states_screens/help_screen_1.hpp; sourceTree = SOURCE_ROOT; };
9522F1E110795EFF0067ECF5 /* help_screen_2.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = help_screen_2.hpp; path = ../../states_screens/help_screen_2.hpp; sourceTree = SOURCE_ROOT; };
9522F1E210795EFF0067ECF5 /* help_screen_2.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = help_screen_2.cpp; path = ../../states_screens/help_screen_2.cpp; sourceTree = SOURCE_ROOT; };
9522F1E310795EFF0067ECF5 /* help_screen_3.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = help_screen_3.hpp; path = ../../states_screens/help_screen_3.hpp; sourceTree = SOURCE_ROOT; };
9522F1E410795EFF0067ECF5 /* help_screen_3.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = help_screen_3.cpp; path = ../../states_screens/help_screen_3.cpp; sourceTree = SOURCE_ROOT; };
9522F1E9107961560067ECF5 /* options_screen_av.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = options_screen_av.cpp; path = ../../states_screens/options_screen_av.cpp; sourceTree = SOURCE_ROOT; };
9522F1EA107961560067ECF5 /* options_screen_av.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = options_screen_av.hpp; path = ../../states_screens/options_screen_av.hpp; sourceTree = SOURCE_ROOT; };
9522F1EB107961560067ECF5 /* options_screen_input.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = options_screen_input.cpp; path = ../../states_screens/options_screen_input.cpp; sourceTree = SOURCE_ROOT; };
9522F1EC107961560067ECF5 /* options_screen_players.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = options_screen_players.hpp; path = ../../states_screens/options_screen_players.hpp; sourceTree = SOURCE_ROOT; };
9522F1ED107961560067ECF5 /* options_screen_players.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = options_screen_players.cpp; path = ../../states_screens/options_screen_players.cpp; sourceTree = SOURCE_ROOT; };
9522F1EE107961560067ECF5 /* options_screen_input.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = options_screen_input.hpp; path = ../../states_screens/options_screen_input.hpp; sourceTree = SOURCE_ROOT; };
9524739410497C75000C197E /* dynamic_ribbon_widget.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = dynamic_ribbon_widget.hpp; path = ../../guiengine/widgets/dynamic_ribbon_widget.hpp; sourceTree = SOURCE_ROOT; };
9524739510497C75000C197E /* dynamic_ribbon_widget.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = dynamic_ribbon_widget.cpp; path = ../../guiengine/widgets/dynamic_ribbon_widget.cpp; sourceTree = SOURCE_ROOT; };
95263DE00FD7471900CF5F92 /* grand_prix_data.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = grand_prix_data.cpp; path = ../../race/grand_prix_data.cpp; sourceTree = SOURCE_ROOT; };
@@ -421,8 +447,6 @@
958330C310122B4A00C5137E /* credits.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = credits.hpp; path = ../../states_screens/credits.hpp; sourceTree = SOURCE_ROOT; };
958330C410122B4A00C5137E /* kart_selection.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = kart_selection.cpp; path = ../../states_screens/kart_selection.cpp; sourceTree = SOURCE_ROOT; };
958330C510122B4A00C5137E /* kart_selection.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = kart_selection.hpp; path = ../../states_screens/kart_selection.hpp; sourceTree = SOURCE_ROOT; };
958330C610122B4A00C5137E /* options_screen.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = options_screen.cpp; path = ../../states_screens/options_screen.cpp; sourceTree = SOURCE_ROOT; };
958330C710122B4A00C5137E /* options_screen.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = options_screen.hpp; path = ../../states_screens/options_screen.hpp; sourceTree = SOURCE_ROOT; };
958330C810122B4A00C5137E /* race_gui.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = race_gui.cpp; path = ../../states_screens/race_gui.cpp; sourceTree = SOURCE_ROOT; };
958330C910122B4A00C5137E /* race_gui.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = race_gui.hpp; path = ../../states_screens/race_gui.hpp; sourceTree = SOURCE_ROOT; };
958330CA10122B4A00C5137E /* state_manager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = state_manager.cpp; path = ../../states_screens/state_manager.cpp; sourceTree = SOURCE_ROOT; };
@@ -1242,12 +1266,28 @@
95D2343D1078227A00625256 /* feature_unlocked.hpp */,
958330C410122B4A00C5137E /* kart_selection.cpp */,
958330C510122B4A00C5137E /* kart_selection.hpp */,
958330C610122B4A00C5137E /* options_screen.cpp */,
958330C710122B4A00C5137E /* options_screen.hpp */,
958330C810122B4A00C5137E /* race_gui.cpp */,
958330C910122B4A00C5137E /* race_gui.hpp */,
9522F1E9107961560067ECF5 /* options_screen_av.cpp */,
9522F1EA107961560067ECF5 /* options_screen_av.hpp */,
9522F1EB107961560067ECF5 /* options_screen_input.cpp */,
9522F1EE107961560067ECF5 /* options_screen_input.hpp */,
9522F1ED107961560067ECF5 /* options_screen_players.cpp */,
9522F1EC107961560067ECF5 /* options_screen_players.hpp */,
958330CA10122B4A00C5137E /* state_manager.cpp */,
958330CB10122B4A00C5137E /* state_manager.hpp */,
9522F124107948AD0067ECF5 /* main_menu_screen.cpp */,
9522F123107948AD0067ECF5 /* main_menu_screen.hpp */,
9522F15A107949780067ECF5 /* race_setup_screen.cpp */,
9522F159107949780067ECF5 /* race_setup_screen.hpp */,
9522F15C10794A350067ECF5 /* tracks_screen.cpp */,
9522F15D10794A350067ECF5 /* tracks_screen.hpp */,
9522F1DE10795E8A0067ECF5 /* help_screen_1.cpp */,
9522F1DF10795E8A0067ECF5 /* help_screen_1.hpp */,
9522F1E210795EFF0067ECF5 /* help_screen_2.cpp */,
9522F1E110795EFF0067ECF5 /* help_screen_2.hpp */,
9522F1E410795EFF0067ECF5 /* help_screen_3.cpp */,
9522F1E310795EFF0067ECF5 /* help_screen_3.hpp */,
);
name = states_screens;
path = ../../states_screens;
@@ -2471,7 +2511,6 @@
958330D310122B4A00C5137E /* widget.cpp in Sources */,
958330D410122B4A00C5137E /* credits.cpp in Sources */,
958330D510122B4A00C5137E /* kart_selection.cpp in Sources */,
958330D610122B4A00C5137E /* options_screen.cpp in Sources */,
958330D710122B4A00C5137E /* race_gui.cpp in Sources */,
958330D810122B4A00C5137E /* state_manager.cpp in Sources */,
9583319910123B0200C5137E /* abstract_state_manager.cpp in Sources */,
@@ -2510,6 +2549,15 @@
95C77D6F106958E10080838E /* check_sphere.cpp in Sources */,
95D233F51078203900625256 /* cutscene.cpp in Sources */,
95D2343F1078227A00625256 /* feature_unlocked.cpp in Sources */,
9522F125107948AD0067ECF5 /* main_menu_screen.cpp in Sources */,
9522F15B107949780067ECF5 /* race_setup_screen.cpp in Sources */,
9522F15E10794A350067ECF5 /* tracks_screen.cpp in Sources */,
9522F1E010795E8A0067ECF5 /* help_screen_1.cpp in Sources */,
9522F1E510795EFF0067ECF5 /* help_screen_2.cpp in Sources */,
9522F1E610795EFF0067ECF5 /* help_screen_3.cpp in Sources */,
9522F1EF107961560067ECF5 /* options_screen_av.cpp in Sources */,
9522F1F0107961560067ECF5 /* options_screen_input.cpp in Sources */,
9522F1F1107961560067ECF5 /* options_screen_players.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

View File

@@ -41,7 +41,7 @@
#include "race/history.hpp"
#include "race/race_manager.hpp"
#include "states_screens/kart_selection.hpp"
#include "states_screens/options_screen.hpp"
#include "states_screens/options_screen_input.hpp"
#include "states_screens/state_manager.hpp"
InputManager *input_manager;
@@ -223,7 +223,7 @@ void InputManager::inputSensing(Input::InputType type, int deviceID, int btnID,
if( abs(value) < Input::MAX_VALUE/2 && m_sensed_input->deviceID == deviceID &&
m_sensed_input->btnID == btnID)
{
OptionsScreen::gotSensedInput(m_sensed_input);
OptionsScreenInput::getInstance()->gotSensedInput(m_sensed_input);
}
}
@@ -287,8 +287,10 @@ void InputManager::input(Input::InputType type, int deviceID, int btnID, int axi
if ((player != NULL) && (action == PA_RESCUE))
{
// returns true if the event was handled
if (KartSelectionScreen::playerQuit( player ))
if (KartSelectionScreen::getInstance()->playerQuit( player ))
{
return; // we're done here
}
}
/* The way this is currently structured, any time an event is
@@ -312,7 +314,9 @@ void InputManager::input(Input::InputType type, int deviceID, int btnID, int axi
device = m_device_manager->getGamePadFromIrrID(deviceID);
if (device != NULL)
KartSelectionScreen::playerJoin( device, false );
{
KartSelectionScreen::getInstance()->playerJoin( device, false );
}
}
return; // we're done here, ignore devices that aren't associated with players
}

View File

@@ -49,7 +49,6 @@
#include "graphics/irr_driver.hpp"
#include "graphics/material_manager.hpp"
#include "guiengine/engine.hpp"
#include "states_screens/state_manager.hpp"
#include "io/file_manager.hpp"
#include "input/input_manager.hpp"
#include "input/device_manager.hpp"
@@ -64,6 +63,8 @@
#include "race/highscore_manager.hpp"
#include "race/history.hpp"
#include "race/race_manager.hpp"
#include "states_screens/main_menu_screen.hpp"
#include "states_screens/state_manager.hpp"
#include "tracks/track.hpp"
#include "tracks/track_manager.hpp"
#include "utils/translation.hpp"
@@ -625,7 +626,7 @@ int main(int argc, char *argv[] )
if(!UserConfigParams::m_no_start_screen)
{
StateManager::get()->pushMenu("main.stkgui");
StateManager::get()->pushScreen(MainMenuScreen::getInstance());
}
else
{

View File

@@ -17,6 +17,7 @@
#include "states_screens/credits.hpp"
#include "states_screens/state_manager.hpp"
#include <fstream>
@@ -67,12 +68,12 @@ namespace GUIEngine
}
};
CreditsSection* Credits::getCurrentSection()
CreditsSection* CreditsScreen::getCurrentSection()
{
return m_sections.get(m_sections.size()-1);
}
Credits::Credits()
CreditsScreen::CreditsScreen() : Screen("credits.stkgui")
{
reset();
@@ -81,14 +82,14 @@ namespace GUIEngine
std::ifstream file( creditsfile.c_str() ) ;
stringw line;
std::string getline;
while( std::getline( file, getline ) )
while (std::getline( file, getline ))
{
line = getline.c_str();
line = line.trim();
if(line.size() < 1) continue; // empty line
if(line[0] == '=' && line[line.size()-1] == '=')
if (line[0] == '=' && line[line.size()-1] == '=')
{
line = stringw( line.subString(1, line.size()-2).c_str() );
line = line.trim();
@@ -97,7 +98,7 @@ namespace GUIEngine
//std::cout << "Section : " << (char*)(cversion.c_str()) << std::endl;
m_sections.push_back( new CreditsSection(line) );
}
else if(line[0] == '-')
else if (line[0] == '-')
{
line = stringw( line.subString(1, line.size()-1).c_str() );
line = line.trim();
@@ -119,7 +120,7 @@ namespace GUIEngine
}
void Credits::setArea(const int x, const int y, const int w, const int h)
void CreditsScreen::setArea(const int x, const int y, const int w, const int h)
{
this->x = x;
this->y = y;
@@ -129,7 +130,7 @@ namespace GUIEngine
m_section_rect = core::rect< s32 >( x, y, x+w, y+h/6 );
}
void Credits::reset()
void CreditsScreen::reset()
{
m_curr_section = 0;
m_curr_element = -1;
@@ -137,7 +138,7 @@ namespace GUIEngine
m_time_element = 2.5f;
}
void Credits::render(const float elapsed_time)
void CreditsScreen::onUpdate(float elapsed_time, irr::video::IVideoDriver*)
{
time_before_next_step -= elapsed_time*0.8f; // multiply by 0.8 to slow it down a bit as a whole
@@ -251,11 +252,25 @@ namespace GUIEngine
*/
}
static Credits* singleton = NULL;
Credits* Credits::getInstance()
void CreditsScreen::init()
{
if(singleton == NULL) singleton = new Credits();
Widget* w = getWidget<Widget>("animated_area");
assert(w != NULL);
return singleton;
reset();
setArea(w->x, w->y, w->w, w->h);
}
void CreditsScreen::tearDown()
{
}
void CreditsScreen::eventCallback(GUIEngine::Widget* widget, const std::string& name)
{
if(name == "back")
{
StateManager::get()->escapePressed();
}
}
} // end namespace

View File

@@ -20,39 +20,44 @@
#define HEADER_CREDITS_HPP
#include "irrlicht.h"
using namespace irr;
#include "guiengine/screen.hpp"
#include "utils/ptr_vector.hpp"
namespace GUIEngine
{
class CreditsSection;
class Credits
{
float m_time_element;
ptr_vector<CreditsSection, HOLD> m_sections;
CreditsSection* getCurrentSection();
int x, y, w, h;
core::rect< s32 > m_section_rect;
int m_curr_section;
int m_curr_element;
float time_before_next_step;
public:
Credits();
static Credits* getInstance();
void setArea(const int x, const int y, const int w, const int h);
// start from beginning again
void reset();
void render(const float elapsed_time);
};
class CreditsScreen : public GUIEngine::Screen, public GUIEngine::ScreenSingleton<CreditsScreen>
{
float m_time_element;
ptr_vector<CreditsSection, HOLD> m_sections;
CreditsSection* getCurrentSection();
int x, y, w, h;
core::rect< s32 > m_section_rect;
int m_curr_section;
int m_curr_element;
float time_before_next_step;
friend class GUIEngine::ScreenSingleton<CreditsScreen>;
CreditsScreen();
public:
void setArea(const int x, const int y, const int w, const int h);
// start from beginning again
void reset();
void onUpdate(float dt, irr::video::IVideoDriver*);
void init();
void tearDown();
void eventCallback(GUIEngine::Widget* widget, const std::string& name);
};
}
#endif

View File

@@ -18,7 +18,7 @@
#include "guiengine/engine.hpp"
#include "guiengine/widget.hpp"
#include "states_screens/dialogs/enter_player_name_dialog.hpp"
#include "states_screens/options_screen.hpp"
#include "states_screens/options_screen_players.hpp"
#include "utils/translation.hpp"
using namespace GUIEngine;
@@ -99,8 +99,10 @@ void EnterPlayerNameDialog::onEnterPressedInternal()
// ---- Otherwise, accept entered name
stringw playerName = textCtrl->getText();
if(playerName.size() > 0)
OptionsScreen::gotNewPlayerName( playerName );
if (playerName.size() > 0)
{
OptionsScreenPlayers::getInstance()->gotNewPlayerName( playerName );
}
// irrLicht is too stupid to remove focus from deleted widgets
// so do it by hand

View File

@@ -19,7 +19,7 @@
#include "config/player.hpp"
#include "guiengine/engine.hpp"
#include "guiengine/widget.hpp"
#include "states_screens/options_screen.hpp"
#include "states_screens/options_screen_players.hpp"
#include "states_screens/dialogs/player_info_dialog.hpp"
#include "utils/string_utils.hpp"
#include "utils/translation.hpp"
@@ -183,13 +183,13 @@ void PlayerInfoDialog::onEnterPressedInternal()
// ------------------------------------------------------------------------------------------------------
bool PlayerInfoDialog::processEvent(std::string& eventSource)
{
if(eventSource == "renameplayer")
if (eventSource == "renameplayer")
{
// accept entered name
stringw playerName = textCtrl->getText();
if(playerName.size() > 0)
if (playerName.size() > 0)
{
OptionsScreen::gotNewPlayerName( playerName, m_player );
OptionsScreenPlayers::getInstance()->gotNewPlayerName( playerName, m_player );
}
// irrLicht is too stupid to remove focus from deleted widgets
@@ -202,14 +202,14 @@ bool PlayerInfoDialog::processEvent(std::string& eventSource)
dismiss();
return true;
}
else if(eventSource == "removeplayer")
else if (eventSource == "removeplayer")
{
showConfirmDialog();
return true;
}
else if(eventSource == "confirmremove")
else if (eventSource == "confirmremove")
{
OptionsScreen::deletePlayer( m_player );
OptionsScreenPlayers::getInstance()->deletePlayer( m_player );
// irrLicht is too stupid to remove focus from deleted widgets
// so do it by hand

View File

@@ -25,6 +25,8 @@
#include "network/network_manager.hpp"
#include "race/race_manager.hpp"
#include "states_screens/dialogs/race_over_dialog.hpp"
#include "states_screens/kart_selection.hpp"
#include "states_screens/main_menu_screen.hpp"
#include "states_screens/state_manager.hpp"
#include "utils/string_utils.hpp"
#include "utils/translation.hpp"
@@ -251,8 +253,8 @@ bool RaceOverDialog::processEvent(std::string& eventSource)
ModalDialog::dismiss();
RaceManager::getWorld()->unpause();
race_manager->exitRace();
StateManager::get()->resetAndGoToMenu("main.stkgui");
StateManager::get()->pushMenu("karts.stkgui");
StateManager::get()->resetAndGoToScreen(MainMenuScreen::getInstance());
StateManager::get()->pushScreen(KartSelectionScreen::getInstance());
return true;
}
else if (eventSource == "backtomenu")
@@ -260,7 +262,7 @@ bool RaceOverDialog::processEvent(std::string& eventSource)
ModalDialog::dismiss();
RaceManager::getWorld()->unpause();
race_manager->exitRace();
StateManager::get()->resetAndGoToMenu("main.stkgui");
StateManager::get()->resetAndGoToScreen(MainMenuScreen::getInstance());
input_manager->setMode(InputManager::MENU);
return true;
}

View File

@@ -24,6 +24,9 @@
#include "modes/world.hpp"
#include "network/network_manager.hpp"
#include "race/race_manager.hpp"
#include "states_screens/help_screen_1.hpp"
#include "states_screens/options_screen_av.hpp"
#include "states_screens/main_menu_screen.hpp"
#include "states_screens/state_manager.hpp"
#include "utils/translation.hpp"
@@ -228,20 +231,20 @@ bool RacePausedDialog::processEvent(std::string& eventSource)
{
ModalDialog::dismiss();
race_manager->exitRace();
StateManager::get()->resetAndGoToMenu("main.stkgui");
StateManager::get()->resetAndGoToScreen(MainMenuScreen::getInstance());
input_manager->setMode(InputManager::MENU);
return true;
}
else if (selection == "help")
{
dismiss();
StateManager::get()->pushMenu("help1.stkgui");
StateManager::get()->pushScreen(HelpScreen1::getInstance());
return true;
}
else if (selection == "options")
{
dismiss();
StateManager::get()->pushMenu("options_av.stkgui");
StateManager::get()->pushScreen(OptionsScreenAV::getInstance());
return true;
}
else if (selection == "restart")

View File

@@ -11,6 +11,7 @@
#include <SColor.h>
static const char* CUTSCENE_NAME = "feature_unlocked";
/*
static FeatureUnlockedCutScene* singleton = NULL;
void FeatureUnlockedCutScene::show()
@@ -25,13 +26,13 @@ void FeatureUnlockedCutScene::show()
StateManager::get()->pushCutScene(CUTSCENE_NAME);
}
*/
FeatureUnlockedCutScene::FeatureUnlockedCutScene() : CutScene(CUTSCENE_NAME)
{
}
void FeatureUnlockedCutScene::prepare()
void FeatureUnlockedCutScene::init()
{
m_angle = 0.0f;
@@ -97,9 +98,9 @@ void FeatureUnlockedCutScene::prepare()
} // for i<getMaterialCount
*/
}
void FeatureUnlockedCutScene::terminate()
void FeatureUnlockedCutScene::tearDown()
{
printf("+++++++ FeatureUnlockedCutScene:Terminate +++++++++\n");
printf("+++++++ FeatureUnlockedCutScene:tearDown +++++++++\n");
irr_driver->removeNode(m_sky);
m_sky = NULL;
@@ -158,3 +159,6 @@ void FeatureUnlockedCutScene::onUpdate(float dt, irr::video::IVideoDriver* drive
true/* center h */, true /* center v */ );
}
void FeatureUnlockedCutScene::eventCallback(GUIEngine::Widget* widget, const std::string& name)
{
}

View File

@@ -2,13 +2,15 @@
#define HEADER_FEATURE_UNLOCKED_HPP
#include "guiengine/cutscene.hpp"
#include "guiengine/screen.hpp"
namespace irr { namespace scene { class ISceneNode; class ICameraSceneNode; class ILightSceneNode; } }
class FeatureUnlockedCutScene : public GUIEngine::CutScene
class FeatureUnlockedCutScene : public GUIEngine::CutScene, public GUIEngine::ScreenSingleton<FeatureUnlockedCutScene>
{
friend class GUIEngine::ScreenSingleton<FeatureUnlockedCutScene>;
FeatureUnlockedCutScene();
void prepare();
/** sky angle, 0-360 */
float m_angle;
@@ -26,10 +28,13 @@ class FeatureUnlockedCutScene : public GUIEngine::CutScene
irr::scene::ISceneNode* m_key;
irr::scene::ILightSceneNode* m_light;
public:
static void show();
void onUpdate(float dt, irr::video::IVideoDriver*);
void terminate();
void init();
void tearDown();
void eventCallback(GUIEngine::Widget* widget, const std::string& name);
};
#endif

View File

@@ -0,0 +1,56 @@
// 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/help_screen_1.hpp"
#include "states_screens/help_screen_2.hpp"
#include "states_screens/help_screen_3.hpp"
#include "guiengine/widget.hpp"
#include "states_screens/state_manager.hpp"
using namespace GUIEngine;
HelpScreen1::HelpScreen1() : Screen("help1.stkgui")
{
}
void HelpScreen1::eventCallback(Widget* widget, const std::string& name)
{
if (name == "category")
{
std::string selection = ((RibbonWidget*)widget)->getSelectionIDString(GUI_PLAYER_ID).c_str();
//if (selection == "page1") StateManager::get()->replaceTopMostScreen(Help1Screen::getInstance());
//else
if (selection == "page2") StateManager::get()->replaceTopMostScreen(HelpScreen2::getInstance());
else if (selection == "page3") StateManager::get()->replaceTopMostScreen(HelpScreen3::getInstance());
}
else if (name == "back")
{
StateManager::get()->escapePressed();
}
}
void HelpScreen1::init()
{
RibbonWidget* w = this->getWidget<RibbonWidget>("category");
if (w != NULL) w->select( "page1", GUI_PLAYER_ID );
}
void HelpScreen1::tearDown()
{
}

View File

@@ -0,0 +1,37 @@
// 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.
#ifndef HEADER_HELP_SCREEN_1_HPP
#define HEADER_HELP_SCREEN_1_HPP
#include "guiengine/screen.hpp"
namespace GUIEngine { class Widget; }
class HelpScreen1 : public GUIEngine::Screen, public GUIEngine::ScreenSingleton<HelpScreen1>
{
friend class GUIEngine::ScreenSingleton<HelpScreen1>;
HelpScreen1();
public:
void eventCallback(GUIEngine::Widget* widget, const std::string& name);
void init();
void tearDown();
};
#endif

View File

@@ -0,0 +1,56 @@
// 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/help_screen_1.hpp"
#include "states_screens/help_screen_2.hpp"
#include "states_screens/help_screen_3.hpp"
#include "guiengine/widget.hpp"
#include "states_screens/state_manager.hpp"
using namespace GUIEngine;
HelpScreen2::HelpScreen2() : Screen("help2.stkgui")
{
}
void HelpScreen2::eventCallback(Widget* widget, const std::string& name)
{
if (name == "category")
{
std::string selection = ((RibbonWidget*)widget)->getSelectionIDString(GUI_PLAYER_ID).c_str();
if(selection == "page1") StateManager::get()->replaceTopMostScreen(HelpScreen1::getInstance());
//else if(selection == "page2") StateManager::get()->replaceTopMostScreen(HelpScreen2::getInstance());
else if(selection == "page3") StateManager::get()->replaceTopMostScreen(HelpScreen3::getInstance());
}
else if (name == "back")
{
StateManager::get()->escapePressed();
}
}
void HelpScreen2::init()
{
RibbonWidget* w = this->getWidget<RibbonWidget>("category");
if (w != NULL) w->select( "page2", GUI_PLAYER_ID );
}
void HelpScreen2::tearDown()
{
}

View File

@@ -0,0 +1,37 @@
// 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.
#ifndef HEADER_HELP_SCREEN_2_HPP
#define HEADER_HELP_SCREEN_2_HPP
#include "guiengine/screen.hpp"
namespace GUIEngine { class Widget; }
class HelpScreen2 : public GUIEngine::Screen, public GUIEngine::ScreenSingleton<HelpScreen2>
{
friend class GUIEngine::ScreenSingleton<HelpScreen2>;
HelpScreen2();
public:
void eventCallback(GUIEngine::Widget* widget, const std::string& name);
void init();
void tearDown();
};
#endif

View File

@@ -0,0 +1,56 @@
// 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/help_screen_1.hpp"
#include "states_screens/help_screen_2.hpp"
#include "states_screens/help_screen_3.hpp"
#include "guiengine/widget.hpp"
#include "states_screens/state_manager.hpp"
using namespace GUIEngine;
HelpScreen3::HelpScreen3() : Screen("help3.stkgui")
{
}
void HelpScreen3::eventCallback(Widget* widget, const std::string& name)
{
if (name == "category")
{
std::string selection = ((RibbonWidget*)widget)->getSelectionIDString(GUI_PLAYER_ID).c_str();
if (selection == "page1") StateManager::get()->replaceTopMostScreen(HelpScreen1::getInstance());
else if (selection == "page2") StateManager::get()->replaceTopMostScreen(HelpScreen2::getInstance());
//else if(selection == "page3") StateManager::get()->replaceTopMostScreen(Help3Screen::getInstance());
}
else if (name == "back")
{
StateManager::get()->escapePressed();
}
}
void HelpScreen3::init()
{
RibbonWidget* w = this->getWidget<RibbonWidget>("category");
if (w != NULL) w->select( "page3", GUI_PLAYER_ID );
}
void HelpScreen3::tearDown()
{
}

View File

@@ -0,0 +1,38 @@
// 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.
#ifndef HEADER_HELP_SCREEN_3_HPP
#define HEADER_HELP_SCREEN_3_HPP
#include "guiengine/screen.hpp"
namespace GUIEngine { class Widget; }
class HelpScreen3 : public GUIEngine::Screen, public GUIEngine::ScreenSingleton<HelpScreen3>
{
friend class GUIEngine::ScreenSingleton<HelpScreen3>;
HelpScreen3();
public:
void eventCallback(GUIEngine::Widget* widget, const std::string& name);
void init();
void tearDown();
};
#endif

View File

@@ -24,7 +24,6 @@
#include "guiengine/widget.hpp"
#include "guiengine/engine.hpp"
#include "guiengine/screen.hpp"
#include "states_screens/state_manager.hpp"
#include "input/input.hpp"
#include "input/input_manager.hpp"
#include "input/device_manager.hpp"
@@ -33,6 +32,8 @@
#include "io/file_manager.hpp"
#include "karts/kart.hpp"
#include "karts/kart_properties_manager.hpp"
#include "states_screens/race_setup_screen.hpp"
#include "states_screens/state_manager.hpp"
#include "utils/translation.hpp"
#include "utils/random_generator.hpp"
#include "utils/string_utils.hpp"
@@ -43,8 +44,6 @@ InputDevice* player_1_device = NULL;
using namespace GUIEngine;
namespace KartSelectionScreen
{
class PlayerKartWidget;
// ref only since we're adding them to a Screen, and the Screen will take ownership of these widgets
@@ -479,15 +478,19 @@ KartHoverListener* karthoverListener = NULL;
#if 0
#pragma mark -
#pragma mark Functions
#pragma mark KartSelectionScreen
#endif
KartSelectionScreen::KartSelectionScreen() : Screen("karts.stkgui")
{
}
// Return true if event was handled successfully
bool playerJoin(InputDevice* device, bool firstPlayer)
bool KartSelectionScreen::playerJoin(InputDevice* device, bool firstPlayer)
{
std::cout << "playerJoin() ==========\n";
DynamicRibbonWidget* w = getCurrentScreen()->getWidget<DynamicRibbonWidget>("karts");
DynamicRibbonWidget* w = this->getWidget<DynamicRibbonWidget>("karts");
if (w == NULL)
{
std::cerr << "playerJoin(): Called outside of kart selection screen.\n";
@@ -501,7 +504,7 @@ bool playerJoin(InputDevice* device, bool firstPlayer)
// ---- Get available area for karts
// make a copy of the area, ands move it to be outside the screen
Widget rightarea = *getCurrentScreen()->getWidget("playerskarts");
Widget rightarea = *this->getWidget("playerskarts");
rightarea.x = irr_driver->getFrameSize().Width; // start at the rightmost of the screen
// ---- Create new active player
@@ -519,14 +522,14 @@ bool playerJoin(InputDevice* device, bool firstPlayer)
// the others as needed. But if player 0 leaves, it will be impossible for remaining players
// to select their ident
getCurrentScreen()->manualAddWidget(newPlayer);
this->manualAddWidget(newPlayer);
newPlayer->add();
g_player_karts.push_back(newPlayer);
// ---- Divide screen space among all karts
const int amount = g_player_karts.size();
Widget* fullarea = getCurrentScreen()->getWidget("playerskarts");
Widget* fullarea = this->getWidget("playerskarts");
const int splitWidth = fullarea->w / amount;
for (int n=0; n<amount; n++)
@@ -545,11 +548,11 @@ PlayerKartWidget* removedWidget = NULL;
// -----------------------------------------------------------------------------
// Return true if event was handled succesfully
bool playerQuit(ActivePlayer* player)
bool KartSelectionScreen::playerQuit(ActivePlayer* player)
{
int playerID = -1;
DynamicRibbonWidget* w = getCurrentScreen()->getWidget<DynamicRibbonWidget>("karts");
DynamicRibbonWidget* w = this->getWidget<DynamicRibbonWidget>("karts");
if (w == NULL )
{
std::cout << "playerQuit() called outside of kart selection screen.\n";
@@ -590,14 +593,14 @@ bool playerQuit(ActivePlayer* player)
removedWidget = g_player_karts.remove(playerID);
StateManager::get()->removeActivePlayer(playerID);
renumberKarts();
Widget* fullarea = getCurrentScreen()->getWidget("playerskarts");
Widget* fullarea = this->getWidget("playerskarts");
removedWidget->move( removedWidget->x + removedWidget->w/2, fullarea->y + fullarea->h, 0, 0);
return true;
}
// -----------------------------------------------------------------------------
void kartSelectionUpdate(float delta)
void KartSelectionScreen::onUpdate(float delta, irr::video::IVideoDriver*)
{
const int amount = g_player_karts.size();
for (int n=0; n<amount; n++)
@@ -612,119 +615,122 @@ void kartSelectionUpdate(float delta)
if (removedWidget->w == 0 || removedWidget->h == 0)
{
// destruct when too small (for "disappear" effects)
GUIEngine::getCurrentScreen()->manualRemoveWidget(removedWidget);
this->manualRemoveWidget(removedWidget);
delete removedWidget;
removedWidget = NULL;
}
}
}
// -----------------------------------------------------------------------------
void KartSelectionScreen::tearDown()
{
//g_player_karts.clearWithoutDeleting();
g_player_karts.clearAndDeleteAll();
}
// -----------------------------------------------------------------------------
void KartSelectionScreen::init()
{
// FIXME: Reload previous kart selection screen state
g_player_karts.clearAndDeleteAll();
StateManager::get()->resetActivePlayers();
input_manager->getDeviceList()->setAssignMode(DETECT_NEW);
DynamicRibbonWidget* w = this->getWidget<DynamicRibbonWidget>("karts");
assert( w != NULL );
if (karthoverListener == NULL)
{
karthoverListener = new KartHoverListener();
w->registerHoverListener(karthoverListener);
}
//Widget* area = this->getWidget("playerskarts");
if (!this->m_inited)
{
// Build kart list
std::vector<int> group = kart_properties_manager->getKartsInGroup("standard");
const int kart_amount = group.size();
// add Tux (or whatever default kart) first
std::string& default_kart = UserConfigParams::m_default_kart;
for(int n=0; n<kart_amount; n++)
{
const KartProperties* prop = kart_properties_manager->getKartById(group[n]);
if (prop->getIdent() == default_kart)
{
std::string icon_path = file_manager->getDataDir() ;
icon_path += "/karts/" + prop->getIdent() + "/" + prop->getIconFile();
w->addItem(prop->getName(), prop->getIdent().c_str(), icon_path.c_str());
break;
}
}
// add others
for(int n=0; n<kart_amount; n++)
{
const KartProperties* prop = kart_properties_manager->getKartById(group[n]);
if (prop->getIdent() != default_kart)
{
std::string icon_path = file_manager->getDataDir() ;
icon_path += "/karts/" + prop->getIdent() + "/" + prop->getIconFile();
w->addItem(prop->getName(), prop->getIdent().c_str(), icon_path.c_str());
}
}
this->m_inited = true;
}
/*
TODO: Ultimately, it'd be nice to *not* delete g_player_karts so that
when players return to the kart selection screen, it will appear as
it did when they left (at least when returning from the track menu).
Rebuilding the screen is a little tricky.
*/
if (g_player_karts.size() > 0)
{
// FIXME: trying to rebuild the screen
for (int n = 0; n < g_player_karts.size(); n++)
{
PlayerKartWidget *pkw;
pkw = g_player_karts.get(n);
this->manualAddWidget(pkw);
pkw->add();
}
}
else // For now this is what will happen
{
playerJoin( input_manager->getDeviceList()->getLatestUsedDevice(), true );
w->updateItemDisplay();
}
// Player 0 select first kart (Tux)
w->setSelection(0, 0);
w->m_rows[0].requestFocus();
this->m_inited = true;
}
// -----------------------------------------------------------------------------
/**
* Callback handling events from the kart selection menu
*/
void menuEventKarts(Widget* widget, const std::string& name)
void KartSelectionScreen::eventCallback(Widget* widget, const std::string& name)
{
if(name == "tearDown")
if (name == "kartgroups")
{
//g_player_karts.clearWithoutDeleting();
g_player_karts.clearAndDeleteAll();
}
else if(name == "init")
{
// FIXME: Reload previous kart selection screen state
g_player_karts.clearAndDeleteAll();
StateManager::get()->resetActivePlayers();
input_manager->getDeviceList()->setAssignMode(DETECT_NEW);
DynamicRibbonWidget* w = getCurrentScreen()->getWidget<DynamicRibbonWidget>("karts");
assert( w != NULL );
if (karthoverListener == NULL)
{
karthoverListener = new KartHoverListener();
w->registerHoverListener(karthoverListener);
}
//Widget* area = getCurrentScreen()->getWidget("playerskarts");
if (!getCurrentScreen()->m_inited)
{
// Build kart list
std::vector<int> group = kart_properties_manager->getKartsInGroup("standard");
const int kart_amount = group.size();
// add Tux (or whatever default kart) first
std::string& default_kart = UserConfigParams::m_default_kart;
for(int n=0; n<kart_amount; n++)
{
const KartProperties* prop = kart_properties_manager->getKartById(group[n]);
if (prop->getIdent() == default_kart)
{
std::string icon_path = file_manager->getDataDir() ;
icon_path += "/karts/" + prop->getIdent() + "/" + prop->getIconFile();
w->addItem(prop->getName(), prop->getIdent().c_str(), icon_path.c_str());
break;
}
}
// add others
for(int n=0; n<kart_amount; n++)
{
const KartProperties* prop = kart_properties_manager->getKartById(group[n]);
if (prop->getIdent() != default_kart)
{
std::string icon_path = file_manager->getDataDir() ;
icon_path += "/karts/" + prop->getIdent() + "/" + prop->getIconFile();
w->addItem(prop->getName(), prop->getIdent().c_str(), icon_path.c_str());
}
}
getCurrentScreen()->m_inited = true;
}
/*
TODO: Ultimately, it'd be nice to *not* delete g_player_karts so that
when players return to the kart selection screen, it will appear as
it did when they left (at least when returning from the track menu).
Rebuilding the screen is a little tricky.
*/
if (g_player_karts.size() > 0)
{
// FIXME: trying to rebuild the screen
for (int n = 0; n < g_player_karts.size(); n++)
{
PlayerKartWidget *pkw;
pkw = g_player_karts.get(n);
getCurrentScreen()->manualAddWidget(pkw);
pkw->add();
}
}
else // For now this is what will happen
{
playerJoin( input_manager->getDeviceList()->getLatestUsedDevice(), true );
w->updateItemDisplay();
}
// Player 0 select first kart (Tux)
w->setSelection(0, 0);
w->m_rows[0].requestFocus();
getCurrentScreen()->m_inited = true;
} // end if init
else if (name == "kartgroups")
{
RibbonWidget* tabs = getCurrentScreen()->getWidget<RibbonWidget>("kartgroups");
RibbonWidget* tabs = this->getWidget<RibbonWidget>("kartgroups");
assert(tabs != NULL);
std::string selection = tabs->getSelectionIDString(GUI_PLAYER_ID);
DynamicRibbonWidget* w = getCurrentScreen()->getWidget<DynamicRibbonWidget>("karts");
DynamicRibbonWidget* w = this->getWidget<DynamicRibbonWidget>("karts");
w->clearItems();
// TODO : preserve selection of karts for all players
@@ -762,7 +768,7 @@ void menuEventKarts(Widget* widget, const std::string& name)
}
else if (name == "karts")
{
DynamicRibbonWidget* w = getCurrentScreen()->getWidget<DynamicRibbonWidget>("karts");
DynamicRibbonWidget* w = this->getWidget<DynamicRibbonWidget>("karts");
assert( w != NULL );
ptr_vector< ActivePlayer, HOLD >& players = StateManager::get()->getActivePlayers();
@@ -800,17 +806,17 @@ void menuEventKarts(Widget* widget, const std::string& name)
//Return to assign mode
input_manager->getDeviceList()->setAssignMode(ASSIGN);
StateManager::get()->pushMenu("racesetup.stkgui");
StateManager::get()->pushScreen( RaceSetupScreen::getInstance() );
}
}
// -----------------------------------------------------------------------------
void renumberKarts()
void KartSelectionScreen::renumberKarts()
{
DynamicRibbonWidget* w = getCurrentScreen()->getWidget<DynamicRibbonWidget>("karts");
DynamicRibbonWidget* w = this->getWidget<DynamicRibbonWidget>("karts");
assert( w != NULL );
Widget* fullarea = getCurrentScreen()->getWidget("playerskarts");
Widget* fullarea = this->getWidget("playerskarts");
const int splitWidth = fullarea->w / g_player_karts.size();
printf("Renumbering karts...");
@@ -862,5 +868,3 @@ GUIEngine::EventPropagation PlayerNameSpinner::focused(const int playerID)
return GUIEngine::EVENT_LET;
} // focused
}

View File

@@ -18,6 +18,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <string>
#include "guiengine/screen.hpp"
namespace GUIEngine
{
@@ -26,11 +27,19 @@ namespace GUIEngine
class InputDevice;
class ActivePlayer;
namespace KartSelectionScreen
class KartSelectionScreen : public GUIEngine::Screen, public GUIEngine::ScreenSingleton<KartSelectionScreen>
{
friend class GUIEngine::ScreenSingleton<KartSelectionScreen>;
KartSelectionScreen();
public:
bool playerJoin(InputDevice* device, bool firstPlayer);
bool playerQuit(ActivePlayer* player);
void kartSelectionUpdate(float delta);
void renumberKarts();
void menuEventKarts(GUIEngine::Widget* widget, const std::string& name);
}
void init();
void tearDown();
void eventCallback(GUIEngine::Widget* widget, const std::string& name);
void onUpdate(float dt, irr::video::IVideoDriver*);
};

View File

@@ -0,0 +1,81 @@
// 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/main_menu_screen.hpp"
#include "guiengine/widget.hpp"
#include "main_loop.hpp"
#include "states_screens/credits.hpp"
#include "states_screens/feature_unlocked.hpp"
#include "states_screens/kart_selection.hpp"
#include "states_screens/help_screen_1.hpp"
#include "states_screens/options_screen_av.hpp"
#include "states_screens/state_manager.hpp"
using namespace GUIEngine;
MainMenuScreen::MainMenuScreen() : Screen("main.stkgui")
{
}
void MainMenuScreen::init()
{
}
void MainMenuScreen::tearDown()
{
}
void MainMenuScreen::eventCallback(Widget* widget, const std::string& name)
{
RibbonWidget* ribbon = dynamic_cast<RibbonWidget*>(widget);
if (ribbon == NULL) return; // only interesting stuff in main menu is the ribbons
std::string selection = ribbon->getSelectionIDString(GUI_PLAYER_ID);
if (selection == "network")
{
printf("+++++ FeatureUnlockedCutScene::show() +++++\n");
// FIXME : remove, temporary test
StateManager::get()->pushScreen(FeatureUnlockedCutScene::getInstance());
}
if (selection == "new")
{
StateManager::get()->pushScreen( KartSelectionScreen::getInstance() );
}
else if (selection == "options")
{
StateManager::get()->pushScreen( OptionsScreenAV::getInstance() );
}
else if (selection == "quit")
{
main_loop->abort();
return;
}
else if (selection == "about")
{
StateManager::get()->pushScreen(CreditsScreen::getInstance());
}
else if (selection == "help")
{
StateManager::get()->pushScreen(HelpScreen1::getInstance());
}
}

View File

@@ -0,0 +1,38 @@
// 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.
#ifndef HEADER_MAIN_MENU_SCREEN_HPP
#define HEADER_MAIN_MENU_SCREEN_HPP
#include "guiengine/screen.hpp"
namespace GUIEngine { class Widget; }
/**
* Callback handling events from the main menu
*/
class MainMenuScreen : public GUIEngine::Screen, public GUIEngine::ScreenSingleton<MainMenuScreen>
{
friend class GUIEngine::ScreenSingleton<MainMenuScreen>;
MainMenuScreen();
public:
void eventCallback(GUIEngine::Widget* widget, const std::string& name);
void init();
void tearDown();
};
#endif

View File

@@ -1,645 +0,0 @@
// 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 "audio/sound_manager.hpp"
#include "audio/sfx_manager.hpp"
#include "audio/sfx_base.hpp"
#include "config/player.hpp"
#include "config/device_config.hpp"
#include "graphics/irr_driver.hpp"
#include "guiengine/engine.hpp"
#include "guiengine/screen.hpp"
#include "guiengine/widget.hpp"
#include "input/input_manager.hpp"
#include "input/device_manager.hpp"
#include "io/file_manager.hpp"
#include "states_screens/dialogs/enter_player_name_dialog.hpp"
#include "states_screens/dialogs/player_info_dialog.hpp"
#include "states_screens/dialogs/press_a_key_dialog.hpp"
#include "states_screens/options_screen.hpp"
#include "states_screens/state_manager.hpp"
#include <iostream>
#include <sstream>
using namespace GUIEngine;
/**
* Callback handling events from the options menus
*/
namespace OptionsScreen
{
void eventInput(Widget* widget, const std::string& name);
// -----------------------------------------------------------------------------
void initAudioVideo(Widget* widget, const std::string& name)
{
// ---- sfx volume
SpinnerWidget* gauge = getCurrentScreen()->getWidget<SpinnerWidget>("sfx_volume");
assert(gauge != NULL);
gauge->setValue( (int)(sfx_manager->getMasterSFXVolume()*10.0f) );
gauge = getCurrentScreen()->getWidget<SpinnerWidget>("music_volume");
assert(gauge != NULL);
gauge->setValue( (int)(sound_manager->getMasterMusicVolume()*10.f) );
// ---- music volume
CheckBoxWidget* sfx = getCurrentScreen()->getWidget<CheckBoxWidget>("sfx_enabled");
CheckBoxWidget* music = getCurrentScreen()->getWidget<CheckBoxWidget>("music_enabled");
// ---- audio enables/disables
sfx->setState( UserConfigParams::m_sfx );
music->setState( UserConfigParams::m_music );
// ---- video modes
{
DynamicRibbonWidget* res = getCurrentScreen()->getWidget<DynamicRibbonWidget>("resolutions");
assert( res != NULL );
CheckBoxWidget* full = getCurrentScreen()->getWidget<CheckBoxWidget>("fullscreen");
assert( full != NULL );
full->setState( UserConfigParams::m_fullscreen );
// --- get resolution list from irrlicht the first time
if(!getCurrentScreen()->m_inited)
{
const std::vector<VideoMode>& modes = irr_driver->getVideoModes();
const int amount = modes.size();
for(int n=0; n<amount; n++)
{
const int w = modes[n].width;
const int h = modes[n].height;
const float ratio = (float)w / h;
char name[32];
sprintf( name, "%ix%i", w, h );
#define ABOUT_EQUAL(a , b) (fabsf( a - b ) < 0.01)
if( ABOUT_EQUAL( ratio, (5.0f/4.0f) ) )
res->addItem(name, name, file_manager->getDataDir() + "/gui/screen54.png");
else if( ABOUT_EQUAL( ratio, (4.0f/3.0f) ) )
res->addItem(name, name, file_manager->getDataDir() + "/gui/screen43.png");
else if( ABOUT_EQUAL( ratio, (16.0f/10.0f) ) )
res->addItem(name, name, file_manager->getDataDir() + "/gui/screen1610.png");
else if( ABOUT_EQUAL( ratio, (5.0f/3.0f) ) )
res->addItem(name, name, file_manager->getDataDir() + "/gui/screen53.png");
else if( ABOUT_EQUAL( ratio, (3.0f/2.0f) ) )
res->addItem(name, name, file_manager->getDataDir() + "/gui/screen32.png");
else
{
std::cout << "Unknown screen size ratio : " << ratio << std::endl;
// FIXME - do something better than showing a random icon
res->addItem(name,name, file_manager->getDataDir() + "/gui/screen1610.png");
}
#undef ABOUT_EQUAL
} // next resolution
} // end if not inited
res->updateItemDisplay();
// ---- select curernt resolution every time
const std::vector<VideoMode>& modes = irr_driver->getVideoModes();
const int amount = modes.size();
for(int n=0; n<amount; n++)
{
const int w = modes[n].width;
const int h = modes[n].height;
char name[32];
sprintf( name, "%ix%i", w, h );
if(w == UserConfigParams::m_width && h == UserConfigParams::m_height)
{
//std::cout << "************* Detected right resolution!!! " << n << "\n";
// that's the current one
res->setSelection(n);
break;
}
} // end for
}
}
// -----------------------------------------------------------------------------
void eventAudioVideo(Widget* widget, const std::string& name)
{
if(name == "music_volume")
{
SpinnerWidget* w = dynamic_cast<SpinnerWidget*>(widget);
assert(w != NULL);
sound_manager->setMasterMusicVolume( w->getValue()/10.0f );
}
else if(name == "sfx_volume")
{
static SFXBase* sample_sound = NULL;
SpinnerWidget* w = dynamic_cast<SpinnerWidget*>(widget);
assert(w != NULL);
if(sample_sound == NULL)
sample_sound = sfx_manager->newSFX( SFXManager::SOUND_SKID );
sample_sound->volume(1);
sfx_manager->setMasterSFXVolume( w->getValue()/10.0f );
UserConfigParams::m_sfx_volume = w->getValue()/10.0f;
// play a sample sound to show the user what this volume is like
sample_sound->position ( Vec3(0,0,0) );
if(sample_sound->getStatus() != SFXManager::SFX_PLAYING)
{
sample_sound->play();
}
}
else if(name == "music_enabled")
{
CheckBoxWidget* w = dynamic_cast<CheckBoxWidget*>(widget);
UserConfigParams::m_music = w->getState();
std::cout << "music state is now " << (bool)UserConfigParams::m_music << std::endl;
if(w->getState() == false)
sound_manager->stopMusic();
else
sound_manager->startMusic(sound_manager->getCurrentMusic());
}
else if(name == "sfx_enabled")
{
CheckBoxWidget* w = dynamic_cast<CheckBoxWidget*>(widget);
UserConfigParams::m_sfx = w->getState();
}
else if(name == "apply_resolution")
{
using namespace GUIEngine;
UserConfigParams::m_prev_width = UserConfigParams::m_width;
UserConfigParams::m_prev_height = UserConfigParams::m_height;
DynamicRibbonWidget* w1 = getCurrentScreen()->getWidget<DynamicRibbonWidget>("resolutions");
assert(w1 != NULL);
const std::string& res = w1->getSelectionIDString(GUI_PLAYER_ID);
int w = -1, h = -1;
if( sscanf(res.c_str(), "%ix%i", &w, &h) != 2 || w == -1 || h == -1 )
{
std::cerr << "Failed to decode resolution : " << res.c_str() << std::endl;
return;
}
CheckBoxWidget* w2 = getCurrentScreen()->getWidget<CheckBoxWidget>("fullscreen");
assert(w2 != NULL);
UserConfigParams::m_width = w;
UserConfigParams::m_height = h;
UserConfigParams::m_fullscreen = w2->getState();
irr_driver->changeResolution();
}
}
// -----------------------------------------------------------------------------
void updateInputButtons(DeviceConfig* config)
{
// Should never happen
if (config == NULL)
{
printf("ERROR: No configuration associated with device?\n");
abort();
}
{
ButtonWidget* btn = getCurrentScreen()->getWidget<ButtonWidget>("binding_up");
btn->setLabel( config->getBindingAsString(PA_ACCEL) );
}
{
ButtonWidget* btn = getCurrentScreen()->getWidget<ButtonWidget>("binding_down");
btn->setLabel( config->getBindingAsString(PA_BRAKE) );
}
{
ButtonWidget* btn = getCurrentScreen()->getWidget<ButtonWidget>("binding_left");
btn->setLabel( config->getBindingAsString(PA_LEFT) );
}
{
ButtonWidget* btn = getCurrentScreen()->getWidget<ButtonWidget>("binding_right");
btn->setLabel( config->getBindingAsString(PA_RIGHT) );
}
{
ButtonWidget* btn = getCurrentScreen()->getWidget<ButtonWidget>("binding_fire");
btn->setLabel( config->getBindingAsString(PA_FIRE) );
}
{
ButtonWidget* btn = getCurrentScreen()->getWidget<ButtonWidget>("binding_nitro");
btn->setLabel( config->getBindingAsString(PA_NITRO) );
}
{
ButtonWidget* btn = getCurrentScreen()->getWidget<ButtonWidget>("binding_drift");
btn->setLabel( config->getBindingAsString(PA_DRIFT) );
}
{
ButtonWidget* btn = getCurrentScreen()->getWidget<ButtonWidget>("binding_rescue");
btn->setLabel( config->getBindingAsString(PA_RESCUE) );
}
{
ButtonWidget* btn = getCurrentScreen()->getWidget<ButtonWidget>("binding_look_back");
btn->setLabel( config->getBindingAsString(PA_LOOK_BACK) );
}
}
// -----------------------------------------------------------------------------
void initInput(Widget* widget, const std::string& name)
{
DynamicRibbonWidget* devices = getCurrentScreen()->getWidget<DynamicRibbonWidget>("devices");
assert( devices != NULL );
if(!getCurrentScreen()->m_inited)
{
devices->addItem("Keyboard","keyboard", file_manager->getDataDir() + "/gui/keyboard.png");
const int gpad_config_count = input_manager->getDeviceList()->getGamePadConfigAmount();
for(int i = 0; i < gpad_config_count; i++)
{
GamepadConfig *config = input_manager->getDeviceList()->getGamepadConfig(i);
// Don't display the configuration if a matching device is not available
if (config->isInUse())
{
const irr::core::stringw name = config->getName().c_str();
std::ostringstream gpname;
gpname << "gamepad" << i;
const std::string internal_name = gpname.str();
const std::string iconpath = file_manager->getDataDir() + "/gui/gamepad.png";
devices->addItem(name, internal_name, iconpath);
}
}
getCurrentScreen()->m_inited = true;
}
devices->updateItemDisplay();
// trigger displaying bindings for default selected device
const std::string name2("devices");
eventInput(devices, name2);
}
// -----------------------------------------------------------------------------
void initPlayers(Widget* widget, const std::string& name)
{
ListWidget* players = getCurrentScreen()->getWidget<ListWidget>("players");
assert(players != NULL);
const int playerAmount = UserConfigParams::m_all_players.size();
for(int n=0; n<playerAmount; n++)
{
players->addItem( UserConfigParams::m_all_players[n].getName() );
}
}
void eventPlayers(Widget* widget, const std::string& name)
{
if(name == "addplayer")
{
new EnterPlayerNameDialog(0.5f, 0.4f);
}
else if(name == "players")
{
// Find which player in the list was clicked
ListWidget* players = getCurrentScreen()->getWidget<ListWidget>("players");
assert(players != NULL);
std::string selectedPlayer = players->getSelectionName();
const int playerAmount = UserConfigParams::m_all_players.size();
for(int n=0; n<playerAmount; n++)
{
if(UserConfigParams::m_all_players[n].getName() == selectedPlayer)
{
new PlayerInfoDialog( &UserConfigParams::m_all_players[n], 0.5f, 0.6f );
return;
}
} // end for
}
}
// -----------------------------------------------------------------------------
static PlayerAction binding_to_set;
static std::string binding_to_set_button;
void eventInput(Widget* widget, const std::string& name)
{
if(name == "devices")
{
DynamicRibbonWidget* devices = getCurrentScreen()->getWidget<DynamicRibbonWidget>("devices");
assert(devices != NULL);
const std::string& selection = devices->getSelectionIDString(GUI_PLAYER_ID);
if( selection.find("gamepad") != std::string::npos )
{
int i = -1, read = 0;
read = sscanf( selection.c_str(), "gamepad%i", &i );
if(read == 1 && i != -1)
{
updateInputButtons( input_manager->getDeviceList()->getGamepadConfig(i) );
}
else
{
std::cerr << "Cannot read internal input device ID : " << selection.c_str() << std::endl;
}
}
else if(selection == "keyboard")
{
updateInputButtons( input_manager->getDeviceList()->getKeyboard(0)->getConfiguration() );
}
else
{
std::cerr << "Cannot read internal input device ID : " << selection.c_str() << std::endl;
}
}
else if(name.find("binding_") != std::string::npos)
{
binding_to_set_button = name;
if(name == "binding_up")
{
binding_to_set = PA_ACCEL;
}
else if(name == "binding_down")
{
binding_to_set = PA_BRAKE;
}
else if(name == "binding_left")
{
binding_to_set = PA_LEFT;
}
else if(name == "binding_right")
{
binding_to_set = PA_RIGHT;
}
else if(name == "binding_fire")
{
binding_to_set = PA_FIRE;
}
else if(name == "binding_nitro")
{
binding_to_set = PA_NITRO;
}
else if(name == "binding_drift")
{
binding_to_set = PA_DRIFT;
}
else if(name == "binding_rescue")
{
binding_to_set = PA_RESCUE;
}
else if(name == "binding_look_back")
{
binding_to_set = PA_LOOK_BACK;
}
else
{
std::cerr << "Unknown binding name : " << name.c_str() << std::endl;
return;
}
DynamicRibbonWidget* devices = getCurrentScreen()->getWidget<DynamicRibbonWidget>("devices");
assert( devices != NULL );
std::cout << "\n% Entering sensing mode for " << devices->getSelectionIDString(GUI_PLAYER_ID).c_str() << std::endl;
new PressAKeyDialog(0.4f, 0.4f);
std::string selection = devices->getSelectionIDString(GUI_PLAYER_ID);
if (selection == "keyboard")
{
input_manager->setMode(InputManager::INPUT_SENSE_KEYBOARD);
}
else if (selection.find("gamepad") != std::string::npos)
{
input_manager->setMode(InputManager::INPUT_SENSE_GAMEPAD);
}
else
{
std::cerr << "unknown selection device in options : " << selection.c_str() << std::endl;
}
}
}
#define MAX_VALUE 32768
// -----------------------------------------------------------------------------
void gotSensedInput(Input* sensedInput)
{
DynamicRibbonWidget* devices = getCurrentScreen()->getWidget<DynamicRibbonWidget>("devices");
assert( devices != NULL );
std::string deviceID = devices->getSelectionIDString(GUI_PLAYER_ID);
const bool keyboard = sensedInput->type == Input::IT_KEYBOARD && deviceID== "keyboard";
const bool gamepad = (sensedInput->type == Input::IT_STICKMOTION ||
sensedInput->type == Input::IT_STICKBUTTON) &&
deviceID.find("gamepad") != std::string::npos;
if(!keyboard && !gamepad) return;
if(gamepad)
{
if(sensedInput->type != Input::IT_STICKMOTION &&
sensedInput->type != Input::IT_STICKBUTTON)
return; // that kind of input does not interest us
}
if(keyboard)
{
std::cout << "% Binding " << KartActionStrings[binding_to_set] << " : setting to keyboard key " << sensedInput->btnID << " \n\n";
KeyboardDevice* keyboard = input_manager->getDeviceList()->getKeyboard(0);
keyboard->getConfiguration()->setBinding(binding_to_set, Input::IT_KEYBOARD, sensedInput->btnID, Input::AD_NEUTRAL);
// refresh display
initInput(NULL, "init");
}
else if(gamepad)
{
std::cout << "% Binding " << KartActionStrings[binding_to_set] << " : setting to gamepad #" << sensedInput->deviceID << " : ";
if(sensedInput->type == Input::IT_STICKMOTION)
{
std::cout << "axis " << sensedInput->btnID << " direction " <<
(sensedInput->axisDirection == Input::AD_NEGATIVE ? "-" : "+") << "\n\n";
}
else if(sensedInput->type == Input::IT_STICKBUTTON)
{
std::cout << "button " << sensedInput->btnID << "\n\n";
}
else
std::cout << "Sensed unknown gamepad event type??\n";
int configID = -1;
sscanf( devices->getSelectionIDString(GUI_PLAYER_ID).c_str(), "gamepad%i", &configID );
/*
if(sscanf( devices->getSelectionIDString().c_str(), "gamepad%i", &gamepadID ) != 1 ||
gamepadID >= input_manager->getDeviceList()->getGamePadAmount())
{
if(gamepadID >= input_manager->getDeviceList()->getGamePadAmount() || gamepadID == -1 )
{
std::cerr << "gamepad ID does not exist (or failed to read it) : " << gamepadID << "\n";
gamepadID = sensedInput->deviceID;
}
if(input_manager->getDeviceList()->getGamepadConfig(gamepadID)->m_index != sensedInput->deviceID)
{
// should not happen, but let's try to be bulletproof...
std::cerr << "The key that was pressed is not on the gamepad we're trying to configure! ID in list=" << gamepadID <<
" which has irrID " << input_manager->getDeviceList()->getGamePad(gamepadID)->m_index <<
" and we got input from " << sensedInput->deviceID << "\n";
}
}
*/
GamepadConfig* config = input_manager->getDeviceList()->getGamepadConfig(configID);
config->setBinding(binding_to_set, sensedInput->type, sensedInput->btnID,
(Input::AxisDirection)sensedInput->axisDirection);
// refresh display
initInput(NULL, "init");
}
else
{
return;
}
ModalDialog::dismiss();
input_manager->setMode(InputManager::MENU);
// re-select the previous button
ButtonWidget* btn = getCurrentScreen()->getWidget<ButtonWidget>(binding_to_set_button.c_str());
if(btn != NULL) GUIEngine::getGUIEnv()->setFocus( btn->getIrrlichtElement() );
// save new binding to file
input_manager->getDeviceList()->serialize();
}
/**
* Adds a new player (if 'player' is NULL) or renames an existing player (if 'player' is not NULL)
*/
void gotNewPlayerName(const stringw& newName, PlayerProfile* player)
{
stringc newNameC( newName );
ListWidget* players = getCurrentScreen()->getWidget<ListWidget>("players");
if(players == NULL) return;
// ---- Add new player
if(player == NULL)
{
UserConfigParams::m_all_players.push_back( new PlayerProfile(newNameC.c_str()) );
players->addItem( newNameC.c_str() );
}
else // ---- Rename existing player
{
player->setName( newNameC.c_str() );
// refresh list display
players->clear();
const int playerAmount = UserConfigParams::m_all_players.size();
for(int n=0; n<playerAmount; n++)
{
players->addItem(UserConfigParams::m_all_players[n].getName());
}
}
// TODO : need to re-save user config here?
}
void deletePlayer(PlayerProfile* player)
{
UserConfigParams::m_all_players.erase(player);
// refresh list display
ListWidget* players = getCurrentScreen()->getWidget<ListWidget>("players");
if(players == NULL) return;
players->clear();
const int playerAmount = UserConfigParams::m_all_players.size();
for(int n=0; n<playerAmount; n++)
{
players->addItem(UserConfigParams::m_all_players[n].getName());
}
// TODO : need to re-save user config here?
}
// -----------------------------------------------------------------------------
// main call (from StateManager); dispatches the call to a specialissed function as needed
void menuEventOptions(Widget* widget, const std::string& name)
{
const std::string& screen_name = getCurrentScreen()->getName();
if(name == "init")
{
const std::string& screen_name = getCurrentScreen()->getName();
RibbonWidget* ribbon = getCurrentScreen()->getWidget<RibbonWidget>("options_choice");
if(ribbon != NULL)
{
if (screen_name == "options_av.stkgui") ribbon->select( "audio_video", GUI_PLAYER_ID );
else if (screen_name == "options_players.stkgui") ribbon->select( "players", GUI_PLAYER_ID );
else if (screen_name == "options_input.stkgui") ribbon->select( "controls", GUI_PLAYER_ID );
}
if(screen_name == "options_av.stkgui") initAudioVideo(widget, name);
else if(screen_name == "options_input.stkgui") initInput(widget, name);
else if(screen_name == "options_players.stkgui") initPlayers(widget, name);
}
else if(name == "options_choice")
{
std::string selection = ((RibbonWidget*)widget)->getSelectionIDString(GUI_PLAYER_ID).c_str();
if(selection == "audio_video") StateManager::get()->replaceTopMostMenu("options_av.stkgui");
else if(selection == "players") StateManager::get()->replaceTopMostMenu("options_players.stkgui");
else if(selection == "controls") StateManager::get()->replaceTopMostMenu("options_input.stkgui");
}
else if(name == "back")
{
StateManager::get()->escapePressed();
}
else
{
if(screen_name == "options_av.stkgui") eventAudioVideo(widget, name);
else if(screen_name == "options_input.stkgui") eventInput(widget, name);
else if(screen_name == "options_players.stkgui") eventPlayers(widget, name);
}
}
}

View File

@@ -0,0 +1,243 @@
// 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/options_screen_input.hpp"
#include "states_screens/options_screen_av.hpp"
#include "states_screens/options_screen_players.hpp"
#include "audio/sound_manager.hpp"
#include "audio/sfx_manager.hpp"
#include "audio/sfx_base.hpp"
#include "config/player.hpp"
#include "config/device_config.hpp"
#include "graphics/irr_driver.hpp"
#include "guiengine/engine.hpp"
#include "guiengine/screen.hpp"
#include "guiengine/widget.hpp"
#include "input/input_manager.hpp"
#include "input/device_manager.hpp"
#include "io/file_manager.hpp"
#include "states_screens/dialogs/enter_player_name_dialog.hpp"
#include "states_screens/dialogs/player_info_dialog.hpp"
#include "states_screens/dialogs/press_a_key_dialog.hpp"
#include "states_screens/state_manager.hpp"
#include <iostream>
#include <sstream>
using namespace GUIEngine;
OptionsScreenAV::OptionsScreenAV() : Screen("options_av.stkgui")
{
}
// -----------------------------------------------------------------------------
void OptionsScreenAV::init()
{
RibbonWidget* ribbon = this->getWidget<RibbonWidget>("options_choice");
if (ribbon != NULL) ribbon->select( "audio_video", GUI_PLAYER_ID );
// ---- sfx volume
SpinnerWidget* gauge = this->getWidget<SpinnerWidget>("sfx_volume");
assert(gauge != NULL);
gauge->setValue( (int)(sfx_manager->getMasterSFXVolume()*10.0f) );
gauge = this->getWidget<SpinnerWidget>("music_volume");
assert(gauge != NULL);
gauge->setValue( (int)(sound_manager->getMasterMusicVolume()*10.f) );
// ---- music volume
CheckBoxWidget* sfx = this->getWidget<CheckBoxWidget>("sfx_enabled");
CheckBoxWidget* music = this->getWidget<CheckBoxWidget>("music_enabled");
// ---- audio enables/disables
sfx->setState( UserConfigParams::m_sfx );
music->setState( UserConfigParams::m_music );
// ---- video modes
{
DynamicRibbonWidget* res = this->getWidget<DynamicRibbonWidget>("resolutions");
assert( res != NULL );
CheckBoxWidget* full = this->getWidget<CheckBoxWidget>("fullscreen");
assert( full != NULL );
full->setState( UserConfigParams::m_fullscreen );
// --- get resolution list from irrlicht the first time
if(!this->m_inited)
{
const std::vector<VideoMode>& modes = irr_driver->getVideoModes();
const int amount = modes.size();
for(int n=0; n<amount; n++)
{
const int w = modes[n].width;
const int h = modes[n].height;
const float ratio = (float)w / h;
char name[32];
sprintf( name, "%ix%i", w, h );
#define ABOUT_EQUAL(a , b) (fabsf( a - b ) < 0.01)
if( ABOUT_EQUAL( ratio, (5.0f/4.0f) ) )
res->addItem(name, name, file_manager->getDataDir() + "/gui/screen54.png");
else if( ABOUT_EQUAL( ratio, (4.0f/3.0f) ) )
res->addItem(name, name, file_manager->getDataDir() + "/gui/screen43.png");
else if( ABOUT_EQUAL( ratio, (16.0f/10.0f) ) )
res->addItem(name, name, file_manager->getDataDir() + "/gui/screen1610.png");
else if( ABOUT_EQUAL( ratio, (5.0f/3.0f) ) )
res->addItem(name, name, file_manager->getDataDir() + "/gui/screen53.png");
else if( ABOUT_EQUAL( ratio, (3.0f/2.0f) ) )
res->addItem(name, name, file_manager->getDataDir() + "/gui/screen32.png");
else
{
std::cout << "Unknown screen size ratio : " << ratio << std::endl;
// FIXME - do something better than showing a random icon
res->addItem(name,name, file_manager->getDataDir() + "/gui/screen1610.png");
}
#undef ABOUT_EQUAL
} // next resolution
} // end if not inited
res->updateItemDisplay();
// ---- select curernt resolution every time
const std::vector<VideoMode>& modes = irr_driver->getVideoModes();
const int amount = modes.size();
for(int n=0; n<amount; n++)
{
const int w = modes[n].width;
const int h = modes[n].height;
char name[32];
sprintf( name, "%ix%i", w, h );
if(w == UserConfigParams::m_width && h == UserConfigParams::m_height)
{
//std::cout << "************* Detected right resolution!!! " << n << "\n";
// that's the current one
res->setSelection(n);
break;
}
} // end for
}
}
// -----------------------------------------------------------------------------
void OptionsScreenAV::eventCallback(Widget* widget, const std::string& name)
{
if (name == "options_choice")
{
std::string selection = ((RibbonWidget*)widget)->getSelectionIDString(GUI_PLAYER_ID).c_str();
if (selection == "audio_video") StateManager::get()->replaceTopMostScreen(OptionsScreenAV::getInstance());
else if (selection == "players") StateManager::get()->replaceTopMostScreen(OptionsScreenPlayers::getInstance());
else if (selection == "controls") StateManager::get()->replaceTopMostScreen(OptionsScreenInput::getInstance());
}
else if(name == "back")
{
StateManager::get()->escapePressed();
}
else if(name == "music_volume")
{
SpinnerWidget* w = dynamic_cast<SpinnerWidget*>(widget);
assert(w != NULL);
sound_manager->setMasterMusicVolume( w->getValue()/10.0f );
}
else if(name == "sfx_volume")
{
static SFXBase* sample_sound = NULL;
SpinnerWidget* w = dynamic_cast<SpinnerWidget*>(widget);
assert(w != NULL);
if(sample_sound == NULL)
sample_sound = sfx_manager->newSFX( SFXManager::SOUND_SKID );
sample_sound->volume(1);
sfx_manager->setMasterSFXVolume( w->getValue()/10.0f );
UserConfigParams::m_sfx_volume = w->getValue()/10.0f;
// play a sample sound to show the user what this volume is like
sample_sound->position ( Vec3(0,0,0) );
if(sample_sound->getStatus() != SFXManager::SFX_PLAYING)
{
sample_sound->play();
}
}
else if(name == "music_enabled")
{
CheckBoxWidget* w = dynamic_cast<CheckBoxWidget*>(widget);
UserConfigParams::m_music = w->getState();
std::cout << "music state is now " << (bool)UserConfigParams::m_music << std::endl;
if(w->getState() == false)
sound_manager->stopMusic();
else
sound_manager->startMusic(sound_manager->getCurrentMusic());
}
else if(name == "sfx_enabled")
{
CheckBoxWidget* w = dynamic_cast<CheckBoxWidget*>(widget);
UserConfigParams::m_sfx = w->getState();
}
else if(name == "apply_resolution")
{
using namespace GUIEngine;
UserConfigParams::m_prev_width = UserConfigParams::m_width;
UserConfigParams::m_prev_height = UserConfigParams::m_height;
DynamicRibbonWidget* w1 = this->getWidget<DynamicRibbonWidget>("resolutions");
assert(w1 != NULL);
const std::string& res = w1->getSelectionIDString(GUI_PLAYER_ID);
int w = -1, h = -1;
if( sscanf(res.c_str(), "%ix%i", &w, &h) != 2 || w == -1 || h == -1 )
{
std::cerr << "Failed to decode resolution : " << res.c_str() << std::endl;
return;
}
CheckBoxWidget* w2 = this->getWidget<CheckBoxWidget>("fullscreen");
assert(w2 != NULL);
UserConfigParams::m_width = w;
UserConfigParams::m_height = h;
UserConfigParams::m_fullscreen = w2->getState();
irr_driver->changeResolution();
}
}
// -----------------------------------------------------------------------------
void OptionsScreenAV::tearDown()
{
}

View File

@@ -0,0 +1,43 @@
// 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.
#ifndef __HEADER_OPTIONS_SCREEN_AV_HPP__
#define __HEADER_OPTIONS_SCREEN_AV_HPP__
#include <string>
#include "irrlicht.h"
#include "guiengine/screen.hpp"
namespace GUIEngine { class Widget; }
struct Input;
class OptionsScreenAV : public GUIEngine::Screen, public GUIEngine::ScreenSingleton<OptionsScreenAV>
{
OptionsScreenAV();
public:
friend class GUIEngine::ScreenSingleton<OptionsScreenAV>;
void eventCallback(GUIEngine::Widget* widget, const std::string& name);
void init();
void tearDown();
};
#endif

View File

@@ -0,0 +1,361 @@
// 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/options_screen_input.hpp"
#include "states_screens/options_screen_av.hpp"
#include "states_screens/options_screen_players.hpp"
#include "audio/sound_manager.hpp"
#include "audio/sfx_manager.hpp"
#include "audio/sfx_base.hpp"
#include "config/player.hpp"
#include "config/device_config.hpp"
#include "graphics/irr_driver.hpp"
#include "guiengine/engine.hpp"
#include "guiengine/screen.hpp"
#include "guiengine/widget.hpp"
#include "input/input_manager.hpp"
#include "input/device_manager.hpp"
#include "io/file_manager.hpp"
#include "states_screens/dialogs/enter_player_name_dialog.hpp"
#include "states_screens/dialogs/player_info_dialog.hpp"
#include "states_screens/dialogs/press_a_key_dialog.hpp"
#include "states_screens/state_manager.hpp"
#include <iostream>
#include <sstream>
using namespace GUIEngine;
OptionsScreenInput::OptionsScreenInput() : Screen("options_input.stkgui")
{
}
// -----------------------------------------------------------------------------
void OptionsScreenInput::updateInputButtons(DeviceConfig* config)
{
// Should never happen
if (config == NULL)
{
printf("ERROR: No configuration associated with device?\n");
abort();
}
{
ButtonWidget* btn = this->getWidget<ButtonWidget>("binding_up");
btn->setLabel( config->getBindingAsString(PA_ACCEL) );
}
{
ButtonWidget* btn = this->getWidget<ButtonWidget>("binding_down");
btn->setLabel( config->getBindingAsString(PA_BRAKE) );
}
{
ButtonWidget* btn = this->getWidget<ButtonWidget>("binding_left");
btn->setLabel( config->getBindingAsString(PA_LEFT) );
}
{
ButtonWidget* btn = this->getWidget<ButtonWidget>("binding_right");
btn->setLabel( config->getBindingAsString(PA_RIGHT) );
}
{
ButtonWidget* btn = this->getWidget<ButtonWidget>("binding_fire");
btn->setLabel( config->getBindingAsString(PA_FIRE) );
}
{
ButtonWidget* btn = this->getWidget<ButtonWidget>("binding_nitro");
btn->setLabel( config->getBindingAsString(PA_NITRO) );
}
{
ButtonWidget* btn = this->getWidget<ButtonWidget>("binding_drift");
btn->setLabel( config->getBindingAsString(PA_DRIFT) );
}
{
ButtonWidget* btn = this->getWidget<ButtonWidget>("binding_rescue");
btn->setLabel( config->getBindingAsString(PA_RESCUE) );
}
{
ButtonWidget* btn = this->getWidget<ButtonWidget>("binding_look_back");
btn->setLabel( config->getBindingAsString(PA_LOOK_BACK) );
}
}
// -----------------------------------------------------------------------------
void OptionsScreenInput::init()
{
RibbonWidget* ribbon = this->getWidget<RibbonWidget>("options_choice");
if (ribbon != NULL) ribbon->select( "controls", GUI_PLAYER_ID );
DynamicRibbonWidget* devices = this->getWidget<DynamicRibbonWidget>("devices");
assert( devices != NULL );
if(!this->m_inited)
{
devices->addItem("Keyboard","keyboard", file_manager->getDataDir() + "/gui/keyboard.png");
const int gpad_config_count = input_manager->getDeviceList()->getGamePadConfigAmount();
for(int i = 0; i < gpad_config_count; i++)
{
GamepadConfig *config = input_manager->getDeviceList()->getGamepadConfig(i);
// Don't display the configuration if a matching device is not available
if (config->isInUse())
{
const irr::core::stringw name = config->getName().c_str();
std::ostringstream gpname;
gpname << "gamepad" << i;
const std::string internal_name = gpname.str();
const std::string iconpath = file_manager->getDataDir() + "/gui/gamepad.png";
devices->addItem(name, internal_name, iconpath);
}
}
this->m_inited = true;
}
devices->updateItemDisplay();
// trigger displaying bindings for default selected device
const std::string name2("devices");
eventCallback(devices, name2);
}
// -----------------------------------------------------------------------------
static PlayerAction binding_to_set;
static std::string binding_to_set_button;
#define MAX_VALUE 32768
void OptionsScreenInput::gotSensedInput(Input* sensedInput)
{
DynamicRibbonWidget* devices = this->getWidget<DynamicRibbonWidget>("devices");
assert( devices != NULL );
std::string deviceID = devices->getSelectionIDString(GUI_PLAYER_ID);
const bool keyboard = sensedInput->type == Input::IT_KEYBOARD && deviceID== "keyboard";
const bool gamepad = (sensedInput->type == Input::IT_STICKMOTION ||
sensedInput->type == Input::IT_STICKBUTTON) &&
deviceID.find("gamepad") != std::string::npos;
if(!keyboard && !gamepad) return;
if(gamepad)
{
if(sensedInput->type != Input::IT_STICKMOTION &&
sensedInput->type != Input::IT_STICKBUTTON)
return; // that kind of input does not interest us
}
if (keyboard)
{
std::cout << "% Binding " << KartActionStrings[binding_to_set] << " : setting to keyboard key " << sensedInput->btnID << " \n\n";
KeyboardDevice* keyboard = input_manager->getDeviceList()->getKeyboard(0);
keyboard->getConfiguration()->setBinding(binding_to_set, Input::IT_KEYBOARD, sensedInput->btnID, Input::AD_NEUTRAL);
// refresh display
init();
}
else if (gamepad)
{
std::cout << "% Binding " << KartActionStrings[binding_to_set] << " : setting to gamepad #" << sensedInput->deviceID << " : ";
if(sensedInput->type == Input::IT_STICKMOTION)
{
std::cout << "axis " << sensedInput->btnID << " direction " <<
(sensedInput->axisDirection == Input::AD_NEGATIVE ? "-" : "+") << "\n\n";
}
else if(sensedInput->type == Input::IT_STICKBUTTON)
{
std::cout << "button " << sensedInput->btnID << "\n\n";
}
else
std::cout << "Sensed unknown gamepad event type??\n";
int configID = -1;
sscanf( devices->getSelectionIDString(GUI_PLAYER_ID).c_str(), "gamepad%i", &configID );
/*
if(sscanf( devices->getSelectionIDString().c_str(), "gamepad%i", &gamepadID ) != 1 ||
gamepadID >= input_manager->getDeviceList()->getGamePadAmount())
{
if(gamepadID >= input_manager->getDeviceList()->getGamePadAmount() || gamepadID == -1 )
{
std::cerr << "gamepad ID does not exist (or failed to read it) : " << gamepadID << "\n";
gamepadID = sensedInput->deviceID;
}
if(input_manager->getDeviceList()->getGamepadConfig(gamepadID)->m_index != sensedInput->deviceID)
{
// should not happen, but let's try to be bulletproof...
std::cerr << "The key that was pressed is not on the gamepad we're trying to configure! ID in list=" << gamepadID <<
" which has irrID " << input_manager->getDeviceList()->getGamePad(gamepadID)->m_index <<
" and we got input from " << sensedInput->deviceID << "\n";
}
}
*/
GamepadConfig* config = input_manager->getDeviceList()->getGamepadConfig(configID);
config->setBinding(binding_to_set, sensedInput->type, sensedInput->btnID,
(Input::AxisDirection)sensedInput->axisDirection);
// refresh display
init();
}
else
{
return;
}
ModalDialog::dismiss();
input_manager->setMode(InputManager::MENU);
// re-select the previous button
ButtonWidget* btn = this->getWidget<ButtonWidget>(binding_to_set_button.c_str());
if(btn != NULL) GUIEngine::getGUIEnv()->setFocus( btn->getIrrlichtElement() );
// save new binding to file
input_manager->getDeviceList()->serialize();
}
// -----------------------------------------------------------------------------
void OptionsScreenInput::tearDown()
{
}
// -----------------------------------------------------------------------------
// main call (from StateManager); dispatches the call to a specialissed function as needed
void OptionsScreenInput::eventCallback(Widget* widget, const std::string& name)
{
//const std::string& screen_name = this->getName();
if(name == "options_choice")
{
std::string selection = ((RibbonWidget*)widget)->getSelectionIDString(GUI_PLAYER_ID).c_str();
if (selection == "audio_video") StateManager::get()->replaceTopMostScreen(OptionsScreenAV::getInstance());
else if (selection == "players") StateManager::get()->replaceTopMostScreen(OptionsScreenPlayers::getInstance());
else if (selection == "controls") StateManager::get()->replaceTopMostScreen(OptionsScreenInput::getInstance());
}
else if(name == "back")
{
StateManager::get()->escapePressed();
}
else if (name == "devices")
{
DynamicRibbonWidget* devices = this->getWidget<DynamicRibbonWidget>("devices");
assert(devices != NULL);
const std::string& selection = devices->getSelectionIDString(GUI_PLAYER_ID);
if( selection.find("gamepad") != std::string::npos )
{
int i = -1, read = 0;
read = sscanf( selection.c_str(), "gamepad%i", &i );
if(read == 1 && i != -1)
{
updateInputButtons( input_manager->getDeviceList()->getGamepadConfig(i) );
}
else
{
std::cerr << "Cannot read internal input device ID : " << selection.c_str() << std::endl;
}
}
else if(selection == "keyboard")
{
updateInputButtons( input_manager->getDeviceList()->getKeyboard(0)->getConfiguration() );
}
else
{
std::cerr << "Cannot read internal input device ID : " << selection.c_str() << std::endl;
}
}
else if(name.find("binding_") != std::string::npos)
{
binding_to_set_button = name;
if(name == "binding_up")
{
binding_to_set = PA_ACCEL;
}
else if(name == "binding_down")
{
binding_to_set = PA_BRAKE;
}
else if(name == "binding_left")
{
binding_to_set = PA_LEFT;
}
else if(name == "binding_right")
{
binding_to_set = PA_RIGHT;
}
else if(name == "binding_fire")
{
binding_to_set = PA_FIRE;
}
else if(name == "binding_nitro")
{
binding_to_set = PA_NITRO;
}
else if(name == "binding_drift")
{
binding_to_set = PA_DRIFT;
}
else if(name == "binding_rescue")
{
binding_to_set = PA_RESCUE;
}
else if(name == "binding_look_back")
{
binding_to_set = PA_LOOK_BACK;
}
else
{
std::cerr << "Unknown binding name : " << name.c_str() << std::endl;
return;
}
DynamicRibbonWidget* devices = this->getWidget<DynamicRibbonWidget>("devices");
assert( devices != NULL );
std::cout << "\n% Entering sensing mode for " << devices->getSelectionIDString(GUI_PLAYER_ID).c_str() << std::endl;
new PressAKeyDialog(0.4f, 0.4f);
std::string selection = devices->getSelectionIDString(GUI_PLAYER_ID);
if (selection == "keyboard")
{
input_manager->setMode(InputManager::INPUT_SENSE_KEYBOARD);
}
else if (selection.find("gamepad") != std::string::npos)
{
input_manager->setMode(InputManager::INPUT_SENSE_GAMEPAD);
}
else
{
std::cerr << "unknown selection device in options : " << selection.c_str() << std::endl;
}
}
}

View File

@@ -0,0 +1,49 @@
// 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.
#ifndef __HEADER_OPTIONS_SCREEN_INPUT_HPP__
#define __HEADER_OPTIONS_SCREEN_INPUT_HPP__
#include <string>
#include "irrlicht.h"
#include "guiengine/screen.hpp"
namespace GUIEngine { class Widget; }
class DeviceConfig;
struct Input;
class OptionsScreenInput : public GUIEngine::Screen, public GUIEngine::ScreenSingleton<OptionsScreenInput>
{
void updateInputButtons(DeviceConfig* config);
OptionsScreenInput();
public:
friend class GUIEngine::ScreenSingleton<OptionsScreenInput>;
void eventCallback(GUIEngine::Widget* widget, const std::string& name);
void gotSensedInput(Input* sensedInput);
void init();
void tearDown();
};
#endif

View File

@@ -0,0 +1,159 @@
// 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/options_screen_input.hpp"
#include "states_screens/options_screen_av.hpp"
#include "states_screens/options_screen_players.hpp"
#include "audio/sound_manager.hpp"
#include "audio/sfx_manager.hpp"
#include "audio/sfx_base.hpp"
#include "config/player.hpp"
#include "config/device_config.hpp"
#include "graphics/irr_driver.hpp"
#include "guiengine/engine.hpp"
#include "guiengine/screen.hpp"
#include "guiengine/widget.hpp"
#include "input/input_manager.hpp"
#include "input/device_manager.hpp"
#include "io/file_manager.hpp"
#include "states_screens/dialogs/enter_player_name_dialog.hpp"
#include "states_screens/dialogs/player_info_dialog.hpp"
#include "states_screens/dialogs/press_a_key_dialog.hpp"
#include "states_screens/state_manager.hpp"
#include <iostream>
#include <sstream>
using namespace GUIEngine;
OptionsScreenPlayers::OptionsScreenPlayers() : Screen("options_players.stkgui")
{
}
// -----------------------------------------------------------------------------
void OptionsScreenPlayers::init()
{
RibbonWidget* ribbon = this->getWidget<RibbonWidget>("options_choice");
if (ribbon != NULL) ribbon->select( "players", GUI_PLAYER_ID );
ListWidget* players = this->getWidget<ListWidget>("players");
assert(players != NULL);
const int playerAmount = UserConfigParams::m_all_players.size();
for(int n=0; n<playerAmount; n++)
{
players->addItem( UserConfigParams::m_all_players[n].getName() );
}
}
/**
* Adds a new player (if 'player' is NULL) or renames an existing player (if 'player' is not NULL)
*/
void OptionsScreenPlayers::gotNewPlayerName(const stringw& newName, PlayerProfile* player)
{
stringc newNameC( newName );
ListWidget* players = this->getWidget<ListWidget>("players");
if(players == NULL) return;
// ---- Add new player
if(player == NULL)
{
UserConfigParams::m_all_players.push_back( new PlayerProfile(newNameC.c_str()) );
players->addItem( newNameC.c_str() );
}
else // ---- Rename existing player
{
player->setName( newNameC.c_str() );
// refresh list display
players->clear();
const int playerAmount = UserConfigParams::m_all_players.size();
for(int n=0; n<playerAmount; n++)
{
players->addItem(UserConfigParams::m_all_players[n].getName());
}
}
// TODO : need to re-save user config here?
}
void OptionsScreenPlayers::deletePlayer(PlayerProfile* player)
{
UserConfigParams::m_all_players.erase(player);
// refresh list display
ListWidget* players = this->getWidget<ListWidget>("players");
if(players == NULL) return;
players->clear();
const int playerAmount = UserConfigParams::m_all_players.size();
for(int n=0; n<playerAmount; n++)
{
players->addItem(UserConfigParams::m_all_players[n].getName());
}
// TODO : need to re-save user config here?
}
// -----------------------------------------------------------------------------
void OptionsScreenPlayers::tearDown()
{
}
// -----------------------------------------------------------------------------
// main call (from StateManager); dispatches the call to a specialissed function as needed
void OptionsScreenPlayers::eventCallback(Widget* widget, const std::string& name)
{
if (name == "options_choice")
{
std::string selection = ((RibbonWidget*)widget)->getSelectionIDString(GUI_PLAYER_ID).c_str();
if (selection == "audio_video") StateManager::get()->replaceTopMostScreen(OptionsScreenAV::getInstance());
else if (selection == "players") StateManager::get()->replaceTopMostScreen(OptionsScreenPlayers::getInstance());
else if (selection == "controls") StateManager::get()->replaceTopMostScreen(OptionsScreenInput::getInstance());
}
else if (name == "back")
{
StateManager::get()->escapePressed();
}
else if (name == "addplayer")
{
new EnterPlayerNameDialog(0.5f, 0.4f);
}
else if (name == "players")
{
// Find which player in the list was clicked
ListWidget* players = this->getWidget<ListWidget>("players");
assert(players != NULL);
std::string selectedPlayer = players->getSelectionName();
const int playerAmount = UserConfigParams::m_all_players.size();
for(int n=0; n<playerAmount; n++)
{
if(UserConfigParams::m_all_players[n].getName() == selectedPlayer)
{
new PlayerInfoDialog( &UserConfigParams::m_all_players[n], 0.5f, 0.6f );
return;
}
} // end for
}
}

View File

@@ -16,26 +16,33 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef __HEADER_OPTIONS_SCREEN_HPP__
#define __HEADER_OPTIONS_SCREEN_HPP__
#ifndef __HEADER_OPTIONS_SCREEN_PLAYERS_HPP__
#define __HEADER_OPTIONS_SCREEN_PLAYERS_HPP__
#include <string>
#include "irrlicht.h"
namespace GUIEngine
{
class Widget;
}
#include "guiengine/screen.hpp"
namespace GUIEngine { class Widget; }
struct Input;
class PlayerProfile;
namespace OptionsScreen
class OptionsScreenPlayers : public GUIEngine::Screen, public GUIEngine::ScreenSingleton<OptionsScreenPlayers>
{
void menuEventOptions(GUIEngine::Widget* widget, const std::string& name);
OptionsScreenPlayers();
public:
friend class GUIEngine::ScreenSingleton<OptionsScreenPlayers>;
void eventCallback(GUIEngine::Widget* widget, const std::string& name);
void gotSensedInput(Input* sensedInput);
void gotNewPlayerName(const irr::core::stringw& newName, PlayerProfile* player=NULL);
void deletePlayer(PlayerProfile* player);
}
void init();
void tearDown();
};
#endif

View File

@@ -0,0 +1,192 @@
// 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 "challenges/unlock_manager.hpp"
#include "guiengine/widget.hpp"
#include "io/file_manager.hpp"
#include "race/race_manager.hpp"
#include "states_screens/race_setup_screen.hpp"
#include "states_screens/state_manager.hpp"
#include "states_screens/tracks_screen.hpp"
#include "utils/translation.hpp"
using namespace GUIEngine;
RaceSetupScreen::RaceSetupScreen() : Screen("racesetup.stkgui")
{
}
void RaceSetupScreen::eventCallback(Widget* widget, const std::string& name)
{
if (name == "difficulty")
{
RibbonWidget* w = dynamic_cast<RibbonWidget*>(widget);
assert(w != NULL);
const std::string& selection = w->getSelectionIDString(GUI_PLAYER_ID);
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);
const std::string selectedMode = w->getSelectionIDString(GUI_PLAYER_ID);
if (selectedMode == "normal")
{
race_manager->setMinorMode(RaceManager::MINOR_MODE_QUICK_RACE);
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")
{
// TODO - 3 strikes battle track selection
race_manager->setMinorMode(RaceManager::MINOR_MODE_3_STRIKES);
}
else if (selectedMode == "locked")
{
std::cout << "Requesting sound to be played\n";
unlock_manager->playLockSound();
}
}
else if (name == "aikartamount")
{
SpinnerWidget* w = dynamic_cast<SpinnerWidget*>(widget);
race_manager->setNumKarts( race_manager->getNumPlayers() + w->getValue() );
}
/*
289 race_manager->setDifficulty((RaceManager::Difficulty)m_difficulty);
290 UserConfigParams::setDefaultNumDifficulty(m_difficulty);
// if there is no AI, there's no point asking the player for the amount of karts.
299 // It will always be the same as the number of human players
300 if(RaceManager::isBattleMode( race_manager->getMinorMode() ))
301 {
302 race_manager->setNumKarts(race_manager->getNumLocalPlayers());
303 // Don't change the default number of karts in user_config
304 }
305 else
306 {
307 race_manager->setNumKarts(m_num_karts);
308 UserConfigParams::setDefaultNumKarts(race_manager->getNumKarts());
309 }
311 if( race_manager->getMajorMode() != RaceManager::MAJOR_MODE_GRAND_PRIX &&
312 RaceManager::modeHasLaps( race_manager->getMinorMode() ) )
313 {
314 race_manager->setNumLaps( m_num_laps );
315 UserConfigParams::setDefaultNumLaps(m_num_laps);
316 }
317 // Might still be set from a previous challenge
318 race_manager->setCoinTarget(0);
input_manager->setMode(InputManager::INGAME);
race_manager->setLocalKartInfo(0, argv[i+1]);
race_manager->setDifficulty(RaceManager::RD_EASY);
race_manager->setDifficulty(RaceManager::RD_HARD);
race_manager->setDifficulty(RaceManager::RD_HARD);
race_manager->setTrack(argv[i+1]);
UserConfigParams::setDefaultNumKarts(stk_config->m_max_karts);
race_manager->setNumKarts(UserConfigParams::getDefaultNumKarts() );
UserConfigParams::getDefaultNumKarts()
StateManager::enterGameState();
race_manager->startNew();
*/
}
void RaceSetupScreen::init()
{
RibbonWidget* w = getWidget<RibbonWidget>("difficulty");
assert( w != NULL );
w->setSelection( race_manager->getDifficulty(), GUI_PLAYER_ID );
SpinnerWidget* kartamount = getWidget<SpinnerWidget>("aikartamount");
kartamount->setValue( race_manager->getNumKarts() - race_manager->getNumPlayers() );
DynamicRibbonWidget* w2 = getWidget<DynamicRibbonWidget>("gamemode");
assert( w2 != NULL );
if (!m_inited)
{
w2->addItem( _("Snaky Competition\nAll blows allowed, so catch weapons and make clever use of them!"),
"normal",
file_manager->getDataDir() + "/gui/mode_normal.png");
w2->addItem( _("Time Trial\nContains no powerups, so only your driving skills matter!"),
"timetrial",
file_manager->getDataDir() + "/gui/mode_tt.png");
if (unlock_manager->isLocked("followtheleader"))
{
w2->addItem( _("Locked!\nFulfill challenges to gain access to locked areas"),
"locked",
file_manager->getDataDir() + "textures/gui_lock.png");
}
else
{
w2->addItem( _("Follow the Leader\nrun 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!"),
"ftl",
file_manager->getDataDir() + "/gui/mode_ftl.png");
}
if (race_manager->getNumPlayers() > 1)
{
w2->addItem( _("3-Strikes Battle\nonly in multiplayer games. Hit others with weapons until they lose all their lives."),
"3strikes",
file_manager->getDataDir() + "/gui/mode_3strikes.png");
}
m_inited = true;
}
w2->updateItemDisplay();
}
void RaceSetupScreen::tearDown()
{
}

View File

@@ -0,0 +1,37 @@
// 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.
#ifndef HEADER_RACE_SETUP_SCREEN_HPP
#define HEADER_RACE_SETUP_SCREEN_HPP
#include "guiengine/screen.hpp"
namespace GUIEngine { class Widget; }
class RaceSetupScreen : public GUIEngine::Screen, public GUIEngine::ScreenSingleton<RaceSetupScreen>
{
friend class GUIEngine::ScreenSingleton<RaceSetupScreen>;
RaceSetupScreen();
public:
void eventCallback(GUIEngine::Widget* widget, const std::string& name);
void init();
void tearDown();
};
#endif

View File

@@ -35,7 +35,6 @@
#include "io/file_manager.hpp"
#include "network/network_manager.hpp"
#include "race/race_manager.hpp"
#include "states_screens/options_screen.hpp"
#include "states_screens/kart_selection.hpp"
#include "states_screens/credits.hpp"
#include "states_screens/dialogs/track_info_dialog.hpp"
@@ -124,306 +123,6 @@ void StateManager::resetActivePlayers()
m_active_players.clearWithoutDeleting();
}
#if 0
#pragma mark -
#pragma mark Callbacks
#endif
// -------------------------------------------------------------------------
/**
* Callback handling events from the main menu
*/
void StateManager::menuEventMain(Widget* widget, const std::string& name)
{
RibbonWidget* ribbon = dynamic_cast<RibbonWidget*>(widget);
if(ribbon == NULL) return; // only interesting stuff in main menu is the ribbons
std::string selection = ribbon->getSelectionIDString(GUI_PLAYER_ID);
if (selection == "network")
{
printf("+++++ FeatureUnlockedCutScene::show() +++++\n");
// FIXME : remove, temporary test
FeatureUnlockedCutScene::show();
}
if (selection == "new")
{
pushMenu("karts.stkgui");
}
else if (selection == "options")
{
StateManager::pushMenu("options_av.stkgui");
}
else if (selection == "quit")
{
main_loop->abort();
return;
}
else if (selection == "about")
{
pushMenu("credits.stkgui");
}
else if (selection == "help")
{
pushMenu("help1.stkgui");
}
}
// -------------------------------------------------------------------------
/**
* Callback handling events from the race setup menu
*/
void StateManager::menuEventRaceSetup(Widget* widget, const std::string& name)
{
if(name == "init")
{
RibbonWidget* w = getCurrentScreen()->getWidget<RibbonWidget>("difficulty");
assert( w != NULL );
w->setSelection( race_manager->getDifficulty(), GUI_PLAYER_ID );
SpinnerWidget* kartamount = getCurrentScreen()->getWidget<SpinnerWidget>("aikartamount");
kartamount->setValue( race_manager->getNumKarts() - race_manager->getNumPlayers() );
DynamicRibbonWidget* w2 = getCurrentScreen()->getWidget<DynamicRibbonWidget>("gamemode");
assert( w2 != NULL );
if(!getCurrentScreen()->m_inited)
{
w2->addItem( _("Snaky Competition\nAll blows allowed, so catch weapons and make clever use of them!"),
"normal",
file_manager->getDataDir() + "/gui/mode_normal.png");
w2->addItem( _("Time Trial\nContains no powerups, so only your driving skills matter!"),
"timetrial",
file_manager->getDataDir() + "/gui/mode_tt.png");
if (unlock_manager->isLocked("followtheleader"))
{
w2->addItem( _("Locked!\nFulfill challenges to gain access to locked areas"),
"locked",
file_manager->getDataDir() + "textures/gui_lock.png");
}
else
{
w2->addItem( _("Follow the Leader\nrun 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!"),
"ftl",
file_manager->getDataDir() + "/gui/mode_ftl.png");
}
if (race_manager->getNumPlayers() > 1)
{
w2->addItem( _("3-Strikes Battle\nonly in multiplayer games. Hit others with weapons until they lose all their lives."),
"3strikes",
file_manager->getDataDir() + "/gui/mode_3strikes.png");
}
getCurrentScreen()->m_inited = true;
}
w2->updateItemDisplay();
}
else if(name == "difficulty")
{
RibbonWidget* w = dynamic_cast<RibbonWidget*>(widget);
assert(w != NULL);
const std::string& selection = w->getSelectionIDString(GUI_PLAYER_ID);
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);
const std::string selectedMode = w->getSelectionIDString(GUI_PLAYER_ID);
if (selectedMode == "normal")
{
race_manager->setMinorMode(RaceManager::MINOR_MODE_QUICK_RACE);
pushMenu("tracks.stkgui");
}
else if (selectedMode == "timetrial")
{
race_manager->setMinorMode(RaceManager::MINOR_MODE_TIME_TRIAL);
pushMenu("tracks.stkgui");
}
else if (selectedMode == "ftl")
{
race_manager->setMinorMode(RaceManager::MINOR_MODE_FOLLOW_LEADER);
pushMenu("tracks.stkgui");
}
else if (selectedMode == "3strikes")
{
// TODO - 3 strikes battle track selection
race_manager->setMinorMode(RaceManager::MINOR_MODE_3_STRIKES);
}
else if (selectedMode == "locked")
{
std::cout << "Requesting sound to be played\n";
unlock_manager->playLockSound();
}
}
else if(name == "aikartamount")
{
SpinnerWidget* w = dynamic_cast<SpinnerWidget*>(widget);
race_manager->setNumKarts( race_manager->getNumPlayers() + w->getValue() );
}
/*
289 race_manager->setDifficulty((RaceManager::Difficulty)m_difficulty);
290 UserConfigParams::setDefaultNumDifficulty(m_difficulty);
// if there is no AI, there's no point asking the player for the amount of karts.
299 // It will always be the same as the number of human players
300 if(RaceManager::isBattleMode( race_manager->getMinorMode() ))
301 {
302 race_manager->setNumKarts(race_manager->getNumLocalPlayers());
303 // Don't change the default number of karts in user_config
304 }
305 else
306 {
307 race_manager->setNumKarts(m_num_karts);
308 UserConfigParams::setDefaultNumKarts(race_manager->getNumKarts());
309 }
311 if( race_manager->getMajorMode() != RaceManager::MAJOR_MODE_GRAND_PRIX &&
312 RaceManager::modeHasLaps( race_manager->getMinorMode() ) )
313 {
314 race_manager->setNumLaps( m_num_laps );
315 UserConfigParams::setDefaultNumLaps(m_num_laps);
316 }
317 // Might still be set from a previous challenge
318 race_manager->setCoinTarget(0);
input_manager->setMode(InputManager::INGAME);
race_manager->setLocalKartInfo(0, argv[i+1]);
race_manager->setDifficulty(RaceManager::RD_EASY);
race_manager->setDifficulty(RaceManager::RD_HARD);
race_manager->setDifficulty(RaceManager::RD_HARD);
race_manager->setTrack(argv[i+1]);
UserConfigParams::setDefaultNumKarts(stk_config->m_max_karts);
race_manager->setNumKarts(UserConfigParams::getDefaultNumKarts() );
UserConfigParams::getDefaultNumKarts()
StateManager::enterGameState();
race_manager->startNew();
*/
}
// -------------------------------------------------------------------------
/**
* Callback handling events from the track menu
*/
void StateManager::menuEventTracks(Widget* widget, const std::string& name)
{
if(name == "init")
{
DynamicRibbonWidget* w = getCurrentScreen()->getWidget<DynamicRibbonWidget>("tracks");
assert( w != NULL );
if (!getCurrentScreen()->m_inited)
{
const int trackAmount = track_manager->getNumberOfTracks();
bool hasLockedTracks = false;
for (int n=0; n<trackAmount; n++)
{
Track* curr = track_manager->getTrack(n);
if (unlock_manager->isLocked(curr->getIdent()))
{
hasLockedTracks = true;
continue;
}
w->addItem(curr->getName(), curr->getIdent(), curr->getScreenshotFile());
}
if (hasLockedTracks)
{
w->addItem(_("Locked Tracks"), "Lock", "textures/gui_lock.png");
}
getCurrentScreen()->m_inited = true;
}
w->updateItemDisplay();
}
// -- track seelction screen
if (name == "tracks")
{
DynamicRibbonWidget* w2 = dynamic_cast<DynamicRibbonWidget*>(widget);
if(w2 != NULL)
{
std::cout << "Clicked on track " << w2->getSelectionIDString(GUI_PLAYER_ID).c_str() << std::endl;
Track* clickedTrack = track_manager->getTrack(w2->getSelectionIDString(GUI_PLAYER_ID));
if (clickedTrack != NULL)
{
ITexture* screenshot = GUIEngine::getDriver()->getTexture( clickedTrack->getScreenshotFile().c_str() );
new TrackInfoDialog( clickedTrack->getIdent(), clickedTrack->getName().c_str(), screenshot, 0.8f, 0.7f);
}
}
}
else if (name == "gps")
{
RibbonWidget* w = dynamic_cast<RibbonWidget*>(widget);
if(w != NULL)
std::cout << "Clicked on GrandPrix " << w->getSelectionIDString(GUI_PLAYER_ID).c_str() << std::endl;
}
}
// -----------------------------------------------------------------------------
/**
* Callback handling events from the options menus
*/
void StateManager::menuEventHelp(Widget* widget, const std::string& name)
{
if(name == "init")
{
RibbonWidget* w = getCurrentScreen()->getWidget<RibbonWidget>("category");
if(w != NULL)
{
const std::string& screen_name = getCurrentScreen()->getName();
if(screen_name == "help1.stkgui") w->select( "page1", GUI_PLAYER_ID );
else if(screen_name == "help2.stkgui") w->select( "page2", GUI_PLAYER_ID );
else if(screen_name == "help3.stkgui") w->select( "page3", GUI_PLAYER_ID );
}
}
// -- options
else if(name == "category")
{
std::string selection = ((RibbonWidget*)widget)->getSelectionIDString(GUI_PLAYER_ID).c_str();
if(selection == "page1") replaceTopMostMenu("help1.stkgui");
else if(selection == "page2") replaceTopMostMenu("help2.stkgui");
else if(selection == "page3") replaceTopMostMenu("help3.stkgui");
}
else if(name == "back")
{
escapePressed();
}
}
// -------------------------------------------------------------------------
@@ -434,6 +133,7 @@ void StateManager::menuEventHelp(Widget* widget, const std::string& name)
* name 'init' and widget set to NULL will be fired, so the screen can be filled
* with the right values or so.
*/
/*
void StateManager::eventCallback(Widget* widget, const std::string& name)
{
std::cout << "event!! " << name.c_str() << std::endl;
@@ -478,7 +178,7 @@ void StateManager::eventCallback(Widget* widget, const std::string& name)
else
std::cerr << "Warning, unknown menu " << screen_name << " in event callback\n";
}
}*/
void StateManager::escapePressed()
{
@@ -509,12 +209,3 @@ void StateManager::escapePressed()
}
void StateManager::onUpdate(float elapsed_time)
{
// FIXME : don't hardcode?
if (getCurrentScreen()->getName() == "credits.stkgui")
Credits::getInstance()->render(elapsed_time);
else if (getCurrentScreen()->getName() == "karts.stkgui")
KartSelectionScreen::kartSelectionUpdate(elapsed_time);
}

View File

@@ -43,15 +43,6 @@ class StateManager : public GUIEngine::AbstractStateManager
ptr_vector<ActivePlayer, HOLD> m_active_players;
void updateActivePlayerIDs();
/** The main 'eventCallback' will dispatch to one of those.
* A few screens have their callbacks in a file of their own because they are
* too big to fit in here.
*/
void menuEventHelp ( GUIEngine::Widget* widget, const std::string& name );
void menuEventTracks ( GUIEngine::Widget* widget, const std::string& name );
void menuEventRaceSetup ( GUIEngine::Widget* widget, const std::string& name );
void menuEventMain ( GUIEngine::Widget* widget, const std::string& name );
public:
ptr_vector<ActivePlayer, HOLD>& getActivePlayers();
@@ -70,8 +61,7 @@ public:
void escapePressed();
void onUpdate(float elpased_time);
void eventCallback(GUIEngine::Widget* widget, const std::string& name);
//void eventCallback(GUIEngine::Widget* widget, const std::string& name);
// singleton
static StateManager* get();

View File

@@ -0,0 +1,94 @@
// 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 "challenges/unlock_manager.hpp"
#include "guiengine/widget.hpp"
#include "states_screens/state_manager.hpp"
#include "states_screens/tracks_screen.hpp"
#include "states_screens/dialogs/track_info_dialog.hpp"
#include "tracks/track.hpp"
#include "tracks/track_manager.hpp"
#include "utils/translation.hpp"
using namespace GUIEngine;
TracksScreen::TracksScreen() : Screen("tracks.stkgui")
{
}
void TracksScreen::eventCallback(Widget* widget, const std::string& name)
{
// -- track seelction screen
if (name == "tracks")
{
DynamicRibbonWidget* w2 = dynamic_cast<DynamicRibbonWidget*>(widget);
if(w2 != NULL)
{
std::cout << "Clicked on track " << w2->getSelectionIDString(GUI_PLAYER_ID).c_str() << std::endl;
Track* clickedTrack = track_manager->getTrack(w2->getSelectionIDString(GUI_PLAYER_ID));
if (clickedTrack != NULL)
{
ITexture* screenshot = GUIEngine::getDriver()->getTexture( clickedTrack->getScreenshotFile().c_str() );
new TrackInfoDialog( clickedTrack->getIdent(), clickedTrack->getName().c_str(), screenshot, 0.8f, 0.7f);
}
}
}
else if (name == "gps")
{
RibbonWidget* w = dynamic_cast<RibbonWidget*>(widget);
if(w != NULL)
std::cout << "Clicked on GrandPrix " << w->getSelectionIDString(GUI_PLAYER_ID).c_str() << std::endl;
}
}
void TracksScreen::init()
{
DynamicRibbonWidget* w = this->getWidget<DynamicRibbonWidget>("tracks");
assert( w != NULL );
if (!this->m_inited)
{
const int trackAmount = track_manager->getNumberOfTracks();
bool hasLockedTracks = false;
for (int n=0; n<trackAmount; n++)
{
Track* curr = track_manager->getTrack(n);
if (unlock_manager->isLocked(curr->getIdent()))
{
hasLockedTracks = true;
continue;
}
w->addItem(curr->getName(), curr->getIdent(), curr->getScreenshotFile());
}
if (hasLockedTracks)
{
w->addItem(_("Locked Tracks"), "Lock", "textures/gui_lock.png");
}
this->m_inited = true;
}
w->updateItemDisplay();
}
void TracksScreen::tearDown()
{
}

View File

@@ -0,0 +1,38 @@
// 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.
#ifndef HEADER_TRACKS_SCREEN_HPP
#define HEADER_TRACKS_SCREEN_HPP
#include "guiengine/screen.hpp"
namespace GUIEngine { class Widget; }
class TracksScreen : public GUIEngine::Screen, public GUIEngine::ScreenSingleton<TracksScreen>
{
friend class GUIEngine::ScreenSingleton<TracksScreen>;
TracksScreen();
public:
void eventCallback(GUIEngine::Widget* widget, const std::string& name);
void init();
void tearDown();
};
#endif