Преглед изворни кода

Fixed the editor crash when recreating var with existing var name. Fixed editing problem with multi-coordinate user-defined variable (Vector3 and Color).

Wei Tjong Yao пре 12 година
родитељ
комит
3599b1e038

+ 33 - 25
Bin/Data/Scripts/Editor/AttributeEditor.as

@@ -487,25 +487,28 @@ void LoadAttributeEditor(UIElement@ parent, const Variant&in value, const Attrib
                 break;
 
             Variant firstValue = vector[subIndex];
-            bool varSameValue = true;
-            if (!sameValue)
+            bool sameValue = true;
+            Array<Variant> varValues;
+
+            // Reevaluate aach variant in the vector
+            for (uint i = 0; i < values.length; ++i)
             {
-                // Reevaluate aach variant in the vector
-                for (uint i = 0; i < values.length; ++i)
+                Array<Variant>@ vector = values[i].GetVariantVector();                
+                if (subIndex < vector.length)
                 {
-                    Array<Variant>@ vector = values[i].GetVariantVector();
-                    if (subIndex >= vector.length || vector[subIndex] != firstValue)
-                    {
-                        varSameValue = false;
-                        break;
-                    }
+                    Variant value = vector[subIndex];
+                    varValues.Push(value);
+                    if (value != firstValue)
+                        sameValue = false;
                 }
+                else
+                    sameValue = false;
             }
 
             // The individual variant in the list is not an attribute of the serializable, the structure is reused for convenience
             AttributeInfo info;
             info.type = firstValue.type;
-            LoadAttributeEditor(parent, firstValue, info, editable, varSameValue, values);
+            LoadAttributeEditor(parent, firstValue, info, editable, sameValue, varValues);
         }
     }
     else if (type == VAR_VARIANTMAP)
@@ -524,25 +527,28 @@ void LoadAttributeEditor(UIElement@ parent, const Variant&in value, const Attrib
                 continue;
 
             Variant firstValue = map[keys[subIndex]];
-            bool varSameValue = true;
-            if (!sameValue)
+            bool sameValue = true;
+            Array<Variant> varValues;
+            
+            // Reevaluate each variant in the map
+            for (uint i = 0; i < values.length; ++i)
             {
-                // Reevaluate each variant in the map
-                for (uint i = 0; i < values.length; ++i)
+                VariantMap map = values[i].GetVariantMap();
+                if (map.Contains(keys[subIndex]))
                 {
-                    VariantMap map = values[i].GetVariantMap();
-                    if (!map.Contains(keys[subIndex]) || map[keys[subIndex]] != firstValue)
-                    {
-                        varSameValue = false;
-                        break;
-                    }
+                    Variant value = map[keys[subIndex]];
+                    varValues.Push(value);
+                    if (value != firstValue)
+                       sameValue = false;
                 }
+                else
+                    sameValue = false;
             }
 
             // The individual variant in the map is not an attribute of the serializable, the structure is reused for convenience
             AttributeInfo info;
             info.type = firstValue.type;
-            LoadAttributeEditor(parent, firstValue, info, editable, varSameValue, values);
+            LoadAttributeEditor(parent, firstValue, info, editable, sameValue, varValues);
         }
     }
     else
@@ -600,7 +606,8 @@ void StoreAttributeEditor(UIElement@ parent, Array<Serializable@>@ serializables
         for (uint i = 0; i < serializables.length; ++i)
         {
             Array<Variant>@ vector = serializables[i].attributes[index].GetVariantVector();
-            Variant[] values(1);
+            Variant[] values;
+            values.Push(vector[subIndex]);  // Each individual variant may have multiple coordinates itself
             GetEditorValue(parent, vector[subIndex].type, null, coordinate, values);
             vector[subIndex] = values[0];
             serializables[i].attributes[index] = Variant(vector);
@@ -610,11 +617,12 @@ void StoreAttributeEditor(UIElement@ parent, Array<Serializable@>@ serializables
     {
         VariantMap map = serializables[0].attributes[index].GetVariantMap();
         ShortStringHash key(parent.vars["Key"].GetUInt());
-        Variant[] values(1);
-        GetEditorValue(parent, map[key].type, null, coordinate, values);
         for (uint i = 0; i < serializables.length; ++i)
         {
             VariantMap map = serializables[i].attributes[index].GetVariantMap();
+            Variant[] values;
+            values.Push(map[key]);  // Each individual variant may have multiple coordinates itself
+            GetEditorValue(parent, map[key].type, null, coordinate, values);
             map[key] = values[0];
             serializables[i].attributes[index] = Variant(map);
         }

+ 12 - 4
Bin/Data/Scripts/Editor/EditorNodeWindow.as

@@ -416,7 +416,10 @@ void CreateNodeVariable(StringHash eventType, VariantMap& eventData)
         overwrite = overwrite || editNodes[i].vars.Contains(newKey);
         editNodes[i].vars[newKey] = newValue;
     }
-    UpdateAttributeInspector(overwrite);
+    if (overwrite)
+        attributesFullDirty = true;
+    else
+        attributesDirty = true;
 }
 
 void DeleteNodeVariable(StringHash eventType, VariantMap& eventData)
@@ -436,7 +439,7 @@ void DeleteNodeVariable(StringHash eventType, VariantMap& eventData)
         erased = editNodes[i].vars.Erase(delKey) || erased;
     }
     if (erased)
-        UpdateAttributeInspector(false);
+        attributesDirty = true;
 }
 
 void CreateUIElementVariable(StringHash eventType, VariantMap& eventData)
@@ -458,7 +461,10 @@ void CreateUIElementVariable(StringHash eventType, VariantMap& eventData)
         overwrite = overwrite || element.vars.Contains(newKey);
         element.vars[newKey] = newValue;
     }
-    UpdateAttributeInspector(overwrite);
+    if (overwrite)
+        attributesFullDirty = true;
+    else
+        attributesDirty = true;
 }
 
 void DeleteUIElementVariable(StringHash eventType, VariantMap& eventData)
@@ -478,7 +484,7 @@ void DeleteUIElementVariable(StringHash eventType, VariantMap& eventData)
         erased = cast<UIElement>(editUIElements[i]).vars.Erase(delKey) || erased;
     }
     if (erased)
-        UpdateAttributeInspector(false);
+        attributesDirty = true;
 }
 
 void CreateNewVariable(VariantMap& eventData, String& newKey, Variant& newValue)
@@ -519,4 +525,6 @@ void DeleteVariable(VariantMap& eventData, String& delKey)
     Button@ button = eventData["Element"].GetUIElement();
     LineEdit@ nameEdit = button.parent.GetChild("VarNameEdit", true);
     delKey = nameEdit.text.Trimmed().Replaced(";", "");
+
+    // Do not actually unregister the variable name as the same variable name may still be used by other attribute list
 }

+ 0 - 1
Bin/Data/Scripts/Editor/EditorSceneWindow.as

@@ -52,7 +52,6 @@ void CreateHierarchyWindow()
         Text@ choice = Text();
         choice.SetStyle(uiStyle, "FileSelectorFilterText");
         choice.text = componentTypes[i];
-        choice.indent = 1;
         IconizeUIElement(choice, componentTypes[i]);
         newComponentList.AddItem(choice);
     }