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