2010-01-25 14:01:22 +01:00
|
|
|
#include "menu.hh"
|
|
|
|
#include "dialogue_box.hh"
|
|
|
|
|
2011-06-10 23:44:13 +02:00
|
|
|
extern bool usbismount;
|
2011-08-08 13:21:52 +02:00
|
|
|
extern bool smbismount;
|
2013-01-19 23:46:32 +01:00
|
|
|
extern bool sdismount;
|
2011-06-05 15:46:38 +02:00
|
|
|
|
2010-01-30 18:59:32 +01:00
|
|
|
class KeyboardTypingListener : public KeyboardListener, TimeoutHandler
|
2010-01-25 14:01:22 +01:00
|
|
|
{
|
2010-01-30 18:59:32 +01:00
|
|
|
public:
|
2010-01-25 14:01:22 +01:00
|
|
|
virtual void stringCallback(const char *str)
|
|
|
|
{
|
|
|
|
/* Remove thyself! */
|
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void keyCallback(bool shift, const char *str)
|
|
|
|
{
|
2010-01-30 18:59:32 +01:00
|
|
|
this->kc = VirtualKeyboard::kbd->stringToKeycode(str);
|
|
|
|
|
|
|
|
if (shift)
|
|
|
|
this->kc |= 0x80;
|
|
|
|
|
|
|
|
TheC64->pushKeyCode(this->kc, false);
|
|
|
|
/* Release it soon */
|
2010-08-15 14:11:23 +02:00
|
|
|
TimerController::controller->arm(this, 1);
|
2010-01-30 18:59:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void timeoutCallback()
|
|
|
|
{
|
|
|
|
TheC64->pushKeyCode(this->kc, true);
|
2010-01-25 14:01:22 +01:00
|
|
|
}
|
2010-01-30 18:59:32 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
int kc;
|
2010-01-25 14:01:22 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
class ExitListener : public DialogueListener
|
|
|
|
{
|
|
|
|
void escapeCallback(DialogueBox *which, int selected)
|
|
|
|
{
|
2010-03-10 12:20:47 +01:00
|
|
|
delete this;
|
2010-01-25 14:01:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void selectCallback(DialogueBox *which, int selected)
|
|
|
|
{
|
|
|
|
/* Cancel? */
|
|
|
|
if (selected != 1)
|
2010-01-30 17:55:21 +01:00
|
|
|
{
|
|
|
|
Gui::gui->exitMenu();
|
2010-02-14 10:38:28 +01:00
|
|
|
TheC64->quit();
|
2010-01-30 17:55:21 +01:00
|
|
|
}
|
2010-03-10 12:20:47 +01:00
|
|
|
|
|
|
|
delete this;
|
2010-01-25 14:01:22 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class MainView;
|
|
|
|
class MainMenu : public Menu
|
|
|
|
{
|
|
|
|
friend class MainView;
|
|
|
|
|
|
|
|
public:
|
|
|
|
MainMenu(Font *font, HelpBox *help) : Menu(font)
|
|
|
|
{
|
|
|
|
this->help = help;
|
2010-03-14 13:03:30 +01:00
|
|
|
this->setText(main_menu_messages);
|
2010-01-25 14:01:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void selectCallback(int which)
|
|
|
|
{
|
|
|
|
switch (which)
|
|
|
|
{
|
2010-03-14 13:03:30 +01:00
|
|
|
case 0: /* Insert disc */
|
2013-01-19 23:46:32 +01:00
|
|
|
if (Gui::gui->np->Port == PORT_SD && sdismount) Gui::gui->dv->setDirectory(Gui::gui->game_base_path_sd);
|
|
|
|
else if (Gui::gui->np->Port == PORT_USB && usbismount) Gui::gui->dv->setDirectory(Gui::gui->game_base_path_usb);
|
2011-08-08 13:21:52 +02:00
|
|
|
else if (Gui::gui->np->Port == PORT_SMB && smbismount) Gui::gui->dv->setDirectory(Gui::gui->game_base_path_smb);
|
2013-01-19 23:46:32 +01:00
|
|
|
else Gui::gui->dv->setDirectory(Gui::gui->game_base_path); //DEFAULT
|
2011-06-05 15:46:38 +02:00
|
|
|
|
2010-01-25 14:01:22 +01:00
|
|
|
Gui::gui->pushView(Gui::gui->dv);
|
2011-06-02 22:50:48 +02:00
|
|
|
|
2010-01-30 19:54:41 +01:00
|
|
|
Gui::gui->dv->runStartSequence(this->p_submenus[0].sel == 0);
|
2010-01-25 14:01:22 +01:00
|
|
|
break;
|
2010-03-14 13:03:30 +01:00
|
|
|
case 2: /* Load/save states */
|
2010-01-25 14:01:22 +01:00
|
|
|
if (this->p_submenus[1].sel == 1)
|
|
|
|
Gui::gui->sgv->saveSnapshot();
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Gui::gui->sgv->setDirectory(Gui::gui->save_game_path);
|
|
|
|
Gui::gui->pushView(Gui::gui->sgv);
|
|
|
|
|
|
|
|
Gui::gui->sgv->setLoadSnapshot(this->p_submenus[1].sel == 0);
|
|
|
|
}
|
|
|
|
break;
|
2010-03-14 13:03:30 +01:00
|
|
|
case 4: /* Keyboard */
|
2010-01-25 14:01:22 +01:00
|
|
|
switch(this->p_submenus[2].sel)
|
|
|
|
{
|
|
|
|
case 0:
|
2010-01-30 16:38:19 +01:00
|
|
|
VirtualKeyboard::kbd->activate(false);
|
2010-01-25 14:01:22 +01:00
|
|
|
VirtualKeyboard::kbd->registerListener(new KeyboardTypingListener());
|
2010-01-30 18:59:32 +01:00
|
|
|
Gui::gui->exitMenu();
|
2010-01-25 14:01:22 +01:00
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
Gui::gui->pushView(Gui::gui->bkv);
|
|
|
|
break;
|
2010-08-23 10:32:48 +02:00
|
|
|
case 2:
|
|
|
|
Gui::gui->np->CursorKeysForJoystick = !Gui::gui->np->CursorKeysForJoystick;
|
|
|
|
if (Gui::gui->np->CursorKeysForJoystick)
|
|
|
|
Gui::gui->status_bar->queueMessage("Cursor keys used as joystick");
|
|
|
|
else
|
|
|
|
Gui::gui->status_bar->queueMessage("Cursor keys used as keyboard cursors");
|
|
|
|
break;
|
2010-01-25 14:01:22 +01:00
|
|
|
default:
|
|
|
|
panic("Illegal selection\n");
|
|
|
|
}
|
|
|
|
break;
|
2010-03-14 13:03:30 +01:00
|
|
|
case 7: /* Game info */
|
2010-01-25 14:01:22 +01:00
|
|
|
Gui::gui->pushView(Gui::gui->giv);
|
2011-06-17 21:36:52 +02:00
|
|
|
break;
|
|
|
|
case 8: /* Help */
|
|
|
|
Gui::gui->pushDialogueBox(new DialogueBox(frodo_help));
|
2010-01-25 14:01:22 +01:00
|
|
|
break;
|
2011-06-17 21:36:52 +02:00
|
|
|
case 9: /* Networking */
|
2010-01-25 14:01:22 +01:00
|
|
|
Gui::gui->pushView(Gui::gui->nv);
|
|
|
|
break;
|
2011-06-17 21:36:52 +02:00
|
|
|
case 10: /* Options */
|
2010-01-25 14:01:22 +01:00
|
|
|
Gui::gui->pushView(Gui::gui->ov);
|
|
|
|
break;
|
2011-06-17 21:36:52 +02:00
|
|
|
case 11: /* Save Prefs */
|
2011-06-02 22:50:48 +02:00
|
|
|
ThePrefs = *Gui::gui->np;
|
|
|
|
ThePrefs.Save(ThePrefs.PrefsPath);
|
|
|
|
Gui::gui->pushDialogueBox(new DialogueBox(save_prefs_done));
|
|
|
|
break;
|
2011-06-17 21:36:52 +02:00
|
|
|
case 12: /* Reset c64 */
|
|
|
|
Gui::gui->status_bar->queueMessage("Resetting the C64");
|
|
|
|
Gui::gui->exitMenu();
|
|
|
|
TheC64->Reset();
|
|
|
|
break;
|
|
|
|
case 13: /* Exit */
|
2010-01-25 14:01:22 +01:00
|
|
|
DialogueBox *exit_dialogue = new DialogueBox(exit_dialogue_messages);
|
|
|
|
exit_dialogue->registerListener(new ExitListener());
|
|
|
|
Gui::gui->pushDialogueBox(exit_dialogue);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void hoverCallback(int which)
|
|
|
|
{
|
|
|
|
this->help->updateHelpMessage(which);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void escapeCallback(int which)
|
|
|
|
{
|
|
|
|
Gui::gui->exitMenu();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
HelpBox *help;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class MainView : public GuiView
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
MainView() : GuiView()
|
|
|
|
{
|
|
|
|
panic_if(!Gui::gui->default_font,
|
|
|
|
"Theme does not seem correctly loaded\n");
|
|
|
|
|
|
|
|
this->help = new HelpBox(Gui::gui->small_font, main_menu_help);
|
|
|
|
this->menu = new MainMenu(Gui::gui->default_font, this->help);
|
|
|
|
}
|
|
|
|
|
|
|
|
~MainView()
|
|
|
|
{
|
|
|
|
delete this->help;
|
|
|
|
delete this->menu;
|
|
|
|
}
|
|
|
|
|
|
|
|
void runLogic()
|
|
|
|
{
|
|
|
|
this->menu->runLogic();
|
|
|
|
}
|
|
|
|
|
2010-02-28 11:06:59 +01:00
|
|
|
void pushEvent(event_t ev)
|
2010-01-25 14:01:22 +01:00
|
|
|
{
|
|
|
|
this->menu->pushEvent(ev);
|
|
|
|
}
|
|
|
|
|
2010-01-30 19:57:24 +01:00
|
|
|
void viewPushCallback()
|
|
|
|
{
|
|
|
|
this->menu->selectOne(0);
|
|
|
|
}
|
|
|
|
|
2010-01-25 14:01:22 +01:00
|
|
|
void 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->infobox, NULL, where, &dst);
|
|
|
|
|
|
|
|
this->menu->draw(where, 50, 70, 300, 400);
|
|
|
|
this->help->draw(where, 354, 24, 264, 210);
|
2010-02-28 08:59:36 +01:00
|
|
|
Gui::gui->server_msgs->draw(where);
|
2010-01-25 14:01:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
MainMenu *menu;
|
|
|
|
HelpBox *help;
|
|
|
|
};
|