6 #include <menu/item/dialog.qh>
7 #include <menu/mutators/_mod.qh>
9 #include <common/command/_mod.qh>
11 .void(entity me, int argsbuf) readInputArgs;
12 .entity firstChild, nextSibling;
14 string _dumptree_space;
15 void _dumptree_open(entity pass, entity me)
19 if (s == "") s = me.classname;
20 else s = strcat(me.classname, ": ", s);
21 print(_dumptree_space, etos(me), " (", s, ")");
25 _dumptree_space = strcat(_dumptree_space, " ");
32 void _dumptree_close(entity pass, entity me)
36 _dumptree_space = substring(_dumptree_space, 0, strlen(_dumptree_space) - 2);
37 print(_dumptree_space, "}\n");
41 float updateConwidths(float width, float height, float pixelheight);
43 void GameCommand(string theCommand)
45 int argc = tokenize_console(theCommand);
46 string ss = strtolower(argv(0));
48 // TODO port these commands to the command system
49 if (argv(0) == "help" || argc == 0)
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");
58 LOG_HELP("\nGeneric commands shared by all programs:");
59 GenericCommand_macro_help();
64 if (GenericCommand(theCommand)) return;
66 if (argv(0) == "sync")
72 if (argv(0) == "update_conwidths_before_vid_restart")
74 updateConwidths(cvar("vid_width"), cvar("vid_height"), cvar("vid_pixelheight"));
79 string filter = string_null;
80 bool close_mode = false;
81 if (cmd == "closemenu")
86 else if (cmd == "directpanelhudmenu")
92 if (cmd == "directmenu")
96 LOG_HELP("Available items (* = closable):");
98 FOREACH_ENTITY_ORDERED(it.name != "", {
99 if (it.classname == "vtbl") continue;
103 if (!startsWith(s, filter)) continue;
104 s = substring(s, strlen(filter), strlen(s) - strlen(filter));
106 if (it.instanceOfContainer && it.closable)
112 else if (argc == 2 && !close_mode && (!isdemo() || argv(1) == "Welcome")) // don't allow this command in demos
114 m_play_click_sound(MENU_SOUND_OPEN);
115 m_goto(strcat(filter, argv(1))); // switch to a menu item
117 else if(argc > 2 && (!isdemo() || argv(1) == "Welcome"))
121 string s = strzone(argv(1)); // dialog name
122 for(int i = 0; (e = nextent(e)); )
123 if(e.classname != "vtbl" && e.name == strcat(filter, s))
125 argsbuf = buf_create();
129 for(i = 2; i < argc; ++i)
130 bufstr_add(argsbuf, argv(i), 1);
131 e.readInputArgs(e, argsbuf);
133 m_goto(strcat(filter, s));
138 // NOTE input args are read even in close mode
141 if (e.instanceOfContainer && e.closable && e.focused)
149 if (argv(0) == "nexposee")
155 if (argv(0) == "servers")
161 if (argv(0) == "profile")
167 if (argv(0) == "skinselect")
169 m_goto("skinselector");
173 if (argv(0) == "languageselect")
175 m_goto("languageselector");
179 if (argv(0) == "settings")
185 if (argv(0) == "inputsettings")
187 m_goto("inputsettings");
191 if (argv(0) == "videosettings")
193 m_goto("videosettings");
197 if (argv(0) == "dumptree")
199 _dumptree_space = "";
200 depthfirst(main, parent, firstChild, nextSibling, _dumptree_open, _dumptree_close, NULL);
204 if(MUTATOR_CALLHOOK(Menu_ConsoleCommand, ss, argc, theCommand)) // handled by a mutator
207 LOG_INFO("Invalid command. For a list of supported commands, try menu_cmd help.");