Просмотр исходного кода

Feature: Inspectable field for Degree and Radian types

BearishSun 7 лет назад
Родитель
Сommit
97fc9e74da

+ 2 - 0
Source/Scripting/MBansheeEditor/MBansheeEditor.csproj

@@ -102,11 +102,13 @@
     <Compile Include="Windows\Inspector\InspectableColorDistribution.cs" />
     <Compile Include="Windows\Inspector\InspectableColorGradient.cs" />
     <Compile Include="Windows\Inspector\InspectableCurve.cs" />
+    <Compile Include="Windows\Inspector\InspectableDegree.cs" />
     <Compile Include="Windows\Inspector\InspectableEnum.cs" />
     <Compile Include="Windows\Inspector\InspectableEuler.cs" />
     <Compile Include="Windows\Inspector\InspectableFloatDistribution.cs" />
     <Compile Include="Windows\Inspector\InspectableLayerMask.cs" />
     <Compile Include="Windows\Inspector\InspectableQuaternion.cs" />
+    <Compile Include="Windows\Inspector\InspectableRadian.cs" />
     <Compile Include="Windows\Inspector\InspectableRRef.cs" />
     <Compile Include="Windows\Inspector\InspectableVector2Distribution.cs" />
     <Compile Include="Windows\Inspector\InspectableVector3Distribution.cs" />

+ 2 - 1
Source/Scripting/MBansheeEditor/Windows/Inspector/InspectableAABox.cs

@@ -28,8 +28,9 @@ namespace BansheeEditor
         ///                     contain other fields, in which case you should increase this value by one.</param>
         /// <param name="layout">Parent layout that all the field elements will be added to.</param>
         /// <param name="property">Serializable property referencing the field whose contents to display.</param>
+        /// <param name="style">Information that can be used for customizing field rendering and behaviour.</param>
         public InspectableAABox(Inspector parent, string title, string path, int depth, InspectableFieldLayout layout,
-            SerializableProperty property)
+            SerializableProperty property, InspectableFieldStyle style)
             : base(parent, title, path, SerializableProperty.FieldType.Object, depth, layout, property)
         { }
 

+ 94 - 0
Source/Scripting/MBansheeEditor/Windows/Inspector/InspectableDegree.cs

@@ -0,0 +1,94 @@
+//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
+//**************** Copyright (c) 2019 Marko Pintera ([email protected]). All rights reserved. **********************//
+using BansheeEngine;
+
+namespace BansheeEditor
+{
+    /** @addtogroup Inspector
+     *  @{
+     */
+
+    /// <summary>
+    /// Displays GUI for a serializable property containing a value in degrees.
+    /// </summary>
+    [CustomInspector(typeof(Degree))]
+    public class InspectableDegree : InspectableField
+    {
+        private GUIFloatField guiFloatField;
+        private InspectableState state;
+        private InspectableFieldStyleInfo style;
+
+        /// <summary>
+        /// Creates a new inspectable float GUI for the specified property.
+        /// </summary>
+        /// <param name="parent">Parent Inspector this field belongs to.</param>
+        /// <param name="title">Name of the property, or some other value to set as the title.</param>
+        /// <param name="path">Full path to this property (includes name of this property and all parent properties).</param>
+        /// <param name="depth">Determines how deep within the inspector nesting hierarchy is this field. Some fields may
+        ///                     contain other fields, in which case you should increase this value by one.</param>
+        /// <param name="layout">Parent layout that all the field elements will be added to.</param>
+        /// <param name="property">Serializable property referencing the field whose contents to display.</param>
+        /// <param name="style">Information that can be used for customizing field rendering and behaviour.</param>
+        public InspectableDegree(Inspector parent, string title, string path, int depth, InspectableFieldLayout layout,
+            SerializableProperty property, InspectableFieldStyleInfo style)
+            : base(parent, title, path, SerializableProperty.FieldType.Object, depth, layout, property)
+        {
+            this.style = style;
+        }
+
+        /// <inheritoc/>
+        protected internal override void Initialize(int layoutIndex)
+        {
+            if (property != null)
+            {
+                guiFloatField = new GUIFloatField(new GUIContent(title));
+                if (style != null)
+                {
+                    if (style.StepStyle != null && style.StepStyle.Step != 0)
+                        guiFloatField.Step = style.StepStyle.Step;
+                    if (style.RangeStyle != null)
+                        guiFloatField.SetRange(style.RangeStyle.Min, style.RangeStyle.Max);
+                }
+                guiFloatField.OnChanged += OnFieldValueChanged;
+                guiFloatField.OnConfirmed += OnFieldValueConfirm;
+                guiFloatField.OnFocusLost += OnFieldValueConfirm;
+
+                layout.AddElement(layoutIndex, guiFloatField);
+            }
+        }
+
+        /// <inheritdoc/>
+        public override InspectableState Refresh(int layoutIndex)
+        {
+            if (guiFloatField != null && !guiFloatField.HasInputFocus)
+                guiFloatField.Value = property.GetValue<Degree>().Degrees;
+
+            InspectableState oldState = state;
+            if (state.HasFlag(InspectableState.Modified))
+                state = InspectableState.NotModified;
+
+            return oldState;
+        }
+
+        /// <summary>
+        /// Triggered when the user inputs a new floating point value.
+        /// </summary>
+        /// <param name="newValue">New value of the float field.</param>
+        private void OnFieldValueChanged(float newValue)
+        {
+            property.SetValue(new Degree(newValue));
+            state |= InspectableState.ModifyInProgress;
+        }
+
+        /// <summary>
+        /// Triggered when the user confirms input in the float field.
+        /// </summary>
+        private void OnFieldValueConfirm()
+        {
+            if (state.HasFlag(InspectableState.ModifyInProgress))
+                state |= InspectableState.Modified;
+        }
+    }
+
+    /** @} */
+}

+ 1 - 1
Source/Scripting/MBansheeEditor/Windows/Inspector/InspectableField.cs

@@ -145,7 +145,7 @@ namespace BansheeEditor
             if (customInspectable != null)
             {
                 field = (InspectableField) Activator.CreateInstance(customInspectable, parent, title, path, depth, layout, 
-                    property);
+                    property, style);
             }
             else
             {

+ 94 - 0
Source/Scripting/MBansheeEditor/Windows/Inspector/InspectableRadian.cs

@@ -0,0 +1,94 @@
+//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
+//**************** Copyright (c) 2019 Marko Pintera ([email protected]). All rights reserved. **********************//
+using BansheeEngine;
+
+namespace BansheeEditor
+{
+    /** @addtogroup Inspector
+     *  @{
+     */
+
+    /// <summary>
+    /// Displays GUI for a serializable property containing a value in radians.
+    /// </summary>
+    [CustomInspector(typeof(Radian))]
+    public class InspectableRadian : InspectableField
+    {
+        private GUIFloatField guiFloatField;
+        private InspectableState state;
+        private InspectableFieldStyleInfo style;
+
+        /// <summary>
+        /// Creates a new inspectable float GUI for the specified property.
+        /// </summary>
+        /// <param name="parent">Parent Inspector this field belongs to.</param>
+        /// <param name="title">Name of the property, or some other value to set as the title.</param>
+        /// <param name="path">Full path to this property (includes name of this property and all parent properties).</param>
+        /// <param name="depth">Determines how deep within the inspector nesting hierarchy is this field. Some fields may
+        ///                     contain other fields, in which case you should increase this value by one.</param>
+        /// <param name="layout">Parent layout that all the field elements will be added to.</param>
+        /// <param name="property">Serializable property referencing the field whose contents to display.</param>
+        /// <param name="style">Information that can be used for customizing field rendering and behaviour.</param>
+        public InspectableRadian(Inspector parent, string title, string path, int depth, InspectableFieldLayout layout,
+            SerializableProperty property, InspectableFieldStyleInfo style)
+            : base(parent, title, path, SerializableProperty.FieldType.Object, depth, layout, property)
+        {
+            this.style = style;
+        }
+
+        /// <inheritoc/>
+        protected internal override void Initialize(int layoutIndex)
+        {
+            if (property != null)
+            {
+                guiFloatField = new GUIFloatField(new GUIContent(title));
+                if (style != null)
+                {
+                    if (style.StepStyle != null && style.StepStyle.Step != 0)
+                        guiFloatField.Step = style.StepStyle.Step;
+                    if (style.RangeStyle != null)
+                        guiFloatField.SetRange(style.RangeStyle.Min, style.RangeStyle.Max);
+                }
+                guiFloatField.OnChanged += OnFieldValueChanged;
+                guiFloatField.OnConfirmed += OnFieldValueConfirm;
+                guiFloatField.OnFocusLost += OnFieldValueConfirm;
+
+                layout.AddElement(layoutIndex, guiFloatField);
+            }
+        }
+
+        /// <inheritdoc/>
+        public override InspectableState Refresh(int layoutIndex)
+        {
+            if (guiFloatField != null && !guiFloatField.HasInputFocus)
+                guiFloatField.Value = property.GetValue<Radian>().Radians;
+
+            InspectableState oldState = state;
+            if (state.HasFlag(InspectableState.Modified))
+                state = InspectableState.NotModified;
+
+            return oldState;
+        }
+
+        /// <summary>
+        /// Triggered when the user inputs a new floating point value.
+        /// </summary>
+        /// <param name="newValue">New value of the float field.</param>
+        private void OnFieldValueChanged(float newValue)
+        {
+            property.SetValue(new Radian(newValue));
+            state |= InspectableState.ModifyInProgress;
+        }
+
+        /// <summary>
+        /// Triggered when the user confirms input in the float field.
+        /// </summary>
+        private void OnFieldValueConfirm()
+        {
+            if (state.HasFlag(InspectableState.ModifyInProgress))
+                state |= InspectableState.Modified;
+        }
+    }
+
+    /** @} */
+}