mirror of
https://github.com/Oibaf66/frodo-wii.git
synced 2024-11-22 19:39:24 +01:00
Refactor game info: Move the box out
This commit is contained in:
parent
fe57609c81
commit
7420b26939
@ -1,6 +1,7 @@
|
||||
#include "menu.hh"
|
||||
#include "file_browser.hh"
|
||||
#include "game_info.hh"
|
||||
#include "game_info_box.hh"
|
||||
|
||||
static const char *game_exts[] = {".d64", ".D64", ".t64", ".T64",
|
||||
".prg",".PRG", ".p00", ".P00", NULL};
|
||||
@ -67,85 +68,10 @@ public:
|
||||
virtual void escapeCallback(int which)
|
||||
{
|
||||
Gui::gui->timerController->disarm(this);
|
||||
Gui::gui->popView();
|
||||
}
|
||||
};
|
||||
|
||||
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 loadGameInfo(const char *what)
|
||||
{
|
||||
this->setText(NULL);
|
||||
memset(this->gi_messages, 0, sizeof(this->gi_messages));
|
||||
|
||||
/* 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] == '[')
|
||||
return;
|
||||
|
||||
size_t len = strlen(Gui::gui->metadata_base_path) + strlen(what) + 6;
|
||||
char *tmp = (char*)xmalloc(len);
|
||||
sprintf(tmp, "%s/%s.lra", Gui::gui->metadata_base_path, what);
|
||||
|
||||
/* Might return NULL, but that's OK */
|
||||
this->gi = GameInfo::loadFromFile(tmp);
|
||||
if (this->gi)
|
||||
{
|
||||
this->gi_messages[0] = "Game:";
|
||||
this->gi_messages[1] = this->gi->name;
|
||||
this->gi_messages[2] = "Author:";
|
||||
this->gi_messages[3] = this->gi->author;
|
||||
this->setText(this->gi_messages);
|
||||
}
|
||||
|
||||
free(tmp);
|
||||
}
|
||||
|
||||
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)
|
||||
return;
|
||||
|
||||
SDL_Rect dst;
|
||||
|
||||
/* Blit the backgrounds */
|
||||
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);
|
||||
}
|
||||
|
||||
private:
|
||||
const char *gi_messages[6];
|
||||
GameInfo *gi;
|
||||
};
|
||||
|
||||
DiscView::DiscView() : GuiView()
|
||||
{
|
||||
|
@ -19,6 +19,17 @@ GameInfo::GameInfo(const char *filename,
|
||||
this->screenshot = image;
|
||||
}
|
||||
|
||||
GameInfo::GameInfo(GameInfo *gi)
|
||||
{
|
||||
this->name = xstrdup(gi->name);
|
||||
this->author = xstrdup(gi->author);
|
||||
this->filename = xstrdup(gi->filename);
|
||||
this->screenshot = NULL;
|
||||
|
||||
if (gi->screenshot)
|
||||
this->screenshot = SDL_DisplayFormatAlpha(gi->screenshot);
|
||||
}
|
||||
|
||||
GameInfo::~GameInfo()
|
||||
{
|
||||
this->resetDefaults();
|
||||
|
@ -22,6 +22,8 @@ public:
|
||||
const char *author = NULL,
|
||||
SDL_Surface *image = NULL);
|
||||
|
||||
GameInfo(GameInfo *gi);
|
||||
|
||||
~GameInfo();
|
||||
|
||||
void resetDefaults();
|
||||
|
85
game_info_box.hh
Normal file
85
game_info_box.hh
Normal file
@ -0,0 +1,85 @@
|
||||
#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 */
|
||||
this->gi = new GameInfo(gi);
|
||||
}
|
||||
|
||||
void loadGameInfo(const char *what)
|
||||
{
|
||||
this->setText(NULL);
|
||||
memset(this->gi_messages, 0, sizeof(this->gi_messages));
|
||||
|
||||
/* 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] == '[')
|
||||
return;
|
||||
|
||||
size_t len = strlen(Gui::gui->metadata_base_path) + strlen(what) + 6;
|
||||
char *tmp = (char*)xmalloc(len);
|
||||
sprintf(tmp, "%s/%s.lra", Gui::gui->metadata_base_path, what);
|
||||
|
||||
/* Might return NULL, but that's OK */
|
||||
this->gi = GameInfo::loadFromFile(tmp);
|
||||
if (this->gi)
|
||||
{
|
||||
this->gi_messages[0] = "Game:";
|
||||
this->gi_messages[1] = this->gi->name;
|
||||
this->gi_messages[2] = "Author:";
|
||||
this->gi_messages[3] = this->gi->author;
|
||||
this->setText(this->gi_messages);
|
||||
}
|
||||
|
||||
free(tmp);
|
||||
}
|
||||
|
||||
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)
|
||||
return;
|
||||
|
||||
SDL_Rect dst;
|
||||
|
||||
/* Blit the backgrounds */
|
||||
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);
|
||||
}
|
||||
|
||||
private:
|
||||
const char *gi_messages[6];
|
||||
GameInfo *gi;
|
||||
};
|
Loading…
Reference in New Issue
Block a user