Browse Source

New files I forgot in previous commit

Marko Pintera 11 years ago
parent
commit
b22d69742d

+ 33 - 0
MBansheeEditor/Inspector/Inspector.cs

@@ -0,0 +1,33 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using BansheeEngine;
+
+namespace BansheeEditor
+{
+    public abstract class Inspector
+    {
+        protected GUIPanel GUI;
+        protected SerializableObject serializableObject;
+
+        internal void Initialize(GUIPanel gui, object instance)
+        {
+            GUI = gui;
+            serializableObject = new SerializableObject(instance);
+        }
+
+        internal void SetArea(int x, int y, int width, int height)
+        {
+            GUI.SetArea(x, y, width, height);
+        }
+
+        internal void Destroy()
+        {
+            GUI.Destroy();
+        }
+
+        internal abstract void Refresh();
+        internal abstract int GetOptimalHeight();
+    }
+}

+ 79 - 0
MBansheeEditor/Inspector/InspectorWindow.cs

@@ -0,0 +1,79 @@
+using System;
+using System.Collections.Generic;
+using BansheeEngine;
+
+namespace BansheeEditor
+{
+    internal sealed class InspectorWindow : EditorWindow
+    {
+        private List<Inspector> inspectors = new List<Inspector>();
+
+        internal void Initialize(SceneObject so)
+        {
+            Clear();
+
+            // TODO - Create SceneObject gui elements (name + transform)
+
+            Component[] allComponents = so.GetComponents();
+            for (int i = 0; i < allComponents.Length; i++)
+            {
+                // TODO
+                //  - Create component foldout
+                //  - Hook up the foldout so when clicked it will expand/collapse the custom inspector or child object
+
+                Inspector inspector = GetInspector(allComponents[i].GetType());
+                inspector.Initialize(CreatePanel(0, 0, 0, 0), allComponents[i]);
+
+                inspectors.Add(inspector);
+            }
+
+            RepositionInspectors();
+        }
+
+        internal void Refresh()
+        {
+            for (int i = 0; i < inspectors.Count; i++)
+                inspectors[i].Refresh();
+        }
+
+        internal void Destroy()
+        {
+            // TODO - Destroy SceneObject GUI elements
+
+            Clear();
+        }
+
+        internal void Clear()
+        {
+            for (int i = 0; i < inspectors.Count; i++)
+                inspectors[i].Destroy();
+
+            inspectors.Clear();
+        }
+
+        protected override void WindowResized(int width, int height)
+        {
+            RepositionInspectors();
+        }
+
+        private void RepositionInspectors()
+        {
+            int curPosition = 0;
+            for (int i = 0; i < inspectors.Count; i++)
+            {
+                int inspectorHeight = inspectors[i].GetOptimalHeight();
+
+                inspectors[i].SetArea(0, curPosition, width, inspectorHeight);
+                curPosition += inspectorHeight;
+            } 
+        }
+
+        private Inspector GetInspector(Type type)
+        {
+            // TODO - Check if type has a custom inspector
+            // and return the custom inspector, otherwise create a generic one
+
+            return new GenericInspector();
+        }
+    }
+}

+ 70 - 0
MBansheeEditor/Inspector/SerializableField.cs

@@ -0,0 +1,70 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Runtime.CompilerServices;
+using System.Text;
+
+namespace BansheeEditor
+{
+    public class SerializableField
+    {
+        public enum FieldType
+        {
+            Int,
+            Float,
+            Bool,
+            String,
+            Color,
+            Vector2,
+            Vector3,
+            Vector4,
+            GameObjectRef,
+            ResourceRef,
+            Object,
+            Array,
+            List,
+            Dictionary
+        }
+
+        private SerializableObject parent;
+        private FieldType type;
+        private int fieldId;
+        private string name;
+
+        internal SerializableField(SerializableObject parent, FieldType type, int fieldId)
+        {
+            this.parent = parent;
+            this.type = type;
+            this.fieldId = fieldId;
+        }
+
+        public FieldType Type
+        {
+            get { return type; }
+        }
+
+        public string Name
+        {
+            get { return name; }
+        }
+
+        public SerializableValue GetValue()
+        {
+            return null; // TODO - Return actual SerializableValue
+        }
+
+        // TODO - Add getters/setters for all fields
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_SetInt32(IntPtr nativeInstance, int fieldId, Int32 value);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern Int32 Internal_GetInt32(IntPtr nativeInstance, int fieldId);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_SetObject(IntPtr nativeInstance, int fieldId, object value);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern object Internal_GetObject(IntPtr nativeInstance, int fieldId);
+    }
+}

+ 42 - 0
SBansheeEngine/Include/BsScriptGUIPanel.h

@@ -0,0 +1,42 @@
+#pragma once
+
+#include "BsScriptEnginePrerequisites.h"
+#include "BsScriptObject.h"
+#include "CmRectI.h"
+
+namespace BansheeEngine
+{
+	class BS_SCR_BE_EXPORT ScriptGUIPanel : public ScriptObject<ScriptGUIPanel>
+	{
+	public:
+		static void initMetaData();
+
+		GUIWidget& getWidget() const { return *mParentWidget; }
+		const CM::RectI& getClippedArea() const { return mClippedArea; }
+
+		void setParentArea(CM::INT32 x, CM::INT32 y, CM::UINT32 width, CM::UINT32 height);
+		void setParentWidget(GUIWidget* widget);
+
+		void registerArea(ScriptGUIArea* area);
+		void unregisterArea(ScriptGUIArea* area);
+
+	protected:
+		ScriptGUIPanel();
+
+		static void initRuntimeData();
+
+		static void internal_createInstance(MonoObject* instance);
+		static void internal_destroyInstance(ScriptGUIPanel* thisPtr);
+		static void internal_setArea(ScriptGUIPanel* thisPtr, CM::INT32 x, CM::INT32 y, 
+			CM::UINT32 width, CM::UINT32 height, CM::UINT16 depth);
+
+		void updateArea();
+
+		GUIWidget* mParentWidget;
+		CM::Vector<ScriptGUIArea*>::type mAreas;
+
+		CM::RectI mParentArea;
+		CM::RectI mMyArea;
+		CM::RectI mClippedArea;
+	};
+}

+ 102 - 0
SBansheeEngine/Source/BsScriptGUIPanel.cpp

@@ -0,0 +1,102 @@
+#include "BsScriptGUIPanel.h"
+#include "BsScriptMeta.h"
+#include "BsMonoField.h"
+#include "BsMonoClass.h"
+#include "BsMonoManager.h"
+#include "BsScriptGUIArea.h"
+#include "BsGUIArea.h"
+#include "BsGUILayout.h"
+
+using namespace CamelotFramework;
+
+namespace BansheeEngine
+{
+	ScriptGUIPanel::ScriptGUIPanel()
+	{
+
+	}
+
+	void ScriptGUIPanel::initMetaData()
+	{
+		metaData = ScriptMeta(BansheeEngineAssemblyName, "BansheeEngine", "GUIPanel", &ScriptGUIPanel::initRuntimeData);
+
+		MonoManager::registerScriptType(&metaData);
+	}
+
+	void ScriptGUIPanel::initRuntimeData()
+	{
+		metaData.scriptClass->addInternalCall("Internal_CreateInstance", &ScriptGUIPanel::internal_createInstance);
+		metaData.scriptClass->addInternalCall("Internal_DestroyInstance", &ScriptGUIPanel::internal_destroyInstance);
+		metaData.scriptClass->addInternalCall("Internal_SetArea", &ScriptGUIPanel::internal_setArea);
+	}
+
+	void ScriptGUIPanel::internal_createInstance(MonoObject* instance)
+	{
+		ScriptGUIPanel* nativeInstance = new (cm_alloc<ScriptGUIPanel>()) ScriptGUIPanel();
+		nativeInstance->createInstance(instance);
+
+		metaData.thisPtrField->setValue(instance, &nativeInstance);
+	}
+
+	void ScriptGUIPanel::internal_destroyInstance(ScriptGUIPanel* thisPtr)
+	{
+		cm_delete(thisPtr);
+	}
+
+	void ScriptGUIPanel::internal_setArea(ScriptGUIPanel* thisPtr, CM::INT32 x, CM::INT32 y, CM::UINT32 width, CM::UINT32 height, CM::UINT16 depth)
+	{
+		thisPtr->mMyArea.x = x;
+		thisPtr->mMyArea.y = y;
+		thisPtr->mMyArea.width = width;
+		thisPtr->mMyArea.height = height;
+
+		thisPtr->updateArea();
+	}
+
+	void ScriptGUIPanel::setParentArea(CM::INT32 x, CM::INT32 y, CM::UINT32 width, CM::UINT32 height)
+	{
+		mParentArea.x = x;
+		mParentArea.y = y;
+		mParentArea.width = width;
+		mParentArea.height = height;
+
+		updateArea();
+	}
+
+	void ScriptGUIPanel::setParentWidget(GUIWidget* widget) 
+	{ 
+		mParentWidget = widget; 
+
+		for(auto& area : mAreas)
+		{
+			area->getInternalValue()->changeParentWidget(widget);
+		}
+	}
+
+	void ScriptGUIPanel::registerArea(ScriptGUIArea* area)
+	{
+		mAreas.push_back(area);
+	}
+
+	void ScriptGUIPanel::unregisterArea(ScriptGUIArea* area)
+	{
+		auto iterFind = std::find(mAreas.begin(), mAreas.end(), area);
+
+		if(iterFind != mAreas.end())
+			mAreas.erase(iterFind);
+	}
+
+	void ScriptGUIPanel::updateArea()
+	{
+		mClippedArea = mMyArea;
+		mClippedArea.x += mParentArea.x;
+		mClippedArea.y += mParentArea.y;
+
+		mClippedArea.clip(mParentArea);
+
+		for(auto& area : mAreas)
+		{
+			area->updateArea();
+		}
+	}
+}