]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Model update fix
authorColdSpirit <coldspiritvolf@gmail.com>
Tue, 21 Dec 2021 08:46:35 +0000 (12:46 +0400)
committerColdSpirit <coldspiritvolf@gmail.com>
Tue, 21 Dec 2021 08:46:35 +0000 (12:46 +0400)
qcsrc/menu/xonotic/dialog_multiplayer_profile.qc
qcsrc/menu/xonotic/dialog_multiplayer_profile.qh
qcsrc/menu/xonotic/playermodel.qc
qcsrc/menu/xonotic/playermodel.qh

index d3b8a70257191aabc1b4015785ed70ad7bf80351..b5c94c1ed3270ead05fde194cb7b888fc40c38eb 100644 (file)
@@ -32,6 +32,12 @@ entity makeXonoticProfileTab()
     }
     registercvar("_menu_profile_color", color, 0);
 
+    string skin = cvar_string("_cl_playerskin");
+    registercvar("_menu_profile_skin", skin, 0);
+
+    string model = cvar_string("_cl_playermodel");
+    registercvar("_menu_profile_model", model, 0);
+
        return me;
 }
 
@@ -44,9 +50,10 @@ void XonoticProfileTab_draw(entity me)
        else
                me.playerNameLabel.alpha = me.playerNameLabelAlpha;
     
-    // if values changed from console
+    // if values changed from console, update it in menu
     if (me.applyButton.disabled)
     {
+        // name field
         string inputName  = cvar_string("_menu_profile_name");
         if (name != inputName)
         {
@@ -54,6 +61,7 @@ void XonoticProfileTab_draw(entity me)
             me.nameInput.loadCvars(me.nameInput);
         }
 
+        // color buttons
         string color = cvar_string("_cl_color");
         string inputColor = cvar_string("_menu_profile_color");
         if (color != inputColor)
@@ -65,6 +73,19 @@ void XonoticProfileTab_draw(entity me)
                 me.colorButtonGroup2[i].loadCvars(me.colorButtonGroup2[i]);
             }
         }
+
+        // player model
+        string skin = cvar_string("_cl_playerskin");
+        string skinInput = cvar_string("_menu_profile_skin");
+        string model = cvar_string("_cl_playermodel");
+        string modelInput = cvar_string("_menu_profile_model");
+        if (skin != skinInput || model != modelInput)
+        {
+            cvar_set("_menu_profile_skin", skin);
+            cvar_set("_menu_profile_model", model);
+            me.playerModelSelector.loadCvars(me.playerModelSelector);
+            me.playerModelSelector.go(me.playerModelSelector, 0);
+        }
     }
 
        SUPER(XonoticProfileTab).draw(me);
@@ -75,14 +96,14 @@ void language_selector_click(entity me, entity btn)
 }
 void XonoticProfileTab_fill(entity me)
 {
-       entity e, pms, label;
+       entity e, 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;"
-               "playerskin $_cl_playerskin;"
+               "playermodel $_menu_profile_model;"
+               "playerskin $_menu_profile_skin;"
                , COMMANDBUTTON_APPLY);
        me.applyButton.disableOnClick = true;
 
@@ -124,15 +145,15 @@ void XonoticProfileTab_fill(entity me)
        me.TR(me);
                //me.TDempty(me, 0); // MODEL LEFT, COLOR RIGHT
                me.TDempty(me, 1); // MODEL RIGHT, COLOR LEFT
-               pms = makeXonoticPlayerModelSelector();
+               me.playerModelSelector = makeXonoticPlayerModelSelector("_menu_profile_skin", "_menu_profile_model");
                me.TD(me, 1, 0.3, e = makeXonoticButton("<<", '0 0 0'));
                        e.onClick = PlayerModelSelector_Prev_Click;
-                       e.onClickEntity = pms;
+                       e.onClickEntity = me.playerModelSelector;
                        e.applyButton = me.applyButton;
-               me.TD(me, 11.5, 1.4, pms);
+               me.TD(me, 11.5, 1.4, me.playerModelSelector);
                me.TD(me, 1, 0.3, e = makeXonoticButton(">>", '0 0 0'));
                        e.onClick = PlayerModelSelector_Next_Click;
-                       e.onClickEntity = pms;
+                       e.onClickEntity = me.playerModelSelector;
                        e.applyButton = me.applyButton;
 
        //me.setFirstColumn(me, me.currentColumn + 2); // MODEL LEFT, COLOR RIGHT
index 7e13792690bd7b44d793dc69355c95644a0405b7..ccf7725181eb85dbae44eba300fb641b7f6054b7 100644 (file)
@@ -14,5 +14,6 @@ CLASS(XonoticProfileTab, XonoticTab)
        ATTRIB(XonoticProfileTab, nameInput, entity);
        ATTRIB(XonoticProfileTab, colorButtonGroup1[COLOR_BUTTONS_COUNT], entity);
        ATTRIB(XonoticProfileTab, colorButtonGroup2[COLOR_BUTTONS_COUNT], entity);
+       ATTRIB(XonoticProfileTab, playerModelSelector, entity);
 ENDCLASS(XonoticProfileTab)
 entity makeXonoticProfileTab();
index 08518d1312a6fd3f59351ca38fcc8daa229c9a8d..a40e2aa9d9aaee783ddd6f78c1d8ee7072891e28 100644 (file)
@@ -1,10 +1,10 @@
 #include "playermodel.qh"
 
-entity makeXonoticPlayerModelSelector()
+entity makeXonoticPlayerModelSelector(string theSkinCvar, string theModelCvar)
 {
        entity me;
        me = NEW(XonoticPlayerModelSelector);
-       me.configureXonoticPlayerModelSelector(me);
+       me.configureXonoticPlayerModelSelector(me, theSkinCvar, theModelCvar);
        return me;
 }
 
@@ -17,8 +17,10 @@ const float BUFMODELS_COUNT = 5;
 
 #define XONVOTE186 1 // (nyov) removal of model text description
 
-void XonoticPlayerModelSelector_configureXonoticPlayerModelSelector(entity me)
+void XonoticPlayerModelSelector_configureXonoticPlayerModelSelector(entity me, string theSkinCvar, string theModelCvar)
 {
+    me.skinCvar = theSkinCvar;
+    me.modelCvar = theModelCvar;
        me.configureXonoticImage(me, string_null, -1);
 }
 
@@ -95,14 +97,14 @@ void XonoticPlayerModelSelector_loadCvars(entity me)
        string skin, modelname;
        float i;
 
-       skin = cvar_string("_cl_playerskin");
-       modelname = cvar_string("_cl_playermodel");
+       skin = cvar_string(me.skinCvar);
+       modelname = cvar_string(me.modelCvar);
 
        for(i = 0; i < me.numModels; ++i)
        {
                if(bufstr_get(me.bufModels, BUFMODELS_COUNT*i+BUFMODELS_MODEL) == modelname)
-               if(bufstr_get(me.bufModels, BUFMODELS_COUNT*i+BUFMODELS_SKIN) == skin)
-                       break;
+            if(bufstr_get(me.bufModels, BUFMODELS_COUNT*i+BUFMODELS_SKIN) == skin)
+                break;
        }
        if(i >= me.numModels) // fail
                i = 0;
@@ -147,8 +149,8 @@ void PlayerModelSelector_Prev_Click(entity btn, entity me)
 void XonoticPlayerModelSelector_saveCvars(entity me)
 {
        // we can't immediately apply here because of flood control
-       cvar_set("_cl_playermodel", me.currentModel);
-       cvar_set("_cl_playerskin", ftos(me.currentSkin));
+       cvar_set(me.modelCvar, me.currentModel);
+       cvar_set(me.skinCvar, ftos(me.currentSkin));
 }
 
 void XonoticPlayerModelSelector_draw(entity me)
index 4635c6ccdb65b438edffe6d28d71b2a492765445..41607f8fc83eb646948df25fbdc55956ae9a2925 100644 (file)
@@ -2,7 +2,7 @@
 
 #include "image.qh"
 CLASS(XonoticPlayerModelSelector, XonoticImage)
-       METHOD(XonoticPlayerModelSelector, configureXonoticPlayerModelSelector, void(entity));
+       METHOD(XonoticPlayerModelSelector, configureXonoticPlayerModelSelector, void(entity, string, string));
        METHOD(XonoticPlayerModelSelector, loadModels, void(entity));
        METHOD(XonoticPlayerModelSelector, loadCvars, void(entity));
        METHOD(XonoticPlayerModelSelector, saveCvars, void(entity));
@@ -24,7 +24,9 @@ CLASS(XonoticPlayerModelSelector, XonoticImage)
        ATTRIB(XonoticPlayerModelSelector, bufModels, float, -1);
        ATTRIB(XonoticPlayerModelSelector, numModels, float, -1);
        ATTRIB(XonoticPlayerModelSelector, idxModels, float, -1);
+       ATTRIB(XonoticPlayerModelSelector, skinCvar, string);
+       ATTRIB(XonoticPlayerModelSelector, modelCvar, string);
 ENDCLASS(XonoticPlayerModelSelector)
-entity makeXonoticPlayerModelSelector();
+entity makeXonoticPlayerModelSelector(string theSkinCvar, string theModelCvar);
 void PlayerModelSelector_Next_Click(entity btn, entity me);
 void PlayerModelSelector_Prev_Click(entity btn, entity me);