From 3964fc779526940e109cb3976a297124461f9cd1 Mon Sep 17 00:00:00 2001 From: stefnotch Date: Fri, 19 Feb 2021 12:55:22 +0100 Subject: [PATCH 1/5] Automatic rename UIControl Items See #213 --- .../CustomEditors/Dedicated/UIControlEditor.cs | 12 ++++++++++++ Source/Engine/Utilities/StringUtils.cs | 13 ++++++------- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/Source/Editor/CustomEditors/Dedicated/UIControlEditor.cs b/Source/Editor/CustomEditors/Dedicated/UIControlEditor.cs index 0fcf9d78a..87c3a8877 100644 --- a/Source/Editor/CustomEditors/Dedicated/UIControlEditor.cs +++ b/Source/Editor/CustomEditors/Dedicated/UIControlEditor.cs @@ -405,7 +405,13 @@ namespace FlaxEditor.CustomEditors.Dedicated for (int i = 0; i < uiControls.Count; i++) { var uiControl = (UIControl)uiControls[i]; + string previousName = uiControl.Control?.GetType()?.Name ?? typeof(UIControl).Name; uiControl.Control = (Control)controlType.CreateInstance(); + if (uiControl.Name.StartsWith(previousName)) + { + string newName = controlType.Name + uiControl.Name.Substring(previousName.Length); + uiControl.Name = StringUtils.IncrementNameNumber(newName, x => uiControl.Parent.GetChild(x) == null); + } } } } @@ -414,7 +420,13 @@ namespace FlaxEditor.CustomEditors.Dedicated for (int i = 0; i < uiControls.Count; i++) { var uiControl = (UIControl)uiControls[i]; + string previousName = uiControl.Control?.GetType()?.Name ?? typeof(UIControl).Name; uiControl.Control = (Control)controlType.CreateInstance(); + if (uiControl.Name.StartsWith(previousName)) + { + string newName = controlType.Name + uiControl.Name.Substring(previousName.Length); + uiControl.Name = StringUtils.IncrementNameNumber(newName, x => uiControl.Parent.GetChild(x) == null); + } } } diff --git a/Source/Engine/Utilities/StringUtils.cs b/Source/Engine/Utilities/StringUtils.cs index 057dd9b86..4dd28e705 100644 --- a/Source/Engine/Utilities/StringUtils.cs +++ b/Source/Engine/Utilities/StringUtils.cs @@ -244,8 +244,8 @@ namespace FlaxEngine return new string(charArray); } - private static readonly Regex IncNameRegex1 = new Regex("^(\\d+)"); - private static readonly Regex IncNameRegex2 = new Regex("^\\)(\\d+)\\("); + private static readonly Regex IncNameRegex1 = new Regex("(\\d+)$"); + private static readonly Regex IncNameRegex2 = new Regex("\\((\\d+)\\)$"); /// /// Tries to parse number in the name brackets at the end of the value and then increment it to create a new name. @@ -264,14 +264,13 @@ namespace FlaxEngine int index; int MaxChecks = 10000; string result; - string reversed = name.Reverse(); // Find '' case - var match = IncNameRegex1.Match(reversed); + var match = IncNameRegex1.Match(name); if (match.Success && match.Groups.Count == 2) { // Get result - string num = match.Groups[0].Value.Reverse(); + string num = match.Groups[0].Value; // Parse value if (int.TryParse(num, out index)) @@ -294,12 +293,12 @@ namespace FlaxEngine } // Find ' ()' case - match = IncNameRegex2.Match(reversed); + match = IncNameRegex2.Match(name); if (match.Success && match.Groups.Count == 2) { // Get result string num = match.Groups[0].Value; - num = num.Substring(1, num.Length - 2).Reverse(); + num = num.Substring(1, num.Length - 2); // Parse value if (int.TryParse(num, out index)) From e176ea749c00312fd76e5c6cc7004c8f2aa2ca34 Mon Sep 17 00:00:00 2001 From: stefnotch Date: Fri, 19 Feb 2021 20:31:30 +0100 Subject: [PATCH 2/5] Technically, reversing a unicode string involves unicode stuff Like this --- Source/Engine/Utilities/StringUtils.cs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/Source/Engine/Utilities/StringUtils.cs b/Source/Engine/Utilities/StringUtils.cs index 4dd28e705..e443f8f11 100644 --- a/Source/Engine/Utilities/StringUtils.cs +++ b/Source/Engine/Utilities/StringUtils.cs @@ -232,16 +232,26 @@ namespace FlaxEngine return result; } + private static IEnumerable GraphemeClusters(this string s) + { + var enumerator = System.Globalization.StringInfo.GetTextElementEnumerator(s); + while (enumerator.MoveNext()) + { + yield return (string)enumerator.Current; + } + } + /// /// Reverses the specified input string. /// + /// Correctly handles all UTF-16 strings /// The string to reverse. /// The reversed string. public static string Reverse(this string s) { - char[] charArray = s.ToCharArray(); - Array.Reverse(charArray); - return new string(charArray); + string[] graphemes = s.GraphemeClusters().ToArray(); + Array.Reverse(graphemes); + return string.Concat(graphemes); } private static readonly Regex IncNameRegex1 = new Regex("(\\d+)$"); From 8fe656b88ff10993b7312167ff0b18888fb83db5 Mon Sep 17 00:00:00 2001 From: stefnotch Date: Sat, 20 Feb 2021 22:07:15 +0100 Subject: [PATCH 3/5] Always focus tab on click --- Source/Editor/GUI/Docking/DockPanel.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Source/Editor/GUI/Docking/DockPanel.cs b/Source/Editor/GUI/Docking/DockPanel.cs index f6e10e653..ff4039e5f 100644 --- a/Source/Editor/GUI/Docking/DockPanel.cs +++ b/Source/Editor/GUI/Docking/DockPanel.cs @@ -290,6 +290,10 @@ namespace FlaxEditor.GUI.Docking } OnSelectedTabChanged(); } + else if (autoFocus && _selectedTab != null && !_selectedTab.ContainsFocus) + { + _selectedTab.Focus(); + } } /// From 74d4bb8dc66374e7913486608382714e545fb22a Mon Sep 17 00:00:00 2001 From: stefnotch Date: Sun, 21 Feb 2021 11:27:18 +0100 Subject: [PATCH 4/5] Fix mouse jittering when pressing both mouse buttons simultaneously --- Source/Editor/Viewport/EditorViewport.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Editor/Viewport/EditorViewport.cs b/Source/Editor/Viewport/EditorViewport.cs index a19589c05..a494aa210 100644 --- a/Source/Editor/Viewport/EditorViewport.cs +++ b/Source/Editor/Viewport/EditorViewport.cs @@ -1140,7 +1140,7 @@ namespace FlaxEditor.Viewport UpdateView(dt, ref moveDelta, ref mouseDelta, out _); } } - if (_input.IsMouseLeftDown) + if (_input.IsMouseLeftDown && false) { // Calculate smooth mouse delta not dependant on viewport size Vector2 offset = _viewMousePos - _startPos; From a2f01ba638893017098a77983542d4cde0a86971 Mon Sep 17 00:00:00 2001 From: stefnotch Date: Mon, 22 Feb 2021 19:27:16 +0100 Subject: [PATCH 5/5] Add more descriptive "no scene" message This is worthwhile, since this is one of the first messages a newcomer will see --- Source/Editor/Windows/SceneTreeWindow.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Editor/Windows/SceneTreeWindow.cs b/Source/Editor/Windows/SceneTreeWindow.cs index 3db4df799..5f6ab1613 100644 --- a/Source/Editor/Windows/SceneTreeWindow.cs +++ b/Source/Editor/Windows/SceneTreeWindow.cs @@ -222,7 +222,7 @@ namespace FlaxEditor.Windows } else if (((ContainerControl)_tree.GetChild(0)).ChildrenCount == 0) { - overlayText = "No scene"; + overlayText = "No scene\nOpen one from the content window"; } if (overlayText != null) {