]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/xonotic/textslider.qc
Merge remote-tracking branch 'origin/master' into terencehill/menu_remove_tab_title
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / xonotic / textslider.qc
1 #ifndef TEXTSLIDER_H
2 #define TEXTSLIDER_H
3 #include "../item/textslider.qc"
4 CLASS(XonoticTextSlider, TextSlider)
5         METHOD(XonoticTextSlider, configureXonoticTextSlider, void(entity, string))
6         METHOD(XonoticTextSlider, setValue, void(entity, float))
7         METHOD(XonoticTextSlider, configureXonoticTextSliderValues, void(entity))
8         ATTRIB(XonoticTextSlider, fontSize, float, SKINFONTSIZE_NORMAL)
9         ATTRIB(XonoticTextSlider, valueSpace, float, SKINWIDTH_SLIDERTEXT)
10         ATTRIB(XonoticTextSlider, image, string, SKINGFX_SLIDER)
11         ATTRIB(XonoticTextSlider, tolerance, vector, SKINTOLERANCE_SLIDER)
12         ATTRIB(XonoticTextSlider, align, float, 0.5)
13         ATTRIB(XonoticTextSlider, color, vector, SKINCOLOR_SLIDER_N)
14         ATTRIB(XonoticTextSlider, colorC, vector, SKINCOLOR_SLIDER_C)
15         ATTRIB(XonoticTextSlider, colorF, vector, SKINCOLOR_SLIDER_F)
16         ATTRIB(XonoticTextSlider, colorD, vector, SKINCOLOR_SLIDER_D)
17         ATTRIB(XonoticTextSlider, color2, vector, SKINCOLOR_SLIDER_S)
18
19         ATTRIB(XonoticTextSlider, cvarName, string, string_null)
20         METHOD(XonoticTextSlider, loadCvars, void(entity))
21         METHOD(XonoticTextSlider, saveCvars, void(entity))
22         ATTRIB(XonoticTextSlider, sendCvars, float, 0)
23
24         ATTRIB(XonoticTextSlider, alpha, float, SKINALPHA_TEXT)
25         ATTRIB(XonoticTextSlider, disabledAlpha, float, SKINALPHA_DISABLED)
26 ENDCLASS(XonoticTextSlider)
27 entity makeXonoticTextSlider(string); // note: you still need to call addValue and configureXonoticTextSliderValues!
28 #endif
29
30 #ifdef IMPLEMENTATION
31 entity makeXonoticTextSlider(string theCvar)
32 {
33         entity me;
34         me = NEW(XonoticTextSlider);
35         me.configureXonoticTextSlider(me, theCvar);
36         return me;
37 }
38 void XonoticTextSlider_configureXonoticTextSlider(entity me, string theCvar)
39 {
40         me.configureSliderVisuals(me, me.fontSize, me.align, me.valueSpace, me.image);
41         if(theCvar)
42         {
43                 me.cvarName = theCvar;
44                 me.tooltip = getZonedTooltipForIdentifier(theCvar);
45                 // don't load it yet
46         }
47 }
48 void XonoticTextSlider_setValue(entity me, float val)
49 {
50         if(val != me.value)
51         {
52                 SUPER(XonoticTextSlider).setValue( me, val );
53                 me.saveCvars(me);
54         }
55 }
56 void XonoticTextSlider_loadCvars(entity me)
57 {
58         if (!me.cvarName)
59                 return;
60
61         float n = tokenize_console(me.cvarName);
62         string s = cvar_string(argv(0));
63         float i;
64         for(i = 1; i < n; ++i)
65                 s = strcat(s, " ", cvar_string(argv(i)));
66         me.setValueFromIdentifier(me, s);
67         if(me.value < 0 && n > 1)
68         {
69                 // if it failed: check if all cvars have the same value
70                 // if yes, try its value as 1-word identifier
71                 for(i = 1; i < n; ++i)
72                         if(cvar_string(argv(i)) != cvar_string(argv(i-1)))
73                                 break;
74                 if(i >= n)
75                         me.setValueFromIdentifier(me, cvar_string(argv(0)));
76         }
77 }
78 void XonoticTextSlider_saveCvars(entity me)
79 {
80         if (!me.cvarName)
81                 return;
82
83         if(me.value >= 0 && me.value < me.nValues)
84         {
85                 float n = tokenize_console(me.cvarName);
86                 if(n == 1)
87                 {
88                         // this is a special case to allow spaces in the identifiers
89                         cvar_set(argv(0), me.getIdentifier(me));
90                         CheckSendCvars(me, argv(0));
91                 }
92                 else
93                 {
94                         float i;
95                         float m = tokenize_console(strcat(me.cvarName, " ", me.getIdentifier(me)));
96                         if(m == n + 1)
97                         {
98                                 for(i = 0; i < n; ++i)
99                                 {
100                                         cvar_set(argv(i), argv(n));
101                                         CheckSendCvars(me, argv(i));
102                                 }
103                         }
104                         else if(m == n * 2)
105                         {
106                                 for(i = 0; i < n; ++i)
107                                 {
108                                         cvar_set(argv(i), argv(i + n));
109                                         CheckSendCvars(me, argv(i));
110                                 }
111                         }
112                         else
113                                 error("XonoticTextSlider: invalid identifier ", me.getIdentifier(me), " does not match cvar list ", me.cvarName);
114                 }
115         }
116 }
117 void XonoticTextSlider_configureXonoticTextSliderValues(entity me)
118 {
119         me.configureTextSliderValues(me, string_null);
120         me.loadCvars(me);
121 }
122 #endif