Xonotic
radiobutton.qc
Go to the documentation of this file.
1 #include "radiobutton.qh"
2 
3 entity 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 }
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.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 = 0;
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  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 }
78 {
79  if(me.cvarValue)
80  {
81  if(me.controlledCvar)
82  {
83  if(me.checked)
84  {
85  if(me.cvarValueIsAnotherCvar)
86  cvar_set(me.controlledCvar, cvar_string(me.cvarValue));
87  else
88  cvar_set(me.controlledCvar, me.cvarValue);
89  }
90  else if(me.cvarOffValue)
91  cvar_set(me.controlledCvar, me.cvarOffValue);
92  }
93  }
94  else
95  {
96  if(me.controlledCvar)
97  {
98  cvar_set(me.controlledCvar, ftos(me.checked));
99  }
100  }
101 }
string string_null
Definition: nil.qh:9
void XonoticRadioButton_saveCvars(entity me)
Definition: radiobutton.qc:77
#define NEW(cname,...)
Definition: oo.qh:105
entity makeXonoticRadioButton(float theGroup, string theCvar, string theValue, string theText)
Definition: radiobutton.qc:10
entity() spawn
entity makeXonoticRadioButton_T(float theGroup, string theCvar, string theValue, string theText, string theTooltip)
Definition: radiobutton.qc:3
void XonoticRadioButton_loadCvars(entity me)
Definition: radiobutton.qc:30
#define SUPER(cname)
Definition: oo.qh:219
void XonoticRadioButton_setChecked(entity me, float val)
Definition: radiobutton.qc:22
void XonoticRadioButton_configureXonoticRadioButton(entity me, float theGroup, string theCvar, string theValue, string theText, string theTooltip)
Definition: radiobutton.qc:14
void XonoticRadioButton_draw(entity me)
Definition: radiobutton.qc:58
#define boolean(value)
Definition: bool.qh:9