- bugfix for invalid language setting in userini

- added debug info to track down tomreyn's issue
This commit is contained in:
Mark Vejvoda 2011-12-05 00:02:32 +00:00
parent dee5b11518
commit 049b2952f2
7 changed files with 531 additions and 465 deletions

View File

@ -400,9 +400,9 @@ void GraphicListBox::setSelectedItem(string item, bool errorOnMissing){
if(iter==items.end()) {
if(errorOnMissing == true) {
for(int idx = 0; idx < items.size(); idx++) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] idx = %d items[idx] = [%s]\n",__FILE__,__FUNCTION__,__LINE__,idx,items[idx].c_str());
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] idx = %d items[idx] = [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,idx,items[idx].c_str());
}
throw runtime_error("Value not found on list box: "+item);
throw runtime_error("[" + instanceName +"] Value not found on list box: [" + item + "]");
}
}
else {

View File

@ -33,6 +33,7 @@ using namespace Shared::Platform;
namespace Glest{ namespace Game{
const char *DEFAULT_LANGUAGE = "english";
// =====================================================
// class Lang
// =====================================================
@ -47,6 +48,10 @@ Lang &Lang::getInstance() {
return lang;
}
string Lang::getDefaultLanguage() const {
return DEFAULT_LANGUAGE;
}
void Lang::loadStrings(string uselanguage, bool loadFonts,
bool fallbackToDefault) {
if(uselanguage.length() == 2) {

View File

@ -57,6 +57,8 @@ public:
string getLanguage() const { return language; }
bool isLanguageLocal(string compareLanguage) const;
bool isUTF8Language() const;
string getDefaultLanguage() const;
map<string,string> getDiscoveredLanguageList(bool searchKeyIsLangName=false);
pair<string,string> getNavtiveNameFromLanguageName(string langName);
};

View File

@ -193,6 +193,12 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu,
for(int i= 0; i < mapFiles.size(); i++){// fetch info and put map in right list
loadMapInfo(Map::getMapPath(mapFiles.at(i), "", false), &mapInfo, false);
if(GameConstants::maxPlayers+1 <= mapInfo.players) {
char szBuf[1024]="";
sprintf(szBuf,"Sorted map list [%d] does not match\ncurrent map playercount [%d] for map [%s]",GameConstants::maxPlayers+1,mapInfo.players,mapInfo.desc.c_str());
throw runtime_error(szBuf);
}
playerSortedMaps[mapInfo.players].push_back(mapFiles.at(i));
formattedPlayerSortedMaps[mapInfo.players].push_back(formatString(mapFiles.at(i)));
if(config.getString("InitialMap", "Conflict") == formattedPlayerSortedMaps[mapInfo.players].back()){

View File

@ -32,6 +32,7 @@ namespace Glest{ namespace Game{
MenuStateOptions::MenuStateOptions(Program *program, MainMenu *mainMenu):
MenuState(program, mainMenu, "config")
{
try {
containerName = "Options";
Lang &lang= Lang::getInstance();
Config &config= Config::getInstance();
@ -317,6 +318,9 @@ MenuStateOptions::MenuStateOptions(Program *program, MainMenu *mainMenu):
listBoxLang.setItems(langResults);
pair<string,string> defaultLang = Lang::getInstance().getNavtiveNameFromLanguageName(config.getString("Lang"));
if(defaultLang.first == "" && defaultLang.second == "") {
defaultLang = Lang::getInstance().getNavtiveNameFromLanguageName(Lang::getInstance().getDefaultLanguage());
}
listBoxLang.setSelectedItem(defaultLang.second + "-" + defaultLang.first);
currentLine-=lineOffset;
@ -526,6 +530,11 @@ MenuStateOptions::MenuStateOptions(Program *program, MainMenu *mainMenu):
GraphicComponent::applyAllCustomProperties(containerName);
}
catch(exception &e) {
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error loading options: %s\n",__FILE__,__FUNCTION__,__LINE__,e.what());
throw runtime_error(string("Error loading options msg: ") + e.what());
}
}
void MenuStateOptions::reloadUI() {
Lang &lang= Lang::getInstance();

View File

@ -78,6 +78,10 @@ MenuStateRoot::MenuStateRoot(Program *program, MainMenu *mainMenu):
mainMessageBox.init(lang.get("Yes"), lang.get("No"));
mainMessageBox.setEnabled(false);
errorMessageBox.registerGraphicComponent(containerName,"errorMessageBox");
errorMessageBox.init(lang.get("Ok"));
errorMessageBox.setEnabled(false);
//PopupMenu popupMenu;
std::vector<string> menuItems;
menuItems.push_back("1");
@ -111,13 +115,14 @@ void MenuStateRoot::reloadUI() {
buttonExit.setText(lang.get("Exit"));
mainMessageBox.init(lang.get("Yes"), lang.get("No"));
errorMessageBox.init(lang.get("Ok"));
console.resetFonts();
GraphicComponent::reloadFontsForRegisterGraphicComponents(containerName);
}
void MenuStateRoot::mouseClick(int x, int y, MouseButton mouseButton){
try {
CoreData &coreData= CoreData::getInstance();
SoundRenderer &soundRenderer= SoundRenderer::getInstance();
@ -126,6 +131,31 @@ void MenuStateRoot::mouseClick(int x, int y, MouseButton mouseButton){
//printf("In popup callback menuItemSelected [%s] menuIndexSelected = %d\n",result.second.c_str(),result.first);
}
//exit message box, has to be the last thing to do in this function
else if(mainMessageBox.getEnabled()){
int button= 1;
if(mainMessageBox.mouseClick(x, y, button)) {
if(button==1) {
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
soundRenderer.playFx(coreData.getClickSoundA());
program->exit();
}
else {
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
//close message box
mainMessageBox.setEnabled(false);
}
}
}
//exit message box, has to be the last thing to do in this function
else if(errorMessageBox.getEnabled()){
int button= 1;
if(mainMessageBox.mouseClick(x, y, button)) {
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
//close message box
errorMessageBox.setEnabled(false);
}
}
else if(mainMessageBox.getEnabled() == false && buttonNewGame.mouseClick(x, y)){
soundRenderer.playFx(coreData.getClickSoundB());
mainMenu->setState(new MenuStateNewGame(program, mainMenu));
@ -146,21 +176,12 @@ void MenuStateRoot::mouseClick(int x, int y, MouseButton mouseButton){
soundRenderer.playFx(coreData.getClickSoundA());
program->exit();
}
//exit message box, has to be the last thing to do in this function
else if(mainMessageBox.getEnabled()){
int button= 1;
if(mainMessageBox.mouseClick(x, y, button)) {
if(button==1) {
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
soundRenderer.playFx(coreData.getClickSoundA());
program->exit();
}
else {
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
//close message box
mainMessageBox.setEnabled(false);
}
}
catch(exception &e) {
char szBuf[1024]="";
sprintf(szBuf,"In [%s::%s Line: %d]\nError in menu event:\n%s\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,e.what());
SystemFlags::OutputDebug(SystemFlags::debugError,szBuf);
showErrorMessageBox(szBuf, "", true);
}
}
@ -174,7 +195,9 @@ void MenuStateRoot::mouseMove(int x, int y, const MouseState *ms){
if (mainMessageBox.getEnabled()) {
mainMessageBox.mouseMove(x, y);
}
if (errorMessageBox.getEnabled()) {
errorMessageBox.mouseMove(x, y);
}
}
bool MenuStateRoot::isMasterserverMode() const {
@ -251,6 +274,9 @@ void MenuStateRoot::render() {
if(mainMessageBox.getEnabled()) {
renderer.renderMessageBox(&mainMessageBox);
}
if(errorMessageBox.getEnabled()) {
renderer.renderMessageBox(&errorMessageBox);
}
if(program != NULL) program->renderProgramMsgBox();
}
@ -314,4 +340,19 @@ void MenuStateRoot::showMessageBox(const string &text, const string &header, boo
}
}
void MenuStateRoot::showErrorMessageBox(const string &text, const string &header, bool toggle){
if(!toggle){
errorMessageBox.setEnabled(false);
}
if(!errorMessageBox.getEnabled()){
errorMessageBox.setText(text);
errorMessageBox.setHeader(header);
errorMessageBox.setEnabled(true);
}
else{
errorMessageBox.setEnabled(false);
}
}
}}//end namespace

View File

@ -34,6 +34,7 @@ private:
GraphicLabel labelVersion;
GraphicMessageBox mainMessageBox;
GraphicMessageBox errorMessageBox;
PopupMenu popupMenu;
@ -47,6 +48,8 @@ public:
virtual void keyDown(SDL_KeyboardEvent key);
void showMessageBox(const string &text, const string &header, bool toggle);
void showErrorMessageBox(const string &text, const string &header, bool toggle);
virtual bool isMasterserverMode() const;
virtual void reloadUI();
};