]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/xonotic/slider.qc
take3: format 903 files
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / xonotic / slider.qc
1 #include "slider.qh"
2
3 entity makeXonoticSlider_T(float theValueMin, float theValueMax, float theValueStep, string theCvar, string theTooltip)
4 {
5         entity me;
6         me = NEW(XonoticSlider);
7         me.configureXonoticSlider(me, theValueMin, theValueMax, theValueStep, theCvar, theTooltip);
8         return me;
9 }
10 entity makeXonoticSlider(float theValueMin, float theValueMax, float theValueStep, string theCvar)
11 {
12         return makeXonoticSlider_T(theValueMin, theValueMax, theValueStep, theCvar, string_null);
13 }
14 void XonoticSlider_configureXonoticSlider(entity me, float theValueMin, float theValueMax, float theValueStep, string theCvar, string theTooltip)
15 {
16         float vp;
17         vp = theValueStep * 10;
18         while (fabs(vp) < fabs(theValueMax - theValueMin) / 40) {
19                 vp *= 10;
20         }
21
22         me.configureSliderVisuals(me, me.fontSize, me.align, me.valueSpace, me.image);
23
24         me.cvarName = (theCvar) ? theCvar : string_null;
25         if (theCvar) {
26                 // Prevent flickering of the slider button by initialising the
27                 // slider out of bounds to hide the button before loading the cvar
28                 me.configureSliderValues(me, theValueMin, theValueMin - theValueStep, theValueMax, theValueStep, theValueStep, vp);
29         } else {
30                 me.configureSliderValues(me, theValueMin, theValueMin, theValueMax, theValueStep, theValueStep, vp);
31         }
32         me.loadCvars(me);
33         setZonedTooltip(me, theTooltip, theCvar);
34 }
35 void XonoticSlider_setValue(entity me, float val)
36 {
37         if (val != me.value) {
38                 SUPER(XonoticSlider).setValue(me, val);
39                 me.saveCvars(me);
40         }
41 }
42 void XonoticSlider_setValue_noAnim(entity me, float val)
43 {
44         if (val != me.value) {
45                 SUPER(XonoticSlider).setValue_noAnim(me, val);
46                 me.saveCvars(me);
47         }
48 }
49 void XonoticSlider_loadCvars(entity me)
50 {
51         if (!me.cvarName) {
52                 return;
53         }
54
55         me.setValue_noAnim(me, cvar(me.cvarName));
56 }
57 void XonoticSlider_saveCvars(entity me)
58 {
59         if (!me.cvarName) {
60                 return;
61         }
62
63         cvar_set(me.cvarName, ftos_mindecimals(me.value));
64
65         CheckSendCvars(me, me.cvarName);
66 }