Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
checkbox.qc
Go to the documentation of this file.
1#include "checkbox.qh"
2
3entity makeXonoticCheckBox_T(float isInverted, string theCvar, string theText, string theTooltip)
4{
5 float m, n;
6 if(isInverted > 1)
7 {
8 n = isInverted - 1;
9 m = -n;
10 }
11 else if(isInverted < -1)
12 {
13 n = isInverted + 1;
14 m = -n;
15 }
16 else if(isInverted == 1)
17 {
18 n = 1;
19 m = 0;
20 }
21 else
22 {
23 n = 0;
24 m = 1;
25 }
26 return makeXonoticCheckBoxEx_T(m, n, theCvar, theText, theTooltip);
27}
28entity makeXonoticCheckBox(float isInverted, string theCvar, string theText)
29{
30 return makeXonoticCheckBox_T(isInverted, theCvar, theText, string_null);
31}
32
33entity makeXonoticCheckBoxEx_T(float theYesValue, float theNoValue, string theCvar, string theText, string theTooltip)
34{
35 entity me;
36 me = NEW(XonoticCheckBox);
37 me.configureXonoticCheckBox(me, theYesValue, theNoValue, theCvar, theText, theTooltip);
38 return me;
39}
40entity makeXonoticCheckBoxEx(float theYesValue, float theNoValue, string theCvar, string theText)
41{
42 return makeXonoticCheckBoxEx_T(theYesValue, theNoValue, theCvar, theText, string_null);
43}
44
45void XonoticCheckBox_configureXonoticCheckBox(entity me, float theYesValue, float theNoValue, string theCvar, string theText, string theTooltip)
46{
47 me.yesValue = theYesValue;
48 me.noValue = theNoValue;
49 me.checked = false;
50 me.controlledCvar = (theCvar) ? theCvar : string_null;
51 me.loadCvars(me);
52 setZonedTooltip(me, theTooltip, theCvar);
53 me.configureCheckBox(me, theText, me.fontSize, me.image);
54}
56{
57 if(val != me.checked)
58 {
59 me.checked = val;
60 me.saveCvars(me);
61 if(me.linkedCheckBox)
62 me.linkedCheckBox.loadCvars(me.linkedCheckBox);
63 }
64}
66{
67 if (!me.controlledCvar)
68 return;
69
70 float m = (me.yesValue + me.noValue) * 0.5;
71 float d = (cvar(me.controlledCvar) - m) / (me.yesValue - m);
72 me.checked = (d > 0);
73}
75{
76 if (!me.controlledCvar)
77 return;
78
79 if(me.checked)
80 cvar_set(me.controlledCvar, ftos_mindecimals(me.yesValue));
81 else
82 cvar_set(me.controlledCvar, ftos_mindecimals(me.noValue));
83
84 CheckSendCvars(me, me.controlledCvar);
85}
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
void CheckSendCvars(entity me, string cvarnamestring)
Definition util.qc:825
void setZonedTooltip(entity e, string theTooltip, string theCvar)
Definition util.qc:257
void cvar_set(string name, string value)
float cvar(string name)
string string_null
Definition nil.qh:9
#define NEW(cname,...)
Definition oo.qh:117
ERASEABLE string ftos_mindecimals(float number)
Converts a number to a string with the minimum number of decimals It assumes that an extreme accuracy...
Definition string.qh:497
entity makeXonoticCheckBox_T(float isInverted, string theCvar, string theText, string theTooltip)
Definition checkbox.qc:3
entity makeXonoticCheckBoxEx_T(float theYesValue, float theNoValue, string theCvar, string theText, string theTooltip)
Definition checkbox.qc:33
entity makeXonoticCheckBox(float isInverted, string theCvar, string theText)
Definition checkbox.qc:28
void XonoticCheckBox_loadCvars(entity me)
Definition checkbox.qc:65
void XonoticCheckBox_configureXonoticCheckBox(entity me, float theYesValue, float theNoValue, string theCvar, string theText, string theTooltip)
Definition checkbox.qc:45
void XonoticCheckBox_saveCvars(entity me)
Definition checkbox.qc:74
void XonoticCheckBox_setChecked(entity me, bool val)
Definition checkbox.qc:55
entity makeXonoticCheckBoxEx(float theYesValue, float theNoValue, string theCvar, string theText)
Definition checkbox.qc:40