]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/command/menu_cmd.qc
93825cd56098d73e2ebe53aa0aee97041fcaf03c
[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                 {
93                         m_play_click_sound(MENU_SOUND_OPEN);
94                         m_goto(strcat(filter, argv(1))); // switch to a menu item
95                 }
96                 if(filter)
97                         strunzone(filter);
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         print(_("Invalid command. For a list of supported commands, try menu_cmd help.\n"));
127 }