2005-02-28 07:16:19 +00:00
|
|
|
//read menu.h
|
|
|
|
|
2004-08-23 00:15:46 +00:00
|
|
|
#include "quakedef.h"
|
2009-11-04 21:16:50 +00:00
|
|
|
#include "shader.h"
|
2004-08-23 00:15:46 +00:00
|
|
|
|
|
|
|
int selectitem;
|
|
|
|
menu_t *menu_script;
|
2006-02-11 02:09:43 +00:00
|
|
|
cvar_t menualias = SCVAR("menualias", "");
|
2004-08-23 00:15:46 +00:00
|
|
|
|
|
|
|
void M_Script_Remove (menu_t *menu)
|
|
|
|
{
|
|
|
|
menu_script = NULL;
|
|
|
|
Cvar_Set(&menualias, "");
|
|
|
|
}
|
|
|
|
qboolean M_Script_Key (int key, menu_t *menu)
|
|
|
|
{
|
|
|
|
if (menu->selecteditem && menu->selecteditem->common.type == mt_edit)
|
|
|
|
return false;
|
2006-11-03 15:53:04 +00:00
|
|
|
if (key >= '0' && key <= '9' && *menualias.string)
|
2004-08-23 00:15:46 +00:00
|
|
|
{
|
2006-11-03 15:53:04 +00:00
|
|
|
if (key == '0') //specal case so that "hello" < "0"... (plus matches common impulses)
|
|
|
|
Cbuf_AddText(va("set option %i\n%s\n", 10, menualias.string), RESTRICT_LOCAL);
|
|
|
|
else
|
|
|
|
Cbuf_AddText(va("set option %i\n%s\n", key-'0', menualias.string), RESTRICT_LOCAL);
|
2004-08-23 00:15:46 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2004-09-07 18:20:05 +00:00
|
|
|
void M_MenuS_Clear_f (void)
|
2004-08-23 00:15:46 +00:00
|
|
|
{
|
|
|
|
if (menu_script)
|
|
|
|
{
|
|
|
|
M_RemoveMenu(menu_script);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Cvar_Set(menualias.name, "");
|
|
|
|
}
|
|
|
|
|
2004-09-07 18:20:05 +00:00
|
|
|
void M_MenuS_Script_f (void) //create a menu.
|
2004-08-23 00:15:46 +00:00
|
|
|
{
|
|
|
|
int items;
|
|
|
|
extern menu_t *currentmenu;
|
|
|
|
menu_t *oldmenu;
|
|
|
|
char *alias = Cmd_Argv(1);
|
|
|
|
// if (key_dest != key_console)
|
|
|
|
key_dest = key_menu;
|
|
|
|
m_state = m_complex;
|
|
|
|
|
|
|
|
selectitem = 0;
|
|
|
|
items=0;
|
|
|
|
|
|
|
|
if (menu_script)
|
|
|
|
{
|
|
|
|
menuoption_t *option;
|
|
|
|
for (option = menu_script->options; option; option = option->common.next)
|
|
|
|
{
|
|
|
|
if (option->common.type == mt_button)
|
|
|
|
{
|
|
|
|
if (menu_script->selecteditem == option)
|
|
|
|
selectitem = items;
|
|
|
|
items++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
selectitem = items - selectitem-1;
|
2004-09-07 18:20:05 +00:00
|
|
|
M_MenuS_Clear_f();
|
2004-08-23 00:15:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
oldmenu = currentmenu;
|
|
|
|
|
|
|
|
menu_script = M_CreateMenu(0);
|
|
|
|
if (oldmenu)
|
|
|
|
{
|
|
|
|
M_HideMenu(oldmenu); //bring to front
|
|
|
|
M_AddMenu(oldmenu);
|
|
|
|
}
|
|
|
|
menu_script->remove = M_Script_Remove;
|
|
|
|
menu_script->key = M_Script_Key;
|
|
|
|
|
|
|
|
if (Cmd_Argc() == 1 || !*alias)
|
|
|
|
Cvar_Set(&menualias, "_");
|
|
|
|
else
|
|
|
|
Cvar_Set(&menualias, alias);
|
|
|
|
}
|
|
|
|
|
2004-09-07 18:20:05 +00:00
|
|
|
void M_MenuS_Box_f (void)
|
2004-08-23 00:15:46 +00:00
|
|
|
{
|
|
|
|
int x = atoi(Cmd_Argv(1));
|
|
|
|
int y = atoi(Cmd_Argv(2));
|
|
|
|
int width = atoi(Cmd_Argv(3));
|
|
|
|
int height = atoi(Cmd_Argv(4));
|
|
|
|
|
|
|
|
if (!menu_script)
|
|
|
|
{
|
|
|
|
Con_Printf("%s with no active menu\n", Cmd_Argv(0));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
MC_AddBox(menu_script, x, y, width/8, height/8);
|
|
|
|
}
|
|
|
|
|
2004-09-07 18:20:05 +00:00
|
|
|
void M_MenuS_CheckBox_f (void)
|
2004-08-23 00:15:46 +00:00
|
|
|
{
|
|
|
|
int x = atoi(Cmd_Argv(1));
|
|
|
|
int y = atoi(Cmd_Argv(2));
|
|
|
|
char *text = Cmd_Argv(3);
|
|
|
|
char *cvarname = Cmd_Argv(4);
|
2004-09-13 03:10:10 +00:00
|
|
|
int bitmask = atoi(Cmd_Argv(5));
|
2004-08-23 00:15:46 +00:00
|
|
|
cvar_t *cvar;
|
|
|
|
|
|
|
|
if (!menu_script)
|
|
|
|
{
|
|
|
|
Con_Printf("%s with no active menu\n", Cmd_Argv(0));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
cvar = Cvar_Get(cvarname, text, 0, "User variables");
|
|
|
|
if (!cvar)
|
|
|
|
return;
|
2004-09-13 03:10:10 +00:00
|
|
|
MC_AddCheckBox(menu_script, x, y, text, cvar, bitmask);
|
2004-08-23 00:15:46 +00:00
|
|
|
}
|
|
|
|
|
2004-09-07 18:20:05 +00:00
|
|
|
void M_MenuS_Slider_f (void)
|
2004-08-23 00:15:46 +00:00
|
|
|
{
|
|
|
|
int x = atoi(Cmd_Argv(1));
|
|
|
|
int y = atoi(Cmd_Argv(2));
|
|
|
|
char *text = Cmd_Argv(3);
|
|
|
|
char *cvarname = Cmd_Argv(4);
|
|
|
|
float min = atof(Cmd_Argv(5));
|
|
|
|
float max = atof(Cmd_Argv(6));
|
|
|
|
cvar_t *cvar;
|
|
|
|
|
|
|
|
if (!menu_script)
|
|
|
|
{
|
|
|
|
Con_Printf("%s with no active menu\n", Cmd_Argv(0));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
cvar = Cvar_Get(cvarname, text, 0, "User variables");
|
|
|
|
if (!cvar)
|
|
|
|
return;
|
2007-05-25 22:16:29 +00:00
|
|
|
MC_AddSlider(menu_script, x, y, text, cvar, min, max, 0);
|
2004-08-23 00:15:46 +00:00
|
|
|
}
|
|
|
|
|
2004-09-07 18:20:05 +00:00
|
|
|
void M_MenuS_Picture_f (void)
|
2004-08-23 00:15:46 +00:00
|
|
|
{
|
|
|
|
int x = atoi(Cmd_Argv(1));
|
|
|
|
int y = atoi(Cmd_Argv(2));
|
|
|
|
char *picname = Cmd_Argv(3);
|
2009-11-04 21:16:50 +00:00
|
|
|
mpic_t *p;
|
2004-08-23 00:15:46 +00:00
|
|
|
|
|
|
|
if (!menu_script)
|
|
|
|
{
|
|
|
|
Con_Printf("%s with no active menu\n", Cmd_Argv(0));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-03-31 01:14:01 +00:00
|
|
|
p = R2D_SafeCachePic(picname);
|
2009-11-04 21:16:50 +00:00
|
|
|
if (!p)
|
|
|
|
return;
|
|
|
|
|
2006-11-03 15:53:04 +00:00
|
|
|
if (!strcmp(Cmd_Argv(1), "-"))
|
2009-11-04 21:16:50 +00:00
|
|
|
MC_AddCenterPicture(menu_script, y, p->height, picname);
|
2006-11-03 15:53:04 +00:00
|
|
|
else
|
2009-11-04 21:16:50 +00:00
|
|
|
MC_AddPicture(menu_script, x, y, p->width, p->height, picname);
|
2004-08-23 00:15:46 +00:00
|
|
|
}
|
|
|
|
|
2004-09-07 18:20:05 +00:00
|
|
|
void M_MenuS_Edit_f (void)
|
2004-08-23 00:15:46 +00:00
|
|
|
{
|
|
|
|
int x = atoi(Cmd_Argv(1));
|
|
|
|
int y = atoi(Cmd_Argv(2));
|
|
|
|
char *text = Cmd_Argv(3);
|
|
|
|
char *def = Cmd_Argv(4);
|
|
|
|
|
|
|
|
if (!menu_script)
|
|
|
|
{
|
|
|
|
Con_Printf("%s with no active menu\n", Cmd_Argv(0));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
MC_AddEditCvar(menu_script, x, y, text, def);
|
|
|
|
}
|
|
|
|
|
2004-09-07 18:20:05 +00:00
|
|
|
void M_MenuS_Text_f (void)
|
2004-08-23 00:15:46 +00:00
|
|
|
{
|
|
|
|
menuoption_t *option;
|
|
|
|
int x = atoi(Cmd_Argv(1));
|
|
|
|
int y = atoi(Cmd_Argv(2));
|
|
|
|
char *text = Cmd_Argv(3);
|
|
|
|
char *command = Cmd_Argv(4);
|
|
|
|
|
|
|
|
if (!menu_script)
|
|
|
|
{
|
|
|
|
Con_Printf("%s with no active menu\n", Cmd_Argv(0));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (Cmd_Argc() == 4)
|
|
|
|
MC_AddBufferedText(menu_script, x, y, text, false, false);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
option = (menuoption_t *)MC_AddConsoleCommand(menu_script, x, y, text, va("set option %s\n%s\n", command, menualias.string));
|
|
|
|
if (selectitem-- == 0)
|
|
|
|
menu_script->selecteditem = option;
|
|
|
|
}
|
|
|
|
}
|
2004-09-07 18:20:05 +00:00
|
|
|
|
2006-03-06 01:41:09 +00:00
|
|
|
void M_MenuS_TextBig_f (void)
|
|
|
|
{
|
|
|
|
menuoption_t *option;
|
|
|
|
int x = atoi(Cmd_Argv(1));
|
|
|
|
int y = atoi(Cmd_Argv(2));
|
|
|
|
char *text = Cmd_Argv(3);
|
|
|
|
char *command = Cmd_Argv(4);
|
|
|
|
|
|
|
|
if (!menu_script)
|
|
|
|
{
|
|
|
|
Con_Printf("%s with no active menu\n", Cmd_Argv(0));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (*command)
|
|
|
|
MC_AddConsoleCommandQBigFont(menu_script, x, y, text, command);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
option = (menuoption_t *)MC_AddConsoleCommand(menu_script, x, y, text, va("set option %s\n%s\n", command, menualias.string));
|
|
|
|
if (selectitem-- == 0)
|
|
|
|
menu_script->selecteditem = option;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-09-07 18:20:05 +00:00
|
|
|
void M_MenuS_Bind_f (void)
|
|
|
|
{
|
|
|
|
int x = atoi(Cmd_Argv(1));
|
|
|
|
int y = atoi(Cmd_Argv(2));
|
|
|
|
char *caption = Cmd_Argv(3);
|
|
|
|
char *command = Cmd_Argv(4);
|
|
|
|
|
|
|
|
if (!menu_script)
|
|
|
|
{
|
|
|
|
Con_Printf("%s with no active menu\n", Cmd_Argv(0));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!*caption)
|
|
|
|
caption = command;
|
|
|
|
|
|
|
|
MC_AddBind(menu_script, x, y, command, caption);
|
|
|
|
}
|
|
|
|
|
2007-01-08 03:13:03 +00:00
|
|
|
void M_MenuS_Comboi_f (void)
|
|
|
|
{
|
|
|
|
int opt;
|
|
|
|
char *opts[64];
|
|
|
|
char *values[64];
|
|
|
|
char valuesb[64][8];
|
|
|
|
int x = atoi(Cmd_Argv(1));
|
|
|
|
int y = atoi(Cmd_Argv(2));
|
|
|
|
char *caption = Cmd_Argv(3);
|
|
|
|
char *command = Cmd_Argv(4);
|
|
|
|
char *line;
|
|
|
|
|
|
|
|
cvar_t *var;
|
|
|
|
|
|
|
|
if (!menu_script)
|
|
|
|
{
|
|
|
|
Con_Printf("%s with no active menu\n", Cmd_Argv(0));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var = Cvar_Get(command, "0", 0, "custom cvars");
|
|
|
|
if (!var)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!*caption)
|
|
|
|
caption = command;
|
|
|
|
|
|
|
|
for (opt = 0; opt < sizeof(opts)/sizeof(opts[0])-2 && *(line=Cmd_Argv(5+opt)); opt++)
|
|
|
|
{
|
|
|
|
opts[opt] = line;
|
2011-07-22 15:11:35 +00:00
|
|
|
Q_snprintfz(valuesb[opt], sizeof(valuesb[opt]), "%i", opt);
|
2007-01-08 03:13:03 +00:00
|
|
|
values[opt] = valuesb[opt];
|
|
|
|
}
|
|
|
|
opts[opt] = NULL;
|
|
|
|
|
2007-08-20 02:13:51 +00:00
|
|
|
MC_AddCvarCombo(menu_script, x, y, caption, var, (const char **)opts, (const char **)values);
|
2007-01-08 03:13:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
char *Hunk_TempString(char *s)
|
|
|
|
{
|
|
|
|
char *h;
|
|
|
|
h = Hunk_TempAllocMore(strlen(s)+1);
|
|
|
|
strcpy(h, s);
|
|
|
|
return h;
|
|
|
|
}
|
|
|
|
|
|
|
|
void M_MenuS_Combos_f (void)
|
|
|
|
{
|
|
|
|
int opt;
|
|
|
|
char *opts[64];
|
|
|
|
char *values[64];
|
|
|
|
int x = atoi(Cmd_Argv(1));
|
|
|
|
int y = atoi(Cmd_Argv(2));
|
|
|
|
char *caption = Cmd_Argv(3);
|
|
|
|
char *command = Cmd_Argv(4);
|
|
|
|
char *line;
|
|
|
|
|
|
|
|
cvar_t *var;
|
|
|
|
|
|
|
|
if (!menu_script)
|
|
|
|
{
|
|
|
|
Con_Printf("%s with no active menu\n", Cmd_Argv(0));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var = Cvar_Get(command, "0", 0, "custom cvars");
|
|
|
|
if (!var)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!*caption)
|
|
|
|
caption = command;
|
|
|
|
|
|
|
|
line = Cmd_Argv(5);
|
|
|
|
if (!*line)
|
|
|
|
{
|
2011-12-05 15:23:40 +00:00
|
|
|
line = Cbuf_GetNext(Cmd_ExecLevel, true);
|
2007-01-08 03:13:03 +00:00
|
|
|
if (*line != '{')
|
|
|
|
Cbuf_InsertText(line, Cmd_ExecLevel, true); //whoops. Stick the trimmed string back in to the cbuf.
|
|
|
|
else
|
|
|
|
line = "{";
|
|
|
|
}
|
|
|
|
if (!strcmp(line, "{"))
|
|
|
|
{
|
|
|
|
char *line;
|
|
|
|
Hunk_TempAlloc(4);
|
|
|
|
for (opt = 0; opt < sizeof(opts)/sizeof(opts[0])-2; opt++)
|
|
|
|
{
|
2011-12-05 15:23:40 +00:00
|
|
|
line = Cbuf_GetNext(Cmd_ExecLevel, true);
|
2007-01-08 03:13:03 +00:00
|
|
|
line = COM_Parse(line);
|
|
|
|
if (!strcmp(com_token, "}"))
|
|
|
|
break;
|
|
|
|
opts[opt] = Hunk_TempString(com_token);
|
|
|
|
line = COM_Parse(line);
|
|
|
|
values[opt] = Hunk_TempString(com_token);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (opt = 0; opt < sizeof(opts)/sizeof(opts[0])-2; opt++)
|
|
|
|
{
|
|
|
|
line = Cmd_Argv(5+opt*2);
|
|
|
|
if (!*line)
|
|
|
|
break;
|
|
|
|
opts[opt] = line;
|
|
|
|
values[opt] = Cmd_Argv(5+opt*2 + 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
opts[opt] = NULL;
|
|
|
|
|
2007-08-20 02:13:51 +00:00
|
|
|
MC_AddCvarCombo(menu_script, x, y, caption, var, (const char **)opts, (const char **)values);
|
2007-01-08 03:13:03 +00:00
|
|
|
}
|
|
|
|
|
2004-08-23 00:15:46 +00:00
|
|
|
/*
|
|
|
|
menuclear
|
|
|
|
menualias menucallback
|
|
|
|
|
|
|
|
menubox 0 0 320 8
|
|
|
|
menutext 0 0 "GO GO GO!!!" "radio21"
|
|
|
|
menutext 0 8 "Fall back" "radio22"
|
|
|
|
menutext 0 8 "Stick together" "radio23"
|
|
|
|
menutext 0 16 "Get in position" "radio24"
|
|
|
|
menutext 0 24 "Storm the front" "radio25"
|
|
|
|
menutext 0 24 "Report in" "radio26"
|
|
|
|
menutext 0 24 "Cancel"
|
|
|
|
*/
|
|
|
|
void M_Script_Init(void)
|
|
|
|
{
|
2004-09-07 18:20:05 +00:00
|
|
|
Cmd_AddCommand("menuclear", M_MenuS_Clear_f);
|
|
|
|
Cmd_AddCommand("conmenu", M_MenuS_Script_f);
|
|
|
|
Cmd_AddCommand("menubox", M_MenuS_Box_f);
|
|
|
|
Cmd_AddCommand("menuedit", M_MenuS_Edit_f);
|
|
|
|
Cmd_AddCommand("menutext", M_MenuS_Text_f);
|
2006-03-06 01:41:09 +00:00
|
|
|
Cmd_AddCommand("menutextbig", M_MenuS_TextBig_f);
|
2004-09-07 18:20:05 +00:00
|
|
|
Cmd_AddCommand("menupic", M_MenuS_Picture_f);
|
|
|
|
Cmd_AddCommand("menucheck", M_MenuS_CheckBox_f);
|
|
|
|
Cmd_AddCommand("menuslider", M_MenuS_Slider_f);
|
|
|
|
Cmd_AddCommand("menubind", M_MenuS_Bind_f);
|
2007-01-08 03:13:03 +00:00
|
|
|
Cmd_AddCommand("menucomboi", M_MenuS_Comboi_f);
|
|
|
|
Cmd_AddCommand("menucombos", M_MenuS_Combos_f);
|
2004-08-23 00:15:46 +00:00
|
|
|
|
|
|
|
Cvar_Register(&menualias, "Scripting");
|
|
|
|
}
|