diff --git a/engine/Sandbox.Engine/Scene/Components/Component.Flags.cs b/engine/Sandbox.Engine/Scene/Components/Component.Flags.cs index f5279493..7a83e873 100644 --- a/engine/Sandbox.Engine/Scene/Components/Component.Flags.cs +++ b/engine/Sandbox.Engine/Scene/Components/Component.Flags.cs @@ -50,6 +50,11 @@ public enum ComponentFlags /// Don't serialize this component when cloning /// NotCloned = 256, + + /// + /// Can edit advanced properties in the component inspector + /// + ShowAdvancedProperties = 512, } public partial class Component diff --git a/engine/Sandbox.Engine/Scene/Components/Component.Serialize.cs b/engine/Sandbox.Engine/Scene/Components/Component.Serialize.cs index 981996ab..46a9847f 100644 --- a/engine/Sandbox.Engine/Scene/Components/Component.Serialize.cs +++ b/engine/Sandbox.Engine/Scene/Components/Component.Serialize.cs @@ -37,7 +37,8 @@ public abstract partial class Component : BytePack.ISerializer { { JsonKeys.Type, t.SerializedName }, { JsonKeys.Id, Id }, - { JsonKeys.Enabled, Enabled } + { JsonKeys.Enabled, Enabled }, + { JsonKeys.Flags, (long)Flags } }; if ( (isSceneForNetwork || isSingleNetworkObject) && this is INetworkSnapshot sw ) @@ -102,6 +103,8 @@ public abstract partial class Component : BytePack.ISerializer Id = (Guid)id; } + DeserializeFlags( node ); + if ( node.TryGetPropertyValue( JsonKeys.Snapshot, out var snapshotNode ) && this is INetworkSnapshot sw ) { var data = snapshotNode.Deserialize(); @@ -117,6 +120,18 @@ public abstract partial class Component : BytePack.ISerializer Enabled = (bool)(jsonData[JsonKeys.Enabled] ?? true); } + private void DeserializeFlags( JsonObject node ) + { + if ( !node.TryGetPropertyValue( JsonKeys.Flags, out var inFlagNode ) ) + return; + + var inFlags = (ComponentFlags)(long)inFlagNode; + + const ComponentFlags savedFlags = ComponentFlags.ShowAdvancedProperties; + + Flags = (Flags & ~savedFlags) | (inFlags & savedFlags); + } + internal void PostDeserialize() { if ( jsonData is null ) diff --git a/engine/Sandbox.System/Attributes/Property.cs b/engine/Sandbox.System/Attributes/Property.cs index 58f31d61..77fb04f5 100644 --- a/engine/Sandbox.System/Attributes/Property.cs +++ b/engine/Sandbox.System/Attributes/Property.cs @@ -15,7 +15,6 @@ public class PropertyAttribute : Attribute, IClassNameProvider, ITitleProvider /// public string Title { get; set; } - public PropertyAttribute() : base() { } @@ -49,3 +48,11 @@ public class InlineEditorAttribute : Attribute { public bool Label { get; set; } = true; } + +/// +/// Some properties are not meant for the average user, hide them unless they really want to see them. +/// +[AttributeUsage( AttributeTargets.Property | AttributeTargets.Field )] +public class AdvancedAttribute : Attribute +{ +} diff --git a/game/addons/tools/Code/Scene/GameObjectInspector/ComponentSheet.cs b/game/addons/tools/Code/Scene/GameObjectInspector/ComponentSheet.cs index 908ac405..70583c6d 100644 --- a/game/addons/tools/Code/Scene/GameObjectInspector/ComponentSheet.cs +++ b/game/addons/tools/Code/Scene/GameObjectInspector/ComponentSheet.cs @@ -50,6 +50,25 @@ public partial class ComponentSheet : Widget /// internal bool Expanded { get; set; } = true; + internal bool ShowAdvanced + { + get + { + return TargetObject.Targets.OfType() + .Any( x => x.IsValid() && x.Flags.Contains( ComponentFlags.ShowAdvancedProperties ) ); + } + set + { + foreach ( var component in TargetObject.Targets.OfType() ) + { + if ( component.IsValid() ) + { + component.Flags = component.Flags.WithFlag( ComponentFlags.ShowAdvancedProperties, value ); + } + } + } + } + /// /// Expands/shrinks the component in the component list. /// @@ -163,6 +182,7 @@ public partial class ComponentSheet : Widget hc.Add( TargetObject ); hc.Add( ViewMode ); + hc.Add( ShowAdvanced ); foreach ( var condition in hideShowConditions ) { @@ -218,10 +238,11 @@ public partial class ComponentSheet : Widget Content.Add( cs ); - cs.AddObject( TargetObject, FilterProperties ); + var showAdvanced = ShowAdvanced; + cs.AddObject( TargetObject, ( o ) => FilterProperties( o, showAdvanced ) ); } - bool FilterProperties( SerializedProperty o ) + bool FilterProperties( SerializedProperty o, bool showAdvanced ) { if ( o.PropertyType is null ) return false; @@ -236,7 +257,8 @@ public partial class ComponentSheet : Widget if ( ViewMode != ComponentViewMode.Events && hideInEventTab ) return false; if ( o.IsMethod ) return true; - if ( !o.HasAttribute() ) return false; + if ( o.HasAttribute() == false ) return false; + if ( o.HasAttribute() && showAdvanced == false ) return false; return true; } diff --git a/game/addons/tools/Code/Scene/GameObjectInspector/ComponentSheetHeader.cs b/game/addons/tools/Code/Scene/GameObjectInspector/ComponentSheetHeader.cs index e19fb47d..aa90287a 100644 --- a/game/addons/tools/Code/Scene/GameObjectInspector/ComponentSheetHeader.cs +++ b/game/addons/tools/Code/Scene/GameObjectInspector/ComponentSheetHeader.cs @@ -114,10 +114,18 @@ public class ComponentSheetHeader : InspectorHeader void FillContextMenu( Menu menu ) { - var o = menu.AddOption( "View Legacy Actions", "sentiment_very_dissatisfied" ); - o.Checkable = true; - o.Checked = Sheet.ViewMode == ComponentViewMode.Events; - o.Toggled = b => Sheet.ViewMode = b ? ComponentViewMode.Events : ComponentViewMode.Default; + { + var o = menu.AddOption( "View Legacy Actions", "sentiment_very_dissatisfied" ); + o.Checkable = true; + o.Checked = Sheet.ViewMode == ComponentViewMode.Events; + o.Toggled = b => Sheet.ViewMode = b ? ComponentViewMode.Events : ComponentViewMode.Default; + } + { + var o = menu.AddOption( "View Advanced Properties", "tune" ); + o.Checkable = true; + o.Checked = Sheet.ShowAdvanced; + o.Toggled = b => Sheet.ShowAdvanced = b; + } menu.AddSeparator(); }