Browse Source

Fixed scene hierarchy window update.
Speed-optimized ListView::SetChildItemsVisible() & ListView::RemoveAllItems() by disabling layout update during processing.

Lasse Öörni 14 năm trước cách đây
mục cha
commit
97eff87a74

+ 7 - 3
Bin/Data/Scripts/Editor/EditorScene.as

@@ -233,9 +233,9 @@ void ScenePostRenderUpdate()
     
     
     if (renderingDebug)
     if (renderingDebug)
         renderer.DrawDebugGeometry(false);
         renderer.DrawDebugGeometry(false);
-    if (physicsDebug)
+    if (physicsDebug && editorScene.physicsWorld !is null)
         editorScene.physicsWorld.DrawDebugGeometry(true);
         editorScene.physicsWorld.DrawDebugGeometry(true);
-    if (octreeDebug)
+    if (octreeDebug && editorScene.octree !is null)
         editorScene.octree.DrawDebugGeometry(true);
         editorScene.octree.DrawDebugGeometry(true);
     
     
     SceneRaycast(false);
     SceneRaycast(false);
@@ -248,6 +248,9 @@ void SceneMouseClick()
 
 
 void SceneRaycast(bool mouseClick)
 void SceneRaycast(bool mouseClick)
 {
 {
+    if (editorScene.octree is null)
+        return;
+    
     DebugRenderer@ debug = editorScene.debugRenderer;
     DebugRenderer@ debug = editorScene.debugRenderer;
     IntVector2 pos = ui.cursorPosition;
     IntVector2 pos = ui.cursorPosition;
 
 
@@ -260,7 +263,8 @@ void SceneRaycast(bool mouseClick)
         if (!result.empty)
         if (!result.empty)
         {
         {
             drawable = result[0].drawable;
             drawable = result[0].drawable;
-            drawable.DrawDebugGeometry(debug, false);
+            if (debug !is null)
+                drawable.DrawDebugGeometry(debug, false);
         }
         }
         if (mouseClick && input.mouseButtonPress[MOUSEB_LEFT])
         if (mouseClick && input.mouseButtonPress[MOUSEB_LEFT])
             SelectComponent(drawable);
             SelectComponent(drawable);

+ 18 - 20
Bin/Data/Scripts/Editor/EditorSceneWindow.as

@@ -113,26 +113,12 @@ uint UpdateSceneWindowNode(uint itemIndex, Node@ node)
     ListView@ list = sceneWindow.GetChild("NodeList", true);
     ListView@ list = sceneWindow.GetChild("NodeList", true);
 
 
     // Remove old item if exists
     // Remove old item if exists
-    /// \todo Recursive update bugs and removes nodes
     uint numItems = list.numItems;
     uint numItems = list.numItems;
     if (itemIndex < numItems)
     if (itemIndex < numItems)
         list.RemoveItem(itemIndex);
         list.RemoveItem(itemIndex);
     if (node is null)
     if (node is null)
         return itemIndex;
         return itemIndex;
 
 
-    if (itemIndex >= numItems)
-    {
-        // Scan for correct place to insert at
-        /// \todo This logic is not correct for parented nodes
-        uint nodeID = node.id;
-        for (itemIndex = 0; itemIndex < numItems; ++itemIndex)
-        {
-            UIElement@ item = list.items[itemIndex];
-            if (uint(item.vars["NodeID"].GetInt()) > nodeID)
-                break;
-        }
-    }
-
     int indent = GetNodeIndent(node);
     int indent = GetNodeIndent(node);
 
 
     Text@ text = Text();
     Text@ text = Text();
@@ -298,14 +284,14 @@ String GetNodeTitle(Node@ node, int indent)
     indentStr.Resize(indent);
     indentStr.Resize(indent);
     for (int i = 0; i < indent; ++i)
     for (int i = 0; i < indent; ++i)
         indentStr[i] = ' ';
         indentStr[i] = ' ';
-    
+
     if (node.id >= FIRST_LOCAL_ID)
     if (node.id >= FIRST_LOCAL_ID)
-        localStr = ", LOCAL";
+        localStr = ", Local";
 
 
     if (node.name.empty)
     if (node.name.empty)
         return indentStr + node.typeName + " (" + node.id + localStr + ")";
         return indentStr + node.typeName + " (" + node.id + localStr + ")";
     else
     else
-        return indentStr + node.typeName + " (" + node.name + localStr +")";
+        return indentStr + node.name + " (" + node.id + localStr + ")";
 }
 }
 
 
 String GetComponentTitle(Component@ component, int indent)
 String GetComponentTitle(Component@ component, int indent)
@@ -317,7 +303,7 @@ String GetComponentTitle(Component@ component, int indent)
         indentStr[i] = ' ';
         indentStr[i] = ' ';
     
     
     if (component.id >= FIRST_LOCAL_ID)
     if (component.id >= FIRST_LOCAL_ID)
-        localStr = " (LOCAL)";
+        localStr = " (Local)";
 
 
     return indentStr + component.typeName + localStr;
     return indentStr + component.typeName + localStr;
 }
 }
@@ -338,14 +324,26 @@ void SelectComponent(Component@ component)
         return;
         return;
     }
     }
 
 
+    // Go in the parent chain up to the first non-root level to make sure the chain is expanded
+    for (;;)
+    {
+        Node@ parent = node.parent;
+        if (node is editorScene || parent is editorScene || parent is null)
+            break;
+        node = parent;
+    }
+
     uint numItems = list.numItems;
     uint numItems = list.numItems;
     uint nodeItem = GetNodeListIndex(node);
     uint nodeItem = GetNodeListIndex(node);
     uint componentItem = GetComponentListIndex(component);
     uint componentItem = GetComponentListIndex(component);
 
 
     if ((nodeItem < numItems) && (componentItem < numItems))
     if ((nodeItem < numItems) && (componentItem < numItems))
     {
     {
-        // Make sure the selected node is expanded
-        list.SetChildItemsVisible(nodeItem, true);
+        // Expand the node chain now, but do not expand the whole scene in case the component was in the root
+        list.items[nodeItem].visible = true;
+        if (nodeItem != 0)
+            list.SetChildItemsVisible(nodeItem, true);
+        list.items[componentItem].visible = true;
         // This causes an event to be sent, in response we set selectedComponent & selectedNode, and refresh editors
         // This causes an event to be sent, in response we set selectedComponent & selectedNode, and refresh editors
         list.selection = componentItem;
         list.selection = componentItem;
     }
     }

+ 12 - 0
Engine/UI/ListView.cpp

@@ -356,11 +356,17 @@ void ListView::RemoveItem(unsigned index)
 
 
 void ListView::RemoveAllItems()
 void ListView::RemoveAllItems()
 {
 {
+    contentElement_->DisableLayoutUpdate();
+    
     unsigned numItems = GetNumItems();
     unsigned numItems = GetNumItems();
     for (unsigned i = 0; i < numItems; ++i)
     for (unsigned i = 0; i < numItems; ++i)
         contentElement_->GetChild(i)->SetSelected(false);
         contentElement_->GetChild(i)->SetSelected(false);
     contentElement_->RemoveAllChildren();
     contentElement_->RemoveAllChildren();
     ClearSelection();
     ClearSelection();
+    
+    contentElement_->EnableLayoutUpdate();
+    contentElement_->UpdateLayout();
+    OnResize();
 }
 }
 
 
 void ListView::SetSelection(unsigned index)
 void ListView::SetSelection(unsigned index)
@@ -543,6 +549,8 @@ void ListView::SetChildItemsVisible(unsigned index, bool enable)
     if (!hierarchyMode_ || index >= numItems)
     if (!hierarchyMode_ || index >= numItems)
         return;
         return;
     
     
+    contentElement_->DisableLayoutUpdate();
+    
     int baseIndent = GetItemIndent(GetItem(index));
     int baseIndent = GetItemIndent(GetItem(index));
     
     
     for (unsigned i = index + 1; i < numItems; ++i)
     for (unsigned i = index + 1; i < numItems; ++i)
@@ -553,6 +561,10 @@ void ListView::SetChildItemsVisible(unsigned index, bool enable)
         else
         else
             break;
             break;
     }
     }
+    
+    contentElement_->EnableLayoutUpdate();
+    contentElement_->UpdateLayout();
+    OnResize();
 }
 }
 
 
 void ListView::SetChildItemsVisible(bool enable)
 void ListView::SetChildItemsVisible(bool enable)