]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/xonotic/commandbutton.qc
Merge branch 'master' into Mario/snake
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / xonotic / commandbutton.qc
1 #ifndef COMMANDBUTTON_CLOSE
2 # define COMMANDBUTTON_CLOSE 1
3 # define COMMANDBUTTON_APPLY 2
4 //# define COMMANDBUTTON_REVERT 4
5 #endif
6
7 #ifndef COMMANDBUTTON_H
8 #define COMMANDBUTTON_H
9 #include "button.qc"
10 CLASS(XonoticCommandButton, XonoticButton)
11         METHOD(XonoticCommandButton, configureXonoticCommandButton, void(entity, string, vector, string, float, string));
12         ATTRIB(XonoticCommandButton, onClickCommand, string, string_null)
13         ATTRIB(XonoticCommandButton, flags, float, 0)
14 ENDCLASS(XonoticCommandButton)
15 entity makeXonoticCommandButton_T(string theText, vector theColor, string theCommand, float closesMenu, string theTooltip);
16 entity makeXonoticCommandButton(string theText, vector theColor, string theCommand, float closesMenu);
17 #endif
18
19 #ifdef IMPLEMENTATION
20 entity makeXonoticCommandButton_T(string theText, vector theColor, string theCommand, float theFlags, string theTooltip)
21 {
22         entity me;
23         me = NEW(XonoticCommandButton);
24         me.configureXonoticCommandButton(me, theText, theColor, theCommand, theFlags, theTooltip);
25         return me;
26 }
27 entity makeXonoticCommandButton(string theText, vector theColor, string theCommand, float theFlags)
28 {
29         return makeXonoticCommandButton_T(theText, theColor, theCommand, theFlags, string_null);
30 }
31
32 void XonoticCommandButton_Click(entity me, entity other)
33 {
34         //if(me.flags & COMMANDBUTTON_APPLY)
35         //      saveAllCvars(me.parent);
36         cmd("\n", me.onClickCommand, "\n");
37         //if(me.flags & COMMANDBUTTON_REVERT)
38         //      loadAllCvars(me.parent);
39         if(me.flags & COMMANDBUTTON_CLOSE)
40                 m_goto(string_null);
41 }
42
43 void XonoticCommandButton_configureXonoticCommandButton(entity me, string theText, vector theColor, string theCommand, float theFlags, string theTooltip)
44 {
45         me.configureXonoticButton(me, theText, theColor, theTooltip);
46         me.onClickCommand = theCommand;
47         me.flags = theFlags;
48         me.onClick = XonoticCommandButton_Click;
49         me.onClickEntity = me;
50 }
51 #endif