Browse Source

Added change event for node name. Fixes correct node names not showing up in editor when using "Load Node" and removes need for hardcoded name update.
Removed code for manual resource reload in the editor, as now automatic live-reload should work on all desktop platforms.

Lasse Öörni 12 years ago
parent
commit
8d0692740b

+ 0 - 7
Bin/Data/Scripts/Editor/EditorNodeWindow.as

@@ -155,13 +155,6 @@ void UpdateNodeAttributes()
 
 void PostEditAttribute(Array<Serializable@>@ serializables, uint index)
 {
-    // If node name changed, update it in the scene window also
-    if (serializables[0].attributeInfos[index].name == "Name")
-    {
-        for (uint i = 0; i < serializables.length; ++i)
-            UpdateSceneWindowNodeOnly(serializables[i]);
-    }
-
     // If a StaticModel/AnimatedModel/Skybox model was changed, apply a possibly different material list
     if (applyMaterialList && serializables[0].attributeInfos[index].name == "Model")
     {

+ 0 - 83
Bin/Data/Scripts/Editor/EditorScene.as

@@ -106,89 +106,6 @@ void SetResourcePath(String newPath, bool usePreferredDir = true)
     sceneResourcePath = newPath;
 }
 
-Array<Resource@> GetSceneResources()
-{
-    Array<Resource@> sceneResources;
-    Array<Node@> allNodes = editorScene.GetChildren(true);
-
-    for (uint i = 0; i < allNodes.length; ++i)
-    {
-        for (uint j = 0; j < allNodes[i].numComponents; ++j)
-        {
-            Component@ comp = allNodes[i].components[j];
-            for (uint k = 0; k < comp.numAttributes; ++k)
-            {
-                Variant attr = comp.attributes[k];
-                if (attr.type == VAR_RESOURCEREF)
-                {
-                    ResourceRef ref = attr.GetResourceRef();
-                    Resource@ resource = cache.GetResource(ref.type, ref.id);
-                    if (resource !is null)
-                        AddResourceIfUnique(sceneResources, resource);
-                }
-                else if (attr.type == VAR_RESOURCEREFLIST)
-                {
-                    ResourceRefList refList = attr.GetResourceRefList();
-                    for (uint l = 0; l < refList.length; ++l)
-                    {
-                        Resource@ resource = cache.GetResource(refList.type, refList.ids[l]);
-                        if (resource !is null)
-                            AddResourceIfUnique(sceneResources, resource);
-                    }
-                }
-                else if (attr.type == VAR_VARIANTVECTOR)
-                {
-                    Array<Variant>@ variants = attr.GetVariantVector();
-                    for (uint l = 0; l < variants.length; ++l)
-                    {
-                        if (variants[l].type == VAR_RESOURCEREF)
-                        {
-                            ResourceRef ref = variants[l].GetResourceRef();
-                            Resource@ resource = cache.GetResource(ref.type, ref.id);
-                            if (resource !is null)
-                                AddResourceIfUnique(sceneResources, resource);
-                        }
-                    }
-                }
-            }
-        }
-    }
-
-    return sceneResources;
-}
-
-void AddResourceIfUnique(Array<Resource@>@ sceneResources, Resource@ resource)
-{
-    for (uint i = 0; i < sceneResources.length; ++i)
-    {
-        if (sceneResources[i] is resource)
-            return;
-    }
-    sceneResources.Push(resource);
-}
-
-void ReloadResources()
-{
-    Array<Resource@> sceneResources = GetSceneResources();
-    for (uint i = 0; i < sceneResources.length; ++i)
-    {
-        // Handle material textures manually
-        Material@ mat = cast<Material>(sceneResources[i]);
-        if (mat !is null)
-        {
-            for (int j = 0; j < MAX_MATERIAL_TEXTURE_UNITS; ++j)
-            {
-                Texture@ tex = mat.textures[j];
-                if (tex !is null)
-                    AddResourceIfUnique(sceneResources, tex);
-            }
-        }
-    }
-
-    for (uint i = 0; i < sceneResources.length; ++i)
-        cache.ReloadResource(sceneResources[i]);
-}
-
 bool LoadScene(const String&in fileName)
 {
     if (fileName.empty)

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

@@ -63,6 +63,7 @@ void CreateSceneWindow()
     SubscribeToEvent(editorScene, "NodeRemoved", "HandleNodeRemoved");
     SubscribeToEvent(editorScene, "ComponentAdded", "HandleComponentAdded");
     SubscribeToEvent(editorScene, "ComponentRemoved", "HandleComponentRemoved");
+    SubscribeToEvent(editorScene, "NodeNameChanged", "HandleNodeNameChanged");
 }
 
 void ShowSceneWindow()
@@ -802,4 +803,13 @@ void HandleComponentRemoved(StringHash eventType, VariantMap& eventData)
         ListView@ list = sceneWindow.GetChild("NodeList", true);
         list.RemoveItem(index);
     }
+}
+
+void HandleNodeNameChanged(StringHash eventType, VariantMap& eventData)
+{
+    if (suppressSceneChanges)
+        return;
+    
+    Node@ node = eventData["Node"].GetNode();
+    UpdateSceneWindowNodeOnly(node);
 }

+ 1 - 4
Bin/Data/Scripts/Editor/EditorUI.as

@@ -125,7 +125,6 @@ void CreateMenuBar()
         filePopup.AddChild(CreateMenuItem("Run script...", 0, 0));
         filePopup.AddChild(CreateMenuDivider());
         filePopup.AddChild(CreateMenuItem("Set resource path...", 0, 0));
-        filePopup.AddChild(CreateMenuItem("Reload resources", 'R', QUAL_CTRL));
         filePopup.AddChild(CreateMenuDivider());
         filePopup.AddChild(CreateMenuItem("Exit", 0, 0));
         uiMenuBar.AddChild(fileMenu);
@@ -377,9 +376,7 @@ void HandleMenuSelected(StringHash eventType, VariantMap& eventData)
         }
     }
 
-    if (action == "Reload resources")
-        ReloadResources();
-    else if (action == "Hierarchy")
+    if (action == "Hierarchy")
         ShowSceneWindow();
     else if (action == "Attribute inspector")
         ShowNodeWindow();

+ 12 - 0
Engine/Scene/Node.cpp

@@ -226,6 +226,18 @@ void Node::SetName(const String& name)
     nameHash_ = StringHash(name);
     
     MarkNetworkUpdate();
+    
+    // Send change event
+    if (scene_)
+    {
+        using namespace NodeNameChanged;
+        
+        VariantMap eventData;
+        eventData[P_SCENE] = (void*)scene_;
+        eventData[P_NODE] = (void*)this;
+        
+        scene_->SendEvent(E_NODENAMECHANGED, eventData);
+    }
 }
 
 void Node::SetPosition(const Vector3& position)

+ 7 - 0
Engine/Scene/SceneEvents.h

@@ -119,6 +119,13 @@ EVENT(E_COMPONENTREMOVED, ComponentRemoved)
     PARAM(P_COMPONENT, Component);          // Component pointer
 }
 
+/// A node's name has changed, requiring refresh in the editor.
+EVENT(E_NODENAMECHANGED, NodeNameChanged)
+{
+    PARAM(P_SCENE, Scene);                  // Scene pointer
+    PARAM(P_NODE, Node);                    // Node pointer
+}
+
 /// The attribute structure of a component has changed, requiring refresh in editor.
 EVENT(E_ATTRIBUTELISTCHANGED, AttributeListChanged)
 {