Added files forgotten in previous commit

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@3766 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria 2009-07-18 18:17:43 +00:00
parent 9016d02b7e
commit 7be81c67df
2 changed files with 189 additions and 0 deletions

View File

@ -0,0 +1,143 @@
// 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 "guiengine/abstract_state_manager.hpp"
#include <vector>
#include "main_loop.hpp"
#include "audio/sound_manager.hpp"
#include "config/player.hpp"
#include "config/user_config.hpp"
#include "graphics/irr_driver.hpp"
#include "guiengine/engine.hpp"
#include "guiengine/modaldialog.hpp"
#include "guiengine/screen.hpp"
#include "guiengine/widget.hpp"
#include "input/device_manager.hpp"
#include "input/input_manager.hpp"
#include "io/file_manager.hpp"
#include "network/network_manager.hpp"
#include "race/race_manager.hpp"
#include "states_screens/options_screen.hpp"
#include "states_screens/kart_selection.hpp"
#include "states_screens/credits.hpp"
#include "utils/translation.hpp"
using namespace GUIEngine;
/**
* Name of the event sent when constructing a menu
*/
const std::string g_init_event = "init";
AbstractStateManager::AbstractStateManager()
{
m_game_mode = false;
}
#if 0
#pragma mark -
#pragma mark Other
#endif
/*
void initGUI()
{
IrrlichtDevice* device = irr_driver->getDevice();
video::IVideoDriver* driver = device->getVideoDriver();
GUIEngine::init(device, driver, &eventCallback);
}
*/
void AbstractStateManager::enterGameState()
{
m_menu_stack.clear();
m_menu_stack.push_back("race");
m_game_mode = true;
cleanForGame();
input_manager->setMode(InputManager::INGAME);
}
bool AbstractStateManager::isGameState()
{
return m_game_mode;
}
#if 0
#pragma mark -
#pragma mark Push/pop menus
#endif
void AbstractStateManager::pushMenu(std::string name)
{
input_manager->setMode(InputManager::MENU);
m_menu_stack.push_back(name);
m_game_mode = false;
switchToScreen(name.c_str());
eventCallback(NULL, g_init_event);
}
void AbstractStateManager::replaceTopMostMenu(std::string name)
{
input_manager->setMode(InputManager::MENU);
m_menu_stack[m_menu_stack.size()-1] = name;
m_game_mode = false;
switchToScreen(name.c_str());
eventCallback(NULL, g_init_event);
}
void AbstractStateManager::reshowTopMostMenu()
{
switchToScreen( m_menu_stack[m_menu_stack.size()-1].c_str() );
eventCallback(NULL, g_init_event);
}
void AbstractStateManager::popMenu()
{
m_menu_stack.pop_back();
if(m_menu_stack.size() == 0)
{
main_loop->abort();
return;
}
m_game_mode = m_menu_stack[m_menu_stack.size()-1] == "race";
std::cout << "-- switching to screen " << m_menu_stack[m_menu_stack.size()-1].c_str() << std::endl;
switchToScreen(m_menu_stack[m_menu_stack.size()-1].c_str());
eventCallback(NULL, g_init_event);
}
void AbstractStateManager::resetAndGoToMenu(std::string name)
{
race_manager->exitRace();
input_manager->setMode(InputManager::MENU);
m_menu_stack.clear();
m_menu_stack.push_back(name);
m_game_mode = false;
sound_manager->positionListener( Vec3(0,0,0), Vec3(0,1,0) );
switchToScreen(name.c_str());
eventCallback(NULL, g_init_event);
}

View File

@ -0,0 +1,46 @@
#ifndef HEADER_ABSTRACT_STATE_MANAGER_HPP
#define HEADER_ABSTRACT_STATE_MANAGER_HPP
#include <vector>
#include <string>
namespace GUIEngine
{
class Widget;
/**
* Abstract base class you must override from to use the GUI engine
*/
class AbstractStateManager
{
protected:
/**
* Whether we are in game mode
*/
bool m_game_mode;
/**
* This stack will contain menu names (e.g. main.stkgui), and/or 'race'.
*/
std::vector<std::string> m_menu_stack;
public:
AbstractStateManager();
virtual ~AbstractStateManager() { }
void pushMenu(std::string name);
void replaceTopMostMenu(std::string name);
void popMenu();
void resetAndGoToMenu(std::string name);
void enterGameState();
bool isGameState();
void reshowTopMostMenu();
// method to override in children
virtual void escapePressed() = 0;
virtual void onUpdate(float elpased_time) = 0;
virtual void eventCallback(Widget* widget, const std::string& name) = 0;
};
}
#endif