Quellcode durchsuchen

Range no longer specifies stepping, Use [Step] instead.
Improved scalability of C# styling logic

marco.bellan vor 9 Jahren
Ursprung
Commit
058d27b6b1

+ 1 - 4
Source/MBansheeEditor/Windows/Inspector/Style/InspectableFieldRangeStyle.cs

@@ -8,11 +8,10 @@ namespace BansheeEditor
     /// </summary>
     public sealed class InspectableFieldRangeStyle : InspectableFieldStyle
     {
-        public InspectableFieldRangeStyle(float min, float max, float step = 0.0f)
+        public InspectableFieldRangeStyle(float min, float max)
         {
             this.Max = max;
             this.Min = min;
-            this.Step = step;
         }
 
         /// <summary>
@@ -23,7 +22,5 @@ namespace BansheeEditor
         /// The minimum value the field can be assigned
         /// </summary>
         public float Min { get; set; }
-
-        public float Step { get; set; }
     }
 }

+ 1 - 1
Source/MBansheeEditor/Windows/Inspector/Style/InspectableFieldStepStyle.cs

@@ -1,7 +1,7 @@
 //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
 //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
 
-namespace BansheeEditor.Windows.Inspector.Style
+namespace BansheeEditor
 {
     /// <summary>
     /// Contains information about the minimum change allowed to a field value

+ 50 - 22
Source/MBansheeEditor/Windows/Inspector/Style/InspectableFieldStyle.cs

@@ -3,45 +3,73 @@
 
 using System;
 using System.Collections.Generic;
-using BansheeEditor.Windows.Inspector.Style;
 using BansheeEngine;
 
 namespace BansheeEditor
 {
+    /// <summary>
+    /// Contains boolean information about a field style
+    /// </summary>
+    public enum InstectableFieldStyleFlags
+    {
+        None = 0,
+        UseSlider = 1,   
+    }
+
+    /// <summary>
+    /// Contains all the information about a field style
+    /// </summary>
+    public struct InspectableFieldStyleInfo
+    {
+        /// <summary>
+        /// Information about the field range
+        /// </summary>
+        public InspectableFieldRangeStyle RangeStyle;
+
+        /// <summary>
+        /// Information about the field stepping
+        /// </summary>
+        public InspectableFieldStepStyle StepStyle;
+
+        /// <summary>
+        /// Boolean information about the field
+        /// </summary>
+        public InstectableFieldStyleFlags StyleFlags;
+    }
     /// <summary>
     /// Contains style information about inspectable items
     /// </summary>
-    public class InspectableFieldStyle
+    public abstract class InspectableFieldStyle
     {
         /// <summary>
         /// Creates all the relevant style information for a SerializableField
         /// </summary>
         /// <param name="field">A SerializableField</param>
         /// <returns>Style information</returns>
-        public static InspectableFieldStyle[] Create(SerializableField field)
+        public static InspectableFieldStyleInfo Create(SerializableField field)
         {
-            List<InspectableFieldStyle> styles = new List<InspectableFieldStyle>();
-            if (field.Range)
-                styles.Add(new InspectableFieldRangeStyle(field.RangeMinimum, field.RangeMaximum));
-            if (field.Step != default(float))
-                styles.Add(new InspectableFieldStepStyle(field.Step));
-            return styles.ToArray();
-        }
+            var styleInfo = new InspectableFieldStyleInfo();
 
-        /// <summary>
-        /// Finds a specific type of style information
-        /// </summary>
-        /// <typeparam name="T">The specified type</typeparam>
-        /// <param name="styleInfo">The array to search into</param>
-        /// <returns>The desired style or default</returns>
-        public static T FindStyle<T>(InspectableFieldStyle[] styleInfo) where T : InspectableFieldStyle
-        {
-            for  (int i = 0; i < styleInfo.Length; i++)
+            styleInfo.RangeStyle = field.Range? new InspectableFieldRangeStyle(field.RangeMinimum, field.RangeMaximum) : null;
+            styleInfo.StepStyle = field.Step != 0? new InspectableFieldStepStyle(field.Step) : null;
+            if (styleInfo.StepStyle != null)
+            {
+                Debug.Log(styleInfo.StepStyle.Step);
+            }
+            else
+            {
+                Debug.Log("Step null");
+            }
+            if (styleInfo.RangeStyle != null)
+            {
+                Debug.Log(styleInfo.RangeStyle.Max);
+                Debug.Log(styleInfo.RangeStyle.Min);
+            }
+            else
             {
-                if (styleInfo[i].GetType() == typeof(T))
-                    return (T)styleInfo[i];
+                Debug.Log("Range null");
             }
-            return default(T);
+            return styleInfo;
         }
     }
 }