1 #include "textslider.qh"
4 #include "../item/textslider.qc"
5 CLASS(XonoticTextSlider, TextSlider)
6 METHOD(XonoticTextSlider, configureXonoticTextSlider, void(entity, string, string));
7 METHOD(XonoticTextSlider, setValue, void(entity, float));
8 METHOD(XonoticTextSlider, setValue_noAnim, void(entity, float));
9 METHOD(XonoticTextSlider, configureXonoticTextSliderValues, void(entity));
10 ATTRIB(XonoticTextSlider, fontSize, float, SKINFONTSIZE_NORMAL)
11 ATTRIB(XonoticTextSlider, valueSpace, float, SKINWIDTH_SLIDERTEXT)
12 ATTRIB(XonoticTextSlider, image, string, SKINGFX_SLIDER)
13 ATTRIB(XonoticTextSlider, tolerance, vector, SKINTOLERANCE_SLIDER)
14 ATTRIB(XonoticTextSlider, align, float, 0.5)
15 ATTRIB(XonoticTextSlider, color, vector, SKINCOLOR_SLIDER_N)
16 ATTRIB(XonoticTextSlider, colorC, vector, SKINCOLOR_SLIDER_C)
17 ATTRIB(XonoticTextSlider, colorF, vector, SKINCOLOR_SLIDER_F)
18 ATTRIB(XonoticTextSlider, colorD, vector, SKINCOLOR_SLIDER_D)
19 ATTRIB(XonoticTextSlider, color2, vector, SKINCOLOR_SLIDER_S)
21 ATTRIB(XonoticTextSlider, cvarName, string, string_null)
22 METHOD(XonoticTextSlider, loadCvars, void(entity));
23 METHOD(XonoticTextSlider, saveCvars, void(entity));
24 ATTRIB(XonoticTextSlider, sendCvars, float, 0)
26 ATTRIB(XonoticTextSlider, alpha, float, SKINALPHA_TEXT)
27 ATTRIB(XonoticTextSlider, disabledAlpha, float, SKINALPHA_DISABLED)
28 ENDCLASS(XonoticTextSlider)
29 entity makeXonoticTextSlider_T(string, string theTooltip);
30 entity makeXonoticTextSlider(string); // note: you still need to call addValue and configureXonoticTextSliderValues!
34 entity makeXonoticTextSlider_T(string theCvar, string theTooltip)
37 me = NEW(XonoticTextSlider);
38 me.configureXonoticTextSlider(me, theCvar, theTooltip);
41 entity makeXonoticTextSlider(string theCvar)
43 return makeXonoticTextSlider_T(theCvar, string_null);
45 void XonoticTextSlider_configureXonoticTextSlider(entity me, string theCvar, string theTooltip)
47 me.configureSliderVisuals(me, me.fontSize, me.align, me.valueSpace, me.image);
48 me.cvarName = (theCvar) ? theCvar : string_null;
49 // me.loadCvars(me); // don't load it yet
50 setZonedTooltip(me, theTooltip, theCvar);
52 void XonoticTextSlider_setValue(entity me, float val)
56 SUPER(XonoticTextSlider).setValue( me, val );
60 void XonoticTextSlider_setValue_noAnim(entity me, float val)
64 SUPER(XonoticTextSlider).setValue_noAnim(me, val);
68 void XonoticTextSlider_loadCvars(entity me)
73 float n = tokenize_console(me.cvarName);
74 string s = cvar_string(argv(0));
76 for(i = 1; i < n; ++i)
77 s = strcat(s, " ", cvar_string(argv(i)));
78 me.setValueFromIdentifier_noAnim(me, s);
79 if(me.value < 0 && n > 1)
81 // if it failed: check if all cvars have the same value
82 // if yes, try its value as 1-word identifier
83 for(i = 1; i < n; ++i)
84 if(cvar_string(argv(i)) != cvar_string(argv(i-1)))
87 me.setValueFromIdentifier_noAnim(me, cvar_string(argv(0)));
90 void XonoticTextSlider_saveCvars(entity me)
95 if(me.value >= 0 && me.value < me.nValues)
97 float n = tokenize_console(me.cvarName);
100 // this is a special case to allow spaces in the identifiers
101 cvar_set(argv(0), me.getIdentifier(me));
102 CheckSendCvars(me, argv(0));
107 float m = tokenize_console(strcat(me.cvarName, " ", me.getIdentifier(me)));
110 for(i = 0; i < n; ++i)
112 cvar_set(argv(i), argv(n));
113 CheckSendCvars(me, argv(i));
118 for(i = 0; i < n; ++i)
120 cvar_set(argv(i), argv(i + n));
121 CheckSendCvars(me, argv(i));
125 error("XonoticTextSlider: invalid identifier ", me.getIdentifier(me), " does not match cvar list ", me.cvarName);
129 void XonoticTextSlider_configureXonoticTextSliderValues(entity me)
131 me.configureTextSliderValues(me, string_null);