]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/xonotic/checkbox.qc
Merge branch 'TimePath/soundregistry' into 'master'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / xonotic / checkbox.qc
1 #ifndef CHECKBOX_H
2 #define CHECKBOX_H
3 #include "../item/checkbox.qc"
4 CLASS(XonoticCheckBox, CheckBox)
5         METHOD(XonoticCheckBox, configureXonoticCheckBox, void(entity, float, float, string, string, string));
6         METHOD(XonoticCheckBox, setChecked, void(entity, float));
7         ATTRIB(XonoticCheckBox, fontSize, float, SKINFONTSIZE_NORMAL)
8         ATTRIB(XonoticCheckBox, image, string, SKINGFX_CHECKBOX)
9         ATTRIB(XonoticCheckBox, yesValue, float, 1)
10         ATTRIB(XonoticCheckBox, noValue, float, 0)
11
12         ATTRIB(XonoticCheckBox, color, vector, SKINCOLOR_CHECKBOX_N)
13         ATTRIB(XonoticCheckBox, colorC, vector, SKINCOLOR_CHECKBOX_C)
14         ATTRIB(XonoticCheckBox, colorF, vector, SKINCOLOR_CHECKBOX_F)
15         ATTRIB(XonoticCheckBox, colorD, vector, SKINCOLOR_CHECKBOX_D)
16
17         ATTRIB(XonoticCheckBox, cvarName, string, string_null)
18         METHOD(XonoticCheckBox, loadCvars, void(entity));
19         METHOD(XonoticCheckBox, saveCvars, void(entity));
20         ATTRIB(XonoticCheckBox, sendCvars, float, 0)
21
22         ATTRIB(XonoticCheckBox, alpha, float, SKINALPHA_TEXT)
23         ATTRIB(XonoticCheckBox, disabledAlpha, float, SKINALPHA_DISABLED)
24 ENDCLASS(XonoticCheckBox)
25 entity makeXonoticCheckBox_T(float, string, string, string);
26 entity makeXonoticCheckBox(float, string, string);
27 entity makeXonoticCheckBoxEx_T(float, float, string, string, string);
28 entity makeXonoticCheckBoxEx(float, float, string, string);
29 #endif
30
31 #ifdef IMPLEMENTATION
32 entity makeXonoticCheckBox_T(float isInverted, string theCvar, string theText, string theTooltip)
33 {
34         float y, n;
35         if(isInverted > 1)
36         {
37                 n = isInverted - 1;
38                 y = -n;
39         }
40         else if(isInverted < -1)
41         {
42                 n = isInverted + 1;
43                 y = -n;
44         }
45         else if(isInverted == 1)
46         {
47                 n = 1;
48                 y = 0;
49         }
50         else
51         {
52                 n = 0;
53                 y = 1;
54         }
55         return makeXonoticCheckBoxEx_T(y, n, theCvar, theText, theTooltip);
56 }
57 entity makeXonoticCheckBox(float isInverted, string theCvar, string theText)
58 {
59         return makeXonoticCheckBox_T(isInverted, theCvar, theText, string_null);
60 }
61
62 entity makeXonoticCheckBoxEx_T(float theYesValue, float theNoValue, string theCvar, string theText, string theTooltip)
63 {
64         entity me;
65         me = NEW(XonoticCheckBox);
66         me.configureXonoticCheckBox(me, theYesValue, theNoValue, theCvar, theText, theTooltip);
67         return me;
68 }
69 entity makeXonoticCheckBoxEx(float theYesValue, float theNoValue, string theCvar, string theText)
70 {
71         return makeXonoticCheckBoxEx_T(theYesValue, theNoValue, theCvar, theText, string_null);
72 }
73
74 void XonoticCheckBox_configureXonoticCheckBox(entity me, float theYesValue, float theNoValue, string theCvar, string theText, string theTooltip)
75 {
76         me.yesValue = theYesValue;
77         me.noValue = theNoValue;
78         me.checked = 0;
79         me.cvarName = (theCvar) ? theCvar : string_null;
80         me.loadCvars(me);
81         setZonedTooltip(me, theTooltip, theCvar);
82         me.configureCheckBox(me, theText, me.fontSize, me.image);
83 }
84 void XonoticCheckBox_setChecked(entity me, float val)
85 {
86         if(val != me.checked)
87         {
88                 me.checked = val;
89                 me.saveCvars(me);
90         }
91 }
92 void XonoticCheckBox_loadCvars(entity me)
93 {
94         float m, d;
95
96         if (!me.cvarName)
97                 return;
98
99         m = (me.yesValue + me.noValue) * 0.5;
100         d = (cvar(me.cvarName) - m) / (me.yesValue - m);
101         me.checked = (d > 0);
102 }
103 void XonoticCheckBox_saveCvars(entity me)
104 {
105         if (!me.cvarName)
106                 return;
107
108         if(me.checked)
109                 cvar_set(me.cvarName, ftos(me.yesValue));
110         else
111                 cvar_set(me.cvarName, ftos(me.noValue));
112
113         CheckSendCvars(me, me.cvarName);
114 }
115 #endif