2010-01-25 14:01:22 +01:00
|
|
|
#include <unistd.h> /* unlink */
|
|
|
|
|
|
|
|
#include <C64.h>
|
2010-01-29 07:35:40 +01:00
|
|
|
#include <utils.hh>
|
2010-01-25 14:01:22 +01:00
|
|
|
|
|
|
|
#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};
|
|
|
|
static const char *prg_exts[] = {".prg",".PRG", ".p00", ".P00", NULL};
|
|
|
|
|
|
|
|
class DiscMenu;
|
|
|
|
|
|
|
|
class DiscView : public GuiView
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
DiscView();
|
|
|
|
|
|
|
|
~DiscView();
|
|
|
|
|
2010-02-28 11:06:59 +01:00
|
|
|
void pushEvent(event_t ev);
|
2010-01-25 14:01:22 +01:00
|
|
|
|
|
|
|
void loadGameInfo(const char *what);
|
|
|
|
|
|
|
|
void setDirectory(const char *path);
|
|
|
|
|
|
|
|
void runStartSequence(bool what);
|
|
|
|
|
2010-02-24 21:25:34 +01:00
|
|
|
void viewPushCallback();
|
|
|
|
|
2010-01-25 14:01:22 +01:00
|
|
|
/* Inherited */
|
|
|
|
void runLogic();
|
|
|
|
|
|
|
|
void draw(SDL_Surface *where);
|
|
|
|
|
|
|
|
DiscMenu *menu;
|
|
|
|
GameInfoBox *gameInfo;
|
|
|
|
};
|
|
|
|
|
2010-01-30 17:49:37 +01:00
|
|
|
class SaveScreenshot : public TimeoutHandler
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
SaveScreenshot() : TimeoutHandler()
|
|
|
|
{
|
|
|
|
/* ~45 seconds from now */
|
2010-08-15 14:11:23 +02:00
|
|
|
TimerController::controller->arm(this, 45000);
|
2010-01-30 17:49:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void timeoutCallback()
|
|
|
|
{
|
|
|
|
if (!Gui::gui->cur_gameInfo->screenshot)
|
2010-03-13 09:55:57 +01:00
|
|
|
{
|
2010-03-21 13:52:32 +01:00
|
|
|
if (Gui::gui->is_active)
|
|
|
|
{
|
|
|
|
/* Rearm if we are in the GUI */
|
2010-08-15 14:11:23 +02:00
|
|
|
TimerController::controller->arm(this, 10000);
|
2010-03-21 13:52:32 +01:00
|
|
|
return;
|
|
|
|
}
|
2010-01-30 20:03:10 +01:00
|
|
|
Gui::gui->cur_gameInfo->setScreenshot(TheC64->TheDisplay->SurfaceFromC64Display());
|
2010-03-13 09:55:57 +01:00
|
|
|
Gui::gui->updateGameInfo(new GameInfo(Gui::gui->cur_gameInfo));
|
|
|
|
}
|
2010-01-30 17:49:37 +01:00
|
|
|
|
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
};
|
2010-01-25 14:01:22 +01:00
|
|
|
|
2010-03-14 13:15:58 +01:00
|
|
|
class StartGameListener : public TimeoutHandler
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
StartGameListener()
|
|
|
|
{
|
2011-06-02 22:50:48 +02:00
|
|
|
|
2010-03-14 13:15:58 +01:00
|
|
|
Gui::gui->status_bar->queueMessage("Resetting the C64");
|
|
|
|
TheC64->Reset();
|
2010-08-15 14:11:23 +02:00
|
|
|
TimerController::controller->arm(this, 4500);
|
2010-03-14 13:15:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void timeoutCallback()
|
|
|
|
{
|
|
|
|
Gui::gui->status_bar->queueMessage("Invoking the load sequence");
|
|
|
|
TheC64->startFakeKeySequence("\nLOAD \"*\",8,1\nRUN\n");
|
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-01-25 14:01:22 +01:00
|
|
|
class DiscMenu : public FileBrowser, TimeoutHandler
|
|
|
|
{
|
|
|
|
friend class DiscView;
|
|
|
|
|
|
|
|
public:
|
|
|
|
DiscMenu(Font *font) :
|
|
|
|
FileBrowser(game_exts, font), TimeoutHandler()
|
|
|
|
{
|
|
|
|
this->runStartSequence = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
~DiscMenu()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void selectCallback(int which)
|
|
|
|
{
|
|
|
|
const char *fileName = this->pp_msgs[this->cur_sel];
|
|
|
|
|
2010-01-30 09:06:32 +01:00
|
|
|
/* If we selected a directory, just take the next one */
|
|
|
|
if (fileName[0] == '[')
|
|
|
|
{
|
|
|
|
this->pushDirectory(fileName);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-01-25 16:23:00 +01:00
|
|
|
snprintf(Gui::gui->np->DrivePath[0], sizeof(Gui::gui->np->DrivePath[0]),
|
2010-01-30 09:06:32 +01:00
|
|
|
"%s/%s", this->cur_path_prefix, fileName);
|
2010-01-25 14:01:22 +01:00
|
|
|
|
|
|
|
if (ext_matches_list(fileName, prg_exts)) {
|
2010-01-30 09:17:42 +01:00
|
|
|
char *tmp_filename;
|
2010-01-25 14:01:22 +01:00
|
|
|
FILE *src, *dst;
|
|
|
|
|
2010-01-30 09:17:42 +01:00
|
|
|
tmp_filename = (char *)xmalloc(strlen(Gui::gui->tmp_path) + 4);
|
|
|
|
sprintf(tmp_filename, "%s/a", Gui::gui->tmp_path);
|
2010-01-25 14:01:22 +01:00
|
|
|
|
|
|
|
/* 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-30 09:17:42 +01:00
|
|
|
free(tmp_filename);
|
2010-01-25 14:01:22 +01:00
|
|
|
}
|
|
|
|
|
2010-08-15 14:11:23 +02:00
|
|
|
TimerController::controller->disarm(this);
|
2010-01-25 14:01:22 +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-30 17:49:37 +01:00
|
|
|
|
2010-01-25 14:01:22 +01:00
|
|
|
Gui::gui->popView();
|
|
|
|
|
|
|
|
if (this->runStartSequence)
|
2010-01-25 16:23:00 +01:00
|
|
|
{
|
2010-01-30 17:49:37 +01:00
|
|
|
/* Timeout and save the screenshot if there isn't one */
|
|
|
|
new SaveScreenshot();
|
2010-03-14 13:15:58 +01:00
|
|
|
/* And the start sequence */
|
|
|
|
new StartGameListener();
|
2010-01-30 17:49:37 +01:00
|
|
|
|
2010-01-25 16:23:00 +01:00
|
|
|
Gui::gui->exitMenu();
|
|
|
|
}
|
2010-01-25 14:01:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void hoverCallback(int which)
|
|
|
|
{
|
2010-08-15 14:11:23 +02:00
|
|
|
TimerController::controller->arm(this, 350);
|
2010-01-25 14:01:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void timeoutCallback()
|
|
|
|
{
|
|
|
|
Gui::gui->dv->loadGameInfo(this->pp_msgs[this->cur_sel]);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void escapeCallback(int which)
|
|
|
|
{
|
2010-08-15 14:11:23 +02:00
|
|
|
TimerController::controller->disarm(this);
|
2010-01-25 14:01:22 +01:00
|
|
|
Gui::gui->popView();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool runStartSequence;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
DiscView::DiscView() : GuiView()
|
|
|
|
{
|
|
|
|
this->menu = new DiscMenu(Gui::gui->default_font);
|
|
|
|
this->gameInfo = new GameInfoBox(Gui::gui->default_font);
|
|
|
|
}
|
|
|
|
|
|
|
|
DiscView::~DiscView()
|
|
|
|
{
|
|
|
|
delete this->menu;
|
|
|
|
delete this->gameInfo;
|
|
|
|
}
|
|
|
|
|
2010-02-24 21:25:34 +01:00
|
|
|
void DiscView::viewPushCallback()
|
|
|
|
{
|
|
|
|
this->gameInfo->setGameInfo(NULL);
|
|
|
|
}
|
|
|
|
|
2010-01-25 14:01:22 +01:00
|
|
|
void DiscView::loadGameInfo(const char *what)
|
|
|
|
{
|
2010-02-24 21:19:37 +01:00
|
|
|
this->gameInfo->loadGameInfo(what, Gui::gui->metadata_base_path);
|
2010-01-25 14:01:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void DiscView::setDirectory(const char *path)
|
|
|
|
{
|
|
|
|
this->menu->setDirectory(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DiscView::runStartSequence(bool what)
|
|
|
|
{
|
|
|
|
this->menu->runStartSequence = what;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DiscView::runLogic()
|
|
|
|
{
|
|
|
|
this->menu->runLogic();
|
|
|
|
}
|
|
|
|
|
2010-02-28 11:06:59 +01:00
|
|
|
void DiscView::pushEvent(event_t ev)
|
2010-01-25 14:01:22 +01:00
|
|
|
{
|
|
|
|
this->menu->pushEvent(ev);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DiscView::draw(SDL_Surface *where)
|
|
|
|
{
|
|
|
|
SDL_Rect dst;
|
|
|
|
|
|
|
|
/* Blit the backgrounds */
|
|
|
|
dst = (SDL_Rect){20,45,300,400};
|
|
|
|
SDL_BlitSurface(Gui::gui->main_menu_bg, NULL, where, &dst);
|
|
|
|
|
|
|
|
dst = (SDL_Rect){350,13,0,0};
|
|
|
|
SDL_BlitSurface(Gui::gui->disc_info, NULL, where, &dst);
|
|
|
|
|
|
|
|
this->menu->draw(where, 50, 70, 280, 375);
|
2010-02-23 21:10:45 +01:00
|
|
|
this->gameInfo->draw(where, 390, 55, 242, 447);
|
2010-01-25 14:01:22 +01:00
|
|
|
}
|