]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/command/menu_cmd.qc
ce682de004af0d6bfbfef7f87576f19460fe48d6
[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         // TODO port these commands to the command system
47         if (argv(0) == "help" || argc == 0)
48         {
49                 LOG_HELP("Usage:^3 menu_cmd <command> [<item>], where possible commands are:");
50                 LOG_HELP("  'sync' reloads all cvars on the current menu page");
51                 LOG_HELP("  'directmenu' shows the menu window named <item> (or the menu window containing an item named <item>)");
52                 LOG_HELP("   if <item> is not specified it shows the list of available items in the console");
53                 LOG_HELP("  'dumptree' dumps the state of the menu as a tree to the console");
54
55                 LOG_HELP("\nGeneric commands shared by all programs:");
56                 GenericCommand_macro_help();
57
58                 return;
59         }
60
61         if (GenericCommand(theCommand)) return;
62
63         if (argv(0) == "sync")
64         {
65                 m_sync();
66                 return;
67         }
68
69         if (argv(0) == "update_conwidths_before_vid_restart")
70         {
71                 updateConwidths(cvar("vid_width"), cvar("vid_height"), cvar("vid_pixelheight"));
72                 return;
73         }
74
75         if (argv(0) == "directmenu" || argv(0) == "directpanelhudmenu")
76         {
77                 string filter = string_null;
78                 if (argv(0) == "directpanelhudmenu") filter = "HUD";
79
80                 if (argc == 1)
81                 {
82                         LOG_HELP("Available items:");
83
84                         FOREACH_ENTITY_ORDERED(it.name != "", {
85                                 if (it.classname == "vtbl") continue;
86                                 string s = it.name;
87                                 if (filter)
88                                 {
89                                         if (!startsWith(s, filter)) continue;
90                                         s = substring(s, strlen(filter), strlen(s) - strlen(filter));
91                                 }
92                                 LOG_HELP(" ", s);
93                         });
94                 }
95                 else if (argc == 2 && !isdemo())     // don't allow this command in demos
96                 {
97                         m_play_click_sound(MENU_SOUND_OPEN);
98                         m_goto(strcat(filter, argv(1))); // switch to a menu item
99                 }
100                 return;
101         }
102
103         if (argv(0) == "nexposee")
104         {
105                 m_goto("nexposee");
106                 return;
107         }
108
109         if (argv(0) == "servers")
110         {
111                 m_goto("servers");
112                 return;
113         }
114
115         if (argv(0) == "profile")
116         {
117                 m_goto("profile");
118                 return;
119         }
120
121         if (argv(0) == "skinselect")
122         {
123                 m_goto("skinselector");
124                 return;
125         }
126
127         if (argv(0) == "languageselect")
128         {
129                 m_goto("languageselector");
130                 return;
131         }
132
133         if (argv(0) == "inputsettings")
134         {
135                 m_goto("inputsettings");
136                 return;
137         }
138
139         if (argv(0) == "videosettings")
140         {
141                 m_goto("videosettings");
142                 return;
143         }
144
145         if (argv(0) == "dumptree")
146         {
147                 _dumptree_space = "";
148                 depthfirst(main, parent, firstChild, nextSibling, _dumptree_open, _dumptree_close, NULL);
149                 return;
150         }
151
152         if(MUTATOR_CALLHOOK(Menu_ConsoleCommand, ss, argc, theCommand)) // handled by a mutator
153                 return;
154
155         LOG_INFO("Invalid command. For a list of supported commands, try menu_cmd help.");
156 }