the quit menu works now. however, quit from the console doesn't

This commit is contained in:
Bill Currie 2002-01-20 00:06:08 +00:00
parent 39d432b6a6
commit 35de51ee31
4 changed files with 217 additions and 14 deletions

View file

@ -1,11 +1,18 @@
void (integer x, integer y, string text) Menu_Begin = #0;
void (void () func) Menu_Draw = #0;
void (integer x, integer y, string name) Menu_Pic = #0;
void (integer x, integer y, string name) Menu_CenterPic = #0;
void (integer x, integer y, string text, void (string text, integer key) func) Menu_Item = #0;
void (void (integer x, integer y) func) Menu_Cursor = #0;
void (integer (integer key, integer unicode, integer down) func) Menu_KeyEvent = #0;
void () Menu_End = #0;
void (string name) Menu_TopMenu = #0;
void (string name) Menu_SelectMenu = #0;
void (integer () func) Menu_SetQuit = #0;
void () Menu_Quit = #0;
void (integer x, integer y, string name) Draw_Pic = #0;
void (integer x, integer y, string text) Draw_String = #0;
float time;
entity self;
@ -22,13 +29,127 @@ string [6] dot = {
"gfx/menudot6.lmp",
};
string [32] quitMessage = {
/* .........1.........2.... */
" Are you gonna quit ",
" this game just like ",
" everything else? ",
" ",
" Milord, methinks that ",
" thou art a lowly ",
" quitter. Is this true? ",
" ",
" Do I need to bust your ",
" face open for trying ",
" to quit? ",
" ",
" Man, I oughta smack you",
" for trying to quit! ",
" Press Y to get ",
" smacked out. ",
" Press Y to quit like a ",
" big loser in life. ",
" Press N to stay proud ",
" and successful! ",
" If you press Y to ",
" quit, I will summon ",
" Satan all over your ",
" hard drive! ",
" Um, Asmodeus dislikes ",
" his children trying to ",
" quit. Press Y to return",
" to your Tinkertoys. ",
" If you quit now, I'll ",
" throw a blanket-party ",
" for you next time! ",
" "
};
integer quit_index;
void (integer x, integer y) spinner =
{
Draw_Pic (x, y, dot[integer(time * 10) % 6]);
};
void (string text, integer key) quit =
void (integer x, integer y, integer width, integer lines) text_box =
{
local integer cx, cy, n;
local string p;
cx = x;
cy = y;
Draw_Pic (cx, cy, "gfx/box_tl.lmp");
for (n = 0; n < lines; n++) {
cy += 8;
Draw_Pic (cx, cy, "gfx/box_ml.lmp");
}
Draw_Pic (cx, cy + 8, "gfx/box_bl.lmp");
cx += 8;
while (width > 0) {
cy = y;
Draw_Pic (cx, cy, "gfx/box_tm.lmp");
p = "gfx/box_mm.lmp";
for (n = 0; n < lines; n++) {
cy += 8;
if (n == 1)
p = "gfx/box_mm2.lmp";
Draw_Pic (cx, cy, p);
}
Draw_Pic (cx, cy + 8, "gfx/box_bm.lmp");
width -= 2;
cx += 16;
}
cy = y;
Draw_Pic (cx, cy, "gfx/box_tr.lmp");
for (n = 0; n < lines; n++) {
cy += 8;
Draw_Pic (cx, cy, "gfx/box_mr.lmp");
}
Draw_Pic (cx, cy + 8, "gfx/box_br.lmp");
};
integer () quit =
{
Menu_SelectMenu ("quit");
quit_index++;
quit_index &= 7;
return 0;
};
void (string text, integer key) quit_f =
{
quit ();
};
integer (integer key, integer unicode, integer down) quit_keyevent =
{
if (key == 'y') {
Menu_Quit ();
return 1;
}
if (key == 'n') {
Menu_SelectMenu (NIL);
return 1;
}
return 0;
};
void () quit_draw =
{
text_box (56, 76, 24, 4);
Draw_String (64, 84, quitMessage[quit_index *4 + 0]);
Draw_String (64, 92, quitMessage[quit_index *4 + 1]);
Draw_String (64, 100, quitMessage[quit_index *4 + 2]);
Draw_String (64, 108, quitMessage[quit_index *4 + 3]);
};
void () single_player_menu =
@ -63,11 +184,22 @@ void () main_menu =
multi_player_menu ();
options_menu ();
help_menu ();
Menu_Item (54, 112, "", quit);
Menu_Item (54, 112, "", quit_f);
Menu_End ();
};
void () quit_menu =
{
Menu_Begin (0, 0, "quit");
Menu_KeyEvent (quit_keyevent);
Menu_Draw (quit_draw);
Menu_End ();
};
void () menu_init =
{
main_menu ();
quit_menu ();
Menu_TopMenu ("main");
Menu_SetQuit (quit);
};

View file

@ -57,6 +57,7 @@ typedef struct console_data_s {
double *realtime;
int force_commandline;
int ormask;
void (*quit)(void);
} console_data_t;
#endif // __QF_plugin_console_h_

View file

@ -560,7 +560,7 @@ DrawInputLine (int x, int y, inputline_t *il)
static void
DrawInput (void)
{
if (key_dest != key_console && !con_data.force_commandline)
if (key_dest != key_console)// && !con_data.force_commandline)
return; // don't draw anything (always draw if not active)
DrawInputLine (8, con_vislines - 22, input_line);

View file

@ -40,6 +40,7 @@ static const char rcsid[] =
#include "QF/plugin.h"
#include "QF/progs.h"
#include "QF/render.h"
#include "QF/sys.h"
#include "QF/vfs.h"
typedef struct menu_pic_s {
@ -58,6 +59,7 @@ typedef struct menu_item_s {
func_t func;
func_t cursor;
func_t keyevent;
func_t draw;
const char *text;
menu_pic_t *pics;
} menu_item_t;
@ -66,8 +68,7 @@ static progs_t menu_pr_state;
static menu_item_t *menu;
static hashtab_t *menu_hash;
static func_t menu_init;
static func_t menu_keyevent;
static func_t menu_draw;
static func_t menu_quit;
static const char *top_menu;
static int
@ -79,10 +80,6 @@ menu_resolve_globals (void)
if (!(f = ED_FindFunction (&menu_pr_state, sym = "menu_init")))
goto error;
menu_init = (func_t)(f - menu_pr_state.pr_functions);
if ((f = ED_FindFunction (&menu_pr_state, "menu_keyevent")))
menu_keyevent = (func_t)(f - menu_pr_state.pr_functions);
if ((f = ED_FindFunction (&menu_pr_state, "menu_draw")))
menu_draw = (func_t)(f - menu_pr_state.pr_functions);
return 1;
error:
Con_Printf ("%s: undefined function %s\n", menu_pr_state.progs_name, sym);
@ -143,12 +140,18 @@ bi_Menu_Begin (progs_t *pr)
m->text = strdup (text);
if (menu)
menu_add_item (menu, m);
else
top_menu = m->text;
menu = m;
Hash_Add (menu_hash, m);
}
static void
bi_Menu_Draw (progs_t *pr)
{
func_t func = G_FUNCTION (pr, OFS_PARM0);
menu->draw = func;
}
static void
bi_Menu_Pic (progs_t *pr)
{
@ -224,6 +227,40 @@ bi_Menu_End (progs_t *pr)
menu = menu->parent;
}
static void
bi_Menu_TopMenu (progs_t *pr)
{
const char *name = G_STRING (pr, OFS_PARM0);
if (top_menu)
free ((char*)top_menu);
top_menu = strdup (name);
}
static void
bi_Menu_SelectMenu (progs_t *pr)
{
const char *name = G_STRING (pr, OFS_PARM0);
menu = Hash_Find (menu_hash, name);
}
static void
bi_Menu_SetQuit (progs_t *pr)
{
func_t func = G_FUNCTION (pr, OFS_PARM0);
menu_quit = func;
}
static void
bi_Menu_Quit (progs_t *pr)
{
if (con_data.quit)
con_data.quit ();
Sys_Quit ();
}
static void
togglemenu_f (void)
{
@ -233,6 +270,17 @@ togglemenu_f (void)
Menu_Enter ();
}
static void
quit_f (void)
{
if (menu_quit) {
PR_ExecuteProgram (&menu_pr_state, menu_quit);
if (!G_INT (&menu_pr_state, OFS_RETURN))
return;
}
bi_Menu_Quit (&menu_pr_state);
}
void
Menu_Init (void)
{
@ -241,17 +289,23 @@ Menu_Init (void)
menu_hash = Hash_NewTable (61, menu_get_key, menu_free, 0);
PR_AddBuiltin (&menu_pr_state, "Menu_Begin", bi_Menu_Begin, -1);
PR_AddBuiltin (&menu_pr_state, "Menu_Draw", bi_Menu_Draw, -1);
PR_AddBuiltin (&menu_pr_state, "Menu_Pic", bi_Menu_Pic, -1);
PR_AddBuiltin (&menu_pr_state, "Menu_CenterPic", bi_Menu_CenterPic, -1);
PR_AddBuiltin (&menu_pr_state, "Menu_Item", bi_Menu_Item, -1);
PR_AddBuiltin (&menu_pr_state, "Menu_Cursor", bi_Menu_Cursor, -1);
PR_AddBuiltin (&menu_pr_state, "Menu_KeyEvent", bi_Menu_KeyEvent, -1);
PR_AddBuiltin (&menu_pr_state, "Menu_End", bi_Menu_End, -1);
PR_AddBuiltin (&menu_pr_state, "Menu_TopMenu", bi_Menu_TopMenu, -1);
PR_AddBuiltin (&menu_pr_state, "Menu_SelectMenu", bi_Menu_SelectMenu, -1);
PR_AddBuiltin (&menu_pr_state, "Menu_SetQuit", bi_Menu_SetQuit, -1);
PR_AddBuiltin (&menu_pr_state, "Menu_Quit", bi_Menu_Quit, -1);
R_Progs_Init (&menu_pr_state);
Cmd_AddCommand ("togglemenu", togglemenu_f,
"Toggle the display of the menu");
Cmd_AddCommand ("quit", quit_f, "Exit the program");
}
void
@ -311,6 +365,11 @@ Menu_Draw (void)
*menu_pr_state.globals.time = *menu_pr_state.time;
if (menu->draw) {
PR_ExecuteProgram (&menu_pr_state, menu->draw);
return;
}
item = menu->items[menu->cur_item];
for (m_pic = menu->pics; m_pic; m_pic = m_pic->next) {
@ -333,9 +392,6 @@ Menu_Draw (void)
Draw_Character (item->x, item->y,
12 + ((int) (*con_data.realtime * 4) & 1));
}
if (menu_draw) {
PR_ExecuteProgram (&menu_pr_state, menu_draw);
}
}
void
@ -362,6 +418,20 @@ Menu_KeyEvent (knum_t key, short unicode, qboolean down)
menu->cur_item += menu->num_items - 1;
menu->cur_item %= menu->num_items;
break;
case QFK_RETURN:
case QFM_BUTTON1:
{
menu_item_t *item = menu->items[menu->cur_item];
if (item->func) {
G_INT (&menu_pr_state, OFS_PARM0) = key;
G_INT (&menu_pr_state, OFS_PARM1) =
PR_SetString (&menu_pr_state, item->text);
PR_ExecuteProgram (&menu_pr_state, item->func);
} else {
menu = item;
}
}
break;
default:
break;
}