Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
radiobutton.qc
Go to the documentation of this file.
1#include "radiobutton.qh"
2
3entity makeXonoticRadioButton_T(float theGroup, string theCvar, string theValue, string theText, string theTooltip)
4{
5 entity me;
7 me.configureXonoticRadioButton(me, theGroup, theCvar, theValue, theText, theTooltip);
8 return me;
9}
10entity makeXonoticRadioButton(float theGroup, string theCvar, string theValue, string theText)
11{
12 return makeXonoticRadioButton_T(theGroup, theCvar, theValue, theText, string_null);
13}
14void XonoticRadioButton_configureXonoticRadioButton(entity me, float theGroup, string theCvar, string theValue, string theText, string theTooltip)
15{
16 me.controlledCvar = (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}
23{
24 if(val != me.checked)
25 {
26 me.checked = val;
27 me.saveCvars(me);
28 }
29}
31{
32 if(me.cvarValue)
33 {
34 if(me.controlledCvar)
35 {
36 if(me.cvarValueIsAnotherCvar)
37 me.checked = (cvar_string(me.controlledCvar) == cvar_string(me.cvarValue));
38 else
39 me.checked = (cvar_string(me.controlledCvar) == me.cvarValue);
40 }
41 }
42 else
43 {
44 if(me.controlledCvar)
45 {
46 me.checked = boolean(cvar(me.controlledCvar));
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 = false;
55 }
56 }
57}
59{
60 if (!me.cvarValue)
61 if (!me.controlledCvar)
62 {
63 // this is the "other" option
64 // always select this if none other is
65 entity e;
66 bool found = false;
67 for(e = me.parent.firstChild; e; e = e.nextSibling)
68 if(e.group == me.group)
69 if(e.checked)
70 found = true;
71 if(!found)
72 me.setChecked(me, true);
73 }
74 SUPER(XonoticRadioButton).draw(me);
75}
77{
78 if(me.cvarValue)
79 {
80 if(me.controlledCvar)
81 {
82 if(me.checked)
83 {
84 if(me.cvarValueIsAnotherCvar)
85 cvar_set(me.controlledCvar, cvar_string(me.cvarValue));
86 else
87 cvar_set(me.controlledCvar, me.cvarValue);
88 }
89 else if(me.cvarOffValue)
90 cvar_set(me.controlledCvar, me.cvarOffValue);
91 }
92 }
93 else
94 {
95 if(me.controlledCvar)
96 {
97 cvar_set(me.controlledCvar, ftos(me.checked));
98 }
99 }
100}
#define boolean(value)
Definition bool.qh:9
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
void setZonedTooltip(entity e, string theTooltip, string theCvar)
Definition util.qc:257
void cvar_set(string name, string value)
float cvar(string name)
const string cvar_string(string name)
string ftos(float f)
string string_null
Definition nil.qh:9
#define NEW(cname,...)
Definition oo.qh:117
#define SUPER(cname)
Definition oo.qh:231
void XonoticRadioButton_configureXonoticRadioButton(entity me, float theGroup, string theCvar, string theValue, string theText, string theTooltip)
void XonoticRadioButton_saveCvars(entity me)
void XonoticRadioButton_loadCvars(entity me)
entity makeXonoticRadioButton(float theGroup, string theCvar, string theValue, string theText)
void XonoticRadioButton_draw(entity me)
void XonoticRadioButton_setChecked(entity me, bool val)
entity makeXonoticRadioButton_T(float theGroup, string theCvar, string theValue, string theText, string theTooltip)
Definition radiobutton.qc:3