Add code to save the current game info (not tested)

This commit is contained in:
simon.kagstrom 2010-01-23 14:47:01 +00:00
parent baa43d1cab
commit cd1768a140
3 changed files with 39 additions and 2 deletions

View File

@ -26,7 +26,6 @@ public:
void draw(SDL_Surface *where);
protected:
DiscMenu *menu;
GameInfoBox *gameInfo;
};
@ -48,8 +47,15 @@ public:
virtual void selectCallback(int which)
{
printf("entry %d selected: %s\n", which, this->pp_msgs[which]);
const char *fileName = this->pp_msgs[this->cur_sel];
Gui::gui->timerController->disarm(this);
Gui::gui->dv->loadGameInfo(fileName);
if (Gui::gui->dv->gameInfo->gi)
Gui::gui->updateGameInfo(Gui::gui->dv->gameInfo->gi);
else
Gui::gui->updateGameInfo(new GameInfo(fileName));
}
virtual void hoverCallback(int which)

28
gui.cpp
View File

@ -85,6 +85,7 @@ Gui::Gui()
this->game_base_path = GAME_ROOT_PATH;
this->cur_gameInfo = new GameInfo();
this->gameInfoChanged = false;
this->dlg = NULL;
this->kbd = NULL;
@ -318,6 +319,33 @@ void Gui::updateGameInfo(GameInfo *gi)
panic_if(!gi, "gi must be set\n");
delete this->cur_gameInfo;
this->cur_gameInfo = gi;
this->gameInfoChanged = true;
}
void Gui::saveGameInfo()
{
struct game_info *p = this->cur_gameInfo->dump();
if (p)
{
char buf[255];
FILE *fp;
snprintf(buf, sizeof(buf), "%s/%s",
METADATA_ROOT_PATH, this->cur_gameInfo->filename);
fp = fopen(buf, "w");
if (!fp)
{
warning("Could not open %s for writing\n", buf);
return;
}
int n = fwrite((const void*)p, 1, p->sz, fp);
if (n != p->sz)
warning("Could only write %d bytes of %s\n", n, buf);
fclose(fp);
}
this->gameInfoChanged = false;
}

3
gui.hh
View File

@ -63,6 +63,8 @@ public:
void updateGameInfo(GameInfo *gi);
void saveGameInfo();
void exitMenu();
/* These are private, keep off! */
@ -113,6 +115,7 @@ public:
const char *game_base_path;
GameInfo *cur_gameInfo;
bool gameInfoChanged;
/* New preferences */
Prefs *np;