Ver código fonte

More fixes to GUI dictionary
Fixed GUISkinInspector so it properly updates the values

BearishSun 10 anos atrás
pai
commit
0bd94ece59

+ 10 - 91
MBansheeEditor/GUI/GUIDictionaryField.cs

@@ -512,57 +512,12 @@ namespace BansheeEditor
                 DiscardChanges();
                 DiscardChanges();
             else
             else
             {
             {
-                // Remove the entry, but ensure the rows keep referencing the original keys (dictionaries have undefined
-                // order so we need to compare old vs. new elements to determine if any changed).
-                int oldNumRows = GetNumRows();
-                Dictionary<object, int> oldKeys = new Dictionary<object, int>();
-                for (int i = 0; i < oldNumRows; i++)
-                {
-                    Debug.Log("OLD KEYS: " + i + " - " + ((SerializableProperty)GetKey(i)).GetValue<object>() + " -- " +
-                        ((SerializableProperty)GetValue(GetKey(i))).GetValue<object>());
-                    oldKeys.Add(GetKey(i), i);
-                }
-
                 RemoveEntry(GetKey(rowIdx));
                 RemoveEntry(GetKey(rowIdx));
 
 
-                int newNumRows = GetNumRows();
-                Dictionary<object, int> newKeys = new Dictionary<object, int>();
-                for (int i = 0; i < newNumRows; i++)
-                {
-                    Debug.Log("NEW KEYS: " + i + " - " + ((SerializableProperty)GetKey(i)).GetValue<object>());
-                    newKeys.Add(GetKey(i), i);
-                }
-
-                foreach (var KVP in oldKeys)
-                {
-                    int newRowIdx;
-                    if (newKeys.TryGetValue(KVP.Key, out newRowIdx))
-                    {
-                        if (KVP.Value != newRowIdx)
-                        {
-                            GUIDictionaryFieldRow temp = rows[KVP.Value];
-                            Debug.Log("Swapping: " + KVP.Value + " - " + newRowIdx);
-
-                            temp.SetIndex(newRowIdx);
-                            rows[newRowIdx].SetIndex(KVP.Value);
-
-                            rows[KVP.Value] = rows[newRowIdx];
-                            rows[newRowIdx] = temp;
-                        }
-                    }
-                }
-
-                for (int i = 0; i < newNumRows; i++)
-                    Debug.Log("NEW VALUES: " + i + " - " + ((SerializableProperty)GetKey(i)).GetValue<object>() + " -- " 
-                        + ((SerializableProperty)GetValue(GetKey(i))).GetValue<object>());
-
-                for (int i = oldNumRows - 1; i >= newNumRows; i--)
-                {
-                    rows[i].Destroy();
-                    rows.Remove(i);
-                }
+                rows[rows.Count - 1].Destroy();
+                rows.Remove(rows.Count - 1);
 
 
-                editRow.SetIndex(newNumRows);
+                editRow.SetIndex(GetNumRows());
                 isModified = true;
                 isModified = true;
             }
             }
         }
         }
@@ -728,56 +683,20 @@ namespace BansheeEditor
                     rows[editRowIdx].EditMode = false;
                     rows[editRowIdx].EditMode = false;
                 }
                 }
 
 
-                // Add/remove the entry, but ensure the rows keep referencing the original keys (dictionaries have undefined
-                // order so we need to compare old vs. new elements to determine if any changed).
-                int oldNumRows = GetNumRows();
-                Dictionary<object, int> oldKeys = new Dictionary<object, int>();
-                for (int i = 0; i < oldNumRows; i++)
-                    oldKeys.Add(GetKey(i), i);
-
                 if (editOriginalKey != null) // Editing
                 if (editOriginalKey != null) // Editing
                     EditEntry(editOriginalKey, editKey, editValue);
                     EditEntry(editOriginalKey, editKey, editValue);
                 else // Adding/Cloning
                 else // Adding/Cloning
-                    AddEntry(editKey, editValue);
-
-                int newNumRows = GetNumRows();
-                Dictionary<object, int> newKeys = new Dictionary<object, int>();
-                for (int i = 0; i < newNumRows; i++)
-                    newKeys.Add(GetKey(i), i);
-
-                // Hidden dependency: Initialize must be called after all elements are 
-                // in the dictionary so we do it in two steps
-                for (int i = oldNumRows; i < newNumRows; i++)
-                    rows[i] = CreateRow();
-
-                for (int i = oldNumRows; i < newNumRows; i++)
-                    rows[i].Initialize(this, guiContentLayout, i, depth + 1);
-
-                foreach (var KVP in oldKeys)
                 {
                 {
-                    int newRowIdx;
-                    if (newKeys.TryGetValue(KVP.Key, out newRowIdx))
-                    {
-                        if (KVP.Value != newRowIdx)
-                        {
-                            GUIDictionaryFieldRow temp = rows[KVP.Value];
-
-                            temp.SetIndex(newRowIdx);
-                            rows[newRowIdx].SetIndex(KVP.Value);
-
-                            rows[KVP.Value] = rows[newRowIdx];
-                            rows[newRowIdx] = temp;
-                        }
-                    }
-                }
+                    AddEntry(editKey, editValue);
 
 
-                for (int i = oldNumRows - 1; i >= newNumRows; i--)
-                {
-                    rows[i].Destroy();
-                    rows.Remove(i);
+                    // Hidden dependency: Initialize must be called after all elements are 
+                    // in the dictionary so we do it in two steps
+                    int newRowIdx = rows.Count;
+                    rows[newRowIdx] = CreateRow();
+                    rows[newRowIdx].Initialize(this, guiContentLayout, newRowIdx, depth + 1);
                 }
                 }
 
 
-                editRow.SetIndex(newNumRows);
+                editRow.SetIndex(rows.Count);
 
 
                 editKey = CreateKey();
                 editKey = CreateKey();
                 editValue = CreateValue();
                 editValue = CreateValue();

+ 5 - 7
MBansheeEditor/Inspector/InspectableArray.cs

@@ -20,7 +20,7 @@ namespace BansheeEditor
         /// <param name="layout">Parent layout that all the field elements will be added to.</param>
         /// <param name="layout">Parent layout that all the field elements will be added to.</param>
         /// <param name="property">Serializable property referencing the array whose contents to display.</param>
         /// <param name="property">Serializable property referencing the array whose contents to display.</param>
         public InspectableArray(string title, int depth, InspectableFieldLayout layout, SerializableProperty property)
         public InspectableArray(string title, int depth, InspectableFieldLayout layout, SerializableProperty property)
-            : base(title, depth, layout, property)
+            : base(title, SerializableProperty.FieldType.Array, depth, layout, property)
         {
         {
 
 
         }
         }
@@ -268,13 +268,10 @@ namespace BansheeEditor
             /// <inheritdoc/>
             /// <inheritdoc/>
             protected override GUILayoutX CreateGUI(GUILayoutY layout)
             protected override GUILayoutX CreateGUI(GUILayoutY layout)
             {
             {
-                if (field == null)
-                {
-                    SerializableProperty property = GetValue<SerializableProperty>();
+                SerializableProperty property = GetValue<SerializableProperty>();
 
 
-                    field = CreateInspectable(SeqIndex + ".", 0, Depth + 1,
-                        new InspectableFieldLayout(layout), property);
-                }
+                field = CreateInspectable(SeqIndex + ".", 0, Depth + 1,
+                    new InspectableFieldLayout(layout), property);
 
 
                 return field.GetTitleLayout();
                 return field.GetTitleLayout();
             }
             }
@@ -282,6 +279,7 @@ namespace BansheeEditor
             /// <inheritdoc/>
             /// <inheritdoc/>
             protected internal override InspectableState Refresh()
             protected internal override InspectableState Refresh()
             {
             {
+                field.Property = GetValue<SerializableProperty>();
                 return field.Refresh(0);
                 return field.Refresh(0);
             }
             }
         }
         }

+ 2 - 2
MBansheeEditor/Inspector/InspectableBool.cs

@@ -20,7 +20,7 @@ namespace BansheeEditor
         /// <param name="layout">Parent layout that all the field elements will be added to.</param>
         /// <param name="layout">Parent layout that all the field elements will be added to.</param>
         /// <param name="property">Serializable property referencing the array whose contents to display.</param>
         /// <param name="property">Serializable property referencing the array whose contents to display.</param>
         public InspectableBool(string title, int depth, InspectableFieldLayout layout, SerializableProperty property)
         public InspectableBool(string title, int depth, InspectableFieldLayout layout, SerializableProperty property)
-            : base(title, depth, layout, property)
+            : base(title, SerializableProperty.FieldType.Bool, depth, layout, property)
         {
         {
 
 
         }
         }
@@ -28,7 +28,7 @@ namespace BansheeEditor
         /// <inheritoc/>
         /// <inheritoc/>
         protected internal override void Initialize(int layoutIndex)
         protected internal override void Initialize(int layoutIndex)
         {
         {
-            if (property.Type == SerializableProperty.FieldType.Bool)
+            if (property != null)
             {
             {
                 guiField = new GUIToggleField(new GUIContent(title));
                 guiField = new GUIToggleField(new GUIContent(title));
                 guiField.OnChanged += OnFieldValueChanged;
                 guiField.OnChanged += OnFieldValueChanged;

+ 2 - 2
MBansheeEditor/Inspector/InspectableColor.cs

@@ -20,7 +20,7 @@ namespace BansheeEditor
         /// <param name="layout">Parent layout that all the field elements will be added to.</param>
         /// <param name="layout">Parent layout that all the field elements will be added to.</param>
         /// <param name="property">Serializable property referencing the array whose contents to display.</param>
         /// <param name="property">Serializable property referencing the array whose contents to display.</param>
         public InspectableColor(string title, int depth, InspectableFieldLayout layout, SerializableProperty property)
         public InspectableColor(string title, int depth, InspectableFieldLayout layout, SerializableProperty property)
-            : base(title, depth, layout, property)
+            : base(title, SerializableProperty.FieldType.Color, depth, layout, property)
         {
         {
 
 
         }
         }
@@ -28,7 +28,7 @@ namespace BansheeEditor
         /// <inheritoc/>
         /// <inheritoc/>
         protected internal override void Initialize(int layoutIndex)
         protected internal override void Initialize(int layoutIndex)
         {
         {
-            if (property.Type == SerializableProperty.FieldType.Color)
+            if (property != null)
             {
             {
                 guiField = new GUIColorField(new GUIContent(title));
                 guiField = new GUIColorField(new GUIContent(title));
                 guiField.OnChanged += OnFieldValueChanged;
                 guiField.OnChanged += OnFieldValueChanged;

+ 4 - 1
MBansheeEditor/Inspector/InspectableDictionary.cs

@@ -22,7 +22,7 @@ namespace BansheeEditor
         /// <param name="layout">Parent layout that all the field elements will be added to.</param>
         /// <param name="layout">Parent layout that all the field elements will be added to.</param>
         /// <param name="property">Serializable property referencing the dictionary whose contents to display.</param>
         /// <param name="property">Serializable property referencing the dictionary whose contents to display.</param>
         public InspectableDictionary(string title, int depth, InspectableFieldLayout layout, SerializableProperty property)
         public InspectableDictionary(string title, int depth, InspectableFieldLayout layout, SerializableProperty property)
-            : base(title, depth, layout, property)
+            : base(title, SerializableProperty.FieldType.Dictionary, depth, layout, property)
         {
         {
 
 
         }
         }
@@ -359,6 +359,9 @@ namespace BansheeEditor
             /// <inheritdoc/>
             /// <inheritdoc/>
             protected internal override InspectableState Refresh()
             protected internal override InspectableState Refresh()
             {
             {
+                fieldKey.Property = GetKey<SerializableProperty>();
+                fieldValue.Property = GetValue<SerializableProperty>();
+
                 return fieldValue.Refresh(0);
                 return fieldValue.Refresh(0);
             }
             }
         }
         }

+ 28 - 2
MBansheeEditor/Inspector/InspectableField.cs

@@ -15,21 +15,47 @@ namespace BansheeEditor
         protected SerializableProperty property;
         protected SerializableProperty property;
         protected string title;
         protected string title;
         protected int depth;
         protected int depth;
+        protected SerializableProperty.FieldType type; 
+
+        /// <summary>
+        /// Property this field is displaying contents of.
+        /// </summary>
+        public SerializableProperty Property
+        {
+            get { return property; }
+            set
+            {
+                if (value == null)
+                    throw new ArgumentException("Cannot assign a null property to an inspectable field.");
+
+                if (value.Type != type)
+                {
+                    throw new ArgumentException(
+                        "Attempting to initialize an inspectable field with a property of invalid type.");
+                }
+
+                property = value;
+            }
+        }
 
 
         /// <summary>
         /// <summary>
         /// Creates a new inspectable field GUI for the specified property.
         /// Creates a new inspectable field GUI for the specified property.
         /// </summary>
         /// </summary>
         /// <param name="title">Name of the property, or some other value to set as the title.</param>
         /// <param name="title">Name of the property, or some other value to set as the title.</param>
+        /// <param name="type">Type of property this field will be used for displaying.</param>
         /// <param name="depth">Determines how deep within the inspector nesting hierarchy is this field. Some fields may
         /// <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>
         ///                     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="layout">Parent layout that all the field elements will be added to.</param>
         /// <param name="property">Serializable property referencing the array whose contents to display.</param>
         /// <param name="property">Serializable property referencing the array whose contents to display.</param>
-        public InspectableField(string title, int depth, InspectableFieldLayout layout, SerializableProperty property)
+        public InspectableField(string title, SerializableProperty.FieldType type, 
+            int depth, InspectableFieldLayout layout, SerializableProperty property)
         {
         {
             this.layout = layout;
             this.layout = layout;
             this.title = title;
             this.title = title;
-            this.property = property;
+            this.type = type;
             this.depth = depth;
             this.depth = depth;
+
+            Property = property;
         }
         }
 
 
         /// <summary>
         /// <summary>

+ 2 - 2
MBansheeEditor/Inspector/InspectableFloat.cs

@@ -19,7 +19,7 @@ namespace BansheeEditor
         /// <param name="layout">Parent layout that all the field elements will be added to.</param>
         /// <param name="layout">Parent layout that all the field elements will be added to.</param>
         /// <param name="property">Serializable property referencing the array whose contents to display.</param>
         /// <param name="property">Serializable property referencing the array whose contents to display.</param>
         public InspectableFloat(string title, int depth, InspectableFieldLayout layout, SerializableProperty property)
         public InspectableFloat(string title, int depth, InspectableFieldLayout layout, SerializableProperty property)
-            : base(title, depth, layout, property)
+            : base(title, SerializableProperty.FieldType.Float, depth, layout, property)
         {
         {
 
 
         }
         }
@@ -27,7 +27,7 @@ namespace BansheeEditor
         /// <inheritoc/>
         /// <inheritoc/>
         protected internal override void Initialize(int layoutIndex)
         protected internal override void Initialize(int layoutIndex)
         {
         {
-            if (property.Type == SerializableProperty.FieldType.Float)
+            if (property != null)
             {
             {
                 guiFloatField = new GUIFloatField(new GUIContent(title));
                 guiFloatField = new GUIFloatField(new GUIContent(title));
                 guiFloatField.OnChanged += OnFieldValueChanged;
                 guiFloatField.OnChanged += OnFieldValueChanged;

+ 2 - 2
MBansheeEditor/Inspector/InspectableGameObjectRef.cs

@@ -19,7 +19,7 @@ namespace BansheeEditor
         /// <param name="layout">Parent layout that all the field elements will be added to.</param>
         /// <param name="layout">Parent layout that all the field elements will be added to.</param>
         /// <param name="property">Serializable property referencing the array whose contents to display.</param>
         /// <param name="property">Serializable property referencing the array whose contents to display.</param>
         public InspectableGameObjectRef(string title, int depth, InspectableFieldLayout layout, SerializableProperty property)
         public InspectableGameObjectRef(string title, int depth, InspectableFieldLayout layout, SerializableProperty property)
-            : base(title, depth, layout, property)
+            : base(title, SerializableProperty.FieldType.GameObjectRef, depth, layout, property)
         {
         {
 
 
         }
         }
@@ -27,7 +27,7 @@ namespace BansheeEditor
         /// <inheritoc/>
         /// <inheritoc/>
         protected internal override void Initialize(int layoutIndex)
         protected internal override void Initialize(int layoutIndex)
         {
         {
-            if (property.Type == SerializableProperty.FieldType.GameObjectRef)
+            if (property != null)
             {
             {
                 guiField = new GUIGameObjectField(property.InternalType, new GUIContent(title));
                 guiField = new GUIGameObjectField(property.InternalType, new GUIContent(title));
                 guiField.OnChanged += OnFieldValueChanged;
                 guiField.OnChanged += OnFieldValueChanged;

+ 2 - 2
MBansheeEditor/Inspector/InspectableInt.cs

@@ -19,7 +19,7 @@ namespace BansheeEditor
         /// <param name="layout">Parent layout that all the field elements will be added to.</param>
         /// <param name="layout">Parent layout that all the field elements will be added to.</param>
         /// <param name="property">Serializable property referencing the array whose contents to display.</param>
         /// <param name="property">Serializable property referencing the array whose contents to display.</param>
         public InspectableInt(string title, int depth, InspectableFieldLayout layout, SerializableProperty property)
         public InspectableInt(string title, int depth, InspectableFieldLayout layout, SerializableProperty property)
-            : base(title, depth, layout, property)
+            : base(title, SerializableProperty.FieldType.Int, depth, layout, property)
         {
         {
 
 
         }
         }
@@ -27,7 +27,7 @@ namespace BansheeEditor
         /// <inheritdoc/>
         /// <inheritdoc/>
         protected internal override void Initialize(int layoutIndex)
         protected internal override void Initialize(int layoutIndex)
         {
         {
-            if (property.Type == SerializableProperty.FieldType.Int)
+            if (property != null)
             {
             {
                 guiIntField = new GUIIntField(new GUIContent(title));
                 guiIntField = new GUIIntField(new GUIContent(title));
                 guiIntField.OnChanged += OnFieldValueChanged;
                 guiIntField.OnChanged += OnFieldValueChanged;

+ 5 - 7
MBansheeEditor/Inspector/InspectableList.cs

@@ -22,7 +22,7 @@ namespace BansheeEditor
         /// <param name="layout">Parent layout that all the field elements will be added to.</param>
         /// <param name="layout">Parent layout that all the field elements will be added to.</param>
         /// <param name="property">Serializable property referencing the list whose contents to display.</param>
         /// <param name="property">Serializable property referencing the list whose contents to display.</param>
         public InspectableList(string title, int depth, InspectableFieldLayout layout, SerializableProperty property)
         public InspectableList(string title, int depth, InspectableFieldLayout layout, SerializableProperty property)
-            : base(title, depth, layout, property)
+            : base(title, SerializableProperty.FieldType.List, depth, layout, property)
         {
         {
 
 
         }
         }
@@ -247,13 +247,10 @@ namespace BansheeEditor
             /// <inheritdoc/>
             /// <inheritdoc/>
             protected override GUILayoutX CreateGUI(GUILayoutY layout)
             protected override GUILayoutX CreateGUI(GUILayoutY layout)
             {
             {
-                if (field == null)
-                {
-                    SerializableProperty property = GetValue<SerializableProperty>();
+                SerializableProperty property = GetValue<SerializableProperty>();
 
 
-                    field = CreateInspectable(SeqIndex + ".", 0, Depth + 1,
-                        new InspectableFieldLayout(layout), property);
-                }
+                field = CreateInspectable(SeqIndex + ".", 0, Depth + 1,
+                    new InspectableFieldLayout(layout), property);
 
 
                 return field.GetTitleLayout();
                 return field.GetTitleLayout();
             }
             }
@@ -261,6 +258,7 @@ namespace BansheeEditor
             /// <inheritdoc/>
             /// <inheritdoc/>
             protected internal override InspectableState Refresh()
             protected internal override InspectableState Refresh()
             {
             {
+                field.Property = GetValue<SerializableProperty>();
                 return field.Refresh(0);
                 return field.Refresh(0);
             }
             }
         }
         }

+ 1 - 1
MBansheeEditor/Inspector/InspectableObject.cs

@@ -32,7 +32,7 @@ namespace BansheeEditor
         /// <param name="layout">Parent layout that all the field elements will be added to.</param>
         /// <param name="layout">Parent layout that all the field elements will be added to.</param>
         /// <param name="property">Serializable property referencing the array whose contents to display.</param>
         /// <param name="property">Serializable property referencing the array whose contents to display.</param>
         public InspectableObject(string title, int depth, InspectableFieldLayout layout, SerializableProperty property)
         public InspectableObject(string title, int depth, InspectableFieldLayout layout, SerializableProperty property)
-            : base(title, depth, layout, property)
+            : base(title, SerializableProperty.FieldType.Object, depth, layout, property)
         {
         {
             
             
         }
         }

+ 1 - 1
MBansheeEditor/Inspector/InspectableResourceRef.cs

@@ -19,7 +19,7 @@ namespace BansheeEditor
         /// <param name="layout">Parent layout that all the field elements will be added to.</param>
         /// <param name="layout">Parent layout that all the field elements will be added to.</param>
         /// <param name="property">Serializable property referencing the array whose contents to display.</param>
         /// <param name="property">Serializable property referencing the array whose contents to display.</param>
         public InspectableResourceRef(string title, int depth, InspectableFieldLayout layout, SerializableProperty property)
         public InspectableResourceRef(string title, int depth, InspectableFieldLayout layout, SerializableProperty property)
-            : base(title, depth, layout, property)
+            : base(title, SerializableProperty.FieldType.ResourceRef, depth, layout, property)
         {
         {
 
 
         }
         }

+ 1 - 1
MBansheeEditor/Inspector/InspectableString.cs

@@ -19,7 +19,7 @@ namespace BansheeEditor
         /// <param name="layout">Parent layout that all the field elements will be added to.</param>
         /// <param name="layout">Parent layout that all the field elements will be added to.</param>
         /// <param name="property">Serializable property referencing the array whose contents to display.</param>
         /// <param name="property">Serializable property referencing the array whose contents to display.</param>
         public InspectableString(string title, int depth, InspectableFieldLayout layout, SerializableProperty property)
         public InspectableString(string title, int depth, InspectableFieldLayout layout, SerializableProperty property)
-            : base(title, depth, layout, property)
+            : base(title, SerializableProperty.FieldType.String, depth, layout, property)
         {
         {
 
 
         }
         }

+ 1 - 1
MBansheeEditor/Inspector/InspectableVector2.cs

@@ -19,7 +19,7 @@ namespace BansheeEditor
         /// <param name="layout">Parent layout that all the field elements will be added to.</param>
         /// <param name="layout">Parent layout that all the field elements will be added to.</param>
         /// <param name="property">Serializable property referencing the array whose contents to display.</param>
         /// <param name="property">Serializable property referencing the array whose contents to display.</param>
         public InspectableVector2(string title, int depth, InspectableFieldLayout layout, SerializableProperty property)
         public InspectableVector2(string title, int depth, InspectableFieldLayout layout, SerializableProperty property)
-            : base(title, depth, layout, property)
+            : base(title, SerializableProperty.FieldType.Vector2, depth, layout, property)
         {
         {
 
 
         }
         }

+ 1 - 1
MBansheeEditor/Inspector/InspectableVector3.cs

@@ -19,7 +19,7 @@ namespace BansheeEditor
         /// <param name="layout">Parent layout that all the field elements will be added to.</param>
         /// <param name="layout">Parent layout that all the field elements will be added to.</param>
         /// <param name="property">Serializable property referencing the array whose contents to display.</param>
         /// <param name="property">Serializable property referencing the array whose contents to display.</param>
         public InspectableVector3(string title, int depth, InspectableFieldLayout layout, SerializableProperty property)
         public InspectableVector3(string title, int depth, InspectableFieldLayout layout, SerializableProperty property)
-            : base(title, depth, layout, property)
+            : base(title, SerializableProperty.FieldType.Vector3, depth, layout, property)
         {
         {
 
 
         }
         }

+ 1 - 1
MBansheeEditor/Inspector/InspectableVector4.cs

@@ -19,7 +19,7 @@ namespace BansheeEditor
         /// <param name="layout">Parent layout that all the field elements will be added to.</param>
         /// <param name="layout">Parent layout that all the field elements will be added to.</param>
         /// <param name="property">Serializable property referencing the array whose contents to display.</param>
         /// <param name="property">Serializable property referencing the array whose contents to display.</param>
         public InspectableVector4(string title, int depth, InspectableFieldLayout layout, SerializableProperty property)
         public InspectableVector4(string title, int depth, InspectableFieldLayout layout, SerializableProperty property)
-            : base(title, depth, layout, property)
+            : base(title, SerializableProperty.FieldType.Vector4, depth, layout, property)
         {
         {
 
 
         }
         }

+ 61 - 50
MBansheeEditor/Inspectors/GUISkinInspector.cs

@@ -121,12 +121,10 @@ namespace BansheeEditor
             /// <inheritdoc/>
             /// <inheritdoc/>
             protected override void CreateValueGUI(GUILayoutY layout)
             protected override void CreateValueGUI(GUILayoutY layout)
             {
             {
-                GUIElementStyle value = GetValue<GUIElementStyle>();
-
                 if(valueField == null)
                 if(valueField == null)
                     valueField = new GUIElementStyleGUI();
                     valueField = new GUIElementStyleGUI();
 
 
-                valueField.BuildGUI(value, layout, Depth);
+                valueField.BuildGUI(layout, Depth);
             }
             }
 
 
             /// <inheritdoc/>
             /// <inheritdoc/>
@@ -139,7 +137,7 @@ namespace BansheeEditor
             internal protected override InspectableState Refresh()
             internal protected override InspectableState Refresh()
             {
             {
                 keyField.Value = GetKey<string>();
                 keyField.Value = GetKey<string>();
-                return valueField.Refresh();
+                return valueField.Refresh(GetValue<GUIElementStyle>());
             }
             }
         }
         }
 
 
@@ -202,13 +200,10 @@ namespace BansheeEditor
             /// <summary>
             /// <summary>
             /// Builds GUI for the specified GUI element style.
             /// Builds GUI for the specified GUI element style.
             /// </summary>
             /// </summary>
-            /// <param name="style">Style to display in the GUI.</param>
             /// <param name="layout">Layout to append the GUI elements to.</param>
             /// <param name="layout">Layout to append the GUI elements to.</param>
             /// <param name="depth">Determines the depth at which the element is rendered.</param>
             /// <param name="depth">Determines the depth at which the element is rendered.</param>
-            public void BuildGUI(GUIElementStyle style, GUILayout layout, int depth)
+            public void BuildGUI(GUILayout layout, int depth)
             {
             {
-                this.style = style;
-
                 short backgroundDepth = (short)(Inspector.START_BACKGROUND_DEPTH - depth - 1);
                 short backgroundDepth = (short)(Inspector.START_BACKGROUND_DEPTH - depth - 1);
                 string bgPanelStyle = depth % 2 == 0
                 string bgPanelStyle = depth % 2 == 0
                     ? EditorStyles.InspectorContentBgAlternate
                     ? EditorStyles.InspectorContentBgAlternate
@@ -245,18 +240,18 @@ namespace BansheeEditor
                 contentLayout.AddElement(imagePositionField);
                 contentLayout.AddElement(imagePositionField);
                 contentLayout.AddElement(wordWrapField);
                 contentLayout.AddElement(wordWrapField);
 
 
-                normalGUI.BuildGUI(new LocEdString("Normal"), style.Normal, contentLayout);
-                hoverGUI.BuildGUI(new LocEdString("Hover"), style.Hover, contentLayout);
-                activeGUI.BuildGUI(new LocEdString("Active"), style.Active, contentLayout);
-                focusedGUI.BuildGUI(new LocEdString("Focused"), style.Focused, contentLayout);
-                normalOnGUI.BuildGUI(new LocEdString("NormalOn"), style.NormalOn, contentLayout);
-                hoverOnGUI.BuildGUI(new LocEdString("HoverOn"), style.HoverOn, contentLayout);
-                activeOnGUI.BuildGUI(new LocEdString("ActiveOn"), style.ActiveOn, contentLayout);
-                focusedOnGUI.BuildGUI(new LocEdString("FocusedOn"), style.FocusedOn, contentLayout);
+                normalGUI.BuildGUI(new LocEdString("Normal"), contentLayout);
+                hoverGUI.BuildGUI(new LocEdString("Hover"), contentLayout);
+                activeGUI.BuildGUI(new LocEdString("Active"), contentLayout);
+                focusedGUI.BuildGUI(new LocEdString("Focused"), contentLayout);
+                normalOnGUI.BuildGUI(new LocEdString("NormalOn"), contentLayout);
+                hoverOnGUI.BuildGUI(new LocEdString("HoverOn"), contentLayout);
+                activeOnGUI.BuildGUI(new LocEdString("ActiveOn"), contentLayout);
+                focusedOnGUI.BuildGUI(new LocEdString("FocusedOn"), contentLayout);
 
 
-                borderGUI = new RectOffsetGUI(new LocEdString("Border"), style.Border, contentLayout);
-                marginsGUI = new RectOffsetGUI(new LocEdString("Margins"), style.Margins, contentLayout);
-                contentOffsetGUI = new RectOffsetGUI(new LocEdString("Content offset"), style.ContentOffset, contentLayout);
+                borderGUI = new RectOffsetGUI(new LocEdString("Border"), contentLayout);
+                marginsGUI = new RectOffsetGUI(new LocEdString("Margins"), contentLayout);
+                contentOffsetGUI = new RectOffsetGUI(new LocEdString("Content offset"), contentLayout);
 
 
                 fixedWidthField = new GUIToggleField(new LocEdString("Fixed width"));
                 fixedWidthField = new GUIToggleField(new LocEdString("Fixed width"));
                 widthField = new GUIIntField(new LocEdString("Width"));
                 widthField = new GUIIntField(new LocEdString("Width"));
@@ -284,66 +279,66 @@ namespace BansheeEditor
                     isExpanded = x;
                     isExpanded = x;
                 };
                 };
 
 
-                fontField.OnChanged += x => { style.Font = (Font) x; MarkAsModified(); ConfirmModify(); };
-                fontSizeField.OnChanged += x => { style.FontSize = x; MarkAsModified(); };
+                fontField.OnChanged += x => { GetStyle().Font = (Font) x; MarkAsModified(); ConfirmModify(); };
+                fontSizeField.OnChanged += x => { GetStyle().FontSize = x; MarkAsModified(); };
                 fontSizeField.OnFocusLost += ConfirmModify;
                 fontSizeField.OnFocusLost += ConfirmModify;
                 fontSizeField.OnConfirmed += ConfirmModify;
                 fontSizeField.OnConfirmed += ConfirmModify;
                 horzAlignField.OnSelectionChanged += x =>
                 horzAlignField.OnSelectionChanged += x =>
                 {
                 {
-                    style.TextHorzAlign = (TextHorzAlign)x; 
+                    GetStyle().TextHorzAlign = (TextHorzAlign)x; 
                     MarkAsModified(); 
                     MarkAsModified(); 
                     ConfirmModify();
                     ConfirmModify();
                 };
                 };
                 vertAlignField.OnSelectionChanged += x =>
                 vertAlignField.OnSelectionChanged += x =>
                 {
                 {
-                    style.TextVertAlign = (TextVertAlign)x; 
+                    GetStyle().TextVertAlign = (TextVertAlign)x; 
                     MarkAsModified(); 
                     MarkAsModified(); 
                     ConfirmModify();
                     ConfirmModify();
                 };
                 };
                 imagePositionField.OnSelectionChanged += x =>
                 imagePositionField.OnSelectionChanged += x =>
                 {
                 {
-                    style.ImagePosition = (GUIImagePosition)x; 
+                    GetStyle().ImagePosition = (GUIImagePosition)x; 
                     MarkAsModified(); 
                     MarkAsModified(); 
                     ConfirmModify();
                     ConfirmModify();
                 };
                 };
-                wordWrapField.OnChanged += x => { style.WordWrap = x; MarkAsModified(); ConfirmModify(); };
+                wordWrapField.OnChanged += x => { GetStyle().WordWrap = x; MarkAsModified(); ConfirmModify(); };
 
 
-                normalGUI.OnChanged += x => {style.Normal = x; MarkAsModified(); ConfirmModify(); };
-                hoverGUI.OnChanged += x => {style.Hover = x; MarkAsModified(); ConfirmModify(); };
-                activeGUI.OnChanged += x => {style.Active = x; MarkAsModified(); ConfirmModify(); };
-                focusedGUI.OnChanged += x => {style.Focused = x; MarkAsModified(); ConfirmModify(); };
-                normalOnGUI.OnChanged += x => {style.NormalOn = x; MarkAsModified(); ConfirmModify(); };
-                hoverOnGUI.OnChanged += x => {style.HoverOn = x; MarkAsModified(); ConfirmModify(); };
-                activeOnGUI.OnChanged += x => {style.ActiveOn = x; MarkAsModified(); ConfirmModify(); };
-                focusedOnGUI.OnChanged += x => { style.FocusedOn = x; MarkAsModified(); ConfirmModify(); };
+                normalGUI.OnChanged += x => { GetStyle().Normal = x; MarkAsModified(); ConfirmModify(); };
+                hoverGUI.OnChanged += x => { GetStyle().Hover = x; MarkAsModified(); ConfirmModify(); };
+                activeGUI.OnChanged += x => { GetStyle().Active = x; MarkAsModified(); ConfirmModify(); };
+                focusedGUI.OnChanged += x => { GetStyle().Focused = x; MarkAsModified(); ConfirmModify(); };
+                normalOnGUI.OnChanged += x => { GetStyle().NormalOn = x; MarkAsModified(); ConfirmModify(); };
+                hoverOnGUI.OnChanged += x => { GetStyle().HoverOn = x; MarkAsModified(); ConfirmModify(); };
+                activeOnGUI.OnChanged += x => { GetStyle().ActiveOn = x; MarkAsModified(); ConfirmModify(); };
+                focusedOnGUI.OnChanged += x => { GetStyle().FocusedOn = x; MarkAsModified(); ConfirmModify(); };
 
 
-                borderGUI.OnChanged += x => { style.Border = x; MarkAsModified(); };
-                marginsGUI.OnChanged += x => { style.Margins = x; MarkAsModified(); };
-                contentOffsetGUI.OnChanged += x => { style.ContentOffset = x; MarkAsModified(); };
+                borderGUI.OnChanged += x => { GetStyle().Border = x; MarkAsModified(); };
+                marginsGUI.OnChanged += x => { GetStyle().Margins = x; MarkAsModified(); };
+                contentOffsetGUI.OnChanged += x => { GetStyle().ContentOffset = x; MarkAsModified(); };
 
 
                 borderGUI.OnConfirmed += ConfirmModify;
                 borderGUI.OnConfirmed += ConfirmModify;
                 marginsGUI.OnConfirmed += ConfirmModify;
                 marginsGUI.OnConfirmed += ConfirmModify;
                 contentOffsetGUI.OnConfirmed += ConfirmModify;
                 contentOffsetGUI.OnConfirmed += ConfirmModify;
 
 
-                fixedWidthField.OnChanged += x => { style.FixedWidth = x; MarkAsModified(); ConfirmModify(); };
-                widthField.OnChanged += x => style.Width = x;
+                fixedWidthField.OnChanged += x => { GetStyle().FixedWidth = x; MarkAsModified(); ConfirmModify(); };
+                widthField.OnChanged += x => GetStyle().Width = x;
                 widthField.OnFocusLost += ConfirmModify;
                 widthField.OnFocusLost += ConfirmModify;
                 widthField.OnConfirmed += ConfirmModify;
                 widthField.OnConfirmed += ConfirmModify;
-                minWidthField.OnChanged += x => style.MinWidth = x;
+                minWidthField.OnChanged += x => GetStyle().MinWidth = x;
                 minWidthField.OnFocusLost += ConfirmModify;
                 minWidthField.OnFocusLost += ConfirmModify;
                 minWidthField.OnConfirmed += ConfirmModify;
                 minWidthField.OnConfirmed += ConfirmModify;
-                maxWidthField.OnChanged += x => style.MaxWidth = x;
+                maxWidthField.OnChanged += x => GetStyle().MaxWidth = x;
                 maxWidthField.OnFocusLost += ConfirmModify;
                 maxWidthField.OnFocusLost += ConfirmModify;
                 maxWidthField.OnConfirmed += ConfirmModify;
                 maxWidthField.OnConfirmed += ConfirmModify;
 
 
-                fixedHeightField.OnChanged += x => { style.FixedHeight = x; MarkAsModified(); ConfirmModify(); };
-                heightField.OnChanged += x => style.Height = x;
+                fixedHeightField.OnChanged += x => { GetStyle().FixedHeight = x; MarkAsModified(); ConfirmModify(); };
+                heightField.OnChanged += x => GetStyle().Height = x;
                 heightField.OnFocusLost += ConfirmModify;
                 heightField.OnFocusLost += ConfirmModify;
                 heightField.OnConfirmed += ConfirmModify;
                 heightField.OnConfirmed += ConfirmModify;
-                minHeightField.OnChanged += x => style.MinHeight = x;
+                minHeightField.OnChanged += x => GetStyle().MinHeight = x;
                 minHeightField.OnFocusLost += ConfirmModify;
                 minHeightField.OnFocusLost += ConfirmModify;
                 minHeightField.OnConfirmed += ConfirmModify;
                 minHeightField.OnConfirmed += ConfirmModify;
-                maxHeightField.OnChanged += x => style.MaxHeight = x;
+                maxHeightField.OnChanged += x => GetStyle().MaxHeight = x;
                 maxHeightField.OnFocusLost += ConfirmModify;
                 maxHeightField.OnFocusLost += ConfirmModify;
                 maxHeightField.OnConfirmed += ConfirmModify;
                 maxHeightField.OnConfirmed += ConfirmModify;
 
 
@@ -354,9 +349,12 @@ namespace BansheeEditor
             /// <summary>
             /// <summary>
             /// Updates all GUI elements from the style if style changes.
             /// Updates all GUI elements from the style if style changes.
             /// </summary>
             /// </summary>
+            /// <param name="style">Style to display in the GUI.</param>
             /// <returns>State representing was anything modified between two last calls to <see cref="Refresh"/>.</returns>
             /// <returns>State representing was anything modified between two last calls to <see cref="Refresh"/>.</returns>
-            public InspectableState Refresh()
+            public InspectableState Refresh(GUIElementStyle style)
             {
             {
+                this.style = style;
+
                 InspectableState oldModifiedState = modifiedState;
                 InspectableState oldModifiedState = modifiedState;
                 if (modifiedState.HasFlag(InspectableState.Modified))
                 if (modifiedState.HasFlag(InspectableState.Modified))
                     modifiedState = InspectableState.NotModified;
                     modifiedState = InspectableState.NotModified;
@@ -404,6 +402,15 @@ namespace BansheeEditor
                 return oldModifiedState;
                 return oldModifiedState;
             }
             }
 
 
+            /// <summary>
+            /// Returns the style displayed in the GUI.
+            /// </summary>
+            /// <returns>Style displayed in the GUI.</returns>
+            private GUIElementStyle GetStyle()
+            {
+                return style;
+            }
+
             /// <summary>
             /// <summary>
             /// Marks the contents of the style as modified.
             /// Marks the contents of the style as modified.
             /// </summary>
             /// </summary>
@@ -426,6 +433,7 @@ namespace BansheeEditor
             /// </summary>
             /// </summary>
             private class GUIElementStateStyleGUI
             private class GUIElementStateStyleGUI
             {
             {
+                private GUIElementStateStyle state;
                 private GUIToggle foldout;
                 private GUIToggle foldout;
                 private GUIResourceField textureField;
                 private GUIResourceField textureField;
                 private GUIColorField textColorField;
                 private GUIColorField textColorField;
@@ -446,9 +454,8 @@ namespace BansheeEditor
                 /// Builds the GUI for the specified state style.
                 /// Builds the GUI for the specified state style.
                 /// </summary>
                 /// </summary>
                 /// <param name="title">Text to display on the title bar.</param>
                 /// <param name="title">Text to display on the title bar.</param>
-                /// <param name="state">State object to display in the GUI.</param>
                 /// <param name="layout">Layout to append the GUI elements to.</param>
                 /// <param name="layout">Layout to append the GUI elements to.</param>
-                public void BuildGUI(LocString title, GUIElementStateStyle state, GUILayout layout)
+                public void BuildGUI(LocString title, GUILayout layout)
                 {
                 {
                     foldout = new GUIToggle(title, EditorStyles.Foldout);
                     foldout = new GUIToggle(title, EditorStyles.Foldout);
                     textureField = new GUIResourceField(typeof(SpriteTexture), new LocEdString("Texture"));
                     textureField = new GUIResourceField(typeof(SpriteTexture), new LocEdString("Texture"));
@@ -489,9 +496,11 @@ namespace BansheeEditor
                 /// <summary>
                 /// <summary>
                 /// Updates all GUI elements from the current state values.
                 /// Updates all GUI elements from the current state values.
                 /// </summary>
                 /// </summary>
-                /// <param name="state">State to update the GUI to.</param>
+                /// <param name="state">State object to display in the GUI.</param>
                 public void Refresh(GUIElementStateStyle state)
                 public void Refresh(GUIElementStateStyle state)
                 {
                 {
+                    this.state = state;
+
                     textureField.Value = state.Texture;
                     textureField.Value = state.Texture;
                     textColorField.Value = state.TextColor;
                     textColorField.Value = state.TextColor;
                 }
                 }
@@ -502,6 +511,7 @@ namespace BansheeEditor
             /// </summary>
             /// </summary>
             private class RectOffsetGUI
             private class RectOffsetGUI
             {
             {
+                private RectOffset offset;
                 private GUIIntField offsetLeftField;
                 private GUIIntField offsetLeftField;
                 private GUIIntField offsetRightField;
                 private GUIIntField offsetRightField;
                 private GUIIntField offsetTopField;
                 private GUIIntField offsetTopField;
@@ -521,9 +531,8 @@ namespace BansheeEditor
                 /// Creates a new rectangle offset GUI.
                 /// Creates a new rectangle offset GUI.
                 /// </summary>
                 /// </summary>
                 /// <param name="title">Text to display on the title bar.</param>
                 /// <param name="title">Text to display on the title bar.</param>
-                /// <param name="offset">Rectangle offset object to display in the GUI.</param>
                 /// <param name="layout">Layout to append the GUI elements to.</param>
                 /// <param name="layout">Layout to append the GUI elements to.</param>
-                public RectOffsetGUI(LocString title, RectOffset offset, GUILayout layout)
+                public RectOffsetGUI(LocString title, GUILayout layout)
                 {
                 {
                     GUILayoutX rectLayout = layout.AddLayoutX();
                     GUILayoutX rectLayout = layout.AddLayoutX();
                     rectLayout.AddElement(new GUILabel(title, GUIOption.FixedWidth(100)));
                     rectLayout.AddElement(new GUILabel(title, GUIOption.FixedWidth(100)));
@@ -596,6 +605,8 @@ namespace BansheeEditor
                 /// <param name="offset">Offset to update the GUI to.</param>
                 /// <param name="offset">Offset to update the GUI to.</param>
                 public void Refresh(RectOffset offset)
                 public void Refresh(RectOffset offset)
                 {
                 {
+                    this.offset = offset;
+
                     offsetLeftField.Value = offset.left;
                     offsetLeftField.Value = offset.left;
                     offsetRightField.Value = offset.right;
                     offsetRightField.Value = offset.right;
                     offsetTopField.Value = offset.top;
                     offsetTopField.Value = offset.top;