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