Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
menu_cmd.qc
Go to the documentation of this file.
1#include "menu_cmd.qh"
2
3#include "../menu.qh"
4#include "../item.qh"
5
6#include <menu/item/dialog.qh>
8
10
11.void(entity me, int argsbuf) readInputArgs;
13
16{
17 string s;
18 s = me.toString(me);
19 if (s == "") s = me.classname;
20 else s = strcat(me.classname, ": ", s);
21 print(_dumptree_space, etos(me), " (", s, ")");
22 if (me.firstChild)
23 {
24 print(" {\n");
26 }
27 else
28 {
29 print("\n");
30 }
31}
33{
34 if (me.firstChild)
35 {
37 print(_dumptree_space, "}\n");
38 }
39}
40
41float updateConwidths(float width, float height, float pixelheight);
42
43void GameCommand(string theCommand)
44{
45 int argc = tokenize_console(theCommand);
46 string ss = strtolower(argv(0));
47
48 // TODO port these commands to the command system
49 if (argv(0) == "help" || argc == 0)
50 {
51 LOG_HELP("Usage:^3 menu_cmd <command> [<item>], where possible commands are:");
52 LOG_HELP(" 'sync' reloads all cvars on the current menu page");
53 LOG_HELP(" 'directmenu' shows the menu window named <item> (or the menu window containing an item named <item>)");
54 LOG_HELP(" 'closemenu' closes the menu window named <item> (or the menu window containing an item named <item>)");
55 LOG_HELP(" if <item> is not specified it shows the list of available items in the console");
56 LOG_HELP(" 'dumptree' dumps the state of the menu as a tree to the console");
57 LOG_HELP(" 'isdemo' checks if engine is currently running a demo. If given an <item> then 1 / 0 is placed");
58 LOG_HELP(" in the cvar with that name. Otherwise without an argument the result is printed to console.");
59
60 LOG_HELP("\nGeneric commands shared by all programs:");
62
63 return;
64 }
65
66 if (GenericCommand(theCommand)) return;
67
68 if (argv(0) == "sync")
69 {
70 m_sync();
71 return;
72 }
73
74 if (argv(0) == "update_conwidths_before_vid_restart")
75 {
76 updateConwidths(cvar("vid_width"), cvar("vid_height"), cvar("vid_pixelheight"));
77 return;
78 }
79
80 string argcmd = argv(0);
81 string filter = string_null;
82 bool close_mode = false;
83 if (argcmd == "closemenu")
84 {
85 close_mode = true;
86 argcmd = "directmenu";
87 }
88 else if (argcmd == "directpanelhudmenu")
89 {
90 filter = "HUD";
91 argcmd = "directmenu";
92 }
93
94 if (argcmd == "directmenu")
95 {
96 if (argc == 1)
97 {
98 LOG_HELP("Available items (* = closable):");
99
100 FOREACH_ENTITY_ORDERED(it.name != "", {
101 if (it.classname == "vtbl") continue;
102 string s = it.name;
103 if (filter)
104 {
105 if (!startsWith(s, filter)) continue;
106 s = substring(s, strlen(filter), strlen(s) - strlen(filter));
107 }
108 if (it.instanceOfContainer && it.closable)
109 LOG_HELP(" * ", s);
110 else
111 LOG_HELP(" ", s);
112 });
113 }
114 else if (argc == 2 && !close_mode && (!isdemo() || argv(1) == "Welcome")) // don't allow this command in demos
115 {
117 m_goto(strcat(filter, argv(1)), true); // switch to a menu item
118 }
119 else if(argc > 2 && (!isdemo() || argv(1) == "Welcome"))
120 {
121 entity e = NULL;
122 float argsbuf = 0;
123 string s = strzone(argv(1)); // dialog name
124 for(int i = 0; (e = nextent(e)); )
125 if(e.classname != "vtbl" && e.name == strcat(filter, s))
126 {
127 argsbuf = buf_create();
128 if(argsbuf >= 0)
129 if(e.readInputArgs)
130 {
131 for(i = 2; i < argc; ++i)
132 bufstr_add(argsbuf, argv(i), 1);
133 e.readInputArgs(e, argsbuf);
134 if (!close_mode)
135 m_goto(strcat(filter, s), true);
136 }
137 if(argsbuf >= 0)
138 buf_del(argsbuf);
139
140 // NOTE input args are read even in close mode
141 if (close_mode)
142 {
143 if (e.instanceOfContainer && e.closable && e.focused)
144 Dialog_Close(e, e);
145 }
146 }
147 }
148 return;
149 }
150
151 switch (argv(0))
152 {
153 // unlike menu_cmd directmenu, the menu won't be closed when these menu items will be closed
154 case "nexposee": m_goto("nexposee", false); return;
155 case "servers": m_goto("servers", false); return;
156 case "profile": m_goto("profile", false); return;
157 case "skinselect": m_goto("skinselector", false); return;
158 case "languageselect": m_goto("languageselector", false); return;
159 case "settings": m_goto("settings", false); return;
160 case "inputsettings": m_goto("inputsettings", false); return;
161 case "videosettings": m_goto("videosettings", false); return;
162 }
163
164 if (argv(0) == "dumptree")
165 {
166 _dumptree_space = "";
168 return;
169 }
170
171 if (argv(0) == "isdemo")
172 {
173 int value = isdemo();
174
175 if (argv(1) != "")
176 {
177 cvar_set(argv(1), ftos(value));
178 }
179 else
180 {
181 print(sprintf("%d\n", value));
182 }
183
184 return;
185 }
186
187 if(MUTATOR_CALLHOOK(Menu_ConsoleCommand, ss, argc, theCommand)) // handled by a mutator
188 return;
189
190 LOG_INFO("Invalid command. For a list of supported commands, try menu_cmd help.");
191}
entity parent
Definition animhost.qc:7
#define MUTATOR_CALLHOOK(id,...)
Definition base.qh:143
float height
Definition bobbing.qc:3
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
void depthfirst(entity start,.entity up,.entity downleft,.entity right, void(entity, entity) funcPre, void(entity, entity) funcPost, entity pass)
Definition util.qc:393
string strtolower(string s)
#define strlen
#define tokenize_console
#define buf_create
#define pass(name, colormin, colormax)
void GenericCommand_macro_help()
Definition generic.qc:567
float GenericCommand(string command)
Definition generic.qc:603
#define FOREACH_ENTITY_ORDERED(cond, body)
Definition iter.qh:138
#define main
Definition _all.inc:202
#define LOG_HELP(...)
Definition log.qh:85
#define LOG_INFO(...)
Definition log.qh:65
void Dialog_Close(entity button, entity me)
Definition dialog.qc:7
void m_play_click_sound(string soundfile)
Definition menu.qc:1106
void m_sync()
Definition menu.qc:45
void m_goto(string itemname, bool hide_menu_on_close)
Definition menu.qc:1051
const string MENU_SOUND_OPEN
Definition menu.qh:53
float updateConwidths(float width, float height, float pixelheight)
entity nextSibling
Definition menu_cmd.qc:12
void _dumptree_close(entity pass, entity me)
Definition menu_cmd.qc:32
string _dumptree_space
Definition menu_cmd.qc:14
void GameCommand(string theCommand)
Definition menu_cmd.qc:43
entity firstChild
Definition menu_cmd.qc:12
void _dumptree_open(entity pass, entity me)
Definition menu_cmd.qc:15
void cvar_set(string name, string value)
float isdemo()
entity nextent(entity e)
string substring(string s, float start, float length)
float cvar(string name)
string ftos(float f)
void print(string text,...)
string strzone(string s)
string argv(float n)
string etos(entity e)
string string_null
Definition nil.qh:9
strcat(_("^F4Countdown stopped!"), "\n^BG", _("Teams are too unbalanced."))
#define NULL
Definition post.qh:14
if(frag_attacker.flagcarried)
Definition sv_ctf.qc:2325