From 4593e4c66939ed06e504b8e9427252240279f8d9 Mon Sep 17 00:00:00 2001 From: honzapatCZ Date: Thu, 4 Mar 2021 19:46:27 +0100 Subject: [PATCH 1/4] declaration order sorting --- .../Editor/Content/Items/VisualScriptItem.cs | 4 ++++ .../CustomEditors/Editors/GenericEditor.cs | 12 +++++++++-- Source/Editor/Scripting/ScriptType.cs | 21 +++++++++++++++++++ 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/Source/Editor/Content/Items/VisualScriptItem.cs b/Source/Editor/Content/Items/VisualScriptItem.cs index fd23887ec..22f1d75cc 100644 --- a/Source/Editor/Content/Items/VisualScriptItem.cs +++ b/Source/Editor/Content/Items/VisualScriptItem.cs @@ -75,6 +75,8 @@ namespace FlaxEditor.Content } } + public int MetadataToken => 0; + /// public bool HasAttribute(Type attributeType, bool inherit) { @@ -195,6 +197,8 @@ namespace FlaxEditor.Content /// public ScriptType ValueType => _returnType; + public int MetadataToken => 0; + /// public bool HasAttribute(Type attributeType, bool inherit) { diff --git a/Source/Editor/CustomEditors/Editors/GenericEditor.cs b/Source/Editor/CustomEditors/Editors/GenericEditor.cs index ed6d88e9e..f3569bd65 100644 --- a/Source/Editor/CustomEditors/Editors/GenericEditor.cs +++ b/Source/Editor/CustomEditors/Editors/GenericEditor.cs @@ -173,8 +173,16 @@ namespace FlaxEditor.CustomEditors.Editors return string.Compare(Display.Group, other.Display.Group, StringComparison.InvariantCulture); } - // By name - return string.Compare(Info.Name, other.Info.Name, StringComparison.InvariantCulture); + // By declaration order + if (Info.MetadataToken > other.Info.MetadataToken) + return 1; + else if (Info.MetadataToken < other.Info.MetadataToken) + return -1; + else + { + // By name + return string.Compare(Info.Name, other.Info.Name, StringComparison.InvariantCulture); + } } return 0; diff --git a/Source/Editor/Scripting/ScriptType.cs b/Source/Editor/Scripting/ScriptType.cs index 53c84a1b5..bca6ccf40 100644 --- a/Source/Editor/Scripting/ScriptType.cs +++ b/Source/Editor/Scripting/ScriptType.cs @@ -40,6 +40,22 @@ namespace FlaxEditor.Scripting /// public string Name => _managed?.Name ?? _custom?.Name; + /// + /// Gets a metadata token for sorting so it may not be the actual token. + /// + public int MetadataToken + { + get + { + if (_managed != null && IsProperty) + { + ScriptMemberInfo finfo = DeclaringType.GetField(string.Format("<{0}>k__BackingField", Name), BindingFlags.Instance | BindingFlags.NonPublic); + return finfo.MetadataToken; + } + return _managed?.MetadataToken ?? _custom?.MetadataToken ?? 0; + } + } + /// /// Gets a value indicating whether the type is declared public. /// @@ -1444,6 +1460,11 @@ namespace FlaxEditor.Scripting /// string Name { get; } + /// + /// Gets a metadata token for sorting so it may not be the actual token. + /// + int MetadataToken { get; } + /// /// Gets a value indicating whether the type is declared public. /// From d09bd12e5b7fddb9ad1d5869fd646f3f32dee004 Mon Sep 17 00:00:00 2001 From: honzapatCZ Date: Thu, 4 Mar 2021 19:55:28 +0100 Subject: [PATCH 2/4] declaration at end --- Source/Editor/Scripting/ScriptType.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Source/Editor/Scripting/ScriptType.cs b/Source/Editor/Scripting/ScriptType.cs index bca6ccf40..480ca6a4e 100644 --- a/Source/Editor/Scripting/ScriptType.cs +++ b/Source/Editor/Scripting/ScriptType.cs @@ -47,12 +47,17 @@ namespace FlaxEditor.Scripting { get { + int standardToken = _managed?.MetadataToken ?? _custom?.MetadataToken ?? 0; if (_managed != null && IsProperty) { ScriptMemberInfo finfo = DeclaringType.GetField(string.Format("<{0}>k__BackingField", Name), BindingFlags.Instance | BindingFlags.NonPublic); + if(finfo.MetadataToken == 0) + { + return standardToken; + } return finfo.MetadataToken; } - return _managed?.MetadataToken ?? _custom?.MetadataToken ?? 0; + return standardToken; } } From 406db6704fe1c3a577bd37e4281a70021cb9085c Mon Sep 17 00:00:00 2001 From: honzapatCZ Date: Sun, 7 Mar 2021 11:30:18 +0100 Subject: [PATCH 3/4] Now its an editor option --- .../CustomEditors/Editors/GenericEditor.cs | 16 ++++++------ Source/Editor/Options/GeneralOptions.cs | 25 +++++++++++++++++++ 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/Source/Editor/CustomEditors/Editors/GenericEditor.cs b/Source/Editor/CustomEditors/Editors/GenericEditor.cs index f3569bd65..f430dbf61 100644 --- a/Source/Editor/CustomEditors/Editors/GenericEditor.cs +++ b/Source/Editor/CustomEditors/Editors/GenericEditor.cs @@ -173,16 +173,16 @@ namespace FlaxEditor.CustomEditors.Editors return string.Compare(Display.Group, other.Display.Group, StringComparison.InvariantCulture); } - // By declaration order - if (Info.MetadataToken > other.Info.MetadataToken) - return 1; - else if (Info.MetadataToken < other.Info.MetadataToken) - return -1; - else + if(Editor.Instance.Options.Options.General.ScritpMembersOrder == Options.GeneralOptions.MembersOrder.Declaration) { - // By name - return string.Compare(Info.Name, other.Info.Name, StringComparison.InvariantCulture); + // By declaration order + if (Info.MetadataToken > other.Info.MetadataToken) + return 1; + else if (Info.MetadataToken < other.Info.MetadataToken) + return -1; } + // By name + return string.Compare(Info.Name, other.Info.Name, StringComparison.InvariantCulture); } return 0; diff --git a/Source/Editor/Options/GeneralOptions.cs b/Source/Editor/Options/GeneralOptions.cs index 85174030f..2a6a4c0b5 100644 --- a/Source/Editor/Options/GeneralOptions.cs +++ b/Source/Editor/Options/GeneralOptions.cs @@ -68,6 +68,24 @@ namespace FlaxEditor.Options CompileScripts, } + /// + /// Order of script members show in editor + /// + public enum MembersOrder + { + /// + /// Shows properties/fields in alphabetical order + /// + [Tooltip("Shows properties/fields in alphabetical order")] + Alphabetical, + + /// + /// Shows properties/fields in declaration order + /// + [Tooltip("Shows properties/fields in declaration order")] + Declaration + } + /// /// Gets or sets the scene to load on editor startup. /// @@ -116,6 +134,13 @@ namespace FlaxEditor.Options [EditorDisplay("Scripting", "Force Script Compilation On Startup"), EditorOrder(501), Tooltip("Determines whether automatically compile game scripts before starting the editor.")] public bool ForceScriptCompilationOnStartup { get; set; } = true; + /// + /// Gets or sets a value indicating whether automatically save the Visual Script asset editors when starting the play mode in editor. + /// + [DefaultValue(true)] + [EditorDisplay("Scripting", "Scritp Members Order"), EditorOrder(503), Tooltip("Sets the order of script properties/fields")] + public MembersOrder ScritpMembersOrder { get; set; } = MembersOrder.Alphabetical; + /// /// Gets or sets a value indicating whether automatically save the Visual Script asset editors when starting the play mode in editor. /// From cbe97ef3f001ba18b9eed404fd5235d1003138a2 Mon Sep 17 00:00:00 2001 From: honzapatCZ Date: Sun, 7 Mar 2021 22:42:14 +0100 Subject: [PATCH 4/4] typo --- Source/Editor/CustomEditors/Editors/GenericEditor.cs | 2 +- Source/Editor/Options/GeneralOptions.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/Editor/CustomEditors/Editors/GenericEditor.cs b/Source/Editor/CustomEditors/Editors/GenericEditor.cs index f430dbf61..eec715a6b 100644 --- a/Source/Editor/CustomEditors/Editors/GenericEditor.cs +++ b/Source/Editor/CustomEditors/Editors/GenericEditor.cs @@ -173,7 +173,7 @@ namespace FlaxEditor.CustomEditors.Editors return string.Compare(Display.Group, other.Display.Group, StringComparison.InvariantCulture); } - if(Editor.Instance.Options.Options.General.ScritpMembersOrder == Options.GeneralOptions.MembersOrder.Declaration) + if(Editor.Instance.Options.Options.General.ScriptMembersOrder == Options.GeneralOptions.MembersOrder.Declaration) { // By declaration order if (Info.MetadataToken > other.Info.MetadataToken) diff --git a/Source/Editor/Options/GeneralOptions.cs b/Source/Editor/Options/GeneralOptions.cs index 2a6a4c0b5..8d3948220 100644 --- a/Source/Editor/Options/GeneralOptions.cs +++ b/Source/Editor/Options/GeneralOptions.cs @@ -138,8 +138,8 @@ namespace FlaxEditor.Options /// Gets or sets a value indicating whether automatically save the Visual Script asset editors when starting the play mode in editor. /// [DefaultValue(true)] - [EditorDisplay("Scripting", "Scritp Members Order"), EditorOrder(503), Tooltip("Sets the order of script properties/fields")] - public MembersOrder ScritpMembersOrder { get; set; } = MembersOrder.Alphabetical; + [EditorDisplay("Scripting", "Script Members Order"), EditorOrder(503), Tooltip("Sets the order of script properties/fields")] + public MembersOrder ScriptMembersOrder { get; set; } = MembersOrder.Alphabetical; /// /// Gets or sets a value indicating whether automatically save the Visual Script asset editors when starting the play mode in editor.