| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
- //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
- using BansheeEngine;
- namespace BansheeEditor
- {
- /** @addtogroup Inspectors
- * @{
- */
- /// <summary>
- /// Renders an inspector for the <see cref="GUIWidget"/> component.
- /// </summary>
- [CustomInspector(typeof(GUIWidget))]
- internal class GUIWidgetInspector : Inspector
- {
- private GUIResourceField skinField;
- private GUIGameObjectField cameraField;
- private InspectableState modifyState;
- /// <inheritdoc/>
- protected internal override void Initialize()
- {
- BuildGUI();
- }
- /// <inheritdoc/>
- 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;
- }
- /// <summary>
- /// Recreates all the GUI elements used by this inspector.
- /// </summary>
- 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<GUISkin>(x);
- guiWidget.Skin = skin;
- MarkAsModified();
- ConfirmModify();
- };
- cameraField.OnChanged += x =>
- {
- guiWidget.Camera = x as Camera;
- MarkAsModified();
- ConfirmModify();
- };
- Layout.AddElement(skinField);
- Layout.AddElement(cameraField);
- }
- /// <summary>
- /// Marks the contents of the inspector as modified.
- /// </summary>
- protected void MarkAsModified()
- {
- modifyState |= InspectableState.ModifyInProgress;
- }
- /// <summary>
- /// Confirms any queued modifications.
- /// </summary>
- protected void ConfirmModify()
- {
- if (modifyState.HasFlag(InspectableState.ModifyInProgress))
- modifyState |= InspectableState.Modified;
- }
- }
- /** @} */
- }
|