]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/command/menu_cmd.qc
Merge branch 'master' into Lyberta/StandaloneOverkillWeapons
[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 "../mutators/events.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         if (argv(0) == "help" || argc == 0)
47         {
48                 LOG_INFO(_("Usage: menu_cmd command..., where possible commands are:"));
49                 LOG_INFO(_("  sync - reloads all cvars on the current menu page"));
50                 LOG_INFO(_("  directmenu ITEM - select a menu item as main item"));
51
52                 LOG_INFO("Generic commands shared by all programs:");
53                 GenericCommand_macro_help();
54
55                 return;
56         }
57
58         if (GenericCommand(theCommand)) return;
59
60         if (argv(0) == "sync")
61         {
62                 m_sync();
63                 return;
64         }
65
66         if (argv(0) == "update_conwidths_before_vid_restart")
67         {
68                 updateConwidths(cvar("vid_width"), cvar("vid_height"), cvar("vid_pixelheight"));
69                 return;
70         }
71
72         if (argv(0) == "directmenu" || argv(0) == "directpanelhudmenu")
73         {
74                 string filter = string_null;
75                 if (argv(0) == "directpanelhudmenu") filter = "HUD";
76
77                 if (argc == 1)
78                 {
79                         LOG_INFO(_("Available options:"));
80
81                         FOREACH_ENTITY_ORDERED(it.name != "", {
82                                 if (it.classname == "vtbl") continue;
83                                 string s = it.name;
84                                 if (filter)
85                                 {
86                                         if (!startsWith(s, filter)) continue;
87                                         s = substring(s, strlen(filter), strlen(s) - strlen(filter));
88                                 }
89                                 LOG_INFOF(" %s", s);
90                         });
91                 }
92                 else if (argc == 2 && !isdemo())     // don't allow this command in demos
93                 {
94                         m_play_click_sound(MENU_SOUND_OPEN);
95                         m_goto(strcat(filter, argv(1))); // switch to a menu item
96                 }
97                 return;
98         }
99
100         if (argv(0) == "skinselect")
101         {
102                 m_goto("skinselector");
103                 return;
104         }
105
106         if (argv(0) == "languageselect")
107         {
108                 m_goto("languageselector");
109                 return;
110         }
111
112         if (argv(0) == "videosettings")
113         {
114                 m_goto("videosettings");
115                 return;
116         }
117
118         if (argv(0) == "dumptree")
119         {
120                 _dumptree_space = "";
121                 depthfirst(main, parent, firstChild, nextSibling, _dumptree_open, _dumptree_close, NULL);
122                 return;
123         }
124
125         if(MUTATOR_CALLHOOK(Menu_ConsoleCommand, ss, argc, theCommand)) // handled by a mutator
126                 return;
127
128         LOG_INFO(_("Invalid command. For a list of supported commands, try menu_cmd help."));
129 }