From 70b0064575cad2de0785c5df978f158307779b98 Mon Sep 17 00:00:00 2001 From: "simon.kagstrom" Date: Sat, 2 Jan 2010 12:07:35 +0000 Subject: [PATCH] Add network configuration (including message!) and auto-delete dialogues by default --- dialogue_box.cpp | 12 ++++++++---- dialogue_box.hh | 9 ++------- main_menu.cpp | 8 +++----- menu.cpp | 9 ++++++--- menu_messages.cpp | 11 +++++++++++ menu_messages.hh | 1 + network_menu.cpp | 41 ++++++++++++++++++++++++++++++++++++++++- virtual_keyboard.cpp | 1 + 8 files changed, 72 insertions(+), 20 deletions(-) diff --git a/dialogue_box.cpp b/dialogue_box.cpp index 4b4b2fe..838a0a0 100644 --- a/dialogue_box.cpp +++ b/dialogue_box.cpp @@ -10,10 +10,8 @@ void DialogueListener::selectCallback(DialogueBox *which, int selected) Gui::gui->popDialogueBox(); } -DialogueBox::DialogueBox(const char *msgs[], int cancel) : Menu(NULL), ListenerManager() +DialogueBox::DialogueBox(const char *msgs[], bool delete_on_action) : Menu(NULL), ListenerManager() { - this->m_cancel = cancel; - this->setFont(Gui::gui->default_font); this->setSelectedBackground(NULL, NULL, NULL, Gui::gui->bg_left, Gui::gui->bg_middle, @@ -22,11 +20,11 @@ DialogueBox::DialogueBox(const char *msgs[], int cancel) : Menu(NULL), ListenerM this->setText(msgs, NULL); /* Place on the second to last entry */ this->cur_sel = this->n_entries - 2; + this->delete_on_action = delete_on_action; } int DialogueBox::selectNext(event_t ev) { - printf("Al vobb: %d!\n", ev); /* No up/down movement please! */ if (ev == KEY_UP || ev == KEY_DOWN) return this->cur_sel; @@ -39,6 +37,9 @@ void DialogueBox::selectCallback(int which) if (this->listeners[i]) ((DialogueListener*)this->listeners[i])->selectCallback(this, this->p_submenus[0].sel); + Gui::gui->popDialogueBox(); + if (this->delete_on_action) + delete this; } void DialogueBox::hoverCallback(int which) @@ -51,6 +52,9 @@ void DialogueBox::escapeCallback(int which) if (this->listeners[i]) ((DialogueListener*)this->listeners[i])->selectCallback(this, this->p_submenus[0].sel); + Gui::gui->popDialogueBox(); + if (this->delete_on_action) + delete this; } void DialogueBox::draw(SDL_Surface *where) diff --git a/dialogue_box.hh b/dialogue_box.hh index 6dbffec..a253aea 100644 --- a/dialogue_box.hh +++ b/dialogue_box.hh @@ -19,7 +19,7 @@ public: class DialogueBox : public Menu, public ListenerManager { public: - DialogueBox(const char *msgs[], int cancel = 1); + DialogueBox(const char *msgs[], bool delete_on_action = true); virtual void selectCallback(int which); @@ -31,13 +31,8 @@ public: virtual void draw(SDL_Surface *where); - int cancelIndex() - { - return this->m_cancel; - } - protected: - int m_cancel; + bool delete_on_action; }; #endif /* __DIALOGUE_BOX_HH__ */ diff --git a/main_menu.cpp b/main_menu.cpp index a88c201..c769718 100644 --- a/main_menu.cpp +++ b/main_menu.cpp @@ -20,15 +20,13 @@ class ExitListener : public DialogueListener { void escapeCallback(DialogueBox *which, int selected) { - delete this; } void selectCallback(DialogueBox *which, int selected) { - if (selected != which->cancelIndex()) + /* Cancel? */ + if (selected != 1) exit(0); - Gui::gui->popDialogueBox(); - delete this; } }; @@ -73,7 +71,7 @@ public: break; case 11: /* Exit */ - DialogueBox *exit_dialogue = new DialogueBox(exit_dialogue_messages, 1); + DialogueBox *exit_dialogue = new DialogueBox(exit_dialogue_messages); exit_dialogue->registerListener(new ExitListener()); Gui::gui->pushDialogueBox(exit_dialogue); break; diff --git a/menu.cpp b/menu.cpp index 67cbea2..b75f4aa 100644 --- a/menu.cpp +++ b/menu.cpp @@ -272,10 +272,13 @@ void Menu::runLogic() this->selectNext(ev); break; case KEY_SELECT: - this->selectCallback(this->cur_sel); break; + this->selectCallback(this->cur_sel); + /* Might be deleted */ + return; case KEY_ESCAPE: - this->escapeCallback(this->cur_sel); break; - break; + this->escapeCallback(this->cur_sel); + /* Might be deleted */ + return; default: break; } diff --git a/menu_messages.cpp b/menu_messages.cpp index 874242f..2bf1e5f 100644 --- a/menu_messages.cpp +++ b/menu_messages.cpp @@ -13,6 +13,17 @@ const char **exit_dialogue_messages = (const char*[]){ NULL }; +const char **network_port_dialogue_messages = (const char*[]){ + /*00*/ "Please supply a number as", + /*01*/ "network port", + /*02*/ "#", /* Empty line */ + /*03*/ "#", + /*04*/ "#", + /*05*/ "#", + /*06*/ "^|OK", + NULL +}; + const char **main_menu_messages = (const char*[]){ /*00*/ "File", /*01*/ "^|Insert|Start", diff --git a/menu_messages.hh b/menu_messages.hh index 6f2c249..90bcf31 100644 --- a/menu_messages.hh +++ b/menu_messages.hh @@ -10,5 +10,6 @@ extern const char **options_menu_help[]; /* The menu messages are dynamically generated */ extern const char **network_menu_help[]; +extern const char **network_port_dialogue_messages; #endif diff --git a/network_menu.cpp b/network_menu.cpp index 02d226c..e514765 100644 --- a/network_menu.cpp +++ b/network_menu.cpp @@ -1,9 +1,11 @@ #include "gui.hh" #include "menu.hh" #include "help_box.hh" +#include "virtual_keyboard.hh" class NetworkView; -class NetworkMenu : public Menu + +class NetworkMenu : public Menu, public KeyboardListener { friend class NetworkView; @@ -19,11 +21,48 @@ public: { } + virtual void stringCallback(const char *str) + { + switch (this->cur_sel) + { + case 0: + strncpy(Gui::gui->np->NetworkName, str, sizeof(Gui::gui->np->NetworkName)); + break; + case 1: + strncpy(Gui::gui->np->NetworkServer, str, sizeof(Gui::gui->np->NetworkName)); + break; + case 2: + { + char *endp; + unsigned long v; + + v = strtoul(str, &endp, 0); + if (endp == str) + { + DialogueBox *error_dialogue = new DialogueBox(network_port_dialogue_messages); + Gui::gui->pushDialogueBox(error_dialogue); + } + else + Gui::gui->np->NetworkPort = v; + } break; + default: + panic("Cur sel is %d, not possible!\n", this->cur_sel); + break; + } + this->updateMessages(); + } + virtual void selectCallback(int which) { printf("option entry %d selected: %s\n", which, this->pp_msgs[which]); switch (which) { + case 0: + case 1: + case 2: + Gui::gui->kv->activate(); + Gui::gui->kv->registerListener(this); + break; default: break; } diff --git a/virtual_keyboard.cpp b/virtual_keyboard.cpp index 030ddf7..8e62388 100644 --- a/virtual_keyboard.cpp +++ b/virtual_keyboard.cpp @@ -259,6 +259,7 @@ const char VirtualKeyboard::keycodeToChar(int kc) void VirtualKeyboard::activate() { + Gui::gui->pushView(Gui::gui->kv); this->is_active = true; memset(this->buf, 0, sizeof(struct virtkey) * this->buf_len); this->buf_head = 0;