]> de.git.xonotic.org Git - voretournament/voretournament.git/blob - data/qcsrc/menu/voret/radiobutton.c
Initial checkout of Vore Tournament 0.1.alpha.
[voretournament/voretournament.git] / data / qcsrc / menu / voret / radiobutton.c
1 #ifdef INTERFACE\r
2 CLASS(VoretRadioButton) EXTENDS(RadioButton)\r
3         METHOD(VoretRadioButton, configureVoretRadioButton, void(entity, float, string, string, string))\r
4         METHOD(VoretRadioButton, draw, void(entity))\r
5         METHOD(VoretRadioButton, setChecked, void(entity, float))\r
6         ATTRIB(VoretRadioButton, fontSize, float, SKINFONTSIZE_NORMAL)\r
7         ATTRIB(VoretRadioButton, image, string, SKINGFX_RADIOBUTTON)\r
8         ATTRIB(VoretRadioButton, color, vector, SKINCOLOR_RADIOBUTTON_N)\r
9         ATTRIB(VoretRadioButton, colorC, vector, SKINCOLOR_RADIOBUTTON_C)\r
10         ATTRIB(VoretRadioButton, colorF, vector, SKINCOLOR_RADIOBUTTON_F)\r
11         ATTRIB(VoretRadioButton, colorD, vector, SKINCOLOR_RADIOBUTTON_D)\r
12 \r
13         ATTRIB(VoretRadioButton, cvarName, string, string_null)\r
14         ATTRIB(VoretRadioButton, cvarValue, string, string_null)\r
15         ATTRIB(VoretRadioButton, cvarOffValue, string, string_null)\r
16         METHOD(VoretRadioButton, loadCvars, void(entity))\r
17         METHOD(VoretRadioButton, saveCvars, void(entity))\r
18 \r
19         ATTRIB(VoretRadioButton, alpha, float, SKINALPHA_TEXT)\r
20         ATTRIB(VoretRadioButton, disabledAlpha, float, SKINALPHA_DISABLED)\r
21 ENDCLASS(VoretRadioButton)\r
22 entity makeVoretRadioButton(float, string, string, string);\r
23 #endif\r
24 \r
25 #ifdef IMPLEMENTATION\r
26 entity makeVoretRadioButton(float theGroup, string theCvar, string theValue, string theText)\r
27 {\r
28         entity me;\r
29         me = spawnVoretRadioButton();\r
30         me.configureVoretRadioButton(me, theGroup, theCvar, theValue, theText);\r
31         return me;\r
32 }\r
33 void configureVoretRadioButtonVoretRadioButton(entity me, float theGroup, string theCvar, string theValue, string theText)\r
34 {\r
35         if(theCvar)\r
36         {\r
37                 me.cvarName = theCvar;\r
38                 me.cvarValue = theValue;\r
39                 me.tooltip = getZonedTooltipForIdentifier(theCvar);\r
40                 me.loadCvars(me);\r
41         }\r
42         me.configureRadioButton(me, theText, me.fontSize, me.image, theGroup, 0);\r
43 }\r
44 void setCheckedVoretRadioButton(entity me, float val)\r
45 {\r
46         if(val != me.checked)\r
47         {\r
48                 me.checked = val;\r
49                 me.saveCvars(me);\r
50         }\r
51 }\r
52 void loadCvarsVoretRadioButton(entity me)\r
53 {\r
54         if(me.cvarValue)\r
55         {\r
56                 if(me.cvarName)\r
57                         me.checked = (cvar_string(me.cvarName) == me.cvarValue);\r
58         }\r
59         else\r
60         {\r
61                 if(me.cvarName)\r
62                 {\r
63                         me.checked = !!cvar(me.cvarName);\r
64                 }\r
65                 else\r
66                 {\r
67                         // this is difficult\r
68                         // this is the "generic" selection... but at this time, not\r
69                         // everything is constructed yet.\r
70                         // we need to set this later in draw()\r
71                         me.checked = 0;\r
72                 }\r
73         }\r
74 }\r
75 void drawVoretRadioButton(entity me)\r
76 {\r
77         if not(me.cvarValue)\r
78                 if not(me.cvarName)\r
79                 {\r
80                         // this is the "other" option\r
81                         // always select this if none other is\r
82                         entity e;\r
83                         float found;\r
84                         found = 0;\r
85                         for(e = me.parent.firstChild; e; e = e.nextSibling)\r
86                                 if(e.group == me.group)\r
87                                         if(e.checked)\r
88                                                 found = 1;\r
89                         if(!found)\r
90                                 me.setChecked(me, 1);\r
91                 }\r
92         drawCheckBox(me);\r
93 }\r
94 void saveCvarsVoretRadioButton(entity me)\r
95 {\r
96         if(me.cvarValue)\r
97         {\r
98                 if(me.cvarName)\r
99                 {\r
100                         if(me.checked)\r
101                                 cvar_set(me.cvarName, me.cvarValue);\r
102                         else if(me.cvarOffValue)\r
103                                 cvar_set(me.cvarName, me.cvarOffValue);\r
104                 }\r
105         }\r
106         else\r
107         {\r
108                 if(me.cvarName)\r
109                 {\r
110                         cvar_set(me.cvarName, ftos(me.checked));\r
111                 }\r
112         }\r
113 }\r
114 #endif\r