浏览代码

tags menu

MonkeyFirst 10 年之前
父节点
当前提交
31e2f56808

+ 10 - 1
bin/Data/Scripts/Editor.as

@@ -179,7 +179,8 @@ void LoadConfig()
     XMLElement varNamesElem = configElem.GetChild("varnames");
     XMLElement varNamesElem = configElem.GetChild("varnames");
     XMLElement soundTypesElem = configElem.GetChild("soundtypes");
     XMLElement soundTypesElem = configElem.GetChild("soundtypes");
     XMLElement cubeMapElem = configElem.GetChild("cubegen");
     XMLElement cubeMapElem = configElem.GetChild("cubegen");
-
+    XMLElement defaultTagsElem = configElem.GetChild("tags");
+    
     if (!cameraElem.isNull)
     if (!cameraElem.isNull)
     {
     {
         if (cameraElem.HasAttribute("nearclip")) viewNearClip = cameraElem.GetFloat("nearclip");
         if (cameraElem.HasAttribute("nearclip")) viewNearClip = cameraElem.GetFloat("nearclip");
@@ -309,6 +310,11 @@ void LoadConfig()
         cubeMapGen_Path = cubemapDefaultOutputPath;
         cubeMapGen_Path = cubemapDefaultOutputPath;
         cubeMapGen_Size = 128;
         cubeMapGen_Size = 128;
     }
     }
+    
+    if (!defaultTagsElem.isNull)
+    {
+        if (defaultTagsElem.HasAttribute("tags")) defaultTags = defaultTagsElem.GetAttribute("tags");
+    }
 }
 }
 
 
 void SaveConfig()
 void SaveConfig()
@@ -327,6 +333,7 @@ void SaveConfig()
     XMLElement varNamesElem = configElem.CreateChild("varnames");
     XMLElement varNamesElem = configElem.CreateChild("varnames");
     XMLElement soundTypesElem = configElem.CreateChild("soundtypes");
     XMLElement soundTypesElem = configElem.CreateChild("soundtypes");
     XMLElement cubeGenElem = configElem.CreateChild("cubegen");
     XMLElement cubeGenElem = configElem.CreateChild("cubegen");
+    XMLElement defaultTagsElem = configElem.CreateChild("tags");
 
 
     cameraElem.SetFloat("nearclip", viewNearClip);
     cameraElem.SetFloat("nearclip", viewNearClip);
     cameraElem.SetFloat("farclip", viewFarClip);
     cameraElem.SetFloat("farclip", viewFarClip);
@@ -407,6 +414,8 @@ void SaveConfig()
     cubeGenElem.SetAttribute("path", cubeMapGen_Path);
     cubeGenElem.SetAttribute("path", cubeMapGen_Path);
     cubeGenElem.SetAttribute("size", cubeMapGen_Size);
     cubeGenElem.SetAttribute("size", cubeMapGen_Size);
 
 
+    defaultTagsElem.SetAttribute("tags", defaultTags);
+    
     SaveSoundTypes(soundTypesElem);
     SaveSoundTypes(soundTypesElem);
 
 
     config.Save(File(configFileName, FILE_WRITE));
     config.Save(File(configFileName, FILE_WRITE));

+ 102 - 3
bin/Data/Scripts/Editor/EditorInspectorWindow.as

@@ -33,7 +33,6 @@ const uint LUASCRIPTINSTANCE_ATTRIBUTE_IGNORE = 4;
 
 
 // Node or UIElement hash-to-varname reverse mapping
 // Node or UIElement hash-to-varname reverse mapping
 VariantMap globalVarNames;
 VariantMap globalVarNames;
-
 bool inspectorLocked = false;
 bool inspectorLocked = false;
 
 
 void InitXMLResources()
 void InitXMLResources()
@@ -78,6 +77,8 @@ UIElement@ GetNodeContainer()
     parentContainer.GetChild("TagsLabel", true).SetFixedWidth(LABEL_WIDTH);
     parentContainer.GetChild("TagsLabel", true).SetFixedWidth(LABEL_WIDTH);
     LineEdit@ tagEdit = parentContainer.GetChild("TagsEdit", true);
     LineEdit@ tagEdit = parentContainer.GetChild("TagsEdit", true);
     SubscribeToEvent(tagEdit, "TextChanged", "HandleTagsEdit");
     SubscribeToEvent(tagEdit, "TextChanged", "HandleTagsEdit");
+    UIElement@ tagSelect = parentContainer.GetChild("TagsSelect", true);
+    SubscribeToEvent(tagSelect, "Released", "HandleTagsSelect");
     ++componentContainerStartIndex;
     ++componentContainerStartIndex;
 
 
     return container;
     return container;
@@ -122,6 +123,8 @@ UIElement@ GetUIElementContainer()
     SubscribeToEvent(styleList, "ItemSelected", "HandleStyleItemSelected");
     SubscribeToEvent(styleList, "ItemSelected", "HandleStyleItemSelected");
     LineEdit@ tagEdit = parentContainer.GetChild("TagsEdit", true);
     LineEdit@ tagEdit = parentContainer.GetChild("TagsEdit", true);
     SubscribeToEvent(tagEdit, "TextChanged", "HandleTagsEdit");
     SubscribeToEvent(tagEdit, "TextChanged", "HandleTagsEdit");
+    UIElement@ tagSelect = parentContainer.GetChild("TagsSelect", true);
+    SubscribeToEvent(tagSelect, "Released", "HandleTagsSelect");
     return container;
     return container;
 }
 }
 
 
@@ -681,17 +684,113 @@ void HandleTagsEdit(StringHash eventType, VariantMap& eventData)
 {
 {
     LineEdit@ lineEdit = eventData["Element"].GetPtr();
     LineEdit@ lineEdit = eventData["Element"].GetPtr();
     Array<String> tags = lineEdit.text.Split(';');
     Array<String> tags = lineEdit.text.Split(';');
+    
     if (editUIElement !is null)
     if (editUIElement !is null)
     {
     {
         editUIElement.RemoveAllTags();
         editUIElement.RemoveAllTags();
         for (uint i = 0; i < tags.length; i++)
         for (uint i = 0; i < tags.length; i++)
-            editUIElement.AddTag(tags[i]);
+            editUIElement.AddTag(tags[i].Trimmed());
     }
     }
     else if (editNode !is null)
     else if (editNode !is null)
     {
     {
         editNode.RemoveAllTags();
         editNode.RemoveAllTags();
         for (uint i = 0; i < tags.length; i++)
         for (uint i = 0; i < tags.length; i++)
-            editNode.AddTag(tags[i]);
+            editNode.AddTag(tags[i].Trimmed());
+    }
+}
+
+void HandleTagsSelect(StringHash eventType, VariantMap& eventData)
+{
+    UIElement@ tagSelect = eventData["Element"].GetPtr();
+    
+    if (editNode !is null)
+    {
+        Array<UIElement@> actions;
+        String Indicator = "* ";
+        
+        // 1. Add established tags from Node to menu
+        Array<String> nodeTags = editNode.tags;
+        
+        for (int i =0; i < nodeTags.length; i++) 
+        {
+            bool isHasTag = editNode.HasTag(nodeTags[i]);
+            String taggedIndicator = (isHasTag ? Indicator : "");
+            actions.Push(CreateContextMenuItem(taggedIndicator + nodeTags[i], "HandleTagsMenuSelection", nodeTags[i]));
+        }
+    
+        Array<String> sceneTags = editorScene.tags; 
+        
+        // 2. Add tags from Scene.tags (In this scenario Scene.tags used as storage for frequently used tags in current Scene only)
+        for (int i =0; i < sceneTags.length; i++) 
+        {
+            bool isHasTag = editNode.HasTag(sceneTags[i]);
+            String taggedIndicator = (isHasTag ? Indicator : "");
+            actions.Push(CreateContextMenuItem(taggedIndicator + sceneTags[i], "HandleTagsMenuSelection", sceneTags[i]));
+        }
+
+        // 3. Add default tags
+        Array<String> stdTags = defaultTags.Split(';');
+        for (int i=0; i<stdTags.length; i++) 
+        {
+            bool isHasTag = editNode.HasTag(stdTags[i]);
+            // Add this tag into menu if only Node not tadded with it yet, otherwise it showed on step 1.
+            if (!isHasTag) 
+            {
+                String taggedIndicator = (isHasTag ? Indicator : "");
+                actions.Push(CreateContextMenuItem(taggedIndicator + stdTags[i], "HandleTagsMenuSelection", stdTags[i]));
+            }
+        }
+
+        actions.Push(CreateContextMenuItem("Reset", "HandleTagsMenuSelection", "Reset"));
+        actions.Push(CreateContextMenuItem("Cancel", "HandleTagsMenuSelectionDivisor"));
+        
+        if (actions.length > 0) 
+        {
+            ActivateContextMenu(actions);
+        }
+    }
+}
+void HandleTagsMenuSelectionDivisor() 
+{
+    //do nothing
+}
+void HandleTagsMenuSelection() 
+{
+    if (editNode !is null)
+    {
+        Menu@ menu = GetEventSender();
+        if (menu is null)
+            return;
+            
+        String menuSelectedTag = menu.name;
+        bool isThisDeleteOp = input.keyDown[KEY_LALT];
+        
+        if (menuSelectedTag == "Reset")
+        {
+            editNode.RemoveAllTags();
+            UpdateAttributeInspector();
+            return;
+        }
+        
+        if (isThisDeleteOp) 
+        {
+            if (editNode.HasTag(menuSelectedTag)) 
+            {
+                editNode.RemoveTag(menuSelectedTag.Trimmed());
+            }
+        }
+        else
+        {
+            if (!editNode.HasTag(menuSelectedTag)) 
+            {
+                editNode.AddTag(menuSelectedTag.Trimmed());
+            }
+            else 
+            {
+                editNode.RemoveTag(menuSelectedTag.Trimmed());
+            }
+        }
+        UpdateAttributeInspector();
     }
     }
 }
 }
 
 

+ 14 - 2
bin/Data/Scripts/Editor/EditorSettings.as

@@ -1,7 +1,7 @@
 // Urho3D editor settings dialog
 // Urho3D editor settings dialog
-
 bool subscribedToEditorSettings = false;
 bool subscribedToEditorSettings = false;
 Window@ settingsDialog;
 Window@ settingsDialog;
+String defaultTags;
 
 
 void CreateEditorSettingsDialog()
 void CreateEditorSettingsDialog()
 {
 {
@@ -117,6 +117,10 @@ void UpdateEditorSettingsDialog()
     cubemapName.text = cubeMapGen_Name;
     cubemapName.text = cubeMapGen_Name;
     LineEdit@ cubemapSize = settingsDialog.GetChild("CubeMapGenSize", true);
     LineEdit@ cubemapSize = settingsDialog.GetChild("CubeMapGenSize", true);
     cubemapSize.text = String(cubeMapGen_Size);
     cubemapSize.text = String(cubeMapGen_Size);
+    
+    LineEdit@ defaultTagsEdit = settingsDialog.GetChild("DefaultTagsEdit", true);
+    defaultTagsEdit.text = defaultTags.Trimmed();
+    
 
 
     if (!subscribedToEditorSettings)
     if (!subscribedToEditorSettings)
     {
     {
@@ -170,6 +174,8 @@ void UpdateEditorSettingsDialog()
         SubscribeToEvent(cubemapSize, "TextChanged",  "EditCubemapSize");
         SubscribeToEvent(cubemapSize, "TextChanged",  "EditCubemapSize");
         SubscribeToEvent(cubemapSize, "TextFinished", "EditCubemapSize");
         SubscribeToEvent(cubemapSize, "TextFinished", "EditCubemapSize");
         
         
+        SubscribeToEvent(defaultTagsEdit, "TextFinished", "EditDefaultTags");
+              
         subscribedToEditorSettings = true;
         subscribedToEditorSettings = true;
     }
     }
 }
 }
@@ -430,4 +436,10 @@ void EditCubemapSize(StringHash eventType, VariantMap& eventData)
 {
 {
     LineEdit@ edit = eventData["Element"].GetPtr();
     LineEdit@ edit = eventData["Element"].GetPtr();
     cubeMapGen_Size = edit.text.ToInt();
     cubeMapGen_Size = edit.text.ToInt();
-}
+}
+
+void EditDefaultTags(StringHash eventType, VariantMap& eventData)
+{
+    LineEdit@ edit = eventData["Element"].GetPtr();
+    defaultTags = edit.text;
+}

+ 10 - 0
bin/Data/UI/EditorInspector_Tags.xml

@@ -3,6 +3,16 @@
     <attribute name="Max Size" value="2147483647 17" />
     <attribute name="Max Size" value="2147483647 17" />
     <attribute name="Layout Mode" value="Horizontal" />
     <attribute name="Layout Mode" value="Horizontal" />
     <attribute name="Layout Spacing" value="4" />
     <attribute name="Layout Spacing" value="4" />
+    <element type="Button">
+                <attribute name="Name" value="TagsSelect" />
+                <attribute name="Min Size" value="16 16" />
+                <attribute name="Max Size" value="16 16" />
+                <attribute name="Layout Mode" value="Horizontal" />
+                <element type="BorderImage">
+                    <attribute name="Texture" value="Texture2D;Textures/UI.png" />
+                    <attribute name="Image Rect" value="190 0 208 15" />
+                </element>
+    </element>
     <element type="Text" style="EditorAttributeText">
     <element type="Text" style="EditorAttributeText">
         <attribute name="Name" value="TagsLabel" />
         <attribute name="Name" value="TagsLabel" />
         <attribute name="Text" value="Tags" />
         <attribute name="Text" value="Tags" />

+ 11 - 3
bin/Data/UI/EditorSettingsDialog.xml

@@ -505,7 +505,6 @@
                         <attribute name="Text" value="Frame limiter" />
                         <attribute name="Text" value="Frame limiter" />
                     </element>
                     </element>
                 </element>
                 </element>
-                
                 <element style="ListRow">
                 <element style="ListRow">
                     <attribute name="Layout Spacing" value="20" />
                     <attribute name="Layout Spacing" value="20" />
                     <element type="Text">
                     <element type="Text">
@@ -517,7 +516,6 @@
                         <attribute name="Max Size" value="100 2147483647" />
                         <attribute name="Max Size" value="100 2147483647" />
                      </element>
                      </element>
                 </element>
                 </element>
-                
                 <element style="ListRow">
                 <element style="ListRow">
                     <attribute name="Layout Spacing" value="20" />
                     <attribute name="Layout Spacing" value="20" />
                     <element type="Text">
                     <element type="Text">
@@ -529,7 +527,6 @@
                         <attribute name="Max Size" value="100 2147483647" />
                         <attribute name="Max Size" value="100 2147483647" />
                      </element>
                      </element>
                 </element>
                 </element>
-                
                 <element style="ListRow">
                 <element style="ListRow">
                     <attribute name="Layout Spacing" value="20" />
                     <attribute name="Layout Spacing" value="20" />
                     <element type="Text">
                     <element type="Text">
@@ -541,6 +538,17 @@
                         <attribute name="Max Size" value="100 2147483647" />
                         <attribute name="Max Size" value="100 2147483647" />
                      </element>
                      </element>
                 </element>
                 </element>
+                <element style="ListRow">
+                    <attribute name="Layout Spacing" value="8" />
+                    <element type="Text">
+                        <attribute name="Text" value="Tags " />
+                        <attribute name="Min Size" value="88 17" />
+                        <attribute name="Max Size" value="88 17" />
+                    </element>
+                    <element type="LineEdit">
+                        <attribute name="Name" value="DefaultTagsEdit" />
+                     </element>
+                </element>
             </element>
             </element>
         </element>
         </element>
     </element>
     </element>