From 453db840143548bc1db0f18e2b875bd70dd2259d Mon Sep 17 00:00:00 2001 From: "simon.kagstrom" Date: Sat, 5 Dec 2009 12:04:00 +0000 Subject: [PATCH] Implement and add dialogue boxes as well (for exit currently) --- Makefile | 2 +- dialogue_box.cpp | 14 ++++++ dialogue_box.hh | 7 ++- frodo_menu.cpp | 81 +++++++++++++++++++++++++++++++- frodo_menu.hh | 1 + menu.cpp | 3 ++ menu.hh | 13 +++-- menu_messages.cpp | 36 +++++++++----- menu_messages.hh | 1 + themes/default/dialogue_box.png | Bin 0 -> 2107 bytes 10 files changed, 136 insertions(+), 22 deletions(-) create mode 100644 themes/default/dialogue_box.png diff --git a/Makefile b/Makefile index bad46e3..27e09ea 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ all: menu menu.oo: menu.cpp menu.hh utils.hh font.hh Makefile -frodo_menu.oo: frodo_menu.cpp frodo_menu.hh font.hh menu.hh Makefile +frodo_menu.oo: frodo_menu.cpp frodo_menu.hh font.hh menu.hh sdl_ttf_font.hh dialogue_box.hh Makefile utils.oo: utils.cpp utils.hh Makefile diff --git a/dialogue_box.cpp b/dialogue_box.cpp index ee95640..7a40994 100644 --- a/dialogue_box.cpp +++ b/dialogue_box.cpp @@ -6,6 +6,16 @@ DialogueBox::DialogueBox(Font *font, const char *msgs[], int cancel) : Menu(font this->m_cancel = cancel; this->setText(msgs, NULL); + /* Place on the second to last entry */ + this->cur_sel = this->n_entries - 2; +} + +int DialogueBox::selectNext(event_t ev) +{ + /* No up/down movement please! */ + if (ev == KEY_UP || ev == KEY_DOWN) + return this->cur_sel; + return Menu::selectNext(ev); } void DialogueBox::selectCallback(int which) @@ -13,6 +23,10 @@ void DialogueBox::selectCallback(int which) this->m_selected = this->p_submenus[0].sel; } +void DialogueBox::hoverCallback(int which) +{ +} + void DialogueBox::escapeCallback(int which) { this->m_selected = this->m_cancel; diff --git a/dialogue_box.hh b/dialogue_box.hh index a112669..766298c 100644 --- a/dialogue_box.hh +++ b/dialogue_box.hh @@ -5,18 +5,23 @@ class DialogueBox : public Menu { +public: DialogueBox(Font *font, const char *msgs[], int cancel = 1); virtual void selectCallback(int which); virtual void escapeCallback(int which); + virtual void hoverCallback(int which); + + virtual int selectNext(event_t ev); + int selected() { return this->m_selected; } -private: +protected: int m_selected; int m_cancel; }; diff --git a/frodo_menu.cpp b/frodo_menu.cpp index 95a8b8d..77a791e 100644 --- a/frodo_menu.cpp +++ b/frodo_menu.cpp @@ -4,6 +4,7 @@ #include "menu.hh" #include "frodo_menu.hh" #include "menu_messages.hh" +#include "dialogue_box.hh" #include "sdl_ttf_font.hh" #include "utils.hh" @@ -49,20 +50,78 @@ protected: const char ***all_messages; }; +class MainView; class MainMenu : public Menu { + friend class MainView; + + class ExitDialogue : public DialogueBox + { + public: + ExitDialogue(Font *font) : DialogueBox(font, exit_dialogue_messages, 1) + { + } + + void selectCallback(int which) + { + this->m_selected = this->p_submenus[0].sel; + /* Do the exit */ + if (this->m_selected != this->m_cancel) + exit(1); + } + }; + public: MainMenu(Font *font, HelpMenu *help, GuiView *parent) : Menu(font) { this->parent = parent; this->help = help; + /* The dialogue box is only present when needed */ + this->dialogue = NULL; + } + + ~MainMenu() + { + if (this->dialogue) + delete this->dialogue; + } + + void runLogic() + { + if (this->dialogue) + { + this->dialogue->runLogic(); + if (this->dialogue->selected() >= 0) + { + delete this->dialogue; + this->dialogue = NULL; + } + return; + } + + ((Menu*)this)->runLogic(); + } + + void pushEvent(SDL_Event *ev) + { + if (this->dialogue) + this->dialogue->pushEvent(ev); + else + ((Menu*)this)->pushEvent(ev); } virtual void selectCallback(int which) { printf("entry %d selected: %s\n", which, this->pp_msgs[which]); - if (which == 11) - exit(0); + switch (which) + { + case 11: + this->dialogue = new ExitDialogue(this->font); + this->dialogue->setSelectedBackground(NULL, NULL, NULL, + this->submenu_bg_left, this->submenu_bg_middle, + this->submenu_bg_right); + break; + } } virtual void hoverCallback(int which) @@ -76,6 +135,7 @@ public: } private: + DialogueBox *dialogue; GuiView *parent; HelpMenu *help; }; @@ -92,6 +152,7 @@ public: this->bg = NULL; this->infobox = NULL; this->textbox = NULL; + this->dialogue_bg = NULL; } void updateTheme() @@ -99,6 +160,7 @@ public: this->bg = parent->main_menu_bg; this->infobox = parent->infobox; this->textbox = parent->textbox; + this->dialogue_bg = parent->dialogue_bg; this->menu->setFont(this->parent->default_font); this->help->setFont(this->parent->small_font); @@ -133,6 +195,16 @@ public: this->menu->draw(where, 50, 70, 300, 400); this->help->draw(where, 354, 24, 264, 210); + if (this->menu->dialogue) { + int d_x = where->w / 2 - this->dialogue_bg->w / 2; + int d_y = where->h / 2 - this->dialogue_bg->h / 2; + + dst = (SDL_Rect){d_x, d_y, this->dialogue_bg->w, this->dialogue_bg->h}; + SDL_BlitSurface(this->dialogue_bg, NULL, where, &dst); + + this->menu->dialogue->draw(where, d_x + 10, d_y + 10, + this->dialogue_bg->w - 10, this->dialogue_bg->h - 10); + } } protected: @@ -141,6 +213,7 @@ protected: SDL_Surface *bg; SDL_Surface *infobox; SDL_Surface *textbox; + SDL_Surface *dialogue_bg; }; Gui::Gui() @@ -158,6 +231,7 @@ Gui::Gui() this->infobox = NULL; this->textbox = NULL; this->default_font = NULL; + this->dialogue_bg = NULL; this->small_font = NULL; this->n_views = 0; @@ -182,6 +256,7 @@ bool Gui::setTheme(const char *path) this->main_menu_bg = this->loadThemeImage(path, "main_menu_bg.png"); this->infobox = this->loadThemeImage(path, "infobox.png"); this->textbox = this->loadThemeImage(path, "textbox.png"); + this->dialogue_bg = this->loadThemeImage(path, "dialogue_box.png"); this->default_font = this->loadThemeFont(path, "font.ttf", 18); this->small_font = this->loadThemeFont(path, "font.ttf", 16); @@ -189,6 +264,7 @@ bool Gui::setTheme(const char *path) if (!this->bg_left || !this->bg_right || !this->bg_middle || !this->bg_submenu_left || !this->bg_submenu_right || !this->bg_submenu_middle || + !this->dialogue_bg || !this->default_font || !this->small_font) { @@ -201,6 +277,7 @@ bool Gui::setTheme(const char *path) SDL_FreeSurface(this->background); SDL_FreeSurface(this->main_menu_bg); SDL_FreeSurface(this->infobox); + SDL_FreeSurface(this->dialogue_bg); SDL_FreeSurface(this->textbox); if (this->default_font) diff --git a/frodo_menu.hh b/frodo_menu.hh index 589021f..4771d3b 100644 --- a/frodo_menu.hh +++ b/frodo_menu.hh @@ -74,6 +74,7 @@ public: SDL_Surface *main_menu_bg; SDL_Surface *infobox; SDL_Surface *textbox; + SDL_Surface *dialogue_bg; SDL_Surface *bg_left, *bg_right, *bg_middle, *bg_submenu_left, *bg_submenu_right, *bg_submenu_middle; diff --git a/menu.cpp b/menu.cpp index 594e4d1..e343234 100644 --- a/menu.cpp +++ b/menu.cpp @@ -17,6 +17,7 @@ #include "utils.hh" #define IS_SUBMENU(p_msg) ( (p_msg)[0] == '^' ) +#define IS_EMPTY(p_msg) ( (p_msg)[0] == '#' ) void Menu::printText(SDL_Surface *where, const char *msg, SDL_Color clr, int x, int y, int w, int h) @@ -52,6 +53,8 @@ void Menu::printText(SDL_Surface *where, const char *msg, SDL_Color clr, if (buf[i] == '^' || buf[i] == '|') buf[i] = ' '; } + if (IS_EMPTY(buf)) + buf[0] = ' '; this->font->draw(where, buf, x, y, w, h); free(buf); diff --git a/menu.hh b/menu.hh index 98b534a..dba26b2 100644 --- a/menu.hh +++ b/menu.hh @@ -92,18 +92,21 @@ protected: submenu_t *findSubmenu(int index); - int getNextEntry(int dy); +public: + virtual int getNextEntry(int dy); - int selectOne(int which); + virtual int selectOne(int which); - int selectNext(int dx, int dy); + virtual int selectNext(int dx, int dy); - int selectNext(event_t ev); + virtual int selectNext(event_t ev); - void pushEvent(event_t ev); + virtual void pushEvent(event_t ev); event_t popEvent(); +protected: + const char **pp_msgs; Font *font; SDL_Color text_color; diff --git a/menu_messages.cpp b/menu_messages.cpp index 0c6f37d..6390509 100644 --- a/menu_messages.cpp +++ b/menu_messages.cpp @@ -2,20 +2,30 @@ #include "menu_messages.hh" +const char **exit_dialogue_messages = (const char*[]){ + /*00*/ "Do you really want to exit", + /*01*/ "Frodo?", + /*02*/ "#", /* Empty line */ + /*03*/ "#", + /*04*/ "#", + /*06*/ "^|Yes|Cancel", + NULL +}; + const char **main_menu_messages = (const char*[]){ - /*00*/ "File", - /*01*/ "^|Insert|Start", - /*02*/ "States", - /*03*/ "^|Load|Save|Delete", - /*04*/ "Keyboard", - /*05*/ "^|Type|Macro|Bind", - /*06*/ " ", - /*07*/ "Reset the C=64", - /*08*/ "Networking", - /*09*/ "Options", - /*10*/ "Help", - /*11*/ "Quit", - NULL + /*00*/ "File", + /*01*/ "^|Insert|Start", + /*02*/ "States", + /*03*/ "^|Load|Save|Delete", + /*04*/ "Keyboard", + /*05*/ "^|Type|Macro|Bind", + /*06*/ " ", + /*07*/ "Reset the C=64", + /*08*/ "Networking", + /*09*/ "Options", + /*10*/ "Help", + /*11*/ "Quit", + NULL }; const char **main_menu_help[] = { diff --git a/menu_messages.hh b/menu_messages.hh index 67140da..178f595 100644 --- a/menu_messages.hh +++ b/menu_messages.hh @@ -2,6 +2,7 @@ #define MENU_MESSAGES_HH extern const char **main_menu_messages; +extern const char **exit_dialogue_messages; extern const char **main_menu_help[]; #endif diff --git a/themes/default/dialogue_box.png b/themes/default/dialogue_box.png new file mode 100644 index 0000000000000000000000000000000000000000..52a2e45f05e38b813a20be670b7e893cf053e54e GIT binary patch literal 2107 zcmb_di9g%f7XKx&l~J!kX`6_lpOkKBQJSf=C8NexCQ~hGn^L8th^43{{TaMIOK7W> zsTduxrM5vwEr}#8VT86Qqf2a|ibiM%vChxD&-({n=W{>zoO91T=X}mR_uTJIKI>wy zuDV+l004D|Gj{F(06PiEb1F&@4LQUPfEX;y-TpLC^#U~oEtI?+?d^cgt?`Imnh9yP zQO;Zl0{}JT)`S5M>AH|oIo!dSp#0`5MYXRr_OzfUA=R#M!ufF9;J`rNpm4x8)b~ob z?^XTC>*4s|PKyKL%cBhC@Z^c4haONbMJ3qWSn2gT8RLIO6RId^;)k$}) zZahgXepbVFw#_Q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