Added back support for displaying messages in the GUI (for instance when an old config file is found; though this won't actually happen for the 0.6->0.7 transition since it went from LISP to XML)

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@5259 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria 2010-04-25 01:21:53 +00:00
parent ad97efc12f
commit 8a8408bb23
4 changed files with 60 additions and 54 deletions

View File

@ -40,6 +40,7 @@ static ptr_vector<UserConfigParam, REF> all_params;
#include "config/player.hpp"
#include "config/stk_config.hpp"
#include "guiengine/engine.hpp"
#include "io/file_manager.hpp"
#include "io/xml_node.hpp"
#include "race/race_manager.hpp"
@ -390,45 +391,21 @@ bool UserConfig::loadConfig()
int configFileVersion = CURRENT_CONFIG_VERSION;
if(root->get("version", &configFileVersion) < 1)
{
GUIEngine::showMessage( _("Your config file was malformed, so it was deleted and a new one will be created."), 10.0f);
std::cerr << "Warning, malformed user config file! Contains no version\n";
}
if (configFileVersion < CURRENT_CONFIG_VERSION)
{
// Give some feedback to the user about what was changed.
// Do NOT add a break after the case, so that all changes will be printed
printf("\nConfig file version '%d' is too old.\n"
"The following changes have been applied in the current SuperTuxKart version:\n",
configFileVersion);
int needToAbort=0;
switch(configFileVersion)
{
case 0: printf("- Single window menu, old status display,new keyboard style settings were removed\n");
needToAbort=std::max(needToAbort,0);
case 1: printf("- Key bindings were changed, please check the settings. All existing values were discarded.\n");
needToAbort=std::max(needToAbort,1);// old keybinds wouldn't make any sense
case 2: printf("Added username.\n");
needToAbort=std::max(needToAbort,0);
case 3: printf("Added username for all players.\n");
needToAbort=std::max(needToAbort,0);
case 4: printf("Added jumping, which invalidates all key bindings.\n");
needToAbort=std::max(needToAbort,0);
case 6: printf("Added nitro and drifting, removed jumping and wheelie.\n");
//nitro_name="wheelie";
//drift_name="jump";
needToAbort=std::max(needToAbort,0);
case 99: break;
default: printf("Config file version '%d' is too old. Discarding your configuration. Sorry. :(\n", configFileVersion);
needToAbort=1;
break;
}
if(needToAbort)
{
printf("The old config file is deleted, a new one will be created.\n");
delete root;
return false;
}
printf("This warning can be ignored, the config file will be automatically updated.\n");
// Keep on reading the config files as far as possible
// current version (8) is 100% incompatible with other versions (which were lisp)
// so we just delete the old config. in the future, for smaller updates, we can
// add back the code previously there that upgraded the config file to the new
// format instead of overwriting it.
GUIEngine::showMessage( _("Your config file was too old, so it was deleted and a new one will be created."), 10.0f);
printf("Your config file was too old, so it was deleted and a new one will be created.");
delete root;
return false;
} // if configFileVersion<SUPPORTED_CONFIG_VERSION
// ---- Read parameters values (all parameter objects must have been created before this point if

View File

@ -421,10 +421,20 @@ namespace GUIEngine
return dt;
}
float masterOnlyMessageTime = 0.0f;
void showMasterOnlyString()
struct MenuMessage
{
masterOnlyMessageTime = 5.0f;
irr::core::stringw m_message;
float m_time;
MenuMessage(const wchar_t* message, const float time) : m_message(message), m_time(time)
{
}
};
std::vector<MenuMessage> gui_messages;
void showMessage(const wchar_t* message, const float time)
{
gui_messages.push_back( MenuMessage(message, time) );
}
Widget* getFocusForPlayer(const int playerID)
@ -669,22 +679,35 @@ void render(float elapsed_time)
else World::getWorld()->getRaceGUI()->renderGlobal(elapsed_time);
}
if (masterOnlyMessageTime > 0)
if (gamestate != GAME && !gui_messages.empty())
{
masterOnlyMessageTime -= dt;
core::dimension2d<u32> screen_size = irr_driver->getFrameSize();
const int text_height = getFontHeight() + 20;
const int y_from = screen_size.Height - text_height;
//I18N: message shown when a player that isn't game master tries to modify options that
//I18N: only the game master is allowed to
Private::g_font->draw(_("Only the Game Master may act at this point!"),
core::rect<s32>( core::position2d<s32>(0,y_from),
core::dimension2d<s32>(screen_size.Width, text_height) ),
video::SColor(255, 255, 0, 0),
true /* hcenter */, true /* vcenter */);
int count = 0;
std::vector<MenuMessage>::iterator it;
for (it=gui_messages.begin(); it != gui_messages.end();)
{
if ((*it).m_time > 0.0f)
{
(*it).m_time -= dt;
Private::g_font->draw((*it).m_message.c_str(),
core::rect<s32>( core::position2d<s32>(0, y_from - count*text_height),
core::dimension2d<s32>(screen_size.Width, text_height) ),
video::SColor(255, 255, 0, 0),
true /* hcenter */, true /* vcenter */);
count++;
it++;
}
else
{
it = gui_messages.erase(it);
}
}
}
#if (IRRLICHT_VERSION_MAJOR == 1) && (IRRLICHT_VERSION_MINOR >= 7)

View File

@ -157,10 +157,12 @@ namespace GUIEngine
*/
float getLatestDt();
/** \brief show a warning message to explain to the player that only the game master
* can act at this point
/**
* \brief shows a message at the bottom of the screen for a while
* \param message the message to display
* \param time the time to display the message, in seconds
*/
void showMasterOnlyString();
void showMessage(const wchar_t* message, const float time=5.0f);
/** \brief Add a screen to the list of screens known by the gui engine */
void addScreenToList(Screen* screen);

View File

@ -423,7 +423,9 @@ void InputManager::dispatchInput(Input::InputType type, int deviceID, int btnID,
// early menus where we accept every input because players are not set-up yet
if (m_master_player_only && player == NULL)
{
GUIEngine::showMasterOnlyString();
//I18N: message shown when a player that isn't game master tries to modify options that
//I18N: only the game master is allowed to
GUIEngine::showMessage(_("Only the Game Master may act at this point!"));
return;
}
@ -441,7 +443,9 @@ void InputManager::dispatchInput(Input::InputType type, int deviceID, int btnID,
// If only the master player can act, and this player is not the master, ignore his input
if (m_device_manager->getAssignMode() == ASSIGN && m_master_player_only && playerID != 0)
{
GUIEngine::showMasterOnlyString();
//I18N: message shown when a player that isn't game master tries to modify options that
//I18N: only the game master is allowed to
GUIEngine::showMessage(_("Only the Game Master may act at this point!"));
return;
}