]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/command/menu_cmd.qc
Don't show the Welcome dialog in the campaign, centerprint level description works...
[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 <menu/mutators/_mod.qh>
7
8 #include <common/command/_mod.qh>
9
10 .void(entity me, float argsbuf) readInputArgs;
11 .entity firstChild, nextSibling;
12
13 string _dumptree_space;
14 void _dumptree_open(entity pass, entity me)
15 {
16         string s;
17         s = me.toString(me);
18         if (s == "") s = me.classname;
19         else 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         {
28                 print("\n");
29         }
30 }
31 void _dumptree_close(entity pass, entity me)
32 {
33         if (me.firstChild)
34         {
35                 _dumptree_space = substring(_dumptree_space, 0, strlen(_dumptree_space) - 2);
36                 print(_dumptree_space, "}\n");
37         }
38 }
39
40 float updateConwidths(float width, float height, float pixelheight);
41
42 void GameCommand(string theCommand)
43 {
44         int argc = tokenize_console(theCommand);
45         string ss = strtolower(argv(0));
46
47         // TODO port these commands to the command system
48         if (argv(0) == "help" || argc == 0)
49         {
50                 LOG_HELP("Usage:^3 menu_cmd <command> [<item>], where possible commands are:");
51                 LOG_HELP("  'sync' reloads all cvars on the current menu page");
52                 LOG_HELP("  'directmenu' shows the menu window named <item> (or the menu window containing an item named <item>)");
53                 LOG_HELP("   if <item> is not specified it shows the list of available items in the console");
54                 LOG_HELP("  'dumptree' dumps the state of the menu as a tree to the console");
55
56                 LOG_HELP("\nGeneric commands shared by all programs:");
57                 GenericCommand_macro_help();
58
59                 return;
60         }
61
62         if (GenericCommand(theCommand)) return;
63
64         if (argv(0) == "sync")
65         {
66                 m_sync();
67                 return;
68         }
69
70         if (argv(0) == "update_conwidths_before_vid_restart")
71         {
72                 updateConwidths(cvar("vid_width"), cvar("vid_height"), cvar("vid_pixelheight"));
73                 return;
74         }
75
76         if (argv(0) == "directmenu" || argv(0) == "directpanelhudmenu")
77         {
78                 string filter = string_null;
79                 if (argv(0) == "directpanelhudmenu") filter = "HUD";
80
81                 if (argc == 1)
82                 {
83                         LOG_HELP("Available items:");
84
85                         FOREACH_ENTITY_ORDERED(it.name != "", {
86                                 if (it.classname == "vtbl") continue;
87                                 string s = it.name;
88                                 if (filter)
89                                 {
90                                         if (!startsWith(s, filter)) continue;
91                                         s = substring(s, strlen(filter), strlen(s) - strlen(filter));
92                                 }
93                                 LOG_HELP(" ", s);
94                         });
95                 }
96                 else if (argc == 2 && !isdemo())     // don't allow this command in demos
97                 {
98                         if (argv(1) == "Welcome" && cvar("g_campaign"))
99                                 return;
100                         m_play_click_sound(MENU_SOUND_OPEN);
101                         m_goto(strcat(filter, argv(1))); // switch to a menu item
102                 }
103                 else if(argc > 2 && !isdemo())
104                 {
105                         entity e = NULL;
106                         float argsbuf = 0;
107                         string s = strzone(argv(1)); // dialog name
108                         for(int i = 0; (e = nextent(e)); )
109                                 if(e.classname != "vtbl" && e.name == strcat(filter, s))
110                                 {
111                                         argsbuf = buf_create();
112                                         if(argsbuf >= 0)
113                                         if(e.readInputArgs)
114                                         {
115                                                 for(i = 2; i < argc; ++i)
116                                                         bufstr_add(argsbuf, argv(i), 1);
117                                                 e.readInputArgs(e, argsbuf);
118                                                 m_goto(strcat(filter, s));
119                                         }
120                                         if(argsbuf >= 0)
121                                                 buf_del(argsbuf);
122                                 }
123                 }
124                 return;
125         }
126
127         if (argv(0) == "skinselect")
128         {
129                 m_goto("skinselector");
130                 return;
131         }
132
133         if (argv(0) == "languageselect")
134         {
135                 m_goto("languageselector");
136                 return;
137         }
138
139         if (argv(0) == "videosettings")
140         {
141                 m_goto("videosettings");
142                 return;
143         }
144
145         if (argv(0) == "dumptree")
146         {
147                 _dumptree_space = "";
148                 depthfirst(main, parent, firstChild, nextSibling, _dumptree_open, _dumptree_close, NULL);
149                 return;
150         }
151
152         if(MUTATOR_CALLHOOK(Menu_ConsoleCommand, ss, argc, theCommand)) // handled by a mutator
153                 return;
154
155         LOG_INFO("Invalid command. For a list of supported commands, try menu_cmd help.");
156 }