2002-01-18 19:19:33 +00:00
|
|
|
/*
|
|
|
|
menu.c
|
|
|
|
|
|
|
|
Menu support code and interface to QC
|
|
|
|
|
|
|
|
Copyright (C) 2001 Bill Currie
|
|
|
|
|
|
|
|
Author: Bill Currie
|
|
|
|
Date: 2002/1/18
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
*/
|
2003-01-14 20:18:29 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2002-01-18 19:19:33 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2002-01-19 03:28:52 +00:00
|
|
|
#include "QF/cmd.h"
|
2002-01-18 19:19:33 +00:00
|
|
|
#include "QF/console.h"
|
2002-01-21 07:24:51 +00:00
|
|
|
#include "QF/csqc.h"
|
2002-04-09 17:00:39 +00:00
|
|
|
#include "QF/cvar.h"
|
2002-01-18 23:45:28 +00:00
|
|
|
#include "QF/draw.h"
|
2002-01-18 22:02:59 +00:00
|
|
|
#include "QF/hash.h"
|
2022-09-18 02:30:40 +00:00
|
|
|
#include "QF/keys.h"
|
2002-01-18 19:19:33 +00:00
|
|
|
#include "QF/progs.h"
|
2002-08-27 07:16:28 +00:00
|
|
|
#include "QF/quakefs.h"
|
2002-01-18 22:35:46 +00:00
|
|
|
#include "QF/render.h"
|
2004-01-16 05:46:19 +00:00
|
|
|
#include "QF/ruamoko.h"
|
2007-05-07 12:17:12 +00:00
|
|
|
#include "QF/sound.h"
|
2002-01-20 00:06:08 +00:00
|
|
|
#include "QF/sys.h"
|
2021-06-12 13:50:51 +00:00
|
|
|
|
2021-11-28 13:42:01 +00:00
|
|
|
#include "QF/input/event.h"
|
2021-06-12 13:50:51 +00:00
|
|
|
#include "QF/ui/view.h"
|
2002-01-18 19:19:33 +00:00
|
|
|
|
2012-02-13 12:58:34 +00:00
|
|
|
#include "QF/plugin/console.h"
|
2012-04-11 07:38:15 +00:00
|
|
|
#include "QF/plugin/vid_render.h"
|
2012-02-13 12:58:34 +00:00
|
|
|
|
2002-01-18 19:19:33 +00:00
|
|
|
typedef struct menu_pic_s {
|
|
|
|
struct menu_pic_s *next;
|
|
|
|
int x, y;
|
2002-07-25 05:33:16 +00:00
|
|
|
int srcx, srcy, width, height;
|
2002-01-18 19:19:33 +00:00
|
|
|
const char *name;
|
|
|
|
} menu_pic_t;
|
|
|
|
|
|
|
|
typedef struct menu_item_s {
|
|
|
|
struct menu_item_s *parent;
|
|
|
|
struct menu_item_s **items;
|
|
|
|
int num_items;
|
|
|
|
int max_items;
|
2002-01-19 07:19:39 +00:00
|
|
|
int cur_item;
|
2002-01-18 19:19:33 +00:00
|
|
|
int x, y;
|
2022-01-18 06:32:43 +00:00
|
|
|
pr_func_t func;
|
|
|
|
pr_func_t cursor;
|
|
|
|
pr_func_t keyevent;
|
|
|
|
pr_func_t draw;
|
|
|
|
pr_func_t enter_hook;
|
|
|
|
pr_func_t leave_hook;
|
2002-01-29 22:32:56 +00:00
|
|
|
unsigned fadescreen:1;
|
2002-02-01 17:32:40 +00:00
|
|
|
unsigned allkeys:1;
|
2002-01-18 19:19:33 +00:00
|
|
|
const char *text;
|
|
|
|
menu_pic_t *pics;
|
|
|
|
} menu_item_t;
|
|
|
|
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
static int confirm_quit;
|
|
|
|
static cvar_t confirm_quit_cvar = {
|
|
|
|
.name = "confirm_quit",
|
|
|
|
.description =
|
|
|
|
"confirm quit command",
|
|
|
|
.default_value = "1",
|
|
|
|
.flags = CVAR_ARCHIVE,
|
|
|
|
.value = { .type = &cexpr_int, .value = &confirm_quit },
|
|
|
|
};
|
2002-04-09 17:00:39 +00:00
|
|
|
|
2002-01-18 19:19:33 +00:00
|
|
|
static progs_t menu_pr_state;
|
|
|
|
static menu_item_t *menu;
|
2021-11-08 02:20:04 +00:00
|
|
|
//static keydest_t menu_keydest;
|
2002-01-18 22:02:59 +00:00
|
|
|
static hashtab_t *menu_hash;
|
2022-01-18 06:32:43 +00:00
|
|
|
static pr_func_t menu_init;
|
|
|
|
static pr_func_t menu_quit;
|
|
|
|
static pr_func_t menu_draw_hud;
|
|
|
|
static pr_func_t menu_pre;
|
|
|
|
static pr_func_t menu_post;
|
2002-01-18 23:45:28 +00:00
|
|
|
static const char *top_menu;
|
2002-01-18 22:02:59 +00:00
|
|
|
|
2011-03-21 04:14:14 +00:00
|
|
|
typedef struct menu_func_s {
|
|
|
|
const char *name;
|
2022-01-18 06:32:43 +00:00
|
|
|
pr_func_t *func;
|
2011-03-21 04:14:14 +00:00
|
|
|
} menu_func_t;
|
|
|
|
|
|
|
|
static menu_func_t menu_functions[] = {
|
|
|
|
{"menu_init", &menu_init},
|
|
|
|
{"menu_draw_hud", &menu_draw_hud},
|
|
|
|
{"menu_pre", &menu_pre},
|
|
|
|
{"menu_post", &menu_post},
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
run_menu_pre (void)
|
|
|
|
{
|
|
|
|
PR_ExecuteProgram (&menu_pr_state, menu_pre);
|
|
|
|
}
|
|
|
|
|
2010-11-22 04:26:23 +00:00
|
|
|
static void
|
|
|
|
run_menu_post (void)
|
|
|
|
{
|
|
|
|
PR_ExecuteProgram (&menu_pr_state, menu_post);
|
|
|
|
}
|
|
|
|
|
2002-01-18 22:02:59 +00:00
|
|
|
static int
|
2003-11-20 08:02:32 +00:00
|
|
|
menu_resolve_globals (progs_t *pr)
|
2002-01-18 22:02:59 +00:00
|
|
|
{
|
2003-01-06 18:28:13 +00:00
|
|
|
const char *sym;
|
2020-02-22 13:33:44 +00:00
|
|
|
pr_def_t *def;
|
2002-01-18 22:02:59 +00:00
|
|
|
dfunction_t *f;
|
2011-03-21 04:14:14 +00:00
|
|
|
size_t i;
|
|
|
|
|
|
|
|
for (i = 0;
|
|
|
|
i < sizeof (menu_functions) / sizeof (menu_functions[0]); i++) {
|
|
|
|
sym = menu_functions[i].name;
|
|
|
|
if (!(f = PR_FindFunction (pr, sym)))
|
|
|
|
goto error;
|
2022-01-18 06:32:43 +00:00
|
|
|
*menu_functions[i].func = (pr_func_t) (f - menu_pr_state.pr_functions);
|
2011-03-21 04:14:14 +00:00
|
|
|
}
|
2002-01-18 22:02:59 +00:00
|
|
|
|
2004-11-09 22:30:00 +00:00
|
|
|
if (!(def = PR_FindGlobal (pr, sym = "time")))
|
|
|
|
goto error;
|
2022-01-16 10:32:47 +00:00
|
|
|
menu_pr_state.globals.ftime = &G_FLOAT (pr, def->ofs);//FIXME double time
|
2002-01-18 22:02:59 +00:00
|
|
|
return 1;
|
|
|
|
error:
|
2007-11-06 10:17:14 +00:00
|
|
|
Sys_Printf ("%s: undefined symbol %s\n", pr->progs_name, sym);
|
2002-01-18 22:02:59 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *
|
2012-07-18 13:34:37 +00:00
|
|
|
menu_get_key (const void *m, void *unused)
|
2002-01-18 22:02:59 +00:00
|
|
|
{
|
2007-04-07 05:06:42 +00:00
|
|
|
return ((menu_item_t *) m)->text;
|
2002-01-18 22:02:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
menu_free (void *_m, void *unused)
|
|
|
|
{
|
2002-08-26 23:40:30 +00:00
|
|
|
int i;
|
2007-04-07 05:06:42 +00:00
|
|
|
menu_item_t *m = (menu_item_t *) _m;
|
2002-01-18 22:02:59 +00:00
|
|
|
|
|
|
|
if (m->text)
|
2007-04-07 05:06:42 +00:00
|
|
|
free ((char *) m->text);
|
2002-08-26 23:40:30 +00:00
|
|
|
if (m->parent) {
|
|
|
|
// remove self from parent list to avoid double frees
|
|
|
|
for (i = 0; i < m->parent->num_items; i++)
|
|
|
|
if (m->parent->items[i] == m)
|
|
|
|
m->parent->items[i] = 0;
|
|
|
|
}
|
2002-01-18 22:02:59 +00:00
|
|
|
if (m->items) {
|
|
|
|
for (i = 0; i < m->num_items; i++)
|
2002-08-26 23:40:30 +00:00
|
|
|
if (m->items[i]) {
|
|
|
|
m->items[i]->parent = 0;
|
|
|
|
if (m->items[i]->text)
|
|
|
|
Hash_Del (menu_hash, m->items[i]->text);
|
2002-01-20 04:11:08 +00:00
|
|
|
menu_free (m->items[i], 0);
|
2002-08-26 23:40:30 +00:00
|
|
|
}
|
2002-01-18 22:02:59 +00:00
|
|
|
free (m->items);
|
|
|
|
}
|
|
|
|
while (m->pics) {
|
|
|
|
menu_pic_t *p = m->pics;
|
|
|
|
m->pics = p->next;
|
|
|
|
if (p->name)
|
2007-04-07 05:06:42 +00:00
|
|
|
free ((char *) p->name);
|
2002-01-18 22:02:59 +00:00
|
|
|
free (p);
|
|
|
|
}
|
2002-05-11 00:36:12 +00:00
|
|
|
free (m);
|
2002-01-18 22:02:59 +00:00
|
|
|
}
|
2002-01-18 19:19:33 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
menu_add_item (menu_item_t *m, menu_item_t *i)
|
|
|
|
{
|
|
|
|
if (m->num_items == m->max_items) {
|
|
|
|
m->items = realloc (m->items,
|
|
|
|
(m->max_items + 8) * sizeof (menu_item_t *));
|
|
|
|
m->max_items += 8;
|
|
|
|
}
|
2002-01-18 22:02:59 +00:00
|
|
|
i->parent = m;
|
2002-01-18 19:19:33 +00:00
|
|
|
m->items[m->num_items++] = i;
|
|
|
|
}
|
|
|
|
|
2002-07-25 05:33:16 +00:00
|
|
|
static void
|
|
|
|
menu_pic (int x, int y, const char *name,
|
|
|
|
int srcx, int srcy, int width, int height)
|
|
|
|
{
|
|
|
|
menu_pic_t *pic = malloc (sizeof (menu_pic_t));
|
|
|
|
|
|
|
|
pic->x = x;
|
|
|
|
pic->y = y;
|
|
|
|
pic->name = strdup (name);
|
|
|
|
pic->srcx = srcx;
|
|
|
|
pic->srcy = srcy;
|
|
|
|
pic->width = width;
|
|
|
|
pic->height = height;
|
|
|
|
|
|
|
|
pic->next = menu->pics;
|
|
|
|
menu->pics = pic;
|
|
|
|
}
|
|
|
|
|
2002-01-18 19:19:33 +00:00
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_Menu_Begin (progs_t *pr, void *data)
|
2002-01-18 19:19:33 +00:00
|
|
|
{
|
2002-07-24 21:42:33 +00:00
|
|
|
int x = P_INT (pr, 0);
|
|
|
|
int y = P_INT (pr, 1);
|
2003-04-22 18:20:15 +00:00
|
|
|
const char *text = P_GSTRING (pr, 2);
|
2002-01-18 19:19:33 +00:00
|
|
|
menu_item_t *m = calloc (sizeof (menu_item_t), 1);
|
|
|
|
|
|
|
|
m->x = x;
|
|
|
|
m->y = y;
|
2002-08-26 23:40:30 +00:00
|
|
|
m->text = text && text[0] ? strdup (text) : 0;
|
2002-01-18 22:02:59 +00:00
|
|
|
if (menu)
|
|
|
|
menu_add_item (menu, m);
|
2002-01-18 19:19:33 +00:00
|
|
|
menu = m;
|
2002-08-26 23:40:30 +00:00
|
|
|
if (m->text)
|
|
|
|
Hash_Add (menu_hash, m);
|
2002-01-18 19:19:33 +00:00
|
|
|
}
|
|
|
|
|
2002-01-29 22:32:56 +00:00
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_Menu_FadeScreen (progs_t *pr, void *data)
|
2002-01-29 22:32:56 +00:00
|
|
|
{
|
2002-07-24 21:42:33 +00:00
|
|
|
menu->fadescreen = P_INT (pr, 0);
|
2002-01-29 22:32:56 +00:00
|
|
|
}
|
|
|
|
|
2002-01-20 00:06:08 +00:00
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_Menu_Draw (progs_t *pr, void *data)
|
2002-01-20 00:06:08 +00:00
|
|
|
{
|
2002-07-24 21:42:33 +00:00
|
|
|
menu->draw = P_FUNCTION (pr, 0);
|
2002-03-18 20:20:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_Menu_EnterHook (progs_t *pr, void *data)
|
2002-03-18 20:20:56 +00:00
|
|
|
{
|
2002-07-24 21:42:33 +00:00
|
|
|
menu->enter_hook = P_FUNCTION (pr, 0);
|
2002-03-18 20:20:56 +00:00
|
|
|
}
|
2002-01-20 00:06:08 +00:00
|
|
|
|
2002-03-18 20:20:56 +00:00
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_Menu_LeaveHook (progs_t *pr, void *data)
|
2002-03-18 20:20:56 +00:00
|
|
|
{
|
2002-07-24 21:42:33 +00:00
|
|
|
menu->leave_hook = P_FUNCTION (pr, 0);
|
2002-01-20 00:06:08 +00:00
|
|
|
}
|
|
|
|
|
2002-01-18 19:19:33 +00:00
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_Menu_Pic (progs_t *pr, void *data)
|
2002-01-18 19:19:33 +00:00
|
|
|
{
|
2002-07-24 21:42:33 +00:00
|
|
|
int x = P_INT (pr, 0);
|
|
|
|
int y = P_INT (pr, 1);
|
2003-04-22 18:20:15 +00:00
|
|
|
const char *name = P_GSTRING (pr, 2);
|
2002-01-18 19:19:33 +00:00
|
|
|
|
2002-07-25 05:33:16 +00:00
|
|
|
menu_pic (x, y, name, 0, 0, -1, -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_Menu_SubPic (progs_t *pr, void *data)
|
2002-07-25 05:33:16 +00:00
|
|
|
{
|
|
|
|
int x = P_INT (pr, 0);
|
|
|
|
int y = P_INT (pr, 1);
|
2003-04-22 18:20:15 +00:00
|
|
|
const char *name = P_GSTRING (pr, 2);
|
2002-07-25 05:33:16 +00:00
|
|
|
int srcx = P_INT (pr, 3);
|
|
|
|
int srcy = P_INT (pr, 4);
|
|
|
|
int width = P_INT (pr, 5);
|
|
|
|
int height = P_INT (pr, 6);
|
|
|
|
|
|
|
|
menu_pic (x, y, name, srcx, srcy, width, height);
|
2002-01-18 19:19:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_Menu_CenterPic (progs_t *pr, void *data)
|
2002-01-18 19:19:33 +00:00
|
|
|
{
|
2002-07-24 21:42:33 +00:00
|
|
|
int x = P_INT (pr, 0);
|
|
|
|
int y = P_INT (pr, 1);
|
2003-04-22 18:20:15 +00:00
|
|
|
const char *name = P_GSTRING (pr, 2);
|
2012-04-11 07:38:15 +00:00
|
|
|
qpic_t *qpic = r_funcs->Draw_CachePic (name, 1);
|
2002-01-18 19:19:33 +00:00
|
|
|
|
2002-07-25 05:33:16 +00:00
|
|
|
if (!qpic)
|
2002-01-19 06:18:52 +00:00
|
|
|
return;
|
|
|
|
|
2002-07-25 05:33:16 +00:00
|
|
|
menu_pic (x - qpic->width / 2, y, name, 0, 0, -1, -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_Menu_CenterSubPic (progs_t *pr, void *data)
|
2002-07-25 05:33:16 +00:00
|
|
|
{
|
|
|
|
int x = P_INT (pr, 0);
|
|
|
|
int y = P_INT (pr, 1);
|
2003-04-22 18:20:15 +00:00
|
|
|
const char *name = P_GSTRING (pr, 2);
|
2012-04-11 07:38:15 +00:00
|
|
|
qpic_t *qpic = r_funcs->Draw_CachePic (name, 1);
|
2002-07-25 05:33:16 +00:00
|
|
|
int srcx = P_INT (pr, 3);
|
|
|
|
int srcy = P_INT (pr, 4);
|
|
|
|
int width = P_INT (pr, 5);
|
|
|
|
int height = P_INT (pr, 6);
|
|
|
|
|
|
|
|
if (!qpic)
|
|
|
|
return;
|
|
|
|
|
|
|
|
menu_pic (x - qpic->width / 2, y, name, srcx, srcy, width, height);
|
2002-01-18 19:19:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_Menu_Item (progs_t *pr, void *data)
|
2002-01-18 19:19:33 +00:00
|
|
|
{
|
2002-07-24 21:42:33 +00:00
|
|
|
int x = P_INT (pr, 0);
|
|
|
|
int y = P_INT (pr, 1);
|
2003-04-22 18:20:15 +00:00
|
|
|
const char *text = P_GSTRING (pr, 2);
|
2022-01-18 06:32:43 +00:00
|
|
|
pr_func_t func = P_FUNCTION (pr, 3);
|
2002-07-24 21:42:33 +00:00
|
|
|
int allkeys = P_INT (pr, 4);
|
2002-01-18 19:19:33 +00:00
|
|
|
menu_item_t *mi = calloc (sizeof (menu_item_t), 1);
|
|
|
|
|
|
|
|
mi->x = x;
|
|
|
|
mi->y = y;
|
2002-08-26 23:40:30 +00:00
|
|
|
mi->text = text && text[0] ? strdup (text) : 0;
|
2002-01-18 19:19:33 +00:00
|
|
|
mi->func = func;
|
|
|
|
mi->parent = menu;
|
2002-02-01 17:32:40 +00:00
|
|
|
mi->allkeys = allkeys;
|
2002-01-18 19:19:33 +00:00
|
|
|
menu_add_item (menu, mi);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_Menu_Cursor (progs_t *pr, void *data)
|
2002-01-18 19:19:33 +00:00
|
|
|
{
|
2022-01-18 06:32:43 +00:00
|
|
|
pr_func_t func = P_FUNCTION (pr, 0);
|
2002-01-19 05:56:25 +00:00
|
|
|
|
2002-01-18 19:19:33 +00:00
|
|
|
menu->cursor = func;
|
|
|
|
}
|
|
|
|
|
2002-01-19 20:45:45 +00:00
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_Menu_KeyEvent (progs_t *pr, void *data)
|
2002-01-19 20:45:45 +00:00
|
|
|
{
|
2022-01-18 06:32:43 +00:00
|
|
|
pr_func_t func = P_FUNCTION (pr, 0);
|
2002-01-19 20:45:45 +00:00
|
|
|
|
|
|
|
menu->keyevent = func;
|
|
|
|
}
|
|
|
|
|
2002-01-18 19:19:33 +00:00
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_Menu_End (progs_t *pr, void *data)
|
2002-01-18 19:19:33 +00:00
|
|
|
{
|
|
|
|
menu = menu->parent;
|
|
|
|
}
|
|
|
|
|
2002-01-20 00:06:08 +00:00
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_Menu_TopMenu (progs_t *pr, void *data)
|
2002-01-20 00:06:08 +00:00
|
|
|
{
|
2003-04-22 18:20:15 +00:00
|
|
|
const char *name = P_GSTRING (pr, 0);
|
2002-01-20 00:06:08 +00:00
|
|
|
|
|
|
|
if (top_menu)
|
2007-04-07 05:06:42 +00:00
|
|
|
free ((char *) top_menu);
|
2002-01-20 00:06:08 +00:00
|
|
|
top_menu = strdup (name);
|
|
|
|
}
|
2021-11-28 13:42:01 +00:00
|
|
|
|
2002-01-20 00:06:08 +00:00
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_Menu_SelectMenu (progs_t *pr, void *data)
|
2002-01-20 00:06:08 +00:00
|
|
|
{
|
2003-04-22 18:20:15 +00:00
|
|
|
const char *name = P_GSTRING (pr, 0);
|
2002-01-20 00:06:08 +00:00
|
|
|
|
2002-01-21 19:40:45 +00:00
|
|
|
menu = 0;
|
|
|
|
if (name && *name)
|
|
|
|
menu = Hash_Find (menu_hash, name);
|
2002-01-20 00:32:14 +00:00
|
|
|
if (menu) {
|
2021-11-28 13:42:01 +00:00
|
|
|
Con_SetState (con_menu);
|
2002-03-19 16:59:25 +00:00
|
|
|
if (menu->enter_hook) {
|
2011-03-21 04:14:14 +00:00
|
|
|
run_menu_pre ();
|
2002-03-19 16:59:25 +00:00
|
|
|
PR_ExecuteProgram (&menu_pr_state, menu->enter_hook);
|
2010-11-22 04:26:23 +00:00
|
|
|
run_menu_post ();
|
2002-03-19 16:59:25 +00:00
|
|
|
}
|
2002-01-20 00:32:14 +00:00
|
|
|
} else {
|
2002-01-21 19:40:45 +00:00
|
|
|
if (name && *name)
|
2007-11-06 10:17:14 +00:00
|
|
|
Sys_Printf ("no menu \"%s\"\n", name);
|
2021-11-28 13:42:01 +00:00
|
|
|
Con_SetState (con_inactive);
|
2002-01-20 00:32:14 +00:00
|
|
|
}
|
2002-01-20 00:06:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_Menu_SetQuit (progs_t *pr, void *data)
|
2002-01-20 00:06:08 +00:00
|
|
|
{
|
2022-01-18 06:32:43 +00:00
|
|
|
pr_func_t func = P_FUNCTION (pr, 0);
|
2002-01-20 00:06:08 +00:00
|
|
|
|
|
|
|
menu_quit = func;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_Menu_Quit (progs_t *pr, void *data)
|
2002-01-20 00:06:08 +00:00
|
|
|
{
|
|
|
|
if (con_data.quit)
|
|
|
|
con_data.quit ();
|
|
|
|
Sys_Quit ();
|
|
|
|
}
|
|
|
|
|
2002-01-23 21:07:38 +00:00
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_Menu_GetIndex (progs_t *pr, void *data)
|
2002-01-23 21:07:38 +00:00
|
|
|
{
|
|
|
|
if (menu) {
|
2002-07-24 21:42:33 +00:00
|
|
|
R_INT (pr) = menu->cur_item;
|
2002-01-23 21:07:38 +00:00
|
|
|
} else {
|
2002-07-24 21:42:33 +00:00
|
|
|
R_INT (pr) = -1;
|
2002-01-23 21:07:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-13 09:53:21 +00:00
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_Menu_Next (progs_t *pr, void *data)
|
2013-01-13 09:53:21 +00:00
|
|
|
{
|
|
|
|
menu->cur_item++;
|
|
|
|
menu->cur_item %= menu->num_items;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_Menu_Prev (progs_t *pr, void *data)
|
2013-01-13 09:53:21 +00:00
|
|
|
{
|
|
|
|
menu->cur_item += menu->num_items - 1;
|
|
|
|
menu->cur_item %= menu->num_items;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_Menu_Enter (progs_t *pr, void *data)
|
2013-01-13 09:53:21 +00:00
|
|
|
{
|
|
|
|
menu_item_t *item;
|
|
|
|
|
2013-01-13 12:49:43 +00:00
|
|
|
if (!menu)
|
|
|
|
return;
|
|
|
|
|
2013-01-13 09:53:21 +00:00
|
|
|
item = menu->items[menu->cur_item];
|
|
|
|
if (item->func) {
|
|
|
|
run_menu_pre ();
|
|
|
|
PR_PushFrame (&menu_pr_state);
|
|
|
|
PR_RESET_PARAMS (&menu_pr_state);
|
|
|
|
P_STRING (&menu_pr_state, 0) =
|
|
|
|
PR_SetTempString (&menu_pr_state, item->text);
|
|
|
|
P_INT (&menu_pr_state, 1) = 0;
|
2020-02-25 08:28:32 +00:00
|
|
|
pr->pr_argc = 2;
|
2013-01-13 09:53:21 +00:00
|
|
|
PR_ExecuteProgram (&menu_pr_state, item->func);
|
|
|
|
PR_PopFrame (&menu_pr_state);
|
|
|
|
run_menu_post ();
|
|
|
|
} else {
|
|
|
|
menu = item;
|
|
|
|
if (menu->enter_hook) {
|
|
|
|
run_menu_pre ();
|
|
|
|
PR_ExecuteProgram (&menu_pr_state, menu->enter_hook);
|
|
|
|
run_menu_post ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-26 19:34:53 +00:00
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_Menu_Leave (progs_t *pr, void *data)
|
2013-01-26 19:34:53 +00:00
|
|
|
{
|
|
|
|
if (menu) {
|
|
|
|
if (menu->leave_hook) {
|
|
|
|
run_menu_pre ();
|
|
|
|
PR_ExecuteProgram (&menu_pr_state, menu->leave_hook);
|
|
|
|
run_menu_post ();
|
|
|
|
}
|
|
|
|
menu = menu->parent;
|
|
|
|
if (!menu) {
|
2021-11-28 13:42:01 +00:00
|
|
|
Con_SetState (con_inactive);
|
2013-01-26 19:34:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-01-19 03:28:52 +00:00
|
|
|
static void
|
|
|
|
togglemenu_f (void)
|
|
|
|
{
|
|
|
|
if (menu)
|
|
|
|
Menu_Leave ();
|
|
|
|
else
|
|
|
|
Menu_Enter ();
|
|
|
|
}
|
|
|
|
|
2002-01-20 00:06:08 +00:00
|
|
|
static void
|
|
|
|
quit_f (void)
|
|
|
|
{
|
2010-11-22 04:26:23 +00:00
|
|
|
int ret;
|
|
|
|
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
if (confirm_quit && menu_quit) {
|
2011-03-21 04:14:14 +00:00
|
|
|
run_menu_pre ();
|
2002-01-20 00:06:08 +00:00
|
|
|
PR_ExecuteProgram (&menu_pr_state, menu_quit);
|
2010-11-22 04:26:23 +00:00
|
|
|
ret = R_INT (&menu_pr_state);
|
|
|
|
run_menu_post ();
|
|
|
|
if (!ret)
|
2002-01-20 00:06:08 +00:00
|
|
|
return;
|
|
|
|
}
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_Menu_Quit (&menu_pr_state, 0);
|
2002-01-20 00:06:08 +00:00
|
|
|
}
|
|
|
|
|
2002-01-29 20:53:44 +00:00
|
|
|
static void *
|
|
|
|
menu_allocate_progs_mem (progs_t *pr, int size)
|
|
|
|
{
|
|
|
|
return malloc (size);
|
|
|
|
}
|
|
|
|
|
2002-01-30 06:21:20 +00:00
|
|
|
static void
|
|
|
|
menu_free_progs_mem (progs_t *pr, void *mem)
|
|
|
|
{
|
|
|
|
free (mem);
|
|
|
|
}
|
|
|
|
|
2002-10-22 04:30:20 +00:00
|
|
|
static void *
|
2020-02-21 12:17:28 +00:00
|
|
|
menu_load_file (progs_t *pr, const char *path, off_t *size)
|
2002-10-22 04:30:20 +00:00
|
|
|
{
|
2020-02-21 12:17:28 +00:00
|
|
|
void *data = QFS_LoadFile (QFS_FOpenFile (path), 0);
|
|
|
|
*size = qfs_filesize;
|
|
|
|
return data;
|
2002-10-22 04:30:20 +00:00
|
|
|
}
|
|
|
|
|
2022-01-23 12:54:03 +00:00
|
|
|
#define bi(x,np,params...) {#x, bi_##x, -1, np, {params}}
|
|
|
|
#define p(type) PR_PARAM(type)
|
2004-01-06 05:51:09 +00:00
|
|
|
static builtin_t builtins[] = {
|
2022-01-23 12:54:03 +00:00
|
|
|
bi(Menu_Begin, 3, p(int), p(int), p(string)),
|
|
|
|
bi(Menu_FadeScreen, 1, p(int)),
|
|
|
|
bi(Menu_Draw, 2, p(int), p(int)),
|
|
|
|
bi(Menu_EnterHook, 1, p(func)),
|
|
|
|
bi(Menu_LeaveHook, 1, p(func)),
|
|
|
|
bi(Menu_Pic, 3, p(int), p(int), p(string)),
|
|
|
|
bi(Menu_SubPic, 7, p(int), p(int), p(string),
|
|
|
|
p(int), p(int), p(int), p(int)),
|
|
|
|
bi(Menu_CenterPic, 3, p(int), p(int), p(string)),
|
|
|
|
bi(Menu_CenterSubPic, 7, p(int), p(int), p(string),
|
|
|
|
p(int), p(int), p(int), p(int)),
|
|
|
|
bi(Menu_Item, 5, p(int), p(int), p(string), p(func), p(int)),
|
|
|
|
bi(Menu_Cursor, 1, p(func)),
|
|
|
|
bi(Menu_KeyEvent, 1, p(func)),
|
|
|
|
bi(Menu_End, 0),
|
|
|
|
bi(Menu_TopMenu, 1, p(string)),
|
|
|
|
bi(Menu_SelectMenu, 1, p(string)),
|
|
|
|
bi(Menu_SetQuit, 1, p(func)),
|
|
|
|
bi(Menu_Quit, 0),
|
|
|
|
bi(Menu_GetIndex, 0),
|
|
|
|
bi(Menu_Next, 0),
|
|
|
|
bi(Menu_Prev, 0),
|
|
|
|
bi(Menu_Enter, 0),
|
|
|
|
bi(Menu_Leave, 0),
|
2004-01-06 05:51:09 +00:00
|
|
|
{0},
|
|
|
|
};
|
|
|
|
|
2021-11-28 13:42:01 +00:00
|
|
|
static int//FIXME reimplement users properly (or remove?)
|
|
|
|
Menu_KeyEvent (int key, int unicode, int pressed)
|
|
|
|
{
|
|
|
|
IE_event_t event = {
|
|
|
|
.type = ie_key,
|
|
|
|
.when = Sys_LongTime (),
|
|
|
|
.key = {
|
|
|
|
.code = key,
|
|
|
|
.unicode = unicode,
|
|
|
|
}
|
|
|
|
};
|
|
|
|
return IE_Send_Event (&event);
|
|
|
|
}
|
2013-01-26 19:34:53 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
Menu_Enter_f (void)
|
|
|
|
{
|
|
|
|
if (!Menu_KeyEvent(QFK_RETURN, '\0', true))
|
|
|
|
Menu_KeyEvent('y', 'y', true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Menu_Leave_f (void)
|
|
|
|
{
|
|
|
|
Menu_Leave ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Menu_Prev_f (void)
|
|
|
|
{
|
|
|
|
Menu_KeyEvent (QFK_UP, '\0', true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Menu_Next_f (void)
|
|
|
|
{
|
|
|
|
Menu_KeyEvent (QFK_DOWN, '\0', true);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-01-18 19:19:33 +00:00
|
|
|
void
|
|
|
|
Menu_Init (void)
|
|
|
|
{
|
|
|
|
menu_pr_state.progs_name = "menu.dat";
|
2002-01-29 20:53:44 +00:00
|
|
|
menu_pr_state.allocate_progs_mem = menu_allocate_progs_mem;
|
2002-01-30 06:21:20 +00:00
|
|
|
menu_pr_state.free_progs_mem = menu_free_progs_mem;
|
2002-10-22 04:30:20 +00:00
|
|
|
menu_pr_state.load_file = menu_load_file;
|
2004-11-09 22:35:00 +00:00
|
|
|
menu_pr_state.resolve = menu_resolve_globals;
|
2002-01-18 19:19:33 +00:00
|
|
|
|
2018-10-11 01:06:48 +00:00
|
|
|
menu_pr_state.max_edicts = 0;
|
|
|
|
menu_pr_state.zone_size = 1024 * 1024;
|
2022-02-04 12:53:37 +00:00
|
|
|
menu_pr_state.stack_size = 64 * 1024;
|
2018-10-11 01:06:48 +00:00
|
|
|
|
2020-02-23 06:56:36 +00:00
|
|
|
PR_Init (&menu_pr_state);
|
|
|
|
|
2020-03-25 06:43:16 +00:00
|
|
|
menu_hash = Hash_NewTable (61, menu_get_key, menu_free, 0, 0);
|
2002-01-18 22:02:59 +00:00
|
|
|
|
2022-01-23 15:20:05 +00:00
|
|
|
PR_RegisterBuiltins (&menu_pr_state, builtins, 0);
|
2002-01-18 22:35:46 +00:00
|
|
|
|
2021-12-20 15:47:13 +00:00
|
|
|
RUA_Init (&menu_pr_state, 3);
|
2004-01-16 07:03:58 +00:00
|
|
|
|
2002-01-23 22:37:44 +00:00
|
|
|
InputLine_Progs_Init (&menu_pr_state);
|
2021-12-20 15:47:13 +00:00
|
|
|
RUA_Game_Init (&menu_pr_state, 1);
|
2004-01-16 05:46:19 +00:00
|
|
|
GIB_Progs_Init (&menu_pr_state);
|
2002-01-20 01:39:06 +00:00
|
|
|
PR_Cmds_Init (&menu_pr_state);
|
2002-01-18 22:35:46 +00:00
|
|
|
R_Progs_Init (&menu_pr_state);
|
2007-05-07 12:17:12 +00:00
|
|
|
S_Progs_Init (&menu_pr_state);
|
2004-01-16 05:46:19 +00:00
|
|
|
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
Cvar_Register (&confirm_quit_cvar, 0, 0);
|
2002-04-09 17:00:39 +00:00
|
|
|
|
2002-01-19 03:28:52 +00:00
|
|
|
Cmd_AddCommand ("togglemenu", togglemenu_f,
|
|
|
|
"Toggle the display of the menu");
|
2012-04-12 06:07:28 +00:00
|
|
|
Cmd_RemoveCommand ("quit");
|
2002-01-20 00:06:08 +00:00
|
|
|
Cmd_AddCommand ("quit", quit_f, "Exit the program");
|
2013-01-26 19:34:53 +00:00
|
|
|
Cmd_AddCommand ("Menu_Enter", Menu_Enter_f, "Do menu action/move up in the menu tree.");
|
|
|
|
Cmd_AddCommand ("Menu_Leave", Menu_Leave_f, "Move down in the menu tree.");
|
|
|
|
Cmd_AddCommand ("Menu_Prev", Menu_Prev_f, "Move cursor up.");
|
|
|
|
Cmd_AddCommand ("Menu_Next", Menu_Next_f, "Move cursor up.");
|
2002-01-18 19:19:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Menu_Load (void)
|
|
|
|
{
|
|
|
|
int size;
|
2002-08-27 07:16:28 +00:00
|
|
|
QFile *file;
|
2002-01-18 19:19:33 +00:00
|
|
|
|
2002-01-18 22:02:59 +00:00
|
|
|
Hash_FlushTable (menu_hash);
|
|
|
|
menu = 0;
|
2002-01-18 23:45:28 +00:00
|
|
|
top_menu = 0;
|
2002-01-18 19:19:33 +00:00
|
|
|
|
2003-11-20 08:02:32 +00:00
|
|
|
menu_pr_state.progs = 0;
|
2014-01-23 02:57:57 +00:00
|
|
|
if ((file = QFS_FOpenFile (menu_pr_state.progs_name))) {
|
|
|
|
size = Qfilesize (file);
|
2018-10-11 01:06:48 +00:00
|
|
|
PR_LoadProgsFile (&menu_pr_state, file, size);
|
2002-01-18 19:19:33 +00:00
|
|
|
Qclose (file);
|
2002-01-18 22:02:59 +00:00
|
|
|
|
2020-06-24 13:47:12 +00:00
|
|
|
if (!PR_RunLoadFuncs (&menu_pr_state)
|
|
|
|
|| !PR_RunPostLoadFuncs (&menu_pr_state)) {
|
2002-01-18 19:19:33 +00:00
|
|
|
free (menu_pr_state.progs);
|
|
|
|
menu_pr_state.progs = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!menu_pr_state.progs) {
|
|
|
|
// Not a fatal error, just means no menus
|
|
|
|
Con_SetOrMask (0x80);
|
2007-11-06 10:17:14 +00:00
|
|
|
Sys_Printf ("Menu_Load: could not load %s\n",
|
2002-01-18 22:02:59 +00:00
|
|
|
menu_pr_state.progs_name);
|
2002-01-18 19:19:33 +00:00
|
|
|
Con_SetOrMask (0x00);
|
|
|
|
return;
|
|
|
|
}
|
2011-03-21 04:14:14 +00:00
|
|
|
run_menu_pre ();
|
2004-01-16 07:03:58 +00:00
|
|
|
RUA_Cbuf_SetCbuf (&menu_pr_state, con_data.cbuf);
|
2002-08-20 21:19:53 +00:00
|
|
|
InputLine_Progs_SetDraw (&menu_pr_state, C_DrawInputLine);
|
2002-01-18 22:02:59 +00:00
|
|
|
PR_ExecuteProgram (&menu_pr_state, menu_init);
|
2010-11-22 04:26:23 +00:00
|
|
|
run_menu_post ();
|
2002-01-18 22:02:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2022-11-04 01:38:07 +00:00
|
|
|
Menu_Draw (view_t view)
|
2002-01-18 22:02:59 +00:00
|
|
|
{
|
2002-01-18 23:45:28 +00:00
|
|
|
menu_pic_t *m_pic;
|
2003-05-06 02:19:13 +00:00
|
|
|
int i, x, y;
|
2002-01-19 07:19:39 +00:00
|
|
|
menu_item_t *item;
|
2002-01-18 23:45:28 +00:00
|
|
|
|
2002-01-18 22:02:59 +00:00
|
|
|
if (!menu)
|
|
|
|
return;
|
2002-01-19 07:19:39 +00:00
|
|
|
|
2022-11-04 01:38:07 +00:00
|
|
|
view_pos_t abs = View_GetAbs (view);
|
|
|
|
x = abs.x;
|
|
|
|
y = abs.y;
|
2003-05-06 02:19:13 +00:00
|
|
|
|
2002-01-29 22:32:56 +00:00
|
|
|
if (menu->fadescreen)
|
2012-04-11 07:38:15 +00:00
|
|
|
r_funcs->Draw_FadeScreen ();
|
2002-01-29 22:32:56 +00:00
|
|
|
|
2022-01-16 10:32:47 +00:00
|
|
|
*menu_pr_state.globals.ftime = *con_data.realtime;//FIXME double time
|
2002-01-19 07:19:39 +00:00
|
|
|
|
2002-01-20 00:06:08 +00:00
|
|
|
if (menu->draw) {
|
2010-11-22 04:26:23 +00:00
|
|
|
int ret;
|
|
|
|
|
2011-03-21 04:14:14 +00:00
|
|
|
run_menu_pre ();
|
2022-02-05 01:24:02 +00:00
|
|
|
PR_PushFrame (&menu_pr_state);
|
2005-06-12 09:54:01 +00:00
|
|
|
PR_RESET_PARAMS (&menu_pr_state);
|
2003-05-06 02:19:13 +00:00
|
|
|
P_INT (&menu_pr_state, 0) = x;
|
|
|
|
P_INT (&menu_pr_state, 1) = y;
|
2020-02-25 08:28:32 +00:00
|
|
|
menu_pr_state.pr_argc = 2;
|
2002-01-20 00:06:08 +00:00
|
|
|
PR_ExecuteProgram (&menu_pr_state, menu->draw);
|
2010-11-22 04:26:23 +00:00
|
|
|
ret = R_INT (&menu_pr_state);
|
2022-02-05 01:24:02 +00:00
|
|
|
PR_PopFrame (&menu_pr_state);
|
2010-11-22 04:26:23 +00:00
|
|
|
run_menu_post ();
|
|
|
|
if (!ret)
|
2002-01-23 00:48:03 +00:00
|
|
|
return;
|
2002-01-20 00:06:08 +00:00
|
|
|
}
|
|
|
|
|
2002-01-19 07:19:39 +00:00
|
|
|
|
2002-01-18 23:45:28 +00:00
|
|
|
for (m_pic = menu->pics; m_pic; m_pic = m_pic->next) {
|
2012-04-11 07:38:15 +00:00
|
|
|
qpic_t *pic = r_funcs->Draw_CachePic (m_pic->name, 1);
|
2002-01-18 23:45:28 +00:00
|
|
|
if (!pic)
|
|
|
|
continue;
|
2002-07-25 05:33:16 +00:00
|
|
|
if (m_pic->width > 0 && m_pic->height > 0)
|
2012-04-11 07:38:15 +00:00
|
|
|
r_funcs->Draw_SubPic (x + m_pic->x, y + m_pic->y, pic,
|
2003-05-06 02:19:13 +00:00
|
|
|
m_pic->srcx, m_pic->srcy,
|
2002-07-25 05:33:16 +00:00
|
|
|
m_pic->width, m_pic->height);
|
|
|
|
else
|
2012-04-11 07:38:15 +00:00
|
|
|
r_funcs->Draw_Pic (x + m_pic->x, y + m_pic->y, pic);
|
2002-01-18 23:45:28 +00:00
|
|
|
}
|
|
|
|
for (i = 0; i < menu->num_items; i++) {
|
|
|
|
if (menu->items[i]->text) {
|
2012-04-11 07:38:15 +00:00
|
|
|
r_funcs->Draw_String (x + menu->items[i]->x + 8,
|
|
|
|
y + menu->items[i]->y,
|
2002-01-18 23:45:28 +00:00
|
|
|
menu->items[i]->text);
|
|
|
|
}
|
|
|
|
}
|
2002-01-21 21:38:34 +00:00
|
|
|
if (!menu->items)
|
|
|
|
return;
|
|
|
|
item = menu->items[menu->cur_item];
|
2002-01-18 23:45:28 +00:00
|
|
|
if (menu->cursor) {
|
2011-03-21 04:14:14 +00:00
|
|
|
run_menu_pre ();
|
2022-02-05 01:24:02 +00:00
|
|
|
PR_PushFrame (&menu_pr_state);
|
2005-06-12 09:54:01 +00:00
|
|
|
PR_RESET_PARAMS (&menu_pr_state);
|
2003-05-06 02:19:13 +00:00
|
|
|
P_INT (&menu_pr_state, 0) = x + item->x;
|
|
|
|
P_INT (&menu_pr_state, 1) = y + item->y;
|
2020-02-25 08:28:32 +00:00
|
|
|
menu_pr_state.pr_argc = 2;
|
2002-01-18 23:45:28 +00:00
|
|
|
PR_ExecuteProgram (&menu_pr_state, menu->cursor);
|
2022-02-05 01:24:02 +00:00
|
|
|
PR_PopFrame (&menu_pr_state);
|
2010-11-22 04:26:23 +00:00
|
|
|
run_menu_post ();
|
2002-01-19 07:19:39 +00:00
|
|
|
} else {
|
2012-04-11 07:38:15 +00:00
|
|
|
r_funcs->Draw_Character (x + item->x, y + item->y,
|
|
|
|
12 + ((int) (*con_data.realtime * 4) & 1));
|
2002-01-18 23:45:28 +00:00
|
|
|
}
|
2002-01-18 22:02:59 +00:00
|
|
|
}
|
|
|
|
|
2003-05-14 21:17:32 +00:00
|
|
|
void
|
2022-11-04 01:38:07 +00:00
|
|
|
Menu_Draw_Hud (view_t view)
|
2003-05-14 21:17:32 +00:00
|
|
|
{
|
2011-03-21 04:14:14 +00:00
|
|
|
run_menu_pre ();
|
2022-01-16 10:32:47 +00:00
|
|
|
*menu_pr_state.globals.ftime = *con_data.realtime;//FIXME double time
|
2003-05-23 02:50:15 +00:00
|
|
|
|
2003-05-14 21:17:32 +00:00
|
|
|
PR_ExecuteProgram (&menu_pr_state, menu_draw_hud);
|
2010-11-22 04:26:23 +00:00
|
|
|
run_menu_post ();
|
2003-05-14 21:17:32 +00:00
|
|
|
}
|
|
|
|
|
2021-11-28 13:42:01 +00:00
|
|
|
static int
|
|
|
|
menu_key_event (const IE_event_t *ie_event)
|
2002-01-18 22:02:59 +00:00
|
|
|
{
|
2002-02-01 18:50:56 +00:00
|
|
|
menu_item_t *item;
|
2010-11-22 04:26:23 +00:00
|
|
|
int ret;
|
2021-11-28 13:42:01 +00:00
|
|
|
__auto_type key = ie_event->key;
|
2002-02-01 18:50:56 +00:00
|
|
|
|
2002-01-18 22:02:59 +00:00
|
|
|
if (!menu)
|
2011-03-25 09:02:59 +00:00
|
|
|
return 0;
|
2002-01-19 20:45:45 +00:00
|
|
|
if (menu->keyevent) {
|
2011-03-21 04:14:14 +00:00
|
|
|
run_menu_pre ();
|
2022-02-05 01:24:02 +00:00
|
|
|
PR_PushFrame (&menu_pr_state);
|
2005-06-12 09:54:01 +00:00
|
|
|
PR_RESET_PARAMS (&menu_pr_state);
|
2021-11-28 13:42:01 +00:00
|
|
|
P_INT (&menu_pr_state, 0) = key.code;
|
|
|
|
P_INT (&menu_pr_state, 1) = key.unicode;
|
|
|
|
P_INT (&menu_pr_state, 2) = 1; //FIXME only presses now
|
2020-02-25 08:28:32 +00:00
|
|
|
menu_pr_state.pr_argc = 3;
|
2002-01-19 20:45:45 +00:00
|
|
|
PR_ExecuteProgram (&menu_pr_state, menu->keyevent);
|
2010-11-22 04:26:23 +00:00
|
|
|
ret = R_INT (&menu_pr_state);
|
2022-02-05 01:24:02 +00:00
|
|
|
PR_PopFrame (&menu_pr_state);
|
2010-11-22 04:26:23 +00:00
|
|
|
run_menu_post ();
|
|
|
|
if (ret)
|
2011-03-25 09:02:59 +00:00
|
|
|
return 1;
|
2002-02-01 17:32:40 +00:00
|
|
|
} else if (menu->items && menu->items[menu->cur_item]->func
|
|
|
|
&& menu->items[menu->cur_item]->allkeys) {
|
2011-03-21 04:14:14 +00:00
|
|
|
run_menu_pre ();
|
2004-01-05 07:10:32 +00:00
|
|
|
PR_PushFrame (&menu_pr_state);
|
2002-02-01 18:50:56 +00:00
|
|
|
item = menu->items[menu->cur_item];
|
2005-06-12 09:54:01 +00:00
|
|
|
PR_RESET_PARAMS (&menu_pr_state);
|
2004-01-05 07:10:32 +00:00
|
|
|
P_STRING (&menu_pr_state, 0) = PR_SetTempString (&menu_pr_state,
|
|
|
|
item->text);
|
2021-11-28 13:42:01 +00:00
|
|
|
P_INT (&menu_pr_state, 1) = key.code;
|
2020-02-25 08:28:32 +00:00
|
|
|
menu_pr_state.pr_argc = 2;
|
2002-02-01 18:50:56 +00:00
|
|
|
PR_ExecuteProgram (&menu_pr_state, item->func);
|
2010-11-22 04:26:23 +00:00
|
|
|
ret = R_INT (&menu_pr_state);
|
2022-02-05 01:24:02 +00:00
|
|
|
PR_PopFrame (&menu_pr_state);
|
2010-11-22 04:26:23 +00:00
|
|
|
run_menu_post ();
|
|
|
|
if (ret)
|
2011-03-25 09:02:59 +00:00
|
|
|
return 1;
|
2002-01-19 20:45:45 +00:00
|
|
|
}
|
2021-11-28 13:42:01 +00:00
|
|
|
if (key.code == QFK_ESCAPE) {
|
|
|
|
Menu_Leave ();
|
|
|
|
return 1;
|
|
|
|
}
|
2002-01-21 19:40:45 +00:00
|
|
|
if (!menu || !menu->items)
|
2011-03-25 09:02:59 +00:00
|
|
|
return 0;
|
2021-11-28 13:42:01 +00:00
|
|
|
switch (key.code) {
|
|
|
|
case QFK_ESCAPE:
|
|
|
|
break;
|
2002-01-19 07:19:39 +00:00
|
|
|
case QFK_DOWN:
|
2021-11-08 02:20:04 +00:00
|
|
|
// case QFM_WHEEL_DOWN:
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_Menu_Next (&menu_pr_state, 0);
|
2021-11-28 13:42:01 +00:00
|
|
|
break;
|
2002-01-19 07:19:39 +00:00
|
|
|
case QFK_UP:
|
2021-11-08 02:20:04 +00:00
|
|
|
// case QFM_WHEEL_UP:
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_Menu_Prev (&menu_pr_state, 0);
|
2021-11-28 13:42:01 +00:00
|
|
|
break;
|
2002-01-20 00:06:08 +00:00
|
|
|
case QFK_RETURN:
|
2021-11-08 02:20:04 +00:00
|
|
|
// case QFM_BUTTON1:
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_Menu_Enter (&menu_pr_state, 0);
|
2021-11-28 13:42:01 +00:00
|
|
|
break;
|
2002-01-19 07:19:39 +00:00
|
|
|
default:
|
2021-11-28 13:42:01 +00:00
|
|
|
break;
|
2002-01-19 07:19:39 +00:00
|
|
|
}
|
2021-11-28 13:42:01 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
menu_mouse_event (const IE_event_t *ie_event)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
Menu_EventHandler (const IE_event_t *ie_event)
|
|
|
|
{
|
|
|
|
static int (*handlers[ie_event_count]) (const IE_event_t *ie_event) = {
|
|
|
|
[ie_key] = menu_key_event,
|
|
|
|
[ie_mouse] = menu_mouse_event,
|
|
|
|
};
|
2022-03-30 15:16:29 +00:00
|
|
|
if ((unsigned) ie_event->type >= ie_event_count
|
2021-11-28 13:42:01 +00:00
|
|
|
|| !handlers[ie_event->type]) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return handlers[ie_event->type] (ie_event);
|
2002-01-18 19:19:33 +00:00
|
|
|
}
|
2002-01-18 23:45:28 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
Menu_Enter ()
|
|
|
|
{
|
|
|
|
if (!top_menu) {
|
2021-11-28 13:42:01 +00:00
|
|
|
Con_SetState (con_active);
|
2002-01-18 23:45:28 +00:00
|
|
|
return;
|
|
|
|
}
|
2021-11-28 13:42:01 +00:00
|
|
|
if (!menu) {
|
|
|
|
menu = Hash_Find (menu_hash, top_menu);
|
|
|
|
}
|
2021-03-29 13:39:43 +00:00
|
|
|
if (menu) {
|
2021-11-28 13:42:01 +00:00
|
|
|
Con_SetState (con_menu);
|
2021-03-29 13:39:43 +00:00
|
|
|
if (menu->enter_hook) {
|
|
|
|
run_menu_pre ();
|
|
|
|
PR_ExecuteProgram (&menu_pr_state, menu->enter_hook);
|
|
|
|
run_menu_post ();
|
|
|
|
}
|
2002-03-18 20:20:56 +00:00
|
|
|
}
|
2002-01-18 23:45:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Menu_Leave ()
|
|
|
|
{
|
|
|
|
if (menu) {
|
2002-03-18 20:20:56 +00:00
|
|
|
if (menu->leave_hook) {
|
2011-03-21 04:14:14 +00:00
|
|
|
run_menu_pre ();
|
2002-03-18 20:20:56 +00:00
|
|
|
PR_ExecuteProgram (&menu_pr_state, menu->leave_hook);
|
2010-11-22 04:26:23 +00:00
|
|
|
run_menu_post ();
|
2002-03-18 20:20:56 +00:00
|
|
|
}
|
2002-01-18 23:45:28 +00:00
|
|
|
menu = menu->parent;
|
|
|
|
if (!menu) {
|
2021-11-28 13:42:01 +00:00
|
|
|
Con_SetState (con_inactive);
|
2002-01-18 23:45:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|