6 #include <menu/mutators/_mod.qh>
8 #include <common/command/_mod.qh>
10 .void(entity me, float argsbuf) readInputArgs;
11 .entity firstChild, nextSibling;
13 string _dumptree_space;
14 void _dumptree_open(entity pass, entity me)
18 if (s == "") s = me.classname;
19 else s = strcat(me.classname, ": ", s);
20 print(_dumptree_space, etos(me), " (", s, ")");
24 _dumptree_space = strcat(_dumptree_space, " ");
31 void _dumptree_close(entity pass, entity me)
35 _dumptree_space = substring(_dumptree_space, 0, strlen(_dumptree_space) - 2);
36 print(_dumptree_space, "}\n");
40 float updateConwidths(float width, float height, float pixelheight);
42 void GameCommand(string theCommand)
44 int argc = tokenize_console(theCommand);
45 string ss = strtolower(argv(0));
47 // TODO port these commands to the command system
48 if (argv(0) == "help" || argc == 0)
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(" if <item> is not specified it shows the list of available items in the console");
54 LOG_HELP(" 'dumptree' dumps the state of the menu as a tree to the console");
56 LOG_HELP("\nGeneric commands shared by all programs:");
57 GenericCommand_macro_help();
62 if (GenericCommand(theCommand)) return;
64 if (argv(0) == "sync")
70 if (argv(0) == "update_conwidths_before_vid_restart")
72 updateConwidths(cvar("vid_width"), cvar("vid_height"), cvar("vid_pixelheight"));
76 if (argv(0) == "directmenu" || argv(0) == "directpanelhudmenu")
78 string filter = string_null;
79 if (argv(0) == "directpanelhudmenu") filter = "HUD";
83 LOG_HELP("Available items:");
85 FOREACH_ENTITY_ORDERED(it.name != "", {
86 if (it.classname == "vtbl") continue;
90 if (!startsWith(s, filter)) continue;
91 s = substring(s, strlen(filter), strlen(s) - strlen(filter));
96 else if (argc == 2 && !isdemo()) // don't allow this command in demos
98 if (argv(1) == "Welcome" && cvar("g_campaign"))
100 m_play_click_sound(MENU_SOUND_OPEN);
101 m_goto(strcat(filter, argv(1))); // switch to a menu item
103 else if(argc > 2 && !isdemo())
107 string s = strzone(argv(1)); // dialog name
108 for(int i = 0; (e = nextent(e)); )
109 if(e.classname != "vtbl" && e.name == strcat(filter, s))
111 argsbuf = buf_create();
115 for(i = 2; i < argc; ++i)
116 bufstr_add(argsbuf, argv(i), 1);
117 e.readInputArgs(e, argsbuf);
118 m_goto(strcat(filter, s));
127 if (argv(0) == "skinselect")
129 m_goto("skinselector");
133 if (argv(0) == "languageselect")
135 m_goto("languageselector");
139 if (argv(0) == "videosettings")
141 m_goto("videosettings");
145 if (argv(0) == "dumptree")
147 _dumptree_space = "";
148 depthfirst(main, parent, firstChild, nextSibling, _dumptree_open, _dumptree_close, NULL);
152 if(MUTATOR_CALLHOOK(Menu_ConsoleCommand, ss, argc, theCommand)) // handled by a mutator
155 LOG_INFO("Invalid command. For a list of supported commands, try menu_cmd help.");