]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/xonotic/checkbox_string.qc
e605390f2677e4427f1f2b3d0a8996fff4c5ec79
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / xonotic / checkbox_string.qc
1 #include "checkbox_string.qh"
2 #ifndef CHECKBOX_STRING_H
3 #define CHECKBOX_STRING_H
4 #include "../item/checkbox.qc"
5 CLASS(XonoticCheckBoxString, CheckBox)
6         METHOD(XonoticCheckBoxString, configureXonoticCheckBoxString, void(entity, string, string, string, string));
7         METHOD(XonoticCheckBoxString, setChecked, void(entity, float));
8         ATTRIB(XonoticCheckBoxString, fontSize, float, SKINFONTSIZE_NORMAL)
9         ATTRIB(XonoticCheckBoxString, image, string, SKINGFX_CHECKBOX)
10         ATTRIB(XonoticCheckBoxString, yesString, string, string_null)
11         ATTRIB(XonoticCheckBoxString, noString, string, string_null)
12
13         ATTRIB(XonoticCheckBoxString, color, vector, SKINCOLOR_CHECKBOX_N)
14         ATTRIB(XonoticCheckBoxString, colorC, vector, SKINCOLOR_CHECKBOX_C)
15         ATTRIB(XonoticCheckBoxString, colorF, vector, SKINCOLOR_CHECKBOX_F)
16         ATTRIB(XonoticCheckBoxString, colorD, vector, SKINCOLOR_CHECKBOX_D)
17
18         ATTRIB(XonoticCheckBoxString, cvarName, string, string_null)
19         METHOD(XonoticCheckBoxString, loadCvars, void(entity));
20         METHOD(XonoticCheckBoxString, saveCvars, void(entity));
21         ATTRIB(XonoticCheckBoxString, sendCvars, float, 0)
22
23         ATTRIB(XonoticCheckBoxString, alpha, float, SKINALPHA_TEXT)
24         ATTRIB(XonoticCheckBoxString, disabledAlpha, float, SKINALPHA_DISABLED)
25 ENDCLASS(XonoticCheckBoxString)
26 entity makeXonoticCheckBoxString(string, string, string, string);
27 #endif
28
29 #ifdef IMPLEMENTATION
30 entity makeXonoticCheckBoxString(string theYesValue, string theNoValue, string theCvar, string theText)
31 {
32         entity me;
33         me = NEW(XonoticCheckBoxString);
34         me.configureXonoticCheckBoxString(me, theYesValue, theNoValue, theCvar, theText);
35         return me;
36 }
37 void XonoticCheckBoxString_configureXonoticCheckBoxString(entity me, string theYesValue, string theNoValue, string theCvar, string theText)
38 {
39         me.yesString = theYesValue;
40         me.noString = theNoValue;
41         me.checked = 0;
42         me.cvarName = (theCvar) ? theCvar : string_null;
43         me.loadCvars(me);
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         CheckSendCvars(me, me.cvarName);
70 }
71 #endif