Browse Source

Array inspector buttons work

Marko Pintera 11 years ago
parent
commit
e3cab25c32

+ 1 - 1
BansheeEditor/Source/BsGUIResourceTreeView.cpp

@@ -449,7 +449,7 @@ namespace BansheeEngine
 	{
 		GUITreeView::_changeParentWidget(widget);
 
-		if(widget->getTarget()->getTarget()->isWindow())
+		if (widget != nullptr && widget->getTarget()->getTarget()->isWindow())
 		{
 			RenderWindow* parentWindow = static_cast<RenderWindow*>(widget->getTarget()->getTarget().get());
 			setDropTarget(parentWindow, _getOffset().x, _getOffset().y, _getWidth(), _getHeight());

+ 3 - 7
Inspector.txt

@@ -5,6 +5,8 @@ Test if drag and dropping scene objects works with object and resource fields. E
 
 Test clone method in SerializableProperty
 
+There an error on exit with GUI, likely due to new destruction scheme. I will likely need to adjust C# code so it marks all children as destroyed when parent is destroyed.
+
 Test custom resources:
  - Can I load them? (Will likely need ProjectLIbrary::load)
  - Can I reference them in Component and will the reference be held after after cloning?
@@ -16,14 +18,8 @@ ARRAY
    3. [_________] [X] [C] [^] [¡]
 
 ARRAY TODO:
- - Add a size field and a resize button that updates the array
- - Add Delete/Clone/MoveUp/MoveDown buttons
- - Ensure that case when array is null is handled properly. Will likely need a [Create] button
+ - Ensure that case when array is null is handled properly. Will likely need a [Create] button. And a [Clear] button?
  - Need a GUIFoldout that doesn't have BG and is just a single button.
- - Add IntField that has min/max limits so it cannot go below 0 for array size
-
-Need code for cloning an array element (or pretty much any element)
-Hook up array buttons
 
 TODO:
  - Hook up int field set/get callbacks

+ 1 - 1
MBansheeEditor/DbgCustomInspector.cs

@@ -6,7 +6,7 @@ namespace BansheeEditor
     [CustomInspector(typeof(DbgComponent))]
     public class DbgCustomInspector : Inspector
     {
-        internal override void Refresh()
+        internal override bool Refresh()
         {
             throw new NotImplementedException();
         }

+ 6 - 2
MBansheeEditor/Inspector/GenericInspector.cs

@@ -33,17 +33,21 @@ namespace BansheeEditor
             isInitialized = true;
         }
 
-        internal override void Refresh()
+        internal override bool Refresh()
         {
             if (!isInitialized)
                 Initialize();
 
+            bool anythingModified = false;
+
             int currentIndex = 0;
             foreach (var field in inspectableFields)
             {
-                field.Refresh(currentIndex);
+                anythingModified |= field.Refresh(currentIndex);
                 currentIndex += field.GetNumLayoutElements();
             }
+
+            return anythingModified;
         }
 
         internal override int GetOptimalHeight()

+ 2 - 1
MBansheeEditor/Inspector/InspectableArray.cs

@@ -79,7 +79,6 @@ namespace BansheeEditor
 
             guiLabel = new GUILabel(title); // TODO - Add foldout and hook up its callbacks
             guiSizeField = new GUIIntField();
-            guiSizeField.Value = property.GetArray().GetLength();
             guiSizeField.SetRange(0, int.MaxValue);
             guiResizeBtn = new GUIButton("Resize");
             guiResizeBtn.OnClick += OnResizeButtonClicked;
@@ -142,6 +141,8 @@ namespace BansheeEditor
 
                 childObj.Refresh(0);
             }
+
+            guiSizeField.Value = numArrayElements;
         }
 
         private void OnResizeButtonClicked()

+ 9 - 2
MBansheeEditor/Inspector/InspectableObjectBase.cs

@@ -41,17 +41,24 @@ namespace BansheeEditor
             child.parent = null;
         }
 
-        public virtual void Refresh(int layoutIndex)
+        public virtual bool Refresh(int layoutIndex)
         {
+            bool anythingModified = false;
+
             if (IsModified())
+            {
                 Update(layoutIndex);
+                anythingModified = true;
+            }
 
             int currentIndex = 0;
             for (int i = 0; i < children.Count; i++)
             {
-                children[i].Refresh(currentIndex);
+                anythingModified |= children[i].Refresh(currentIndex);
                 currentIndex += children[i].GetNumLayoutElements();
             }
+
+            return anythingModified;
         }
 
         public int GetNumLayoutElements()

+ 1 - 1
MBansheeEditor/Inspector/Inspector.cs

@@ -35,7 +35,7 @@ namespace BansheeEditor
             GUI.Destroy();
         }
 
-        internal abstract void Refresh();
+        internal abstract bool Refresh();
         internal abstract int GetOptimalHeight();
     }
 }

+ 8 - 1
MBansheeEditor/Inspector/InspectorWindow.cs

@@ -60,8 +60,15 @@ namespace BansheeEditor
 
         internal void Refresh()
         {
+            bool anythingModified = false;
+
             for (int i = 0; i < inspectorData.Count; i++)
-                inspectorData[i].inspector.Refresh();
+            {
+                anythingModified |= inspectorData[i].inspector.Refresh();
+            }
+
+            if (anythingModified)
+                RepositionInspectors();
         }
 
         internal void Destroy()

+ 1 - 6
MBansheeEngine/Program.cs

@@ -111,16 +111,11 @@ namespace BansheeEngine
 
         [MethodImpl(MethodImplOptions.InternalCall)]
         private static extern void UnitTest1_GameObjectClone(SceneObject so);
+
         static void Main()
         {
             UnitTest1_ManagedSerialization();
 
-            //Color newColor = Color.red;
-
-            //dbgStyle.textColor = newColor;
-            //Color myColor = dbgStyle.textColor;
-            //dbgStyle.textColor = myColor;
-
             SerializableObject obj = new SerializableObject(typeof(DbgSerzCls), new DbgSerzCls());
 
             Debug.Log(obj.fields.Length);

+ 1 - 1
SBansheeEngine/Include/BsScriptGUIElement.h

@@ -75,7 +75,7 @@ namespace BansheeEngine
 		{
 			// Elements with a GUIWidget parent are destroyed automatically when widget is destroyed, but those without one
 			// we need to destroy manually.
-			if (getGUIElement()->_getParentWidget() == nullptr)
+			if (!mIsDestroyed && getGUIElement()->_getParentWidget() == nullptr)
 				destroy();
 
 			ScriptObject::_onManagedInstanceDeleted();