mirror of
https://github.com/nzp-team/fteqw.git
synced 2024-11-26 13:50:53 +00:00
Added prompt menu.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4377 fc73d0e0-1445-4013-8a0c-d673dee63da5
This commit is contained in:
parent
d60d64c640
commit
b2d34e6470
2 changed files with 67 additions and 0 deletions
|
@ -573,6 +573,72 @@ void M_Help_Key (int key)
|
|||
|
||||
}
|
||||
|
||||
|
||||
//=============================================================================
|
||||
/* Various callback-based prompts */
|
||||
|
||||
typedef struct
|
||||
{
|
||||
menu_t m;
|
||||
void (*callback)(void *, int);
|
||||
void *ctx;
|
||||
menubutton_t *b_yes;
|
||||
menubutton_t *b_no;
|
||||
menubutton_t *b_cancel;
|
||||
} promptmenu_t;
|
||||
static qboolean M_Menu_Prompt_Button (union menuoption_s *b,struct menu_s *gm, int key)
|
||||
{
|
||||
int action;
|
||||
promptmenu_t *m = (promptmenu_t*)gm;
|
||||
|
||||
if (key != K_ENTER && key != K_KP_ENTER && key != K_MOUSE1)
|
||||
return true;
|
||||
|
||||
if (b == (menuoption_t*)m->b_yes)
|
||||
action = 0;
|
||||
else if (b == (menuoption_t*)m->b_no)
|
||||
action = 1;
|
||||
else //if (b == (menuoption_t*)m->b_cancel)
|
||||
action = -1;
|
||||
if (m->callback)
|
||||
m->callback(m->ctx, action);
|
||||
m->callback = NULL;
|
||||
|
||||
M_RemoveMenu(&m->m);
|
||||
return true;
|
||||
}
|
||||
static void M_Menu_Prompt_Cancel (struct menu_s *gm)
|
||||
{
|
||||
promptmenu_t *m = (promptmenu_t*)gm;
|
||||
if (m->callback)
|
||||
m->callback(m->ctx, -1);
|
||||
m->callback = NULL;
|
||||
}
|
||||
void M_Menu_Prompt (void (*callback)(void *, int), void *ctx, char *m1, char *m2, char *m3, char *optionyes, char *optionno, char *optioncancel)
|
||||
{
|
||||
promptmenu_t *m;
|
||||
|
||||
key_dest = key_menu;
|
||||
m_state = m_complex;
|
||||
|
||||
m = (promptmenu_t*)M_CreateMenuInfront(sizeof(*m) - sizeof(m->m));
|
||||
m->callback = callback;
|
||||
m->ctx = ctx;
|
||||
m->m.remove = M_Menu_Prompt_Cancel;
|
||||
|
||||
MC_AddWhiteText(&m->m, 64, 84, m1, false);
|
||||
MC_AddWhiteText(&m->m, 64, 92, m2, false);
|
||||
MC_AddWhiteText(&m->m, 64, 100, m3, false);
|
||||
|
||||
m->b_yes = MC_AddCommand(&m->m, 64, 116, optionyes, M_Menu_Prompt_Button);
|
||||
m->b_no = MC_AddCommand(&m->m, 144,116, optionno, M_Menu_Prompt_Button);
|
||||
m->b_cancel = MC_AddCommand(&m->m, 224,116, optioncancel, M_Menu_Prompt_Button);
|
||||
|
||||
m->m.selecteditem = (menuoption_t *)m->b_cancel;
|
||||
|
||||
MC_AddBox (&m->m, 56, 76, 25, 5);
|
||||
}
|
||||
|
||||
//=============================================================================
|
||||
/* QUIT MENU */
|
||||
|
||||
|
|
|
@ -111,6 +111,7 @@ void M_ToggleMenu_f (void);
|
|||
mpic_t *M_CachePic (char *path);
|
||||
void M_DrawTextBox (int x, int y, int width, int lines);
|
||||
void M_Menu_Quit_f (void);
|
||||
void M_Menu_Prompt (void (*callback)(void *, int), void *ctx, char *m1, char *m2, char *m3, char *optionyes, char *optionno, char *optioncancel);
|
||||
|
||||
struct menu_s;
|
||||
|
||||
|
|
Loading…
Reference in a new issue