//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
//**************** Copyright (c) 2016 Marko Pintera (marko.pintera@gmail.com). All rights reserved. **********************//
using BansheeEngine;
namespace BansheeEditor
{
/** @addtogroup Inspectors
* @{
*/
///
/// Renders an inspector for the component.
///
[CustomInspector(typeof(GUIWidget))]
internal class GUIWidgetInspector : Inspector
{
private GUIResourceField skinField;
private GUIGameObjectField cameraField;
private InspectableState modifyState;
///
protected internal override void Initialize()
{
BuildGUI();
}
///
protected internal override InspectableState Refresh()
{
GUIWidget guiWidget = InspectedObject as GUIWidget;
if (guiWidget == null)
return InspectableState.NotModified;
skinField.Value = guiWidget.Skin;
cameraField.Value = guiWidget.Camera;
InspectableState oldState = modifyState;
if (modifyState.HasFlag(InspectableState.Modified))
modifyState = InspectableState.NotModified;
return oldState;
}
///
/// Recreates all the GUI elements used by this inspector.
///
private void BuildGUI()
{
Layout.Clear();
GUIWidget guiWidget = InspectedObject as GUIWidget;
if (guiWidget == null)
return;
skinField = new GUIResourceField(typeof(GUISkin), new LocEdString("Skin"));
cameraField = new GUIGameObjectField(typeof (Camera), new LocEdString("Camera"));
skinField.OnChanged += x =>
{
GUISkin skin = Resources.Load(x);
guiWidget.Skin = skin;
MarkAsModified();
ConfirmModify();
};
cameraField.OnChanged += x =>
{
guiWidget.Camera = x as Camera;
MarkAsModified();
ConfirmModify();
};
Layout.AddElement(skinField);
Layout.AddElement(cameraField);
}
///
/// Marks the contents of the inspector as modified.
///
protected void MarkAsModified()
{
modifyState |= InspectableState.ModifyInProgress;
}
///
/// Confirms any queued modifications.
///
protected void ConfirmModify()
{
if (modifyState.HasFlag(InspectableState.ModifyInProgress))
modifyState |= InspectableState.Modified;
}
}
/** @} */
}