]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/command/menu_cmd.qc
Merge branch 'master' into Lyberta/TeamplayOverhaul
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / command / menu_cmd.qc
1 #include "menu_cmd.qh"
2
3 #include "../menu.qh"
4 #include "../item.qh"
5
6 #include <menu/mutators/_mod.qh>
7
8 #include <common/command/_mod.qh>
9
10 .entity firstChild, nextSibling;
11
12 string _dumptree_space;
13 void _dumptree_open(entity pass, entity me)
14 {
15         string s;
16         s = me.toString(me);
17         if (s == "") s = me.classname;
18         else s = strcat(me.classname, ": ", s);
19         print(_dumptree_space, etos(me), " (", s, ")");
20         if (me.firstChild)
21         {
22                 print(" {\n");
23                 _dumptree_space = strcat(_dumptree_space, "  ");
24         }
25         else
26         {
27                 print("\n");
28         }
29 }
30 void _dumptree_close(entity pass, entity me)
31 {
32         if (me.firstChild)
33         {
34                 _dumptree_space = substring(_dumptree_space, 0, strlen(_dumptree_space) - 2);
35                 print(_dumptree_space, "}\n");
36         }
37 }
38
39 float updateConwidths(float width, float height, float pixelheight);
40
41 void GameCommand(string theCommand)
42 {
43         int argc = tokenize_console(theCommand);
44         string ss = strtolower(argv(0));
45
46         if (argv(0) == "help" || argc == 0)
47         {
48                 LOG_INFO(_("Usage: menu_cmd command..., where possible commands are:"));
49                 LOG_INFO(_("  sync - reloads all cvars on the current menu page"));
50                 LOG_INFO(_("  directmenu ITEM - select a menu item as main item"));
51                 LOG_INFO(_("  dumptree - dump the state of the menu as a tree to the console"));
52
53                 LOG_INFO("Generic commands shared by all programs:");
54                 GenericCommand_macro_help();
55
56                 return;
57         }
58
59         if (GenericCommand(theCommand)) return;
60
61         if (argv(0) == "sync")
62         {
63                 m_sync();
64                 return;
65         }
66
67         if (argv(0) == "update_conwidths_before_vid_restart")
68         {
69                 updateConwidths(cvar("vid_width"), cvar("vid_height"), cvar("vid_pixelheight"));
70                 return;
71         }
72
73         if (argv(0) == "directmenu" || argv(0) == "directpanelhudmenu")
74         {
75                 string filter = string_null;
76                 if (argv(0) == "directpanelhudmenu") filter = "HUD";
77
78                 if (argc == 1)
79                 {
80                         LOG_INFO(_("Available options:"));
81
82                         FOREACH_ENTITY_ORDERED(it.name != "", {
83                                 if (it.classname == "vtbl") continue;
84                                 string s = it.name;
85                                 if (filter)
86                                 {
87                                         if (!startsWith(s, filter)) continue;
88                                         s = substring(s, strlen(filter), strlen(s) - strlen(filter));
89                                 }
90                                 LOG_INFOF(" %s", s);
91                         });
92                 }
93                 else if (argc == 2 && !isdemo())     // don't allow this command in demos
94                 {
95                         m_play_click_sound(MENU_SOUND_OPEN);
96                         m_goto(strcat(filter, argv(1))); // switch to a menu item
97                 }
98                 return;
99         }
100
101         if (argv(0) == "skinselect")
102         {
103                 m_goto("skinselector");
104                 return;
105         }
106
107         if (argv(0) == "languageselect")
108         {
109                 m_goto("languageselector");
110                 return;
111         }
112
113         if (argv(0) == "videosettings")
114         {
115                 m_goto("videosettings");
116                 return;
117         }
118
119         if (argv(0) == "dumptree")
120         {
121                 _dumptree_space = "";
122                 depthfirst(main, parent, firstChild, nextSibling, _dumptree_open, _dumptree_close, NULL);
123                 return;
124         }
125
126         if(MUTATOR_CALLHOOK(Menu_ConsoleCommand, ss, argc, theCommand)) // handled by a mutator
127                 return;
128
129         LOG_INFO(_("Invalid command. For a list of supported commands, try menu_cmd help."));
130 }