2010-01-25 10:38:35 +01:00
|
|
|
#include <unistd.h> /* unlink */
|
|
|
|
|
2010-01-25 11:59:08 +01:00
|
|
|
#include <C64.h>
|
|
|
|
|
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"
|
2010-01-16 13:42:28 +01:00
|
|
|
#include "game_info_box.hh"
|
2010-01-25 10:38:35 +01:00
|
|
|
#include "utils.hh"
|
2009-12-15 19:37:34 +01:00
|
|
|
|
|
|
|
static const char *game_exts[] = {".d64", ".D64", ".t64", ".T64",
|
|
|
|
".prg",".PRG", ".p00", ".P00", NULL};
|
2010-01-25 10:38:35 +01:00
|
|
|
static const char *prg_exts[] = {".prg",".PRG", ".p00", ".P00", NULL};
|
2009-12-13 11:02:27 +01:00
|
|
|
|
2009-12-19 14:20:15 +01:00
|
|
|
class DiscMenu;
|
|
|
|
|
|
|
|
class DiscView : public GuiView
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
DiscView();
|
|
|
|
|
|
|
|
~DiscView();
|
|
|
|
|
|
|
|
void pushEvent(SDL_Event *ev);
|
|
|
|
|
|
|
|
void loadGameInfo(const char *what);
|
|
|
|
|
|
|
|
void setDirectory(const char *path);
|
|
|
|
|
2010-01-25 11:59:08 +01:00
|
|
|
void runStartSequence(bool what);
|
|
|
|
|
2009-12-19 14:20:15 +01:00
|
|
|
/* Inherited */
|
|
|
|
void runLogic();
|
|
|
|
|
|
|
|
void draw(SDL_Surface *where);
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2010-01-25 11:59:08 +01:00
|
|
|
this->runStartSequence = false;
|
2009-12-13 11:02:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
~DiscMenu()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void selectCallback(int which)
|
|
|
|
{
|
2010-01-23 15:47:01 +01:00
|
|
|
const char *fileName = this->pp_msgs[this->cur_sel];
|
2010-01-25 10:38:35 +01:00
|
|
|
const char *save_game = strrchr(fileName, '/');
|
|
|
|
|
|
|
|
if (!save_game)
|
|
|
|
save_game = fileName;
|
|
|
|
else
|
|
|
|
save_game = save_game + 1; /* Skip '/' */
|
|
|
|
strncpy(Gui::gui->np->DrivePath[0], fileName, sizeof(Gui::gui->np->DrivePath[0]));
|
|
|
|
|
|
|
|
if (ext_matches_list(fileName, prg_exts)) {
|
|
|
|
char tmp_filename[255];
|
|
|
|
FILE *src, *dst;
|
|
|
|
|
|
|
|
snprintf(tmp_filename, sizeof(tmp_filename), "%s/a", Gui::gui->tmp_path);
|
|
|
|
|
|
|
|
/* Clean temp dir first (we only want one file) */
|
|
|
|
unlink(tmp_filename);
|
|
|
|
|
|
|
|
src = fopen(Gui::gui->np->DrivePath[0], "r");
|
|
|
|
if (src != NULL)
|
|
|
|
{
|
|
|
|
snprintf(Gui::gui->np->DrivePath[0], sizeof(Gui::gui->np->DrivePath[0]),
|
|
|
|
"%s", Gui::gui->tmp_path);
|
|
|
|
|
|
|
|
/* Special handling of .prg: Copy to TMP_PATH and
|
|
|
|
* load that as a dir */
|
|
|
|
dst = fopen(tmp_filename, "w");
|
|
|
|
if (dst)
|
|
|
|
{
|
|
|
|
Uint8 buf[1024];
|
|
|
|
size_t v;
|
|
|
|
|
|
|
|
do {
|
|
|
|
v = fread(buf, 1, sizeof(buf), src);
|
|
|
|
fwrite(buf, 1, v, dst);
|
|
|
|
} while (v > 0);
|
|
|
|
fclose(dst);
|
|
|
|
}
|
|
|
|
fclose(src);
|
|
|
|
}
|
|
|
|
}
|
2010-01-23 15:47:01 +01:00
|
|
|
|
2009-12-16 18:47:03 +01:00
|
|
|
Gui::gui->timerController->disarm(this);
|
2010-01-23 15:47:01 +01:00
|
|
|
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));
|
2010-01-25 10:38:35 +01:00
|
|
|
Gui::gui->popView();
|
2010-01-25 11:59:08 +01:00
|
|
|
|
|
|
|
if (this->runStartSequence)
|
|
|
|
TheC64->startFakeKeySequence("\nLOAD \"*\",8,1\nRUN\n");
|
2009-12-13 11:02:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void hoverCallback(int which)
|
|
|
|
{
|
2010-01-24 09:49:52 +01:00
|
|
|
Gui::gui->timerController->arm(this, 100);
|
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);
|
2010-01-16 13:42:28 +01:00
|
|
|
Gui::gui->popView();
|
2009-12-13 11:02:27 +01:00
|
|
|
}
|
2010-01-25 11:59:08 +01:00
|
|
|
|
|
|
|
bool runStartSequence;
|
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);
|
|
|
|
}
|
|
|
|
|
2010-01-25 11:59:08 +01:00
|
|
|
void DiscView::runStartSequence(bool what)
|
|
|
|
{
|
|
|
|
this->menu->runStartSequence = what;
|
|
|
|
}
|
|
|
|
|
2009-12-19 14:20:15 +01:00
|
|
|
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);
|
|
|
|
}
|