]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/mutators/events.qh
Merge branch 'terencehill/menu_optimization' into 'master'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / mutators / events.qh
1 #ifndef MENU_MUTATORS_EVENTS_H
2 #define MENU_MUTATORS_EVENTS_H
3
4 #include <common/mutators/base.qh>
5
6 // globals
7
8 string cmd_name;
9 int cmd_argc;
10 string cmd_string;
11
12 /**
13  * Called when a menu command is parsed
14  * NOTE: hooks MUST start with if (MUTATOR_RETURNVALUE) return false;
15  * NOTE: return true if you handled the command, return false to continue handling
16  * NOTE: THESE HOOKS MUST NEVER EVER CALL tokenize()
17  * // example:
18  * MUTATOR_HOOKFUNCTION(foo, Menu_ConsoleCommand) {
19  *     if (MUTATOR_RETURNVALUE) return false; // command was already handled
20  *     if (cmd_name == "echocvar" && cmd_argc >= 2) {
21  *         print(cvar_string(argv(1)), "\n");
22  *         return true;
23  *     }
24  *     if (cmd_name == "echostring" && cmd_argc >= 2) {
25  *         print(substring(cmd_string, argv_start_index(1), argv_end_index(-1) - argv_start_index(1)), "\n");
26  *         return true;
27  *     }
28  *     return false;
29  * }
30  */
31 #define EV_Menu_ConsoleCommand(i, o) \
32         /** command name */ i(string, cmd_name) \
33         /** also, argv() can be used */ i(int, cmd_argc) \
34         /** whole command, use only if you really have to */ i(string, cmd_string) \
35         /**/
36 MUTATOR_HOOKABLE(Menu_ConsoleCommand, EV_Menu_ConsoleCommand);
37 #endif