Add network configuration (including message!) and auto-delete

dialogues by default
This commit is contained in:
simon.kagstrom 2010-01-02 12:07:35 +00:00
parent 822f76b11b
commit 70b0064575
8 changed files with 72 additions and 20 deletions

View File

@ -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)

View File

@ -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__ */

View File

@ -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;

View File

@ -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;
}

View File

@ -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",

View File

@ -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

View File

@ -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;
}

View File

@ -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;