frodo-wii/main_menu.cpp

173 lines
3.3 KiB
C++
Raw Normal View History

2009-12-06 20:21:48 +01:00
#include "menu.hh"
#include "dialogue_box.hh"
2009-12-06 20:21:48 +01:00
class KeyboardTypingListener : public KeyboardListener
{
virtual void stringCallback(const char *str)
{
printf("string: %s\n", str);
/* Remove thyself! */
delete this;
}
virtual void keyCallback(bool shift, const char *str)
{
printf("Vobb: %d: %s\n", shift, str);
}
};
class ExitListener : public DialogueListener
{
void escapeCallback(DialogueBox *which, int selected)
{
}
void selectCallback(DialogueBox *which, int selected)
{
/* Cancel? */
if (selected != 1)
exit(0);
}
};
class MainView;
class MainMenu : public Menu
{
friend class MainView;
public:
MainMenu(Font *font, HelpBox *help) : Menu(font)
{
this->help = help;
2010-01-10 20:57:45 +01:00
this->updatePauseState();
}
virtual void selectCallback(int which)
{
printf("entry %d selected: %s\n", which, this->pp_msgs[which]);
switch (which)
{
2010-01-10 20:57:45 +01:00
case 0:
TheC64->IsPaused() ? TheC64->Resume() : TheC64->Pause();
2010-01-16 10:17:09 +01:00
if (TheC64->IsPaused())
Gui::gui->status_bar->queueMessage("C64 emulation paused");
else
Gui::gui->status_bar->queueMessage("C64 emulation resumed");
2010-01-10 20:57:45 +01:00
this->updatePauseState();
break;
case 2: /* Insert disc */
if (this->p_submenus[0].sel == 0) {
Gui::gui->dv->setDirectory("discs");
Gui::gui->pushView(Gui::gui->dv);
}
2009-12-06 20:21:48 +01:00
break;
2010-01-10 20:57:45 +01:00
case 4: /* Load/save states */
2009-12-28 13:38:41 +01:00
break;
2010-01-10 20:57:45 +01:00
case 6: /* Keyboard */
2010-01-06 17:42:55 +01:00
switch(this->p_submenus[2].sel)
{
case 0:
VirtualKeyboard::kbd->activate();
VirtualKeyboard::kbd->registerListener(new KeyboardTypingListener());
break;
case 1:
break;
case 2:
Gui::gui->pushView(Gui::gui->bkv);
break;
default:
panic("Illegal selection\n");
}
2009-12-19 20:17:25 +01:00
break;
case 9: /* Game info */
2009-12-28 13:38:41 +01:00
break;
2010-01-10 20:57:45 +01:00
case 10: /* Networking */
2009-12-29 14:23:01 +01:00
Gui::gui->pushView(Gui::gui->nv);
2009-12-28 13:38:41 +01:00
break;
2010-01-10 20:57:45 +01:00
case 11: /* Options */
2009-12-28 13:38:41 +01:00
Gui::gui->pushView(Gui::gui->ov);
break;
2010-01-10 20:57:45 +01:00
case 12: /* Exit */
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)
{
2009-12-13 09:59:06 +01:00
Gui::gui->exitMenu();
}
private:
2010-01-10 20:57:45 +01:00
void updatePauseState()
{
if (TheC64->IsPaused())
main_menu_messages[0] = "Resume";
else
main_menu_messages[0] = "Pause";
this->setText(main_menu_messages);
}
HelpBox *help;
};
class MainView : public GuiView
{
public:
2009-12-13 09:59:06 +01:00
MainView() : GuiView()
{
2010-01-16 08:11:17 +01:00
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);
}
2009-12-06 20:21:48 +01:00
~MainView()
{
delete this->help;
delete this->menu;
}
void runLogic()
{
this->menu->runLogic();
}
void pushEvent(SDL_Event *ev)
{
this->menu->pushEvent(ev);
}
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);
dst = (SDL_Rect){350,242,0,0};
SDL_BlitSurface(Gui::gui->textbox, NULL, where, &dst);
this->menu->draw(where, 50, 70, 300, 400);
this->help->draw(where, 354, 24, 264, 210);
}
protected:
MainMenu *menu;
HelpBox *help;
};