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