From: ColdSpirit Date: Sun, 1 Oct 2023 16:27:26 +0000 (+0400) Subject: Revert "WIP profile apply fix: subscribe to cvar changes" X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=e3b9666d79552ef0038a4fc13b847529f194306b;p=xonotic%2Fxonotic-data.pk3dir.git Revert "WIP profile apply fix: subscribe to cvar changes" This reverts commit fda407c76ce54e72dfccb825e7c98ff1cc8510dc. --- diff --git a/qcsrc/dpdefs/upstream/menudefs.qc b/qcsrc/dpdefs/upstream/menudefs.qc index 47549c82c..63d2c6388 100644 --- a/qcsrc/dpdefs/upstream/menudefs.qc +++ b/qcsrc/dpdefs/upstream/menudefs.qc @@ -18,7 +18,6 @@ void(float keynr, float ascii) m_keydown; void(float width, float height) m_draw; void(float mode) m_toggle; void() m_shutdown; -void(string name, string oldValue, string newValue) m_cvar_changed; // optional: float(float) m_gethostcachecategory; ///////////////////////////////////////////////////////// diff --git a/qcsrc/menu/_mod.inc b/qcsrc/menu/_mod.inc index b029bc1cf..d2a8d702f 100644 --- a/qcsrc/menu/_mod.inc +++ b/qcsrc/menu/_mod.inc @@ -1,5 +1,4 @@ // generated file; do not modify -#include #include #include #include diff --git a/qcsrc/menu/_mod.qh b/qcsrc/menu/_mod.qh index f3020f519..da8675831 100644 --- a/qcsrc/menu/_mod.qh +++ b/qcsrc/menu/_mod.qh @@ -1,5 +1,4 @@ // generated file; do not modify -#include #include #include #include diff --git a/qcsrc/menu/cvarcallbackitem.qc b/qcsrc/menu/cvarcallbackitem.qc deleted file mode 100644 index da9aabc62..000000000 --- a/qcsrc/menu/cvarcallbackitem.qc +++ /dev/null @@ -1,11 +0,0 @@ -#include "cvarcallbackitem.qh" - -entity createCvarCallbackItem(string theCvarName, cvar_callback theCallback, entity theContext) -{ - entity item; - item = NEW(CvarCallbackItem); - item.cvarName = theCvarName; - item.callback = theCallback; - item.context = theContext; - return item; -} \ No newline at end of file diff --git a/qcsrc/menu/cvarcallbackitem.qh b/qcsrc/menu/cvarcallbackitem.qh deleted file mode 100644 index 0b8621dc6..000000000 --- a/qcsrc/menu/cvarcallbackitem.qh +++ /dev/null @@ -1,11 +0,0 @@ -#pragma once - -#define cvar_callback void(string, string, string, entity) - -CLASS(CvarCallbackItem, Object) - ATTRIB(CvarCallbackItem, cvarName, string); - ATTRIB(CvarCallbackItem, callback, cvar_callback); // old value, new value - ATTRIB(CvarCallbackItem, context, entity); -ENDCLASS(CvarCallbackItem) - -entity createCvarCallbackItem(string theCvarName, cvar_callback theCallback, entity theContext); \ No newline at end of file diff --git a/qcsrc/menu/menu.qc b/qcsrc/menu/menu.qc index 0eb3def83..710dca1e6 100644 --- a/qcsrc/menu/menu.qc +++ b/qcsrc/menu/menu.qc @@ -416,9 +416,9 @@ int menuTooltipState; // 0: static, 1: fading in, 2: fading out, 3: forced fadi bool m_testmousetooltipbox(vector pos) { return !( - (pos.x >= menuTooltipOrigin.x && pos.x < menuTooltipOrigin.x + menuTooltipSize.x) - && (pos.y >= menuTooltipOrigin.y && pos.y < menuTooltipOrigin.y + menuTooltipSize.y) - ); + (pos.x >= menuTooltipOrigin.x && pos.x < menuTooltipOrigin.x + menuTooltipSize.x) + && (pos.y >= menuTooltipOrigin.y && pos.y < menuTooltipOrigin.y + menuTooltipSize.y) + ); } bool m_testtooltipbox(vector tooltippos) { @@ -710,12 +710,12 @@ void m_draw(float width, float height) { menuNotTheFirstFrame = true; if (Menu_Active && !cvar("menu_video_played")) - { - localcmd("cd loop $menu_cdtrack\n"); - // TODO: use this when we have a welcome sound - //localcmd("cd loop $menu_cdtrack; play sound/announcer/default/welcome.wav\n"); - menuLogoAlpha = -0.8; // no idea why, but when I start this at zero, it jumps instead of fading FIXME - } + { + localcmd("cd loop $menu_cdtrack\n"); + // TODO: use this when we have a welcome sound + //localcmd("cd loop $menu_cdtrack; play sound/announcer/default/welcome.wav\n"); + menuLogoAlpha = -0.8; // no idea why, but when I start this at zero, it jumps instead of fading FIXME + } // ALWAYS set this cvar; if we start but menu is not active, this means we want no background music! localcmd("set menu_video_played 1\n"); } @@ -739,8 +739,8 @@ void m_draw(float width, float height) if (Menu_Active) { if (getmousetarget() == (menuMouseMode ? MT_CLIENT : MT_MENU) - && (getkeydest() == KEY_MENU || getkeydest() == KEY_MENU_GRABBED)) - setkeydest(keyGrabber ? KEY_MENU_GRABBED : KEY_MENU); + && (getkeydest() == KEY_MENU || getkeydest() == KEY_MENU_GRABBED)) + setkeydest(keyGrabber ? KEY_MENU_GRABBED : KEY_MENU); else m_hide(); } @@ -999,30 +999,3 @@ void m_play_click_sound(string soundfile) if (!cvar("menu_sounds")) return; localsound(soundfile); } - -void m_cvar_changed(string theCvarName, string oldValue, string newValue) -{ - if (!menuInitialized) return; - - // some variables have name "\n" - // LOG_INFOF("========> QC: Cvar \"%s\" changed from \"%s\" to \"%s\"", - // strreplace("\n", "\\n", theCvarName), - // strreplace("\n", "\\n", oldValue), - // strreplace("\n", "\\n", newValue) - // ); - - // search for subscribed callbacks and call them - IL_EACH(cvarCallbackItems, it.cvarName == theCvarName, - { - // LOG_INFOF("=========> Callback triggered for %s", it.name); - entity theContext = it.context; - it.callback(theCvarName, oldValue, newValue, theContext); - }); -} - -void cvar_onChangeSubscribe(string theCvarName, cvar_callback theCallback, entity theContext) -{ - entity callbackItem; - callbackItem = createCvarCallbackItem(theCvarName, theCallback, theContext); - IL_PUSH(cvarCallbackItems, callbackItem); -} \ No newline at end of file diff --git a/qcsrc/menu/menu.qh b/qcsrc/menu/menu.qh index 5243b6059..2df331950 100644 --- a/qcsrc/menu/menu.qh +++ b/qcsrc/menu/menu.qh @@ -8,8 +8,6 @@ #include #include -#include "cvarcallbackitem.qh" - const int GAME_ISSERVER = BIT(0); const int GAME_CONNECTED = BIT(1); const int GAME_DEVELOPER = BIT(2); @@ -59,8 +57,3 @@ const string MENU_SOUND_WINNER = "sound/menu/winner.wav"; void m_play_focus_sound(); void m_play_click_sound(string soundfile); - -// callback list and method to subscribe -IntrusiveList cvarCallbackItems; -STATIC_INIT(cvarCallbackItems) { cvarCallbackItems = IL_NEW(); } -void cvar_onChangeSubscribe(string, cvar_callback, entity); \ No newline at end of file diff --git a/qcsrc/menu/xonotic/dialog_multiplayer_profile.qc b/qcsrc/menu/xonotic/dialog_multiplayer_profile.qc index 028c740e0..e885ee0b0 100644 --- a/qcsrc/menu/xonotic/dialog_multiplayer_profile.qc +++ b/qcsrc/menu/xonotic/dialog_multiplayer_profile.qc @@ -23,94 +23,17 @@ entity makeXonoticProfileTab() me = NEW(XonoticProfileTab); me.configureDialog(me); - string name = cvar_string("_cl_name"); - string playermodel = cvar_string("_cl_playermodel"); - string playerskin = cvar_string("_cl_playerskin"); - string color = cvar_string("_cl_color"); - // if color unset, set random color (init it) - if (color == cvar_defstring("_cl_color")) + if (cvar_string("_cl_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); - color = ftos(randomColor); - cvar_set("_cl_color", color); + cvar_set("_cl_color", ftos(randomColor)); } - // copy field values from game cvars - cvar_set(MENU_CVAR_COLOR, color); - cvar_set(MENU_CVAR_NAME, name); - cvar_set(MENU_CVAR_SKIN, playerskin); - cvar_set(MENU_CVAR_MODEL, playermodel); - - // subscribe to cvar changes - - // stable branch cvars - cvar_onChangeSubscribe("_cl_name", onCvarChanged, me); - cvar_onChangeSubscribe("_cl_color", onCvarChanged, me); - cvar_onChangeSubscribe("_cl_playermodel", onCvarChanged, me); - - // master branch cvars - cvar_onChangeSubscribe("name", onCvarChanged, me); - cvar_onChangeSubscribe("topcolor", onCvarChanged, me); - cvar_onChangeSubscribe("bottomcolor", onCvarChanged, me); - cvar_onChangeSubscribe("playermodel", onCvarChanged, me); - return me; } -// if values changed from console, update it in menu -void onCvarChanged(string cvarName, string oldValue, string newValue, entity me) -{ - // IMPORTANT: dont change same cvars that was observed to avoid infinite loop - - // nothing to change - if (oldValue == newValue) - { - return; - } - - // not update field values when tab in 'edit mode' - if (!me.applyButton.disabled) - { - return; - } - - // LOG_INFOF("[onCvarChanged]: %s, %s, %s", cvarName, oldValue, newValue); - - // name - if (cvarName == "_cl_name" || cvarName == "name") - { - cvar_set(MENU_CVAR_NAME, newValue); - me.nameInput.loadCvars(me.nameInput); - } - - // model - else if (cvarName == "_cl_playermodel" || cvarName == "playermodel") - { - cvar_set(MENU_CVAR_MODEL, newValue); - me.playerModelSelector.loadCvars(me.playerModelSelector); - me.playerModelSelector.go(me.playerModelSelector, 0); - } - - // skin (skin not tested, dont know what cvars it use) - // else if (cvarName == "_cl_playerskin" || cvarName == "playerskin") - // { - // } - - // color - else if (cvarName == "_cl_color") - { - cvar_set(MENU_CVAR_COLOR, newValue); - me.updateColor(me); - } - else if (cvarName == "topcolor" || cvarName == "bottomcolor") - { - cvar_set(MENU_CVAR_COLOR, cvar_string("_cl_color")); - me.updateColor(me); - } -} - void XonoticProfileTab_draw(entity me) { string name = cvar_string("_cl_name"); @@ -119,6 +42,44 @@ void XonoticProfileTab_draw(entity me) me.playerNameLabel.alpha = ((mod(time * 2, 2) < 1) ? 1 : 0); else me.playerNameLabel.alpha = me.playerNameLabelAlpha; + + // if values changed from console, update it in menu + if (me.applyButton.disabled) + { + // name field + string inputName = cvar_string(MENU_CVAR_NAME); + if (name != inputName) + { + cvar_set(MENU_CVAR_NAME, name); + me.nameInput.loadCvars(me.nameInput); + } + + // color buttons + string color = cvar_string("_cl_color"); + string inputColor = cvar_string(MENU_CVAR_COLOR); + if (color != inputColor) + { + cvar_set(MENU_CVAR_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]); + } + } + + // player model + string skin = cvar_string("_cl_playerskin"); + string skinInput = cvar_string(MENU_CVAR_SKIN); + string model = cvar_string("_cl_playermodel"); + string modelInput = cvar_string(MENU_CVAR_MODEL); + if (skin != skinInput || model != modelInput) + { + cvar_set(MENU_CVAR_SKIN, skin); + cvar_set(MENU_CVAR_MODEL, model); + me.playerModelSelector.loadCvars(me.playerModelSelector); + me.playerModelSelector.go(me.playerModelSelector, 0); + } + } SUPER(XonoticProfileTab).draw(me); } @@ -131,7 +92,7 @@ void XonoticProfileTab_fill(entity me) entity e, label; float i; me.applyButton = makeXonoticCommandButton(_("Apply immediately"), '0 0 0', - "_cl_color \"$"MENU_CVAR_COLOR"\";" + "_cl_color \"$"MENU_CVAR_COLOR"\"" "color -1 -1;" // apply colors contained in _cl_color "name \"$"MENU_CVAR_NAME"\";" "playermodel $"MENU_CVAR_MODEL";" @@ -260,12 +221,3 @@ void XonoticProfileTab_fill(entity me) me.gotoRC(me, me.rows - 1, 0); me.TD(me, 1, me.columns, me.applyButton); } - -void XonoticProfileTab_updateColor(entity me) -{ - for (int i = 0; i < COLOR_BUTTONS_COUNT; i++) - { - me.colorButtonGroup1[i].loadCvars(me.colorButtonGroup1[i]); - me.colorButtonGroup2[i].loadCvars(me.colorButtonGroup2[i]); - } -} \ No newline at end of file diff --git a/qcsrc/menu/xonotic/dialog_multiplayer_profile.qh b/qcsrc/menu/xonotic/dialog_multiplayer_profile.qh index db7393613..ccf772518 100644 --- a/qcsrc/menu/xonotic/dialog_multiplayer_profile.qh +++ b/qcsrc/menu/xonotic/dialog_multiplayer_profile.qh @@ -5,7 +5,6 @@ const int COLOR_BUTTONS_COUNT = 15; CLASS(XonoticProfileTab, XonoticTab) METHOD(XonoticProfileTab, fill, void(entity)); METHOD(XonoticProfileTab, draw, void(entity)); - METHOD(XonoticProfileTab, updateColor, void(entity)); ATTRIB(XonoticProfileTab, intendedWidth, float, 0.9); ATTRIB(XonoticProfileTab, rows, float, 23); ATTRIB(XonoticProfileTab, columns, float, 6.1); // added extra .2 for center space @@ -18,5 +17,3 @@ CLASS(XonoticProfileTab, XonoticTab) ATTRIB(XonoticProfileTab, playerModelSelector, entity); ENDCLASS(XonoticProfileTab) entity makeXonoticProfileTab(); - -cvar_callback onCvarChanged; \ No newline at end of file