When possible use simpler LOG_* macros instead of LOG_*F
[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 .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                 LOG_INFO(_("  dumptree - dump the state of the menu as a tree to the console"));
52                 LOG_INFO("\n");
53
54                 LOG_INFO("Generic commands shared by all programs:");
55                 GenericCommand_macro_help();
56
57                 return;
58         }
59
60         if (GenericCommand(theCommand)) return;
61
62         if (argv(0) == "sync")
63         {
64                 m_sync();
65                 return;
66         }
67
68         if (argv(0) == "update_conwidths_before_vid_restart")
69         {
70                 updateConwidths(cvar("vid_width"), cvar("vid_height"), cvar("vid_pixelheight"));
71                 return;
72         }
73
74         if (argv(0) == "directmenu" || argv(0) == "directpanelhudmenu")
75         {
76                 string filter = string_null;
77                 if (argv(0) == "directpanelhudmenu") filter = "HUD";
78
79                 if (argc == 1)
80                 {
81                         LOG_INFO(_("Available options:"));
82
83                         FOREACH_ENTITY_ORDERED(it.name != "", {
84                                 if (it.classname == "vtbl") continue;
85                                 string s = it.name;
86                                 if (filter)
87                                 {
88                                         if (!startsWith(s, filter)) continue;
89                                         s = substring(s, strlen(filter), strlen(s) - strlen(filter));
90                                 }
91                                 LOG_INFO(" ", s);
92                         });
93                 }
94                 else if (argc == 2 && !isdemo())     // don't allow this command in demos
95                 {
96                         m_play_click_sound(MENU_SOUND_OPEN);
97                         m_goto(strcat(filter, argv(1))); // switch to a menu item
98                 }
99                 return;
100         }
101
102         if (argv(0) == "skinselect")
103         {
104                 m_goto("skinselector");
105                 return;
106         }
107
108         if (argv(0) == "languageselect")
109         {
110                 m_goto("languageselector");
111                 return;
112         }
113
114         if (argv(0) == "videosettings")
115         {
116                 m_goto("videosettings");
117                 return;
118         }
119
120         if (argv(0) == "dumptree")
121         {
122                 _dumptree_space = "";
123                 depthfirst(main, parent, firstChild, nextSibling, _dumptree_open, _dumptree_close, NULL);
124                 return;
125         }
126
127         if(MUTATOR_CALLHOOK(Menu_ConsoleCommand, ss, argc, theCommand)) // handled by a mutator
128                 return;
129
130         LOG_INFO(_("Invalid command. For a list of supported commands, try menu_cmd help."));
131 }