GUIWidgetInspector.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. using BansheeEngine;
  4. namespace BansheeEditor
  5. {
  6. /** @addtogroup Inspectors
  7. * @{
  8. */
  9. /// <summary>
  10. /// Renders an inspector for the <see cref="GUIWidget"/> component.
  11. /// </summary>
  12. [CustomInspector(typeof(GUIWidget))]
  13. internal class GUIWidgetInspector : Inspector
  14. {
  15. private GUIResourceField skinField;
  16. private GUIGameObjectField cameraField;
  17. private InspectableState modifyState;
  18. /// <inheritdoc/>
  19. protected internal override void Initialize()
  20. {
  21. BuildGUI();
  22. }
  23. /// <inheritdoc/>
  24. protected internal override InspectableState Refresh()
  25. {
  26. GUIWidget guiWidget = InspectedObject as GUIWidget;
  27. if (guiWidget == null)
  28. return InspectableState.NotModified;
  29. skinField.Value = guiWidget.Skin;
  30. cameraField.Value = guiWidget.Camera;
  31. InspectableState oldState = modifyState;
  32. if (modifyState.HasFlag(InspectableState.Modified))
  33. modifyState = InspectableState.NotModified;
  34. return oldState;
  35. }
  36. /// <summary>
  37. /// Recreates all the GUI elements used by this inspector.
  38. /// </summary>
  39. private void BuildGUI()
  40. {
  41. Layout.Clear();
  42. GUIWidget guiWidget = InspectedObject as GUIWidget;
  43. if (guiWidget == null)
  44. return;
  45. skinField = new GUIResourceField(typeof(GUISkin), new LocEdString("Skin"));
  46. cameraField = new GUIGameObjectField(typeof (Camera), new LocEdString("Camera"));
  47. skinField.OnChanged += x =>
  48. {
  49. GUISkin skin = Resources.Load<GUISkin>(x);
  50. guiWidget.Skin = skin;
  51. MarkAsModified();
  52. ConfirmModify();
  53. };
  54. cameraField.OnChanged += x =>
  55. {
  56. guiWidget.Camera = x as Camera;
  57. MarkAsModified();
  58. ConfirmModify();
  59. };
  60. Layout.AddElement(skinField);
  61. Layout.AddElement(cameraField);
  62. }
  63. /// <summary>
  64. /// Marks the contents of the inspector as modified.
  65. /// </summary>
  66. protected void MarkAsModified()
  67. {
  68. modifyState |= InspectableState.ModifyInProgress;
  69. }
  70. /// <summary>
  71. /// Confirms any queued modifications.
  72. /// </summary>
  73. protected void ConfirmModify()
  74. {
  75. if (modifyState.HasFlag(InspectableState.ModifyInProgress))
  76. modifyState |= InspectableState.Modified;
  77. }
  78. }
  79. /** @} */
  80. }