]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/xonotic/checkbox_string.qc
Sort menu classes
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / xonotic / checkbox_string.qc
1 #ifndef CHECKBOX_STRING_H
2 #define CHECKBOX_STRING_H
3 CLASS(XonoticCheckBoxString, CheckBox)
4         METHOD(XonoticCheckBoxString, configureXonoticCheckBoxString, void(entity, string, string, string, string))
5         METHOD(XonoticCheckBoxString, setChecked, void(entity, float))
6         ATTRIB(XonoticCheckBoxString, fontSize, float, SKINFONTSIZE_NORMAL)
7         ATTRIB(XonoticCheckBoxString, image, string, SKINGFX_CHECKBOX)
8         ATTRIB(XonoticCheckBoxString, yesString, string, string_null)
9         ATTRIB(XonoticCheckBoxString, noString, string, string_null)
10
11         ATTRIB(XonoticCheckBoxString, color, vector, SKINCOLOR_CHECKBOX_N)
12         ATTRIB(XonoticCheckBoxString, colorC, vector, SKINCOLOR_CHECKBOX_C)
13         ATTRIB(XonoticCheckBoxString, colorF, vector, SKINCOLOR_CHECKBOX_F)
14         ATTRIB(XonoticCheckBoxString, colorD, vector, SKINCOLOR_CHECKBOX_D)
15
16         ATTRIB(XonoticCheckBoxString, cvarName, string, string_null)
17         METHOD(XonoticCheckBoxString, loadCvars, void(entity))
18         METHOD(XonoticCheckBoxString, saveCvars, void(entity))
19         ATTRIB(XonoticCheckBoxString, sendCvars, float, 0)
20
21         ATTRIB(XonoticCheckBoxString, alpha, float, SKINALPHA_TEXT)
22         ATTRIB(XonoticCheckBoxString, disabledAlpha, float, SKINALPHA_DISABLED)
23 ENDCLASS(XonoticCheckBoxString)
24 entity makeXonoticCheckBoxString(string, string, string, string);
25 #endif
26
27 #ifdef IMPLEMENTATION
28 entity makeXonoticCheckBoxString(string theYesValue, string theNoValue, string theCvar, string theText)
29 {
30         entity me;
31         me = NEW(XonoticCheckBoxString);
32         me.configureXonoticCheckBoxString(me, theYesValue, theNoValue, theCvar, theText);
33         return me;
34 }
35 void XonoticCheckBoxString_configureXonoticCheckBoxString(entity me, string theYesValue, string theNoValue, string theCvar, string theText)
36 {
37         me.yesString = theYesValue;
38         me.noString = theNoValue;
39         me.checked = 0;
40         if(theCvar)
41         {
42                 me.cvarName = theCvar;
43                 me.tooltip = getZonedTooltipForIdentifier(theCvar);
44                 me.loadCvars(me);
45         }
46         me.configureCheckBox(me, theText, me.fontSize, me.image);
47 }
48 void XonoticCheckBoxString_setChecked(entity me, float foo)
49 {
50         me.checked = !me.checked;
51         me.saveCvars(me);
52 }
53 void XonoticCheckBoxString_loadCvars(entity me)
54 {
55         if (!me.cvarName)
56                 return;
57
58         if(cvar_string(me.cvarName) == me.yesString)
59                 me.checked = 1;
60 }
61 void XonoticCheckBoxString_saveCvars(entity me)
62 {
63         if (!me.cvarName)
64                 return;
65
66         if(me.checked)
67                 cvar_set(me.cvarName, me.yesString);
68         else
69                 cvar_set(me.cvarName, me.noString);
70
71         CheckSendCvars(me, me.cvarName);
72 }
73 #endif