GUIWidgetInspector.cs 2.8 KB

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