]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/xonotic/radiobutton.qc
Merge branch 'master' into Mario/hagar_notfixed
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / xonotic / radiobutton.qc
1 #include "radiobutton.qh"
2
3 entity makeXonoticRadioButton_T(float theGroup, string theCvar, string theValue, string theText, string theTooltip)
4 {
5         entity me;
6         me = NEW(XonoticRadioButton);
7         me.configureXonoticRadioButton(me, theGroup, theCvar, theValue, theText, theTooltip);
8         return me;
9 }
10 entity makeXonoticRadioButton(float theGroup, string theCvar, string theValue, string theText)
11 {
12         return makeXonoticRadioButton_T(theGroup, theCvar, theValue, theText, string_null);
13 }
14 void XonoticRadioButton_configureXonoticRadioButton(entity me, float theGroup, string theCvar, string theValue, string theText, string theTooltip)
15 {
16         me.cvarName = (theCvar) ? theCvar : string_null;
17         me.cvarValue = theValue;
18         me.loadCvars(me);
19         setZonedTooltip(me, theTooltip, theCvar);
20         me.configureRadioButton(me, theText, me.fontSize, me.image, theGroup, 0);
21 }
22 void XonoticRadioButton_setChecked(entity me, float val)
23 {
24         if(val != me.checked)
25         {
26                 me.checked = val;
27                 me.saveCvars(me);
28         }
29 }
30 void XonoticRadioButton_loadCvars(entity me)
31 {
32         if(me.cvarValue)
33         {
34                 if(me.cvarName)
35                 {
36                         if(me.cvarValueIsAnotherCvar)
37                                 me.checked = (cvar_string(me.cvarName) == cvar_string(me.cvarValue));
38                         else
39                                 me.checked = (cvar_string(me.cvarName) == me.cvarValue);
40                 }
41         }
42         else
43         {
44                 if(me.cvarName)
45                 {
46                         me.checked = boolean(cvar(me.cvarName));
47                 }
48                 else
49                 {
50                         // this is difficult
51                         // this is the "generic" selection... but at this time, not
52                         // everything is constructed yet.
53                         // we need to set this later in draw()
54                         me.checked = 0;
55                 }
56         }
57 }
58 void XonoticRadioButton_draw(entity me)
59 {
60         if (!me.cvarValue)
61                 if (!me.cvarName)
62                 {
63                         // this is the "other" option
64                         // always select this if none other is
65                         entity e;
66                         float found;
67                         found = 0;
68                         for(e = me.parent.firstChild; e; e = e.nextSibling)
69                                 if(e.group == me.group)
70                                         if(e.checked)
71                                                 found = 1;
72                         if(!found)
73                                 me.setChecked(me, 1);
74                 }
75         SUPER(XonoticRadioButton).draw(me);
76 }
77 void XonoticRadioButton_saveCvars(entity me)
78 {
79         if(me.cvarValue)
80         {
81                 if(me.cvarName)
82                 {
83                         if(me.checked)
84                         {
85                                 if(me.cvarValueIsAnotherCvar)
86                                         cvar_set(me.cvarName, cvar_string(me.cvarValue));
87                                 else
88                                         cvar_set(me.cvarName, me.cvarValue);
89                         }
90                         else if(me.cvarOffValue)
91                                 cvar_set(me.cvarName, me.cvarOffValue);
92                 }
93         }
94         else
95         {
96                 if(me.cvarName)
97                 {
98                         cvar_set(me.cvarName, ftos(me.checked));
99                 }
100         }
101 }