diff --git a/Makefile b/Makefile index db932f7..5eb0126 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,8 @@ widget.oo: widget.cpp widget.hh gui.oo: gui.cpp gui.hh Makefile font.hh menu.hh sdl_ttf_font.hh \ dialogue_box.hh help_box.hh main_menu.cpp disc_menu.cpp \ - file_browser.hh timer.hh game_info.hh widget.hh options_menu.cpp + file_browser.hh timer.hh game_info.hh widget.hh options_menu.cpp \ + network_menu.cpp virtual_keyboard.oo: virtual_keyboard.hh virtual_keyboard.cpp widget.hh diff --git a/gui.cpp b/gui.cpp index e515390..2ba6446 100644 --- a/gui.cpp +++ b/gui.cpp @@ -31,6 +31,7 @@ static const char *get_theme_path(const char *dir, const char *what) /* These are a bit of special cases... */ #include "disc_menu.cpp" #include "options_menu.cpp" +#include "network_menu.cpp" #include "main_menu.cpp" GuiView::GuiView() @@ -69,6 +70,7 @@ Gui::Gui() this->mv = new MainView(); this->dv = new DiscView(); this->ov = new OptionsView(); + this->nv = new NetworkView(); this->kv = VirtualKeyboard::kbd; this->pushView(mv); } @@ -133,6 +135,7 @@ bool Gui::setTheme(const char *path) this->dv->updateTheme(); this->kv->updateTheme(); this->ov->updateTheme(); + this->nv->updateTheme(); return true; } diff --git a/gui.hh b/gui.hh index 3ee6540..ec88f54 100644 --- a/gui.hh +++ b/gui.hh @@ -11,6 +11,7 @@ class MainView; class DiscView; class OptionsView; +class NetworkView; class VirtualKeyboard; class Gui @@ -74,6 +75,7 @@ public: MainView *mv; DiscView *dv; OptionsView *ov; + NetworkView *nv; VirtualKeyboard *kv; GuiView **views; int n_views; diff --git a/main_menu.cpp b/main_menu.cpp index b084c8c..e3796cf 100644 --- a/main_menu.cpp +++ b/main_menu.cpp @@ -96,6 +96,7 @@ public: printf("Resetting the C64\n"); break; case 8: /* Networking */ + Gui::gui->pushView(Gui::gui->nv); break; case 9: /* Options */ Gui::gui->pushView(Gui::gui->ov); diff --git a/menu_messages.cpp b/menu_messages.cpp index cb88556..874242f 100644 --- a/menu_messages.cpp +++ b/menu_messages.cpp @@ -122,3 +122,40 @@ const char **options_menu_help[] = { }, NULL, }; + +const char **network_menu_help[] = { + (const char*[]){ + "Setup username to use on", + "the C64 network. Must be", + "set before connceting.", + NULL, + }, + (const char*[]){ + "Setup server hostname.", + "Only for debugging, so", + "leave as it is.", + NULL, + }, + (const char*[]){ + "UDP port to use. Only for", + "debugging, so leave as", + "it is", + NULL, + }, + NULL, + (const char*[]){ + "Connect to the C64", + "network, or disconnect if", + "you are already connected.", + NULL, + }, + NULL, + (const char*[]){ + "Post message to the C64", + "network server. You must", + "be connected to use this.", + NULL, + }, + NULL, +}; + diff --git a/menu_messages.hh b/menu_messages.hh index bf06c2f..6f2c249 100644 --- a/menu_messages.hh +++ b/menu_messages.hh @@ -8,4 +8,7 @@ extern const char **main_menu_help[]; extern const char **options_menu_messages; extern const char **options_menu_help[]; +/* The menu messages are dynamically generated */ +extern const char **network_menu_help[]; + #endif diff --git a/network_menu.cpp b/network_menu.cpp new file mode 100644 index 0000000..b000c2f --- /dev/null +++ b/network_menu.cpp @@ -0,0 +1,138 @@ +#include "gui.hh" +#include "menu.hh" +#include "help_box.hh" + +class NetworkView; +class NetworkMenu : public Menu +{ + friend class NetworkView; + +public: + NetworkMenu(Font *font, HelpBox *help) : Menu(font) + { + this->help = help; + this->updateMessages(); + } + + ~NetworkMenu() + { + } + + virtual void selectCallback(int which) + { + printf("option entry %d selected: %s\n", which, this->pp_msgs[which]); + switch (which) + { + case 0: /* Insert disc */ + break; + case 2: /* Load/save states */ + break; + case 4: /* Keyboard */ + break; + case 7: /* Reset the C64 */ + break; + case 8: /* Networking */ + break; + case 9: /* Options */ + break; + case 10: /* Help */ + break; + } + } + + virtual void hoverCallback(int which) + { + this->help->updateHelpMessage(which); + } + + virtual void escapeCallback(int which) + { + Gui::gui->popView(); + } + +private: + void updateMessages() + { + memset(this->strs, 0, sizeof(this->strs)); + snprintf(this->strs[0], sizeof(this->strs[0]) - 1, "Set username (%s)", + "Vobb"); // FIXME! + snprintf(this->strs[1], sizeof(this->strs[1]) - 1, "Server (%s)", + "play.c64-network.org"); // FIXME! + snprintf(this->strs[2], sizeof(this->strs[2]) - 1, "Server port (%d)", + 46214); // FIXME! + + this->messages[0] = this->strs[0]; + this->messages[1] = this->strs[1]; + this->messages[2] = this->strs[2]; + + this->messages[3] = " "; + this->messages[4] = "Connect to the network!"; + this->messages[5] = " "; + this->messages[6] = "Post network message"; + this->messages[7] = NULL; + this->setText(this->messages); + } + + char strs[3][255]; + const char *messages[8]; + + HelpBox *help; +}; + + +class NetworkView : public GuiView +{ +public: + NetworkView() : GuiView() + { + this->help = new HelpBox(NULL, network_menu_help); + this->menu = new NetworkMenu(NULL, this->help); + } + + ~NetworkView() + { + delete this->help; + delete this->menu; + } + + void updateTheme() + { + this->menu->setFont(Gui::gui->default_font); + this->help->setFont(Gui::gui->small_font); + this->menu->setSelectedBackground(Gui::gui->bg_left, Gui::gui->bg_middle, + Gui::gui->bg_right, Gui::gui->bg_submenu_left, + Gui::gui->bg_submenu_middle, Gui::gui->bg_submenu_right); + } + + 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: + NetworkMenu *menu; + HelpBox *help; +};