frodo-wii/game_info_box.hh

103 lines
2.1 KiB
C++
Raw Normal View History

#ifndef _GAME_INFO_BOX_H_
#define _GAME_INFO_BOX_H_
2010-01-16 13:42:28 +01:00
#include "menu.hh"
#include "game_info.hh"
class GameInfoBox : public Menu
{
public:
GameInfoBox(Font *font) : Menu(font)
{
this->gi = NULL;
memset(this->gi_messages, 0, sizeof(this->gi_messages));
this->setSelectedBackground(NULL, NULL, NULL, NULL, NULL, NULL);
}
void setGameInfo(GameInfo *gi)
{
/* Make a copy */
if (this->gi)
delete this->gi;
2010-01-16 13:42:28 +01:00
this->gi = new GameInfo(gi);
this->updateMessages();
2010-01-16 13:42:28 +01:00
}
void loadGameInfo(const char *what)
{
/* Reset the current game info */
if (this->gi)
{
delete this->gi;
this->gi = NULL;
}
/* No need to do this for directories or the special "None" field */
if ( !(strcmp(what, "None") == 0 ||
what[0] == '[') )
{
size_t len = strlen(Gui::gui->metadata_base_path) + strlen(what) + 6;
char *tmp = (char*)xmalloc(len);
2010-01-16 13:42:28 +01:00
sprintf(tmp, "%s/%s.lra", Gui::gui->metadata_base_path, what);
2010-01-16 13:42:28 +01:00
/* Might return NULL, but that's OK */
this->gi = GameInfo::loadFromFile(tmp);
free(tmp);
2010-01-16 13:42:28 +01:00
}
this->updateMessages();
2010-01-16 13:42:28 +01:00
}
virtual void selectCallback(int which)
{
}
virtual void hoverCallback(int which)
{
}
virtual void escapeCallback(int which)
{
}
void draw(SDL_Surface *where, int x, int y, int w, int h)
{
if (!this->gi)
return;
if (this->gi->screenshot)
{
SDL_Rect dst;
/* Blit the screenshot */
dst = (SDL_Rect){x + w / 2 - this->gi->screenshot->w / 2, y, w, h};
SDL_BlitSurface(this->gi->screenshot, NULL, where, &dst);
Menu::draw(where, x, y + this->gi->screenshot->h + 10,
w, h - this->gi->screenshot->h - 10);
}
else
Menu::draw(where, x, y + 10, w, h - 10);
}
2010-01-16 13:42:28 +01:00
void updateMessages()
{
this->setText(NULL);
memset(this->gi_messages, 0, sizeof(this->gi_messages));
2010-01-16 13:42:28 +01:00
this->gi_messages[0] = "Game:";
this->gi_messages[1] = " ";
this->gi_messages[2] = "Author:";
this->gi_messages[3] = " ";
if (this->gi)
{
this->gi_messages[1] = this->gi->name ? this->gi->name : " ";
this->gi_messages[3] = this->gi->author ? this->gi->author : " ";
}
2010-01-16 13:42:28 +01:00
this->setText(this->gi_messages);
2010-01-16 13:42:28 +01:00
}
const char *gi_messages[6];
GameInfo *gi;
};
#endif /* _GAME_INFO_BOX_H_ */