浏览代码

Created new event for UIElement name changed. Enhanced Hierarchy window to update the list item when the UIElement's 'Name' and 'Is Visible' attribute value changes. Changed editor to ignore other shortcut keys (except ESC) when file selector is modal.

Wei Tjong Yao 12 年之前
父节点
当前提交
7d5fbf6759

+ 5 - 2
Bin/Data/Scripts/Editor/AttributeEditor.as

@@ -132,8 +132,9 @@ UIElement@ CreateStringAttributeEditor(ListView@ list, Array<Serializable@>@ ser
 
 UIElement@ CreateBoolAttributeEditor(ListView@ list, Array<Serializable@>@ serializables, const AttributeInfo&in info, uint index, uint subIndex)
 {
+    bool isUIElement = cast<UIElement>(serializables[0]) !is null;
     UIElement@ parent;
-    if (info.name == "Is Enabled")
+    if (info.name == (isUIElement ? "Is Visible" : "Is Enabled"))
         parent = CreateAttributeEditorParentAsListChild(list, info.name, index, subIndex);
     else
         parent = CreateAttributeEditorParent(list, info.name, index, subIndex);
@@ -341,13 +342,15 @@ uint GetAttributeEditorCount(Array<Serializable@>@ serializables)
     if (!serializables.empty)
     {
         /// \todo When multi-editing, this only counts the editor count of the first serializable
+        bool isUIElement = cast<UIElement>(serializables[0]) !is null;
         for (uint i = 0; i < serializables[0].numAttributes; ++i)
         {
             AttributeInfo info = serializables[0].attributeInfos[i];
             if (!showNonEditableAttribute && info.mode & AM_NOEDIT != 0)
                 continue;
             // "Is Enabled" is not inserted into the main attribute list, so do not count
-            if (info.name == "Is Enabled")
+            // Similarly, for UIElement, "Is Visible" is not inserted
+            if (info.name == (isUIElement ? "Is Visible" : "Is Enabled"))
                 continue;
             if (info.type == VAR_RESOURCEREFLIST)
                 count += serializables[0].attributes[i].GetResourceRefList().length;

+ 23 - 2
Bin/Data/Scripts/Editor/EditorSceneWindow.as

@@ -262,6 +262,9 @@ void SetID(Text@ text, Serializable@ serializable)
         // Store the generated ID into both the variant map of the actual object and the text item
         cast<UIElement>(serializable).vars[UI_ELEMENT_ID_VAR] = uiElementNextID;
         text.vars[UI_ELEMENT_ID_VAR] = uiElementNextID++;
+        // Subscribe to name and visibility changed events
+        SubscribeToEvent(serializable, "ElementNameChanged", "HandleElementNameChanged");
+        SubscribeToEvent(serializable, "VisibleChanged", "HandleElementVisibilityChanged");
     }
 }
 
@@ -741,11 +744,11 @@ void HandleCreateComponent(StringHash eventType, VariantMap& eventData)
         // Some components such as CollisionShape do not create their internal object before the first call to ApplyAttributes()
         // to prevent unnecessary initialization with default values. Call now
         newComponent.ApplyAttributes();
-        
+
         CreateComponentAction action;
         action.Define(newComponent);
         SaveEditAction(action);
-        
+
         FocusComponent(newComponent);
     }
 
@@ -850,3 +853,21 @@ void HandleComponentEnabledChanged(StringHash eventType, VariantMap& eventData)
     UpdateHierarchyItemText(GetComponentListIndex(component), component.enabledEffective);
     attributesDirty = true;
 }
+
+void HandleElementNameChanged(StringHash eventType, VariantMap& eventData)
+{
+    if (suppressUIElementChanges)
+        return;
+
+    UIElement@ element = eventData["Element"].GetUIElement();
+    UpdateHierarchyItemText(GetListIndex(element), element.visible, GetUIElementTitle(element));
+}
+
+void HandleElementVisibilityChanged(StringHash eventType, VariantMap& eventData)
+{
+    if (suppressUIElementChanges)
+        return;
+
+    UIElement@ element = eventData["Element"].GetUIElement();
+    UpdateHierarchyItemText(GetListIndex(element), element.visible);
+}

+ 14 - 10
Bin/Data/Scripts/Editor/EditorUI.as

@@ -14,6 +14,7 @@ const ShortStringHash CURSOR_TYPE("Cursor");
 const String TEMP_SCENE_NAME("_tempscene_.xml");
 const ShortStringHash CALLBACK_VAR("Callback");
 const ShortStringHash POPUP_ORIGIN_VAR("Origin");
+const ShortStringHash INDENT_MODIFIED_BY_ICON_VAR("IconIndented");
 
 const int SHOW_POPUP_INDICATOR = -1;
 
@@ -697,9 +698,6 @@ void HandleKeyDown(StringHash eventType, VariantMap& eventData)
 {
     int key = eventData["Key"].GetInt();
 
-    if (key == KEY_F1)
-        console.Toggle();
-
     if (key == KEY_ESC)
     {
         UIElement@ front = ui.frontElement;
@@ -715,15 +713,21 @@ void HandleKeyDown(StringHash eventType, VariantMap& eventData)
             front.visible = false;
         }
     }
+    
+    // Ignore other keys when UI has a modal element
+    else if (ui.modalElement !is null)
+        return;
 
-    if (key == KEY_F2)
+    else if (key == KEY_F1)
+        console.Toggle();
+    else if (key == KEY_F2)
         ToggleRenderingDebug();
-    if (key == KEY_F3)
+    else if (key == KEY_F3)
         TogglePhysicsDebug();
-    if (key == KEY_F4)
+    else if (key == KEY_F4)
         ToggleOctreeDebug();
 
-    if (eventData["Qualifiers"].GetInt() == QUAL_CTRL)
+    else if (eventData["Qualifiers"].GetInt() == QUAL_CTRL)
     {
         if (key == '1')
             editMode = EDIT_MOVE;
@@ -731,7 +735,7 @@ void HandleKeyDown(StringHash eventType, VariantMap& eventData)
             editMode = EDIT_ROTATE;
         else if (key == '3')
             editMode = EDIT_SCALE;
-        if (key == '4')
+        else if (key == '4')
             editMode = EDIT_SELECT;
         else if (key == '5')
             axisMode = AxisMode(axisMode ^ AXIS_LOCAL);
@@ -831,7 +835,7 @@ void IconizeUIElement(UIElement@ element, const String&in iconType)
             icon.Remove();
 
         // Revert back the indent but only if it is indented by this function
-        if (element.vars["IconIndented"].GetBool())
+        if (element.vars[INDENT_MODIFIED_BY_ICON_VAR].GetBool())
             element.indent = 0;
 
         return;
@@ -841,7 +845,7 @@ void IconizeUIElement(UIElement@ element, const String&in iconType)
     if (element.indent == 0)
     {
         element.indent = 1;
-        element.vars["IconIndented"] = true;
+        element.vars[INDENT_MODIFIED_BY_ICON_VAR] = true;
     }
 
     // If no icon yet then create one with the correct indent and size in respect to the UI element

+ 2 - 3
Bin/Data/Scripts/Editor/EditorUIElement.as

@@ -88,7 +88,7 @@ void OpenUIElement(const String&in fileName)
 
     UpdateHierarchyItem(element, true);
 
-    suppressSceneChanges = false;
+    suppressUIElementChanges = false;
 }
 
 bool CloseUIElement()
@@ -101,9 +101,8 @@ bool CloseUIElement()
         while (!element.vars.Contains(FILENAME_VAR))
             element = element.parent;
         element.Remove();
-
-        UpdateHierarchyItem(GetListIndex(element), null, null);
     }
+    UpdateHierarchyItem(editorUIElement, true);
 
     suppressUIElementChanges = false;
 

+ 7 - 0
Engine/UI/UIElement.cpp

@@ -444,6 +444,13 @@ bool UIElement::SaveXML(Serializer& dest)
 void UIElement::SetName(const String& name)
 {
     name_ = name;
+
+    using namespace ElementNameChanged;
+
+    VariantMap eventData;
+    eventData[P_ELEMENT] = (void*)this;
+
+    SendEvent(E_ELEMENTNAMECHANGED, eventData);
 }
 
 void UIElement::SetPosition(const IntVector2& position)

+ 6 - 0
Engine/UI/UIEvents.h

@@ -223,4 +223,10 @@ EVENT(E_ELEMENTREMOVED, ElementRemoved)
     PARAM(P_ELEMENT, Element);              // UIElement pointer
 }
 
+/// An element's name has changed.
+EVENT(E_ELEMENTNAMECHANGED, ElementNameChanged)
+{
+    PARAM(P_ELEMENT, Element);              // UIElement pointer
+}
+
 }