#include "tile.h" // getTexturePath
#include "filesys.h"
#include "util/string.h"
+#include "subgame.h"
struct CreateWorldDestMainMenu : public CreateWorldDest
{
{}
void accepted(std::wstring name, std::string gameid)
{
- m_menu->createNewWorld(name, gameid);
+ if(!string_allowed_blacklist(wide_to_narrow(name), WORLDNAME_BLACKLISTED_CHARS))
+ m_menu->displayMessageMenu(wgettext("Cannot create world: Name contains invalid characters"));
+ else
+ m_menu->createNewWorld(name, gameid);
}
GUIMainMenu *m_menu;
};
return TAB_SINGLEPLAYER; // Default
}
+void GUIMainMenu::displayMessageMenu(std::wstring msg)
+{
+ (new GUIMessageMenu(env, parent, -1, menumgr, msg))->drop();
+}
\ No newline at end of file
void createNewWorld(std::wstring name, std::string gameid);
void deleteWorld(const std::vector<std::string> &paths);
int getTab();
+ void displayMessageMenu(std::wstring msg);
private:
MainMenuData *m_data;
return true;
}
+/*
+ Checks if a string contains no blacklisted characters (opposite
+ function of string_allowed())
+*/
+inline bool string_allowed_blacklist(const std::string & s, const std::string & blacklisted_chars)
+{
+ for(unsigned int i = 0; i < s.length(); i++)
+ {
+ bool invalid = false;
+ for(unsigned int j = 0; j < blacklisted_chars.length(); j++)
+ {
+ if(s[i] == blacklisted_chars[j])
+ {
+ invalid = true;
+ break;
+ }
+ }
+ if(invalid)
+ return false;
+ }
+ return true;
+}
+
/*
Forcefully wraps string into rows using \n
(no word wrap, used for showing paths in gui)