Xonotic
colorbutton.qc
Go to the documentation of this file.
1 #include "colorbutton.qh"
2 
3 entity makeXonoticColorButton(float theGroup, float theColor, float theValue)
4 {
5  entity me;
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.controlledCvar = "_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 }
40 {
41  if(val != me.checked)
42  {
43  me.checked = val;
44  me.saveCvars(me);
45  }
46 }
48 {
49  if (!me.controlledCvar)
50  return;
51 
52  if(cvar_string(me.controlledCvar) == cvar_defstring(me.controlledCvar))
53  cvar_set(me.controlledCvar, ftos(16 * floor(random() * 15) + floor(random() * 15)));
54 
55  if(me.cvarPart == 1)
56  me.checked = (cvar(me.controlledCvar) & 240) == me.cvarValueFloat * 16;
57  else
58  me.checked = (cvar(me.controlledCvar) & 15) == me.cvarValueFloat;
59 }
61 {
62  if (!me.controlledCvar)
63  return;
64 
65  if(me.checked)
66  {
67  if(me.cvarPart == 1)
68  cvar_set(me.controlledCvar, ftos((cvar(me.controlledCvar) & 15) + me.cvarValueFloat * 16));
69  else
70  cvar_set(me.controlledCvar, ftos((cvar(me.controlledCvar) & 240) + me.cvarValueFloat));
71  }
72 }
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 }
string string_null
Definition: nil.qh:9
#define NEW(cname,...)
Definition: oo.qh:105
entity() spawn
#define SUPER(cname)
Definition: oo.qh:219
void XonoticColorButton_draw(entity me)
Definition: colorbutton.qc:73
void XonoticColorButton_configureXonoticColorButton(entity me, float theGroup, float theColor, float theValue)
Definition: colorbutton.qc:10
void XonoticColorButton_loadCvars(entity me)
Definition: colorbutton.qc:47
void XonoticColorButton_setChecked(entity me, float val)
Definition: colorbutton.qc:39
entity makeXonoticColorButton(float theGroup, float theColor, float theValue)
Definition: colorbutton.qc:3
void XonoticColorButton_saveCvars(entity me)
Definition: colorbutton.qc:60
#define colormapPaletteColor(c, isPants)
Definition: color.qh:5