]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Implement _cl_name syncronization from console to menu, it works only if the name...
authorterencehill <piuntn@gmail.com>
Fri, 13 Oct 2023 06:49:48 +0000 (08:49 +0200)
committerterencehill <piuntn@gmail.com>
Fri, 13 Oct 2023 06:49:48 +0000 (08:49 +0200)
qcsrc/menu/menu.qc
qcsrc/menu/xonotic/dialog_multiplayer_profile.qc

index a6a79642897850c23882962b743fe24155f1f2e8..710dca1e6685be3d57671237bd9a1647148cfa55 100644 (file)
@@ -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);
index c0d72a61b099d7e1164cabd91a751fa77f456f16..e0495cca527efe899a8678b2cacd9b1fa3f51ee4 100644 (file)
@@ -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));