From: ColdSpirit Date: Tue, 21 Dec 2021 08:03:29 +0000 (+0400) Subject: Color update fix X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=223371b9262611f6fd56caf6e3ad5a8274280df0;p=xonotic%2Fxonotic-data.pk3dir.git Color update fix --- diff --git a/qcsrc/menu/xonotic/colorbutton.qc b/qcsrc/menu/xonotic/colorbutton.qc index 49bffed25..accb1f7e7 100644 --- a/qcsrc/menu/xonotic/colorbutton.qc +++ b/qcsrc/menu/xonotic/colorbutton.qc @@ -1,13 +1,13 @@ #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) { @@ -30,7 +30,7 @@ void XonoticColorButton_configureXonoticColorButton(entity me, float theGroup, f // no change break; } - me.controlledCvar = "_cl_color"; + me.controlledCvar = theControlledCvar; me.cvarValueFloat = theValue; me.cvarPart = theColor; me.loadCvars(me); @@ -49,9 +49,6 @@ void XonoticColorButton_loadCvars(entity 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 diff --git a/qcsrc/menu/xonotic/colorbutton.qh b/qcsrc/menu/xonotic/colorbutton.qh index 5c729fcb8..50c9779ec 100644 --- a/qcsrc/menu/xonotic/colorbutton.qh +++ b/qcsrc/menu/xonotic/colorbutton.qh @@ -2,7 +2,7 @@ #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); @@ -16,4 +16,4 @@ CLASS(XonoticColorButton, RadioButton) METHOD(XonoticColorButton, loadCvars, void(entity)); METHOD(XonoticColorButton, saveCvars, void(entity)); ENDCLASS(XonoticColorButton) -entity makeXonoticColorButton(float, float, float); +entity makeXonoticColorButton(string, float, float, float); diff --git a/qcsrc/menu/xonotic/dialog_multiplayer_profile.qc b/qcsrc/menu/xonotic/dialog_multiplayer_profile.qc index ecda61c22..d3b8a7025 100644 --- a/qcsrc/menu/xonotic/dialog_multiplayer_profile.qc +++ b/qcsrc/menu/xonotic/dialog_multiplayer_profile.qc @@ -22,24 +22,49 @@ entity makeXonoticProfileTab() 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); @@ -53,6 +78,7 @@ void XonoticProfileTab_fill(entity 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;" @@ -113,22 +139,22 @@ void XonoticProfileTab_fill(entity me) 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; } // ==================== diff --git a/qcsrc/menu/xonotic/dialog_multiplayer_profile.qh b/qcsrc/menu/xonotic/dialog_multiplayer_profile.qh index 9e40fe3f0..7e1379269 100644 --- a/qcsrc/menu/xonotic/dialog_multiplayer_profile.qh +++ b/qcsrc/menu/xonotic/dialog_multiplayer_profile.qh @@ -1,6 +1,7 @@ #pragma once #include "tab.qh" +const int COLOR_BUTTONS_COUNT = 15; CLASS(XonoticProfileTab, XonoticTab) METHOD(XonoticProfileTab, fill, void(entity)); METHOD(XonoticProfileTab, draw, void(entity)); @@ -11,5 +12,7 @@ CLASS(XonoticProfileTab, XonoticTab) 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();