Sfoglia il codice sorgente

WIP Step attribute

marco.bellan 9 anni fa
parent
commit
5bc43df6d0

+ 3 - 2
Source/MBansheeEditor/MBansheeEditor.csproj

@@ -71,8 +71,9 @@
     <Compile Include="Inspectors\SliderJointInspector.cs" />
     <Compile Include="Inspectors\SphereColliderInspector.cs" />
     <Compile Include="Inspectors\SphericalJointInspector.cs" />
-    <Compile Include="Windows\Inspector\InspectableFieldRangeStyle.cs" />
-    <Compile Include="Windows\Inspector\InspectableFieldStyle.cs" />
+    <Compile Include="Windows\Inspector\Style\InspectableFieldRangeStyle.cs" />
+    <Compile Include="Windows\Inspector\Style\InspectableFieldStepStyle.cs" />
+    <Compile Include="Windows\Inspector\Style\InspectableFieldStyle.cs" />
     <Compile Include="Windows\Inspector\InspectableRangedField.cs" />
     <Compile Include="Windows\Inspector\InspectableRangedFloat.cs" />
     <Compile Include="Windows\Inspector\InspectableRangedInt.cs" />

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

@@ -146,6 +146,7 @@ namespace BansheeEditor
             else
             {
                 InspectableFieldRangeStyle rangeInfo = null;
+
                 if (style != null)
                     rangeInfo = InspectableFieldStyle.FindStyle<InspectableFieldRangeStyle>(style);
                 switch (property.Type)

+ 0 - 25
Source/MBansheeEditor/Windows/Inspector/InspectableFieldRangeStyle.cs

@@ -1,25 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace BansheeEditor
-{
-    /// <summary>
-    /// Contains info about the range of values a field can store
-    /// </summary>
-    public class InspectableFieldRangeStyle : InspectableFieldStyle
-    {
-        public float Max { get; set; }
-        public float Min { get; set; }
-        public float Step { get; set; }
-
-        public InspectableFieldRangeStyle(float min, float max, float step = 0.0f)
-        {
-            this.Max = max;
-            this.Min = min;
-            this.Step = step;
-        }
-    }
-}

+ 0 - 34
Source/MBansheeEditor/Windows/Inspector/InspectableFieldStyle.cs

@@ -1,34 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using BansheeEditor;
-using BansheeEngine;
-
-namespace BansheeEditor
-{
-    /// <summary>
-    /// Contains style information about inspectable items
-    /// </summary>
-    public class InspectableFieldStyle
-    {
-        public static InspectableFieldStyle[] Create(SerializableField field)
-        {
-            List<InspectableFieldStyle> styles = new List<InspectableFieldStyle>();
-            if (field.Range)
-                styles.Add(new InspectableFieldRangeStyle(field.RangeMinimum, field.RangeMaximum, field.RangeStep));
-            return styles.ToArray();
-        }
-
-        public static T FindStyle<T>(InspectableFieldStyle[] styleInfo) where T : InspectableFieldRangeStyle
-        {
-            for  (int i = 0; i < styleInfo.Length; i++)
-            {
-                if (styleInfo[i].GetType() == typeof(T))
-                    return (T)styleInfo[i];
-            }
-            return default(T);
-        }
-    }
-}

+ 29 - 0
Source/MBansheeEditor/Windows/Inspector/Style/InspectableFieldRangeStyle.cs

@@ -0,0 +1,29 @@
+//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
+//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
+
+namespace BansheeEditor
+{
+    /// <summary>
+    /// Contains info about the range of values a field can store
+    /// </summary>
+    public sealed class InspectableFieldRangeStyle : InspectableFieldStyle
+    {
+        public InspectableFieldRangeStyle(float min, float max, float step = 0.0f)
+        {
+            this.Max = max;
+            this.Min = min;
+            this.Step = step;
+        }
+
+        /// <summary>
+        /// The maximum value the field can be assigned
+        /// </summary>
+        public float Max { get; set; }
+        /// <summary>
+        /// The minimum value the field can be assigned
+        /// </summary>
+        public float Min { get; set; }
+
+        public float Step { get; set; }
+    }
+}

+ 22 - 0
Source/MBansheeEditor/Windows/Inspector/Style/InspectableFieldStepStyle.cs

@@ -0,0 +1,22 @@
+//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
+//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
+
+namespace BansheeEditor.Windows.Inspector.Style
+{
+    /// <summary>
+    /// Contains information about the minimum change allowed to a field value
+    /// </summary>
+    public sealed class InspectableFieldStepStyle : InspectableFieldStyle
+    {
+
+        public InspectableFieldStepStyle(float step)
+        {
+            this.Step = step;
+        }
+
+        /// <summary>
+        /// Minimum change of the field. Every change will be rounded to a multiple of this value
+        /// </summary>
+        public float Step { get; set; }
+    }
+}

+ 47 - 0
Source/MBansheeEditor/Windows/Inspector/Style/InspectableFieldStyle.cs

@@ -0,0 +1,47 @@
+//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
+//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
+
+using System;
+using System.Collections.Generic;
+using BansheeEditor.Windows.Inspector.Style;
+using BansheeEngine;
+
+namespace BansheeEditor
+{
+    /// <summary>
+    /// Contains style information about inspectable items
+    /// </summary>
+    public 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)
+        {
+            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();
+        }
+
+        /// <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++)
+            {
+                if (styleInfo[i].GetType() == typeof(T))
+                    return (T)styleInfo[i];
+            }
+            return default(T);
+        }
+    }
+}

+ 1 - 0
Source/MBansheeEngine/MBansheeEngine.csproj

@@ -51,6 +51,7 @@
     <Compile Include="Audio\Interop\NativeAudioSource.cs" />
     <Compile Include="GUI\GUICanvas.cs" />
     <Compile Include="Rendering\PostProcessSettings.cs" />
+    <Compile Include="Serialization\Step.cs" />
     <Compile Include="Utility\AsyncOp.cs" />
     <Compile Include="Math\Bounds.cs" />
     <Compile Include="Utility\Builtin.cs" />

+ 1 - 4
Source/MBansheeEngine/Serialization/Range.cs

@@ -19,18 +19,15 @@ namespace BansheeEngine
         /// </summary>
         /// <param name="min">Minimum boundary of the range to clamp the field value to.</param>
         /// <param name="max">Maximum boundary of the range to clamp the field value to.</param>
-        /// <param name="step">Minimum change of the field value every change should be multiple of.</param>
         /// 
-        public Range(float min, float max, float step=0f)
+        public Range(float min, float max)
         {
             this.min = min;
             this.max = max;
-            this.step = step;
         }
 
         private float min;
         private float max;
-        private float step;
     }
 
     /** @} */

+ 3 - 3
Source/MBansheeEngine/Serialization/SerializableField.cs

@@ -79,9 +79,9 @@ namespace BansheeEngine
         /// <summary>
         /// Returns the step of the range
         /// </summary>
-        public float RangeStep
+        public float Step
         {
-            get { return Range ? Internal_GetRangeStep(mCachedPtr) : 0; }
+            get { return Range ? Internal_GetStep(mCachedPtr) : 0; }
         }
 
         /// <summary>
@@ -152,7 +152,7 @@ namespace BansheeEngine
         private static extern float Internal_GetRangeMinimum(IntPtr field);
 
         [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern float Internal_GetRangeStep(IntPtr field);
+        private static extern float Internal_GetStep(IntPtr field);
     }
 
     /** @} */

+ 28 - 0
Source/MBansheeEngine/Serialization/Step.cs

@@ -0,0 +1,28 @@
+//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
+//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
+using System;
+
+namespace BansheeEngine
+{
+    /** @addtogroup Serialization
+     *  @{
+     */
+
+    /// <summary>
+    /// Makes an integer or a floating point field vary by multiples of the specified value.
+    /// </summary>
+    [AttributeUsage(AttributeTargets.Field)]
+    public sealed class Step : Attribute
+    {
+        /// <summary>
+        /// Creates a new Step attribute
+        /// </summary>
+        /// <param name="step">Minimum change of the field. Every change will be rounded to a multiple of this value</param>
+        public Step(float step)
+        {
+            this.step = step;
+        }
+
+        private float step;
+    }
+}

+ 3 - 2
Source/SBansheeEngine/Include/BsManagedSerializableObjectInfo.h

@@ -63,7 +63,8 @@ namespace BansheeEngine
 	{
 		Serializable = 0x01,
 		Inspectable = 0x02,
-		Range = 0x04
+		Range = 0x04,
+		Step = 0x08
 	};
 
 	/**	Contains information about a type of a managed serializable object. */
@@ -263,7 +264,7 @@ namespace BansheeEngine
 		float getRangeMaximum() const;
 
 		/** Returns the step value of a Range attribute */
-		float getRangeStep() const;
+		float getStep() const;
 
 		String mName;
 		UINT32 mFieldId;

+ 4 - 0
Source/SBansheeEngine/Include/BsScriptAssemblyManager.h

@@ -80,6 +80,9 @@ namespace BansheeEngine
 
 		/** Gets the managed class for BansheeEngine.Range attribute */
 		MonoClass* getRangeAttribute() const { return mRangeAttribute; }
+
+		/** Gets the managed class for BansheeEngine.Step attribute */
+		MonoClass* getStepAttribute() const { return mStepAttribute; }
 	private:
 		/**	Deletes all stored managed serializable object infos for all assemblies. */
 		void clearScriptObjects();
@@ -107,6 +110,7 @@ namespace BansheeEngine
 		MonoClass* mSerializeFieldAttribute;
 		MonoClass* mHideInInspectorAttribute;
 		MonoClass* mRangeAttribute;
+		MonoClass* mStepAttribute;
 	};
 
 	/** @} */

+ 1 - 1
Source/SBansheeEngine/Include/BsScriptSerializableField.h

@@ -38,7 +38,7 @@ namespace BansheeEngine
 		static void internal_setValue(ScriptSerializableField* nativeInstance, MonoObject* instance, MonoObject* value);
 		static float internal_getRangeMaximum(ScriptSerializableField* nativeInstance);
 		static float internal_getRangeMinimum(ScriptSerializableField* nativeInstance);
-		static float internal_getRangeStep(ScriptSerializableField* nativeInstance);
+		static float internal_getStep(ScriptSerializableField* nativeInstance);
 	};
 
 	/** @} */

+ 3 - 3
Source/SBansheeEngine/Source/BsManagedSerializableObjectInfo.cpp

@@ -127,12 +127,12 @@ namespace BansheeEngine
 		return 0;
 	}
 
-	float ManagedSerializableFieldInfo::getRangeStep() const
+	float ManagedSerializableFieldInfo::getStep() const
 	{
-		if (((UINT32)mFlags & (UINT32)ScriptFieldFlags::Range) != 0)
+		if (((UINT32)mFlags & (UINT32)ScriptFieldFlags::Step) != 0)
 		{
 
-			MonoClass* range = ScriptAssemblyManager::instance().getRangeAttribute();
+			MonoClass* range = ScriptAssemblyManager::instance().getStepAttribute();
 			if (range != nullptr)
 			{
 				float step = 0;

+ 9 - 1
Source/SBansheeEngine/Source/BsScriptAssemblyManager.cpp

@@ -33,7 +33,8 @@ namespace BansheeEngine
 		: mBaseTypesInitialized(false), mSystemArrayClass(nullptr), mSystemGenericListClass(nullptr)
 		, mSystemGenericDictionaryClass(nullptr), mSystemTypeClass(nullptr), mComponentClass(nullptr)
 		, mSceneObjectClass(nullptr), mMissingComponentClass(nullptr), mSerializeObjectAttribute(nullptr)
-		, mDontSerializeFieldAttribute(nullptr), mSerializeFieldAttribute(nullptr), mHideInInspectorAttribute(nullptr), mRangeAttribute(nullptr)
+		, mDontSerializeFieldAttribute(nullptr), mSerializeFieldAttribute(nullptr), mHideInInspectorAttribute(nullptr)
+		, mRangeAttribute(nullptr), mStepAttribute(nullptr)
 	{
 
 	}
@@ -140,6 +141,8 @@ namespace BansheeEngine
 				}
 				if (field->hasAttribute(mRangeAttribute))
 					fieldInfo->mFlags = (ScriptFieldFlags)((UINT32)fieldInfo->mFlags | (UINT32)ScriptFieldFlags::Range);
+				if (field->hasAttribute(mStepAttribute))
+					fieldInfo->mFlags = (ScriptFieldFlags)((UINT32)fieldInfo->mFlags | (UINT32)ScriptFieldFlags::Step);
 
 				objInfo->mFieldNameToId[fieldInfo->mName] = fieldInfo->mFieldId;
 				objInfo->mFields[fieldInfo->mFieldId] = fieldInfo;
@@ -436,6 +439,7 @@ namespace BansheeEngine
 		mSerializeFieldAttribute = nullptr;
 		mHideInInspectorAttribute = nullptr;
 		mRangeAttribute = nullptr;
+		mStepAttribute = nullptr;
 	}
 
 	void ScriptAssemblyManager::initializeBaseTypes()
@@ -477,6 +481,10 @@ namespace BansheeEngine
 		if (mRangeAttribute == nullptr)
 			BS_EXCEPT(InvalidStateException, "Cannot find Range managed class.");
 
+		mStepAttribute = bansheeEngineAssembly->getClass("BansheeEngine", "Step");
+		if (mStepAttribute == nullptr)
+			BS_EXCEPT(InvalidStateException, "Cannot find Step managed class.");
+
 		mComponentClass = bansheeEngineAssembly->getClass("BansheeEngine", "Component");
 		if(mComponentClass == nullptr)
 			BS_EXCEPT(InvalidStateException, "Cannot find Component managed class.");

+ 2 - 2
Source/SBansheeEngine/Source/BsScriptSerializableField.cpp

@@ -25,7 +25,7 @@ namespace BansheeEngine
 		metaData.scriptClass->addInternalCall("Internal_SetValue", &ScriptSerializableField::internal_setValue);
 		metaData.scriptClass->addInternalCall("Internal_GetRangeMaximum", &ScriptSerializableField::internal_getRangeMaximum);
 		metaData.scriptClass->addInternalCall("Internal_GetRangeMinimum", &ScriptSerializableField::internal_getRangeMinimum);
-		metaData.scriptClass->addInternalCall("Internal_GetRangeStep", &ScriptSerializableField::internal_getRangeStep);
+		metaData.scriptClass->addInternalCall("Internal_GetStep", &ScriptSerializableField::internal_getStep);
 	}
 
 	ScriptSerializableField* ScriptSerializableField::create(MonoObject* parentObject, const SPtr<ManagedSerializableFieldInfo>& fieldInfo)
@@ -66,5 +66,5 @@ namespace BansheeEngine
 	}
 	float ScriptSerializableField::internal_getRangeMaximum(ScriptSerializableField* nativeInstance) { return nativeInstance->mFieldInfo->getRangeMaximum(); }
 	float ScriptSerializableField::internal_getRangeMinimum(ScriptSerializableField* nativeInstance) { return nativeInstance->mFieldInfo->getRangeMinimum(); }
-	float ScriptSerializableField::internal_getRangeStep(ScriptSerializableField* nativeInstance) { return nativeInstance->mFieldInfo->getRangeStep(); }
+	float ScriptSerializableField::internal_getStep(ScriptSerializableField* nativeInstance) { return nativeInstance->mFieldInfo->getStep(); }
 }