]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/gamecommand.qc
Merge commit 'origin/fruitiex/newpanelhud' into diabolik/newpanelhud
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / gamecommand.qc
1 void GameCommand_Init()
2 {
3         // make gg call menu QC theCommands
4         localcmd("alias qc_cmd \"menu_cmd $*\"\n");
5 }
6
7 string _dumptree_space;
8 void _dumptree_open(entity pass, entity me)
9 {
10         string s;
11         s = me.toString(me);
12         if(s == "")
13                 s = me.classname;
14         else
15                 s = strcat(me.classname, ": ", s);
16         print(_dumptree_space, etos(me), " (", s, ")");
17         if(me.firstChild)
18         {
19                 print(" {\n");
20                 _dumptree_space = strcat(_dumptree_space, "  ");
21         }
22         else
23                 print("\n");
24 }
25 void _dumptree_close(entity pass, entity me)
26 {
27         if(me.firstChild)
28         {
29                 _dumptree_space = substring(_dumptree_space, 0, strlen(_dumptree_space) - 2);
30                 print(_dumptree_space, "}\n");
31         }
32 }
33
34 void GameCommand(string theCommand)
35 {
36         float argc;
37         argc = tokenize_console(theCommand);
38
39         if(argv(0) == "help" || argc == 0)
40         {
41                 print("Usage: menu_cmd theCommand..., where possible theCommands are:\n");
42                 print("  sync - reloads all cvars on the current menu page\n");
43                 print("  directmenu ITEM - select a menu item as main item\n");
44                 GameCommand_Generic("help");
45                 return;
46         }
47
48         if(GameCommand_Generic(theCommand))
49                 return;
50
51         if(argv(0) == "sync")
52         {
53                 loadAllCvars(main);
54                 return;
55         }
56
57         if(argv(0) == "directmenu") if(argc == 2)
58         {
59                 // switch to a menu item
60                 if(!isdemo()) // don't allow this command in demos
61                         m_goto(argv(1));
62                 return;
63         }
64
65         if(argv(0) == "directpanelhudmenu")
66         {
67                 // switch to a menu item
68                 m_goto("HUDOptions");
69                 entity panelvar;
70                 panelvar = findstring(NULL, name, "HUDOptions");
71                 panelvar.change(panelvar, stof(argv(1)));
72                 return;
73         }
74
75         if(argv(0) == "skinselect")
76         {
77                 m_goto_skin_selector();
78                 return;
79         }
80
81         if(argv(0) == "videosettings")
82         {
83                 m_goto_video_settings();
84                 return;
85         }
86
87         if(argv(0) == "dumptree")
88         {
89                 _dumptree_space = "";
90                 depthfirst(main, parent, firstChild, nextSibling, _dumptree_open, _dumptree_close, NULL);
91                 return;
92         }
93
94         if(argv(0) == "setresolution")
95         {
96                 updateConwidths();
97                 return;
98         }
99
100 #if 0
101         if(argv(0) == "tokentest")
102         {
103                 string s;
104                 float i, n;
105
106                 print("SANE tokenizer:\n");
107                 s = cvar_string("tokentest");
108                 n = tokenize_console_force_builtin(s);
109                 for(i = -n; i < n; ++i)
110                 {
111                         print("token ", ftos(i), ": '", argv(i), "' = ");
112                         print(ftos(argv_start_index(i)), " to ", ftos(argv_end_index(i)), "\n");
113                 }
114                 print(".\n");
115
116                 print("INSANE tokenizer:\n");
117                 s = cvar_string("tokentest");
118                 n = tokenize(s);
119                 for(i = -n; i < n; ++i)
120                 {
121                         print("token ", ftos(i), ": '", argv(i), "' = ");
122                         print(ftos(argv_start_index(i)), " to ", ftos(argv_end_index(i)), "\n");
123                 }
124                 print(".\n");
125
126                 print("EMULATED tokenizer:\n");
127                 s = cvar_string("tokentest");
128                 n = tokenize_console_force_emulation(s);
129                 for(i = -n; i < n; ++i)
130                 {
131                         print("token ", ftos(i), ": '", argv(i), "' = ");
132                         print(ftos(argv_start_index(i)), " to ", ftos(argv_end_index(i)), "\n");
133                 }
134                 print(".\n");
135                 return;
136         }
137 #endif
138
139         print("Invalid theCommand. For a list of supported theCommands, try menu_cmd help.\n");
140 }