Browse Source

Foldout expand/collapse callbacks work

Marko Pintera 11 years ago
parent
commit
8f22d0d2a1

+ 2 - 1
BansheeEditor/Include/BsGUIFoldout.h

@@ -33,7 +33,8 @@ namespace BansheeEngine
 	protected:
 		virtual ~GUIFoldout();
 
-	protected:
+		void toggleTriggered(bool value);
+
 		static const String FOLDOUT_BUTTON_STYLE;
 		static const String FOLDOUT_BG_STYLE;
 		static const String FOLDOUT_LABEL_STYLE;

+ 13 - 0
BansheeEditor/Source/BsGUIFoldout.cpp

@@ -8,6 +8,8 @@
 #include "BsGUIWidget.h"
 #include "BsGUIMouseEvent.h"
 
+using namespace std::placeholders;
+
 namespace BansheeEngine
 {
 	const String GUIFoldout::FOLDOUT_BUTTON_STYLE = "FoldoutButton";
@@ -25,6 +27,8 @@ namespace BansheeEngine
 		_registerChildElement(mLabel);
 		_registerChildElement(mToggle);
 		_registerChildElement(mBackground);
+
+		mToggle->onToggled.connect(std::bind(&GUIFoldout::toggleTriggered, this, _1));
 	}
 
 	GUIFoldout::~GUIFoldout()
@@ -88,6 +92,15 @@ namespace BansheeEngine
 		}
 	}
 
+	void GUIFoldout::toggleTriggered(bool value)
+	{
+		mIsExpanded = value;
+
+		markContentAsDirty();
+
+		onStateChanged(value);
+	}
+
 	void GUIFoldout::_updateLayoutInternal(INT32 x, INT32 y, UINT32 width, UINT32 height,
 		RectI clipRect, UINT8 widgetDepth, UINT16 areaDepth)
 	{

+ 17 - 10
Inspector.txt

@@ -1,25 +1,18 @@
 Update C# GUIElementStyle
+Update GUIFoldout with sub styles
 
 TODO:
  - Hook up int field set/get callbacks
     - Ensure int field isn't updated from app when in focus
- - Hook up foldout expand/collapse callbacks
  - Think about how to handle arrays, adding and deleting elements from them.
    - Will likely need GUILayout::GetElementIndex()
  - I should add project and scene tree views to the main editor window to make inspector testing easier
  - Entire foldout should be clickable, not just the toggle button
  - Extend text field so it can be multi-line
  - Port to C#:
-   - IntField
-   - FloatField
-   - ColorField
-   - ToggleField
-   - TextField
-   - Vector2Field
-   - Vector3Field
-   - Vector4Field
    - GameObjectField
    - ResourceField
+   - Create InspectableObjects for all different field types
  - Ensure get/set value from inspector fields works 
  - Add array fields and ensure they work/update properly
  - Extend GameObject field so it can only accept a certain type
@@ -33,7 +26,10 @@ TODO:
 
 TO PONDER:
  - How to limit resource/object fields to a custom type (user created type possibly)
- - Need to figure out a better way of setting styles for container GUI elements (e.g. GUIFoldout requires three different styles)
+ - How will I create undo/redo operations for serializable fields?
+   - UndoRedo.RecordField - Saves current state of the field, before you modify it
+     - Accepts a source object and a path that allows us to follow its properties to the exact modified field
+	 - Source object will be stored by its ID (it can either be GameObject or Resource, nothing else)
 
 KEEP IN MIND:
  - Clicking on an object/resource in inspector should ping it in their window
@@ -57,6 +53,17 @@ KEEP IN MIND:
 
 
 
+
+
+
+
+
+
+
+
+
+
+
 
 
 

+ 18 - 0
MBansheeEditor/GUI/GUIFoldout.cs

@@ -30,6 +30,18 @@ namespace BansheeEditor
             Internal_SetContent(mCachedPtr, content);
         }
 
+        public bool IsExpanded()
+        {
+            bool expanded;
+            Internal_IsExpanded(mCachedPtr, out expanded);
+            return expanded;
+        }
+
+        public void SetExpanded(bool expanded)
+        {
+            Internal_SetExpanded(mCachedPtr, expanded);
+        }
+
         private void DoOnToggled(bool expanded)
         {
             if (OnToggled != null)
@@ -41,5 +53,11 @@ namespace BansheeEditor
 
         [MethodImpl(MethodImplOptions.InternalCall)]
         private static extern void Internal_SetContent(IntPtr nativeInstance, GUIContent content);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_SetExpanded(IntPtr nativeInstance, bool expanded);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_IsExpanded(IntPtr nativeInstance, out bool expanded);
     }
 }

+ 11 - 3
MBansheeEditor/Inspector/InspectorWindow.cs

@@ -11,6 +11,7 @@ namespace BansheeEditor
             public GUIFoldout foldout;
             public GUIPanelContainer container;
             public Inspector inspector;
+            public bool expanded = true;
         }
 
         private List<InspectorData> inspectorData = new List<InspectorData>();
@@ -38,7 +39,8 @@ namespace BansheeEditor
                 data.inspector = GetInspector(allComponents[i].GetType());
                 data.inspector.Initialize(inspectorPanel, allComponents[i]);
 
-                data.foldout.OnToggled += (bool expanded) => Foldout_OnToggled(data.inspector, expanded);
+                data.foldout.SetExpanded(true);
+                data.foldout.OnToggled += (bool expanded) => Foldout_OnToggled(data, expanded);
 
                 inspectorData.Add(data);
             }
@@ -48,9 +50,12 @@ namespace BansheeEditor
             RepositionInspectors();
         }
 
-        void Foldout_OnToggled(Inspector inspector, bool expanded)
+        void Foldout_OnToggled(InspectorData inspectorData, bool expanded)
         {
-            inspector.SetVisible(expanded);
+            inspectorData.expanded = expanded;
+            inspectorData.inspector.SetVisible(expanded);
+
+            RepositionInspectors();
         }
 
         internal void Refresh()
@@ -97,6 +102,9 @@ namespace BansheeEditor
             {
                 int inspectorHeight = inspectorData[i].inspector.GetOptimalHeight();
 
+                if (!inspectorData[i].expanded)
+                    inspectorHeight = 0;
+
                 inspectorData[i].inspector.SetArea(0, curPosition, width, inspectorHeight);
                 inspectorData[i].container.SetLayoutOptions(GUIOption.FixedHeight(inspectorHeight));
                 curPosition += inspectorHeight;

+ 2 - 0
SBansheeEditor/Include/BsScriptGUIFoldout.h

@@ -13,6 +13,8 @@ namespace BansheeEngine
 	private:
 		static void internal_createInstance(MonoObject* instance, MonoObject* content, MonoString* style, MonoArray* guiOptions);
 		static void internal_setContent(ScriptGUIFoldout* nativeInstance, MonoObject* content);
+		static void internal_setExpanded(ScriptGUIFoldout* nativeInstance, bool expanded);
+		static void internal_getIsExpanded(ScriptGUIFoldout* nativeInstance, bool* isExpanded);
 
 		static void onToggled(MonoObject* instance, bool expanded);
 

+ 16 - 0
SBansheeEditor/Source/BsScriptGUIFoldout.cpp

@@ -32,6 +32,8 @@ namespace BansheeEngine
 	{
 		metaData.scriptClass->addInternalCall("Internal_CreateInstance", &ScriptGUIFoldout::internal_createInstance);
 		metaData.scriptClass->addInternalCall("Internal_SetContent", &ScriptGUIFoldout::internal_setContent);
+		metaData.scriptClass->addInternalCall("Internal_SetExpanded", &ScriptGUIFoldout::internal_setExpanded);
+		metaData.scriptClass->addInternalCall("Internal_IsExpanded", &ScriptGUIFoldout::internal_getIsExpanded);
 
 		onToggledThunk = (OnToggledThunkDef)metaData.scriptClass->getMethod("DoOnToggled", 1).getThunk();
 	}
@@ -59,6 +61,20 @@ namespace BansheeEngine
 		// TODO - Update GUIFoldout once it has a label
 	}
 
+	void ScriptGUIFoldout::internal_setExpanded(ScriptGUIFoldout* nativeInstance, bool expanded)
+	{
+		GUIFoldout* foldout = static_cast<GUIFoldout*>(nativeInstance->getGUIElement());
+
+		foldout->setExpanded(expanded);
+	}
+
+	void ScriptGUIFoldout::internal_getIsExpanded(ScriptGUIFoldout* nativeInstance, bool* isExpanded)
+	{
+		GUIFoldout* foldout = static_cast<GUIFoldout*>(nativeInstance->getGUIElement());
+
+		*isExpanded = foldout->isExpanded();
+	}
+
 	void ScriptGUIFoldout::onToggled(MonoObject* instance, bool expanded)
 	{
 		MonoException* exception = nullptr;