From 356f1b8e8fc1f9185b03430c2e27956fe428ed06 Mon Sep 17 00:00:00 2001 From: terencehill Date: Fri, 13 Oct 2023 08:49:48 +0200 Subject: [PATCH] Implement _cl_name syncronization from console to menu, it works only if the name input box text hasn't changed --- qcsrc/menu/menu.qc | 1 - .../xonotic/dialog_multiplayer_profile.qc | 32 ++++++++++++------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/qcsrc/menu/menu.qc b/qcsrc/menu/menu.qc index a6a796428..710dca1e6 100644 --- a/qcsrc/menu/menu.qc +++ b/qcsrc/menu/menu.qc @@ -67,7 +67,6 @@ void m_init() } prvm_language = strzone(prvm_language); cvar_set("_menu_prvm_language", prvm_language); - cvar_set("_menu_profile_apply_button_command_executed", "-1"); #ifdef WATERMARK LOG_TRACEF("^4MQC Build information: ^1%s", WATERMARK); diff --git a/qcsrc/menu/xonotic/dialog_multiplayer_profile.qc b/qcsrc/menu/xonotic/dialog_multiplayer_profile.qc index c0d72a61b..e0495cca5 100644 --- a/qcsrc/menu/xonotic/dialog_multiplayer_profile.qc +++ b/qcsrc/menu/xonotic/dialog_multiplayer_profile.qc @@ -34,6 +34,12 @@ entity makeXonoticProfileTab() return me; } +bool nameinputbox_changed; +void NameInputBox_Change(entity box, entity me) +{ + nameinputbox_changed = true; +} + bool autocvar__menu_profile_apply_button_command_executed; void XonoticProfileTab_draw(entity me) { @@ -46,20 +52,10 @@ void XonoticProfileTab_draw(entity me) // when this cvar is set to 1 we are sure the apply button command has really taken effect // we can't assume that it gets executed in one frame due to how cmd works - if (autocvar__menu_profile_apply_button_command_executed == -1) // set to -1 on menu init - { - cvar_set("_menu_profile_apply_button_command_executed", "0"); - // initialize the input name box text - string inputName = cvar_string(MENU_CVAR_NAME); - if (name != inputName) - { - cvar_set(MENU_CVAR_NAME, name); - me.nameInput.loadCvars(me.nameInput); - } - } - else if (autocvar__menu_profile_apply_button_command_executed == 1) // set to 1 by the apply button command + if (autocvar__menu_profile_apply_button_command_executed) // set by the apply button command { cvar_set("_menu_profile_apply_button_command_executed", "0"); + nameinputbox_changed = false; // color buttons string color = cvar_string("_cl_color"); @@ -87,6 +83,16 @@ void XonoticProfileTab_draw(entity me) me.playerModelSelector.go(me.playerModelSelector, 0); } } + else if (!nameinputbox_changed) + { + // check if _cl_name has changed in console + string inputName = cvar_string(MENU_CVAR_NAME); + if (name != inputName) + { + cvar_set(MENU_CVAR_NAME, name); + me.nameInput.loadCvars(me.nameInput); + } + } SUPER(XonoticProfileTab).draw(me); } @@ -130,6 +136,8 @@ void XonoticProfileTab_fill(entity me) me.nameInput.saveImmediately = 0; // Sorry, can't do this, it spams "name" commands. me.nameInput.enableClearButton = 0; me.nameInput.applyButton = me.applyButton; + me.nameInput.onChange = NameInputBox_Change; + me.nameInput.onChangeEntity = me; label.textEntity = me.nameInput; me.TR(me); me.TD(me, 5, 1, e = makeXonoticColorpicker(me.nameInput)); -- 2.39.2