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 = me.toString(me);
18 if (s == "") s = me.classname;
19 else s = strcat(me.classname, ": ", s);
20 print(_dumptree_space, etos(me), " (", s, ")");
21 if (me.firstChild)
22 {
23 print(" {\n");
25 }
26 else
27 {
28 print("\n");
29 }
30}
32{
33 if (me.firstChild)
34 {
36 print(_dumptree_space, "}\n");
37 }
38}
39
40float updateConwidths(float width, float height, float pixelheight);
41
42void GameCommand(string theCommand)
43{
44 int argc = tokenize_console(theCommand);
45 string ss = strtolower(argv(0));
46
47 // TODO port these commands to the command system
48 if (argv(0) == "help" || argc == 0)
49 {
50 LOG_HELP("Usage:^3 menu_cmd <command> [<item>], where possible commands are:");
51 LOG_HELP(" 'sync' reloads all cvars on the current menu page");
52 LOG_HELP(" 'directmenu' shows the menu window named <item> (or the menu window containing an item named <item>)");
53 LOG_HELP(" 'closemenu' closes the menu window named <item> (or the menu window containing an item named <item>)");
54 LOG_HELP(" if <item> is not specified it shows the list of available items in the console");
55 LOG_HELP(" 'dumptree' dumps the state of the menu as a tree to the console");
56 LOG_HELP(" 'isdemo' checks if engine is currently running a demo. If given an <item> then 1 / 0 is placed");
57 LOG_HELP(" in the cvar with that name. Otherwise without an argument the result is printed to console.");
58
59 LOG_HELP("\nGeneric commands shared by all programs:");
61
62 return;
63 }
64
65 if (GenericCommand(theCommand)) return;
66
67 if (argv(0) == "sync")
68 {
69 m_sync();
70 return;
71 }
72
73 if (argv(0) == "update_conwidths_before_vid_restart")
74 {
75 updateConwidths(cvar("vid_width"), cvar("vid_height"), cvar("vid_pixelheight"));
76 return;
77 }
78
79 string argcmd = argv(0);
80 string filter = string_null;
81 bool close_mode = false;
82 if (argcmd == "closemenu")
83 {
84 close_mode = true;
85 argcmd = "directmenu";
86 }
87 else if (argcmd == "directpanelhudmenu")
88 {
89 filter = "HUD";
90 argcmd = "directmenu";
91 }
92
93 if (argcmd == "directmenu")
94 {
95 if (argc == 1)
96 {
97 LOG_HELP("Available items (* = closable):");
98
99 FOREACH_ENTITY_ORDERED(it.name != "", {
100 if (it.classname == "vtbl") continue;
101 string s = it.name;
102 if (filter)
103 {
104 if (!startsWith(s, filter)) continue;
105 s = substring(s, strlen(filter), strlen(s) - strlen(filter));
106 }
107 if (it.instanceOfContainer && it.closable)
108 LOG_HELP(" * ", s);
109 else
110 LOG_HELP(" ", s);
111 });
112 }
113 else if (argc == 2 && !close_mode && (!isdemo() || argv(1) == "Welcome")) // don't allow this command in demos
114 {
116 m_goto(strcat(filter, argv(1)), true); // switch to a menu item
117 }
118 else if(argc > 2 && (!isdemo() || argv(1) == "Welcome"))
119 {
120 entity e = NULL;
121 float argsbuf = 0;
122 string s = strzone(argv(1)); // dialog name
123 for(int i = 0; (e = nextent(e)); )
124 if(e.classname != "vtbl" && e.name == strcat(filter, s))
125 {
126 argsbuf = buf_create();
127 if(argsbuf >= 0)
128 if(e.readInputArgs)
129 {
130 for(i = 2; i < argc; ++i)
131 bufstr_add(argsbuf, argv(i), 1);
132 e.readInputArgs(e, argsbuf);
133 if (!close_mode)
134 m_goto(strcat(filter, s), true);
135 }
136 if(argsbuf >= 0)
137 buf_del(argsbuf);
138
139 // NOTE input args are read even in close mode
140 if (close_mode)
141 {
142 if (e.instanceOfContainer && e.closable && e.focused)
143 Dialog_Close(e, e);
144 }
145 }
146 }
147 return;
148 }
149
150 switch (argv(0))
151 {
152 // unlike menu_cmd directmenu, the menu won't be closed when these menu items will be closed
153 case "nexposee": m_goto("nexposee", false); return;
154 case "servers": m_goto("servers", false); return;
155 case "profile": m_goto("profile", false); return;
156 case "skinselect": m_goto("skinselector", false); return;
157 case "languageselect": m_goto("languageselector", false); return;
158 case "settings": m_goto("settings", false); return;
159 case "inputsettings": m_goto("inputsettings", false); return;
160 case "videosettings": m_goto("videosettings", false); return;
161 }
162
163 if (argv(0) == "dumptree")
164 {
165 _dumptree_space = "";
167 return;
168 }
169
170 if (argv(0) == "isdemo")
171 {
172 int value = isdemo();
173
174 if (argv(1) != "")
175 {
176 cvar_set(argv(1), ftos(value));
177 }
178 else
179 {
180 print(sprintf("%d\n", value));
181 }
182
183 return;
184 }
185
186 if(MUTATOR_CALLHOOK(Menu_ConsoleCommand, ss, argc, theCommand)) // handled by a mutator
187 return;
188
189 LOG_INFO("Invalid command. For a list of supported commands, try menu_cmd help.");
190}
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:392
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:1111
void m_sync()
Definition menu.qc:45
void m_goto(string itemname, bool hide_menu_on_close)
Definition menu.qc:1056
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:31
string _dumptree_space
Definition menu_cmd.qc:14
void GameCommand(string theCommand)
Definition menu_cmd.qc:42
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:2318