mirror of
https://github.com/glest/glest-source.git
synced 2025-09-29 00:48:58 +02:00
bugfixes for loading saved games with bad data or wrong game version
This commit is contained in:
@@ -6183,7 +6183,7 @@ void Game::loadGame(string name,Program *programPtr,bool isMasterserverMode,cons
|
|||||||
if(gameVer != glestVersionString && checkVersionComptability(gameVer, glestVersionString) == false) {
|
if(gameVer != glestVersionString && checkVersionComptability(gameVer, glestVersionString) == false) {
|
||||||
char szBuf[8096]="";
|
char szBuf[8096]="";
|
||||||
snprintf(szBuf,8096,lang.get("SavedGameBadVersion").c_str(),gameVer.c_str(),glestVersionString.c_str());
|
snprintf(szBuf,8096,lang.get("SavedGameBadVersion").c_str(),gameVer.c_str(),glestVersionString.c_str());
|
||||||
throw megaglest_runtime_error(szBuf);
|
throw megaglest_runtime_error(szBuf,true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Found saved game version that matches your application version: [%s] --> [%s]\n",gameVer.c_str(),glestVersionString.c_str());
|
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Found saved game version that matches your application version: [%s] --> [%s]\n",gameVer.c_str(),glestVersionString.c_str());
|
||||||
@@ -6244,7 +6244,7 @@ void Game::loadGame(string name,Program *programPtr,bool isMasterserverMode,cons
|
|||||||
if(gameVer != glestVersionString && checkVersionComptability(gameVer, glestVersionString) == false) {
|
if(gameVer != glestVersionString && checkVersionComptability(gameVer, glestVersionString) == false) {
|
||||||
char szBuf[8096]="";
|
char szBuf[8096]="";
|
||||||
snprintf(szBuf,8096,lang.get("SavedGameBadVersion").c_str(),gameVer.c_str(),glestVersionString.c_str());
|
snprintf(szBuf,8096,lang.get("SavedGameBadVersion").c_str(),gameVer.c_str(),glestVersionString.c_str());
|
||||||
throw megaglest_runtime_error(szBuf);
|
throw megaglest_runtime_error(szBuf,true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Found saved game version that matches your application version: [%s] --> [%s]\n",gameVer.c_str(),glestVersionString.c_str());
|
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Found saved game version that matches your application version: [%s] --> [%s]\n",gameVer.c_str(),glestVersionString.c_str());
|
||||||
|
@@ -121,6 +121,10 @@ MenuStateLoadGame::MenuStateLoadGame(Program *program, MainMenu *mainMenu):
|
|||||||
listFiles();
|
listFiles();
|
||||||
slotsScrollBar.setElementCount(filenames.size());
|
slotsScrollBar.setElementCount(filenames.size());
|
||||||
|
|
||||||
|
mainMessageBox.registerGraphicComponent(containerName,"mainMessageBox");
|
||||||
|
mainMessageBox.init(lang.get("Ok"),450);
|
||||||
|
mainMessageBox.setEnabled(false);
|
||||||
|
|
||||||
GraphicComponent::applyAllCustomProperties(containerName);
|
GraphicComponent::applyAllCustomProperties(containerName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -183,6 +187,8 @@ void MenuStateLoadGame::reloadUI() {
|
|||||||
deleteButton.setText(lang.get("Delete"));
|
deleteButton.setText(lang.get("Delete"));
|
||||||
loadButton.setText(lang.get("LoadGame"));
|
loadButton.setText(lang.get("LoadGame"));
|
||||||
|
|
||||||
|
mainMessageBox.init(lang.get("Ok"),450);
|
||||||
|
|
||||||
GraphicComponent::reloadFontsForRegisterGraphicComponents(containerName);
|
GraphicComponent::reloadFontsForRegisterGraphicComponents(containerName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -191,6 +197,15 @@ void MenuStateLoadGame::mouseClick(int x, int y, MouseButton mouseButton){
|
|||||||
CoreData &coreData= CoreData::getInstance();
|
CoreData &coreData= CoreData::getInstance();
|
||||||
SoundRenderer &soundRenderer= SoundRenderer::getInstance();
|
SoundRenderer &soundRenderer= SoundRenderer::getInstance();
|
||||||
|
|
||||||
|
if(mainMessageBox.getEnabled()) {
|
||||||
|
int button= 0;
|
||||||
|
if(mainMessageBox.mouseClick(x, y, button)) {
|
||||||
|
mainMessageBox.setEnabled(false);
|
||||||
|
|
||||||
|
Lang &lang= Lang::getInstance();
|
||||||
|
mainMessageBox.init(lang.get("Ok"),450);
|
||||||
|
}
|
||||||
|
}
|
||||||
if(abortButton.mouseClick(x, y)) {
|
if(abortButton.mouseClick(x, y)) {
|
||||||
soundRenderer.playFx(coreData.getClickSoundB());
|
soundRenderer.playFx(coreData.getClickSoundB());
|
||||||
mainMenu->setState(new MenuStateRoot(program, mainMenu));
|
mainMenu->setState(new MenuStateRoot(program, mainMenu));
|
||||||
@@ -245,7 +260,12 @@ void MenuStateLoadGame::mouseClick(int x, int y, MouseButton mouseButton){
|
|||||||
snprintf(szBuf,8096,lang.get("LoadGameLoadingFile","",true).c_str(),filename.c_str());
|
snprintf(szBuf,8096,lang.get("LoadGameLoadingFile","",true).c_str(),filename.c_str());
|
||||||
console.addLineOnly(szBuf);
|
console.addLineOnly(szBuf);
|
||||||
|
|
||||||
|
try {
|
||||||
Game::loadGame(filename,program,false);
|
Game::loadGame(filename,program,false);
|
||||||
|
}
|
||||||
|
catch(const megaglest_runtime_error &ex) {
|
||||||
|
showMessageBox(ex.what(), lang.get("Notice"), true);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//mainMenu->setState(new MenuStateRoot(program, mainMenu));
|
//mainMenu->setState(new MenuStateRoot(program, mainMenu));
|
||||||
@@ -389,6 +409,9 @@ void MenuStateLoadGame::render(){
|
|||||||
renderer.renderTextureQuad(550,slotLinesYBase-300+slotsLineHeight,400,300,previewTexture,1.0f);
|
renderer.renderTextureQuad(550,slotLinesYBase-300+slotsLineHeight,400,300,previewTexture,1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(mainMessageBox.getEnabled()) {
|
||||||
|
renderer.renderMessageBox(&mainMessageBox);
|
||||||
|
}
|
||||||
|
|
||||||
renderer.renderConsole(&console,false,false);
|
renderer.renderConsole(&console,false,false);
|
||||||
if(program != NULL) program->renderProgramMsgBox();
|
if(program != NULL) program->renderProgramMsgBox();
|
||||||
@@ -423,4 +446,19 @@ void MenuStateLoadGame::keyDown(SDL_KeyboardEvent key) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MenuStateLoadGame::showMessageBox(const string &text, const string &header, bool toggle) {
|
||||||
|
if(toggle == false) {
|
||||||
|
mainMessageBox.setEnabled(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(mainMessageBox.getEnabled() == false) {
|
||||||
|
mainMessageBox.setText(text);
|
||||||
|
mainMessageBox.setHeader(header);
|
||||||
|
mainMessageBox.setEnabled(true);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
mainMessageBox.setEnabled(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}}//end namespace
|
}}//end namespace
|
||||||
|
@@ -45,6 +45,8 @@ private:
|
|||||||
|
|
||||||
GraphicLine lines[2];
|
GraphicLine lines[2];
|
||||||
|
|
||||||
|
GraphicMessageBox mainMessageBox;
|
||||||
|
|
||||||
string saveGameDir;
|
string saveGameDir;
|
||||||
int slotLinesYBase;
|
int slotLinesYBase;
|
||||||
int slotsLineHeight;
|
int slotsLineHeight;
|
||||||
@@ -61,10 +63,14 @@ public:
|
|||||||
virtual void keyDown(SDL_KeyboardEvent key);
|
virtual void keyDown(SDL_KeyboardEvent key);
|
||||||
|
|
||||||
void reloadUI();
|
void reloadUI();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void clearSlots();
|
void clearSlots();
|
||||||
void deleteSlot(int i);
|
void deleteSlot(int i);
|
||||||
void listFiles();
|
void listFiles();
|
||||||
|
|
||||||
|
void showMessageBox(const string &text, const string &header, bool toggle);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@@ -4179,7 +4179,7 @@ Unit * Unit::loadGame(const XmlNode *rootNode, GameSettings *settings, Faction *
|
|||||||
// int deadCount;
|
// int deadCount;
|
||||||
result->deadCount = unitNode->getAttribute("deadCount")->getIntValue();
|
result->deadCount = unitNode->getAttribute("deadCount")->getIntValue();
|
||||||
// float progress; //between 0 and 1
|
// float progress; //between 0 and 1
|
||||||
result->progress = unitNode->getAttribute("progress")->getIntValue();
|
result->progress = unitNode->getAttribute("progress")->getFloatValue();
|
||||||
// float lastAnimProgress; //between 0 and 1
|
// float lastAnimProgress; //between 0 and 1
|
||||||
result->lastAnimProgress = unitNode->getAttribute("lastAnimProgress")->getFloatValue();
|
result->lastAnimProgress = unitNode->getAttribute("lastAnimProgress")->getFloatValue();
|
||||||
// float animProgress; //between 0 and 1
|
// float animProgress; //between 0 and 1
|
||||||
|
Reference in New Issue
Block a user