Implemented viewing the help menu in-game

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@4009 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria 2009-09-06 18:45:38 +00:00
parent d891996797
commit 5aa52c20ce
16 changed files with 102 additions and 37 deletions

View File

@ -56,6 +56,7 @@
<spacer width="50" height="45" />
</div>
<button id="back" x="20" y="-40" width="250" height="35" align="left" text="Back to main menu"/>
<button id="back" x="20" y="-40" width="250" height="35" align="left"
I18N="In the help menu, to return to the previous screen" text="Back"/>
</stkgui>

View File

@ -60,6 +60,7 @@
</box>
<spacer width="50" height="45" />
</div>
<button id="back" x="20" y="-40" width="250" height="35" align="left" text="Back to main menu"/>
<button id="back" x="20" y="-40" width="250" height="35" align="left"
I18N="In the help menu, to return to the previous screen" text="Back"/>
</stkgui>

View File

@ -60,6 +60,7 @@
<spacer width="50" height="45" />
</div>
<button id="back" x="20" y="-40" width="250" height="35" align="left" text="Back to main menu"/>
<button id="back" x="20" y="-40" width="250" height="35" align="left"
I18N="In the help menu, to return to the previous screen" text="Back"/>
</stkgui>

View File

@ -509,7 +509,7 @@ void IrrDriver::displayFPS()
const int fps = m_device->getVideoDriver()->getFPS();
// Min and max info tracking, per mode, so user can check game vs menus
bool current_state = StateManager::get()->isGameState();
bool current_state = StateManager::get()->getGameState() == GUIEngine::GAME;
static bool prev_state = false;
static int min = 999; // Absurd values for start will print first time
static int max = 0; // but no big issue, maybe even "invisible"
@ -545,7 +545,7 @@ void IrrDriver::update(float dt)
m_device->getVideoDriver()->beginScene(false, true, video::SColor(255,100,101,140));
{ // just to mark the beding/end scene block
if(!StateManager::get()->isGameState())
if (StateManager::get()->getGameState() != GUIEngine::GAME)
{
// this code needs to go outside beginScene() / endScene() since
// the model view widget will do off-screen rendering there
@ -569,7 +569,7 @@ void IrrDriver::update(float dt)
}
// GUI is active
if (!inRace || GUIEngine::ModalDialog::isADialogActive())
//if (!inRace || GUIEngine::ModalDialog::isADialogActive())
{
GUIEngine::render(dt);
}

View File

@ -32,6 +32,7 @@
#include "input/device_manager.hpp"
#include "input/input_manager.hpp"
#include "io/file_manager.hpp"
#include "modes/world.hpp"
#include "network/network_manager.hpp"
#include "race/race_manager.hpp"
#include "states_screens/options_screen.hpp"
@ -54,7 +55,7 @@ const std::string g_teardown_event = "tearDown";
AbstractStateManager::AbstractStateManager()
{
m_game_mode = false;
m_game_mode = MENU;
}
#if 0
@ -75,12 +76,12 @@ void AbstractStateManager::enterGameState()
{
m_menu_stack.clear();
m_menu_stack.push_back("race");
m_game_mode = true;
m_game_mode = GAME;
cleanForGame();
input_manager->setMode(InputManager::INGAME);
}
bool AbstractStateManager::isGameState()
GameState AbstractStateManager::getGameState()
{
return m_game_mode;
}
@ -93,25 +94,38 @@ bool AbstractStateManager::isGameState()
void AbstractStateManager::pushMenu(std::string name)
{
// currently, only a single in-game menu is supported
assert(m_game_mode != INGAME_MENU);
// Send tear-down event to previous menu
if (m_menu_stack.size() > 0) eventCallback(NULL, g_teardown_event);
if (m_menu_stack.size() > 0 && m_game_mode != GAME) eventCallback(NULL, g_teardown_event);
input_manager->setMode(InputManager::MENU);
m_menu_stack.push_back(name);
m_game_mode = false;
if (m_game_mode == GAME)
{
m_game_mode = INGAME_MENU;
RaceManager::getWorld()->pause();
}
else
{
m_game_mode = MENU;
}
switchToScreen(name.c_str());
// Send init event to new menu
eventCallback(NULL, g_init_event);
}
void AbstractStateManager::replaceTopMostMenu(std::string name)
{
assert(m_game_mode != GAME);
// Send tear-down event to previous menu
if (m_menu_stack.size() > 0) eventCallback(NULL, g_teardown_event);
input_manager->setMode(InputManager::MENU);
m_menu_stack[m_menu_stack.size()-1] = name;
m_game_mode = false;
switchToScreen(name.c_str());
// Send init event to new menu
@ -120,6 +134,8 @@ void AbstractStateManager::replaceTopMostMenu(std::string name)
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);
@ -131,22 +147,38 @@ void AbstractStateManager::reshowTopMostMenu()
void AbstractStateManager::popMenu()
{
assert(m_game_mode != GAME);
// Send tear-down event to menu
eventCallback(NULL, g_teardown_event);
m_menu_stack.pop_back();
if(m_menu_stack.size() == 0)
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());
input_manager->getDeviceList()->setAssignMode(NO_ASSIGN); // No assign mode on menus by default
eventCallback(NULL, g_init_event);
if (m_menu_stack[m_menu_stack.size()-1] == "race")
{
m_menu_stack.push_back("race");
if (m_game_mode == INGAME_MENU)
{
RaceManager::getWorld()->unpause();
}
m_game_mode = GAME;
cleanForGame();
input_manager->setMode(InputManager::INGAME);
}
else
{
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);
}
}
void AbstractStateManager::resetAndGoToMenu(std::string name)
@ -155,7 +187,7 @@ void AbstractStateManager::resetAndGoToMenu(std::string name)
input_manager->setMode(InputManager::MENU);
m_menu_stack.clear();
m_menu_stack.push_back(name);
m_game_mode = false;
m_game_mode = MENU;
sound_manager->positionListener( Vec3(0,0,0), Vec3(0,1,0) );
switchToScreen(name.c_str());
eventCallback(NULL, g_init_event);

View File

@ -8,6 +8,13 @@ namespace GUIEngine
{
class Widget;
enum GameState
{
MENU,
GAME,
INGAME_MENU
};
/**
* Abstract base class you must override from to use the GUI engine
*/
@ -17,7 +24,7 @@ protected:
/**
* Whether we are in game mode
*/
bool m_game_mode;
GameState m_game_mode;
/**
* This stack will contain menu names (e.g. main.stkgui), and/or 'race'.
@ -33,7 +40,9 @@ public:
void popMenu();
void resetAndGoToMenu(std::string name);
void enterGameState();
bool isGameState();
GameState getGameState();
void reshowTopMostMenu();
/* ***********************************

View File

@ -191,11 +191,22 @@ void render(float elapsed_time)
GUIEngine::dt = elapsed_time;
// ---- menu drawing
// draw background image and sections
const bool gui_state = !g_state_manager->isGameState();
if (gui_state)
const GameState gamestate = g_state_manager->getGameState();
if (gamestate == MENU)
{
g_skin->drawBgImage();
}
else if (gamestate == INGAME_MENU)
{
g_skin->drawBGFadeColor();
}
if (gamestate != GAME)
{
g_skin->renderSections();
}
@ -203,7 +214,7 @@ void render(float elapsed_time)
g_env->drawAll();
// ---- some menus may need updating
if (!g_state_manager->isGameState())
if (gamestate != GAME)
{
g_state_manager->onUpdate(elapsed_time);
}

View File

@ -43,7 +43,7 @@ EventHandler::~EventHandler()
bool EventHandler::OnEvent (const SEvent &event)
{
if(event.EventType == EET_GUI_EVENT ||
(!GUIEngine::getStateManager()->isGameState() && event.EventType != EET_KEY_INPUT_EVENT &&
(GUIEngine::getStateManager()->getGameState() != GUIEngine::GAME && event.EventType != EET_KEY_INPUT_EVENT &&
event.EventType != EET_JOYSTICK_INPUT_EVENT)
)
{

View File

@ -244,7 +244,7 @@ void Screen::calculateLayout(ptr_vector<Widget>& widgets, Widget* parent)
void Screen::addWidgets()
{
if(!m_loaded) loadFromFile();
if (!m_loaded) loadFromFile();
addWidgetsRecursively( m_widgets );

View File

@ -946,7 +946,7 @@ void Skin::renderSections(ptr_vector<Widget>* within_vector)
void Skin::draw2DRectangle (IGUIElement *element, const video::SColor &color, const core::rect< s32 > &rect, const core::rect< s32 > *clip)
{
if(GUIEngine::getStateManager()->isGameState()) return; // ignore in game mode
if (GUIEngine::getStateManager()->getGameState() == GUIEngine::GAME) return; // ignore in game mode
//const bool focused = GUIEngine::getGUIEnv()->hasFocus(element);
const int id = element->getID();
@ -1088,12 +1088,17 @@ void Skin::draw3DSunkenPane (IGUIElement *element, video::SColor bgcolor, bool f
// GUIEngine::getDriver()->draw2DRectangle( SColor(255, 0, 150, 0), rect );
}
core::rect< s32 > Skin::draw3DWindowBackground (IGUIElement *element, bool drawTitleBar, video::SColor titleBarColor, const core::rect< s32 > &rect, const core::rect< s32 > *clip)
void Skin::drawBGFadeColor()
{
// fade out background
SColor& color = SkinConfig::m_colors["dialog_background::neutral"];
GUIEngine::getDriver()->draw2DRectangle( color,
core::rect< s32 >(position2d< s32 >(0,0) , GUIEngine::getDriver()->getCurrentRenderTargetSize()) );
}
core::rect< s32 > Skin::draw3DWindowBackground (IGUIElement *element, bool drawTitleBar, video::SColor titleBarColor, const core::rect< s32 > &rect, const core::rect< s32 > *clip)
{
drawBGFadeColor();
// draw frame
drawBoxFromStretchableTexture( ModalDialog::getCurrent(), rect, SkinConfig::m_render_params["window::neutral"]);

View File

@ -244,6 +244,7 @@ namespace GUIEngine
void renderSections(ptr_vector<Widget>* within_vector=NULL);
void drawBgImage();
void drawBGFadeColor();
// irrlicht's callbacks
virtual void draw2DRectangle (IGUIElement *element, const video::SColor &color, const core::rect< s32 > &pos, const core::rect< s32 > *clip);

View File

@ -1,10 +1,11 @@
#include "states_screens/state_manager.hpp"
#include "config/device_config.hpp"
#include "guiengine/abstract_state_manager.hpp"
#include "input/input.hpp"
#include "input/input_device.hpp"
#include "modes/world.hpp"
#include "race/race_manager.hpp"
#include "states_screens/state_manager.hpp"
InputDevice::InputDevice()
@ -88,7 +89,7 @@ void GamePadDevice::setButtonPressed(const int i, bool isButtonPressed)
void GamePadDevice::resetAxisDirection(const int axis, Input::AxisDirection direction, ActivePlayer* player)
{
KeyBinding bind;
if(!StateManager::get()->isGameState()) return; // ignore this while in menus
if (StateManager::get()->getGameState() != GUIEngine::GAME) return; // ignore this while in menus
PlayerKart* pk = player->getKart();
if (pk == NULL)

View File

@ -246,7 +246,7 @@ void InputManager::input(Input::InputType type, int deviceID, int btnID, int axi
// in menus, some keyboard keys are standard (before each player selected his device)
// FIXME: should enter always work to accept for a player using keyboard?
if (!StateManager::get()->isGameState() && type == Input::IT_KEYBOARD && m_mode == MENU &&
if (StateManager::get()->getGameState() != GUIEngine::GAME && type == Input::IT_KEYBOARD && m_mode == MENU &&
m_device_manager->playerAssignMode() == NO_ASSIGN)
{
action = PA_FIRST;
@ -315,7 +315,7 @@ void InputManager::input(Input::InputType type, int deviceID, int btnID, int axi
}
// ... when in-game
if (StateManager::get()->isGameState() && !GUIEngine::ModalDialog::isADialogActive())
if (StateManager::get()->getGameState() == GUIEngine::GAME && !GUIEngine::ModalDialog::isADialogActive())
{
// Find the corresponding PlayerKart from our ActivePlayer instance
PlayerKart* pk;
@ -508,7 +508,7 @@ bool InputManager::input(const SEvent& event)
// block events in all modes but initial menus (except in text boxes to allow typing, and exceptm in modal dialogs in-game)
return getDeviceList()->playerAssignMode() != NO_ASSIGN && !GUIEngine::isWithinATextBox &&
(!GUIEngine::ModalDialog::isADialogActive() && StateManager::get()->isGameState());
(!GUIEngine::ModalDialog::isADialogActive() && StateManager::get()->getGameState() == GUIEngine::GAME);
}
//-----------------------------------------------------------------------------

View File

@ -78,7 +78,7 @@ float MainLoop::getLimitedDt()
// Throttle fps if more than maximum, which can reduce
// the noise the fan on a graphics card makes.
// When in menus, reduce FPS much, it's not necessary to push to the maximum for plain menus
const int max_fps = StateManager::get()->isGameState() ? UserConfigParams::m_max_fps : 35;
const int max_fps = (StateManager::get()->getGameState() == GUIEngine::GAME ? UserConfigParams::m_max_fps : 35);
const int current_fps = (int)(1000.0f/dt);
if( current_fps > max_fps )
{

View File

@ -235,6 +235,9 @@ bool RacePausedDialog::processEvent(std::string& eventSource)
else if (selection == "help")
{
// TODO
dismiss();
StateManager::get()->pushMenu("help1.stkgui");
return true;
}
else if (selection == "options")
{

View File

@ -468,7 +468,7 @@ void StateManager::escapePressed()
ModalDialog::dismiss();
}
// In-game
else if(m_game_mode)
else if(m_game_mode == GAME)
{
new RacePausedDialog(0.8f, 0.6f);
//resetAndGoToMenu("main.stkgui");