]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/xonotic/colorbutton.qc
Merge branch 'master' into terencehill/glowmod_color_fix
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / xonotic / colorbutton.qc
1 #include "colorbutton.qh"
2
3 entity makeXonoticColorButton(float theGroup, float theColor, float theValue)
4 {
5         entity me;
6         me = NEW(XonoticColorButton);
7         me.configureXonoticColorButton(me, theGroup, theColor, theValue);
8         return me;
9 }
10 void XonoticColorButton_configureXonoticColorButton(entity me, float theGroup, float theColor, float theValue)
11 {
12         switch(theValue)
13         {
14                 // rearrange 1..14 for rainbow order
15                 case  1: theValue = 10; break;
16                 case  2: theValue =  4; break;
17                 case  3: theValue =  1; break;
18                 case  4: theValue = 14; break;
19                 case  5: theValue = 12; break;
20                 case  6: theValue =  7; break;
21                 case  7: theValue =  3; break;
22                 case  8: theValue =  2; break;
23                 case  9: theValue =  6; break;
24                 case 10: theValue =  5; break;
25                 case 11: theValue = 13; break;
26                 case 12: theValue = 11; break;
27                 case 13: theValue =  8; break;
28                 case 14: theValue =  9; break;
29                 default:
30                         // no change
31                         break;
32         }
33         me.cvarName = "_cl_color";
34         me.cvarValueFloat = theValue;
35         me.cvarPart = theColor;
36         me.loadCvars(me);
37         me.configureRadioButton(me, string_null, me.fontSize, me.image, theGroup, 0);
38 }
39 void XonoticColorButton_setChecked(entity me, float val)
40 {
41         if(val != me.checked)
42         {
43                 me.checked = val;
44                 me.saveCvars(me);
45         }
46 }
47 void XonoticColorButton_loadCvars(entity me)
48 {
49         if (!me.cvarName)
50                 return;
51
52         if(cvar_string(me.cvarName) == cvar_defstring(me.cvarName))
53                 cvar_set(me.cvarName, ftos(16 * floor(random() * 15) + floor(random() * 15)));
54
55         if(me.cvarPart == 1)
56                 me.checked = (cvar(me.cvarName) & 240) == me.cvarValueFloat * 16;
57         else
58                 me.checked = (cvar(me.cvarName) & 15) == me.cvarValueFloat;
59 }
60 void XonoticColorButton_saveCvars(entity me)
61 {
62         if (!me.cvarName)
63                 return;
64
65         if(me.checked)
66         {
67                 if(me.cvarPart == 1)
68                         cvar_set(me.cvarName, ftos((cvar(me.cvarName) & 15) + me.cvarValueFloat * 16));
69                 else
70                         cvar_set(me.cvarName, ftos((cvar(me.cvarName) & 240) + me.cvarValueFloat));
71         }
72 }
73 void XonoticColorButton_draw(entity me)
74 {
75         me.color  = colormapPaletteColor(me.cvarValueFloat, me.cvarPart);
76         me.colorC = me.color;
77         me.colorF = me.color;
78         me.colorD = me.color;
79         SUPER(XonoticColorButton).draw(me);
80 }