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