Added the option to show an error ingame if deprecated WML is being used.

NOTE some versions of Visual Studio (including 6) have a broken
std::getline implementation see

http://support.microsoft.com/default.aspx?scid=kb;EN-US;q240015 when

this compier is used an error will be generated (not really test but
should work.)
This commit is contained in:
Mark de Wever 2007-03-11 15:32:28 +00:00
parent d71f9fb723
commit 145084823b
6 changed files with 91 additions and 0 deletions

View file

@ -39,6 +39,7 @@ Version 1.3.1+svn:
* remove some old backward compatibility support
* user interface:
* new sounds for user interface events
* added the option to show warnings about deprecated WML usage
* misceleanous bug fixes
* an friendly healer hill now stop poisoned unit to lose HP
* a unit that dies while attacking will now correctly play it's own death

View file

@ -19,6 +19,8 @@ Version 1.3.1+svn:
* User interface:
* Interface actions such as pressing a button, toggling a checkbox or
opening a menu (among others) will now emit small sounds.
* If deprecated WML is being encountered and error message will be shown,
this way creators of WML code can be easier informed about the problems.
* Language and translations
* Updated translations: Bulgarian, Czech, Danish, Dutch, German, Italian,
Norwegian, Portuguese (Brazil).

View file

@ -33,6 +33,7 @@
#include "gettext.hpp"
#include "variable.hpp"
#include "serialization/string_utils.hpp"
#include "wesconfig.h"
#include <cstdlib>
#include <deque>
@ -95,6 +96,68 @@ message_dialog::~message_dialog()
{
}
// std::getline might be broken in Visual Studio so show a warning
#ifdef _MSC_VER
#warning your compiler's std::getline might be broken see http://support.microsoft.com/default.aspx?scid=kb;EN-US;q240015
#endif
/**
* shows the errors encountered in WML thusfar, to avoid a lot of the same messages
* to be shown, identical messages are shown once with the between braces the number
* of times that message was encountered. The order in which the messages are shown
* does not need to be the order in which these messages are encountered.
* Messages are always written to std::cerr
*/
void show_wml_errors()
{
// Get all unique messages in messages with the number of encounters for
// these messages
std::map<std::string, int> messages;
while(true) {
std::string msg;
std::getline(lg::wml_error, msg);
if(lg::wml_error.eof()) {
break;
}
if(msg == "") {
continue;
}
if(messages.find(msg) == messages.end()) {
messages[msg] = 1;
} else {
messages[msg]++;
}
}
// make sure the eof flag is cleared otherwise no new messages are shown
lg::wml_error.clear();
// show the messages collected
std::string caption = "Deprecated WML found";
for(std::map<std::string, int>::const_iterator itor = messages.begin();
itor != messages.end(); ++itor) {
std::stringstream msg;
msg << itor->first;
if(itor->second > 1) {
msg << " (" << itor->second << ")";
}
if(WML_ERROR_DIALOG == 1) {
// show in a dialog
gui::dialog msg_dlg(*screen, caption, msg.str(), gui::OK_ONLY);
msg_dlg.show(-1 ,-1);
} else {
// show as chat message
screen->add_chat_message(caption, 0, msg.str(), display::MESSAGE_PUBLIC, false);
}
std::cerr << caption << ": " << msg << '\n';
}
}
} //end anonymous namespace
namespace game_events {
@ -2346,6 +2409,11 @@ bool pump()
result = true;
++i.first;
}
// dialogs can only be shown if the display is not locked
if(! screen->update_locked()) {
show_wml_errors();
}
}
return result;

View file

@ -124,4 +124,6 @@ void scope_logger::do_indent() const
output_ << " ";
}
std::stringstream wml_error;
} // namespace lg

View file

@ -55,6 +55,16 @@ public:
void do_indent() const;
};
/**
* Use this logger to send errors due to deprecated WML the preferred format is
* xxx is deprecated, support will be removed in version X. or
* xxx is deprecated, support has been removed in version X.
*
* After every wml event the errors are shown to the user so they can inform
* the campaign maintainer
*/
extern std::stringstream wml_error;
} // namespace lg
#define log_scope(a) lg::scope_logger scope_logging_object__(lg::general, a);

View file

@ -12,4 +12,12 @@
# endif
#endif
/**
* WML errors can be shown in 2 ways, as dialog or as chat message
* if WML_ERROR_DIALOG == 1 it's shown as dialog else as chat message
* for development versions the dialog should be used for the stable
* releases the chat messages
*/
#define WML_ERROR_DIALOG 1
#endif