2009-12-13 11:02:27 +01:00
|
|
|
#include "menu.hh"
|
2009-12-15 19:37:34 +01:00
|
|
|
#include "file_browser.hh"
|
2009-12-19 14:20:15 +01:00
|
|
|
#include "game_info.hh"
|
2009-12-15 19:37:34 +01:00
|
|
|
|
|
|
|
static const char *game_exts[] = {".d64", ".D64", ".t64", ".T64",
|
|
|
|
".prg",".PRG", ".p00", ".P00", NULL};
|
2009-12-13 11:02:27 +01:00
|
|
|
|
2009-12-19 14:20:15 +01:00
|
|
|
class DiscMenu;
|
|
|
|
class GameInfoBox;
|
|
|
|
|
|
|
|
class DiscView : public GuiView
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
DiscView();
|
|
|
|
|
|
|
|
~DiscView();
|
|
|
|
|
|
|
|
void pushEvent(SDL_Event *ev);
|
|
|
|
|
|
|
|
void loadGameInfo(const char *what);
|
|
|
|
|
|
|
|
void setDirectory(const char *path);
|
|
|
|
|
|
|
|
/* Inherited */
|
|
|
|
void runLogic();
|
|
|
|
|
|
|
|
void draw(SDL_Surface *where);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
DiscMenu *menu;
|
|
|
|
GameInfoBox *gameInfo;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-12-16 18:47:03 +01:00
|
|
|
class DiscMenu : public FileBrowser, TimeoutHandler
|
2009-12-13 11:02:27 +01:00
|
|
|
{
|
|
|
|
friend class DiscView;
|
|
|
|
|
|
|
|
public:
|
2009-12-28 09:46:18 +01:00
|
|
|
DiscMenu(Font *font) :
|
|
|
|
FileBrowser(game_exts, font), TimeoutHandler()
|
2009-12-13 11:02:27 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
~DiscMenu()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void selectCallback(int which)
|
|
|
|
{
|
|
|
|
printf("entry %d selected: %s\n", which, this->pp_msgs[which]);
|
2009-12-16 18:47:03 +01:00
|
|
|
Gui::gui->timerController->disarm(this);
|
2009-12-13 11:02:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void hoverCallback(int which)
|
|
|
|
{
|
2009-12-19 14:25:46 +01:00
|
|
|
Gui::gui->timerController->arm(this, 5);
|
2009-12-16 18:47:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void timeoutCallback()
|
|
|
|
{
|
|
|
|
printf("Hovering timed out over %s\n",
|
|
|
|
this->pp_msgs[this->cur_sel]);
|
2009-12-28 09:46:18 +01:00
|
|
|
Gui::gui->dv->loadGameInfo(this->pp_msgs[this->cur_sel]);
|
2009-12-13 11:02:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void escapeCallback(int which)
|
|
|
|
{
|
2009-12-16 18:47:03 +01:00
|
|
|
Gui::gui->timerController->disarm(this);
|
2009-12-13 11:02:27 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-12-19 14:20:15 +01:00
|
|
|
class GameInfoBox : public Menu
|
2009-12-13 11:02:27 +01:00
|
|
|
{
|
|
|
|
public:
|
2009-12-19 14:20:15 +01:00
|
|
|
GameInfoBox(Font *font) : Menu(font)
|
2009-12-13 11:02:27 +01:00
|
|
|
{
|
2009-12-19 14:20:15 +01:00
|
|
|
this->gi = NULL;
|
|
|
|
memset(this->gi_messages, 0, sizeof(this->gi_messages));
|
2010-01-16 08:11:17 +01:00
|
|
|
this->setSelectedBackground(NULL, NULL, NULL, NULL, NULL, NULL);
|
2009-12-13 11:02:27 +01:00
|
|
|
}
|
|
|
|
|
2009-12-19 14:20:15 +01:00
|
|
|
void loadGameInfo(const char *what)
|
2009-12-13 11:02:27 +01:00
|
|
|
{
|
2009-12-19 14:25:46 +01:00
|
|
|
this->setText(NULL);
|
2009-12-19 14:20:15 +01:00
|
|
|
memset(this->gi_messages, 0, sizeof(this->gi_messages));
|
|
|
|
|
2009-12-19 14:25:46 +01:00
|
|
|
/* Reset the current game info */
|
2009-12-19 14:20:15 +01:00
|
|
|
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;
|
2009-12-19 14:25:46 +01:00
|
|
|
this->setText(this->gi_messages);
|
2009-12-19 14:20:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
free(tmp);
|
2009-12-13 11:02:27 +01:00
|
|
|
}
|
|
|
|
|
2009-12-19 14:20:15 +01:00
|
|
|
virtual void selectCallback(int which)
|
2009-12-13 11:02:27 +01:00
|
|
|
{
|
|
|
|
}
|
2009-12-19 14:20:15 +01:00
|
|
|
virtual void hoverCallback(int which)
|
2009-12-13 11:02:27 +01:00
|
|
|
{
|
|
|
|
}
|
2009-12-19 14:20:15 +01:00
|
|
|
virtual void escapeCallback(int which)
|
2009-12-13 11:02:27 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-12-19 14:20:15 +01:00
|
|
|
void draw(SDL_Surface *where, int x, int y, int w, int h)
|
2009-12-13 11:02:27 +01:00
|
|
|
{
|
2009-12-19 14:20:15 +01:00
|
|
|
if (!this->gi)
|
|
|
|
return;
|
|
|
|
if (!this->gi->screenshot)
|
|
|
|
return;
|
2009-12-13 11:02:27 +01:00
|
|
|
|
2009-12-19 14:20:15 +01:00
|
|
|
SDL_Rect dst;
|
2009-12-13 11:02:27 +01:00
|
|
|
|
2009-12-19 14:20:15 +01:00
|
|
|
/* 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);
|
2009-12-13 11:02:27 +01:00
|
|
|
|
2009-12-19 14:20:15 +01:00
|
|
|
Menu::draw(where, x, y + this->gi->screenshot->h + 10,
|
|
|
|
w, h - this->gi->screenshot->h - 10);
|
2009-12-13 11:02:27 +01:00
|
|
|
}
|
|
|
|
|
2009-12-19 14:20:15 +01:00
|
|
|
private:
|
|
|
|
const char *gi_messages[6];
|
|
|
|
GameInfo *gi;
|
2009-12-13 11:02:27 +01:00
|
|
|
};
|
2009-12-19 14:20:15 +01:00
|
|
|
|
|
|
|
DiscView::DiscView() : GuiView()
|
|
|
|
{
|
2010-01-16 08:11:17 +01:00
|
|
|
this->menu = new DiscMenu(Gui::gui->default_font);
|
|
|
|
this->gameInfo = new GameInfoBox(Gui::gui->default_font);
|
2009-12-19 14:20:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
DiscView::~DiscView()
|
|
|
|
{
|
|
|
|
delete this->menu;
|
|
|
|
delete this->gameInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DiscView::loadGameInfo(const char *what)
|
|
|
|
{
|
|
|
|
this->gameInfo->loadGameInfo(what);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DiscView::setDirectory(const char *path)
|
|
|
|
{
|
|
|
|
this->menu->setDirectory(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DiscView::runLogic()
|
|
|
|
{
|
|
|
|
this->menu->runLogic();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DiscView::pushEvent(SDL_Event *ev)
|
|
|
|
{
|
|
|
|
this->menu->pushEvent(ev);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DiscView::draw(SDL_Surface *where)
|
|
|
|
{
|
|
|
|
SDL_Rect dst;
|
|
|
|
|
|
|
|
/* Blit the backgrounds */
|
|
|
|
dst = (SDL_Rect){20,45,300,400};
|
2010-01-06 08:48:42 +01:00
|
|
|
SDL_BlitSurface(Gui::gui->main_menu_bg, NULL, where, &dst);
|
2009-12-19 14:20:15 +01:00
|
|
|
|
|
|
|
dst = (SDL_Rect){350,13,0,0};
|
2010-01-06 08:48:42 +01:00
|
|
|
SDL_BlitSurface(Gui::gui->disc_info, NULL, where, &dst);
|
2009-12-19 14:20:15 +01:00
|
|
|
|
|
|
|
this->menu->draw(where, 50, 70, 280, 375);
|
|
|
|
this->gameInfo->draw(where, 360, 55, 262, 447);
|
|
|
|
}
|