#include "colorbutton.qh"
-entity makeXonoticColorButton(float theGroup, float theColor, float theValue)
+entity makeXonoticColorButton(string theControlledCvar, float theGroup, float theColor, float theValue)
{
entity me;
me = NEW(XonoticColorButton);
- me.configureXonoticColorButton(me, theGroup, theColor, theValue);
+ me.configureXonoticColorButton(me, theControlledCvar, theGroup, theColor, theValue);
return me;
}
-void XonoticColorButton_configureXonoticColorButton(entity me, float theGroup, float theColor, float theValue)
+void XonoticColorButton_configureXonoticColorButton(entity me, string theControlledCvar, float theGroup, float theColor, float theValue)
{
switch(theValue)
{
// no change
break;
}
- me.controlledCvar = "_cl_color";
+ me.controlledCvar = theControlledCvar;
me.cvarValueFloat = theValue;
me.cvarPart = theColor;
me.loadCvars(me);
if (!me.controlledCvar)
return;
- if(cvar_string(me.controlledCvar) == cvar_defstring(me.controlledCvar))
- cvar_set(me.controlledCvar, ftos(16 * floor(random() * 15) + floor(random() * 15)));
-
if(me.cvarPart == 1)
me.checked = (cvar(me.controlledCvar) & 240) == me.cvarValueFloat * 16;
else
#include "../item/radiobutton.qh"
CLASS(XonoticColorButton, RadioButton)
- METHOD(XonoticColorButton, configureXonoticColorButton, void(entity, float, float, float));
+ METHOD(XonoticColorButton, configureXonoticColorButton, void(entity, string, float, float, float));
METHOD(XonoticColorButton, setChecked, void(entity, float));
METHOD(XonoticColorButton, draw, void(entity));
ATTRIB(XonoticColorButton, fontSize, float, 0);
METHOD(XonoticColorButton, loadCvars, void(entity));
METHOD(XonoticColorButton, saveCvars, void(entity));
ENDCLASS(XonoticColorButton)
-entity makeXonoticColorButton(float, float, float);
+entity makeXonoticColorButton(string, float, float, float);
string name = cvar_string("_cl_name");
registercvar("_menu_profile_name", name, 0);
+ string color = cvar_string("_cl_color");
+ // if color unset, set random color
+ if(color == cvar_defstring("_cl_color"))
+ {
+ // idk what meaning of 16, maybe just COLOR_BUTTONS_COUNT+1
+ float randomColor = 16 * floor(random() * COLOR_BUTTONS_COUNT) + floor(random() * COLOR_BUTTONS_COUNT);
+ cvar_set("_cl_color", ftos(randomColor));
+ }
+ registercvar("_menu_profile_color", color, 0);
+
return me;
}
void XonoticProfileTab_draw(entity me)
{
string name = cvar_string("_cl_name");
- string input_name = cvar_string("_menu_profile_name");
if(name == "Player")
me.playerNameLabel.alpha = ((mod(time * 2, 2) < 1) ? 1 : 0);
else
me.playerNameLabel.alpha = me.playerNameLabelAlpha;
- // if name changed from console
- if (me.applyButton.disabled && name != input_name)
+ // if values changed from console
+ if (me.applyButton.disabled)
{
- cvar_set("_menu_profile_name", name);
- me.nameInput.loadCvars(me.nameInput);
+ string inputName = cvar_string("_menu_profile_name");
+ if (name != inputName)
+ {
+ cvar_set("_menu_profile_name", name);
+ me.nameInput.loadCvars(me.nameInput);
+ }
+
+ string color = cvar_string("_cl_color");
+ string inputColor = cvar_string("_menu_profile_color");
+ if (color != inputColor)
+ {
+ cvar_set("_menu_profile_color", color);
+ for (int i = 0; i < COLOR_BUTTONS_COUNT; i++)
+ {
+ me.colorButtonGroup1[i].loadCvars(me.colorButtonGroup1[i]);
+ me.colorButtonGroup2[i].loadCvars(me.colorButtonGroup2[i]);
+ }
+ }
}
SUPER(XonoticProfileTab).draw(me);
entity e, pms, label;
float i;
me.applyButton = makeXonoticCommandButton(_("Apply immediately"), '0 0 0',
+ "_cl_color \"$_menu_profile_color\""
"color -1 -1;" // apply colors contained in _cl_color
"name \"$_menu_profile_name\";"
"playermodel $_cl_playermodel;"
me.gotoRC(me, me.currentRow, 0); me.setFirstColumn(me, me.currentColumn); // MODEL RIGHT, COLOR LEFT
me.TR(me);
me.TD(me, 1, 1, e = makeXonoticHeaderLabel(_("Glowing color")));
- for(i = 0; i < 15; ++i)
+ for(i = 0; i < COLOR_BUTTONS_COUNT; ++i)
{
if(mod(i, 5) == 0)
me.TR(me);
- me.TDNoMargin(me, 1, 0.2, e = makeXonoticColorButton(1, 0, i), '0 1 0');
- e.applyButton = me.applyButton;
+ me.TDNoMargin(me, 1, 0.2, me.colorButtonGroup1[i] = makeXonoticColorButton("_menu_profile_color", 1, 0, i), '0 1 0');
+ me.colorButtonGroup1[i].applyButton = me.applyButton;
}
me.TR(me);
me.TR(me);
me.TD(me, 1, 1, e = makeXonoticHeaderLabel(_("Detail color")));
- for(i = 0; i < 15; ++i)
+ for(i = 0; i < COLOR_BUTTONS_COUNT; ++i)
{
if(mod(i, 5) == 0)
me.TR(me);
- me.TDNoMargin(me, 1, 0.2, e = makeXonoticColorButton(2, 1, i), '0 1 0');
- e.applyButton = me.applyButton;
+ me.TDNoMargin(me, 1, 0.2, me.colorButtonGroup2[i] = makeXonoticColorButton("_menu_profile_color", 2, 1, i), '0 1 0');
+ me.colorButtonGroup2[i].applyButton = me.applyButton;
}
// ====================
#pragma once
#include "tab.qh"
+const int COLOR_BUTTONS_COUNT = 15;
CLASS(XonoticProfileTab, XonoticTab)
METHOD(XonoticProfileTab, fill, void(entity));
METHOD(XonoticProfileTab, draw, void(entity));
ATTRIB(XonoticProfileTab, playerNameLabelAlpha, float, SKINALPHA_HEADER);
ATTRIB(XonoticProfileTab, applyButton, entity);
ATTRIB(XonoticProfileTab, nameInput, entity);
+ ATTRIB(XonoticProfileTab, colorButtonGroup1[COLOR_BUTTONS_COUNT], entity);
+ ATTRIB(XonoticProfileTab, colorButtonGroup2[COLOR_BUTTONS_COUNT], entity);
ENDCLASS(XonoticProfileTab)
entity makeXonoticProfileTab();