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