]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/xonotic/checkbox.qc
Merge branch 'master' into Mario/balance
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / xonotic / checkbox.qc
1 #include "checkbox.qh"
2
3 entity makeXonoticCheckBox_T(float isInverted, string theCvar, string theText, string theTooltip)
4 {
5         float y, n;
6         if(isInverted > 1)
7         {
8                 n = isInverted - 1;
9                 y = -n;
10         }
11         else if(isInverted < -1)
12         {
13                 n = isInverted + 1;
14                 y = -n;
15         }
16         else if(isInverted == 1)
17         {
18                 n = 1;
19                 y = 0;
20         }
21         else
22         {
23                 n = 0;
24                 y = 1;
25         }
26         return makeXonoticCheckBoxEx_T(y, n, theCvar, theText, theTooltip);
27 }
28 entity makeXonoticCheckBox(float isInverted, string theCvar, string theText)
29 {
30         return makeXonoticCheckBox_T(isInverted, theCvar, theText, string_null);
31 }
32
33 entity 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 }
40 entity makeXonoticCheckBoxEx(float theYesValue, float theNoValue, string theCvar, string theText)
41 {
42         return makeXonoticCheckBoxEx_T(theYesValue, theNoValue, theCvar, theText, string_null);
43 }
44
45 void 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 = 0;
50         me.cvarName = (theCvar) ? theCvar : string_null;
51         me.loadCvars(me);
52         setZonedTooltip(me, theTooltip, theCvar);
53         me.configureCheckBox(me, theText, me.fontSize, me.image);
54 }
55 void XonoticCheckBox_setChecked(entity me, float val)
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 }
65 void XonoticCheckBox_loadCvars(entity me)
66 {
67         float m, d;
68
69         if (!me.cvarName)
70                 return;
71
72         m = (me.yesValue + me.noValue) * 0.5;
73         d = (cvar(me.cvarName) - m) / (me.yesValue - m);
74         me.checked = (d > 0);
75 }
76 void XonoticCheckBox_saveCvars(entity me)
77 {
78         if (!me.cvarName)
79                 return;
80
81         if(me.checked)
82                 cvar_set(me.cvarName, ftos_mindecimals(me.yesValue));
83         else
84                 cvar_set(me.cvarName, ftos_mindecimals(me.noValue));
85
86         CheckSendCvars(me, me.cvarName);
87 }