SliderJointInspector.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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="SliderJoint"/> component.
  11. /// </summary>
  12. [CustomInspector(typeof(SliderJoint))]
  13. internal class SliderJointInspector : JointInspector
  14. {
  15. private GUIToggleField enableLimitField = new GUIToggleField(new LocEdString("Enable limit"));
  16. private LimitLinearRangeGUI limitGUI;
  17. private GUILayoutX limitLayout;
  18. /// <inheritdoc/>
  19. protected internal override void Initialize()
  20. {
  21. SliderJoint joint = InspectedObject as SliderJoint;
  22. if (joint != null)
  23. BuildGUI(joint);
  24. }
  25. /// <inheritdoc/>
  26. protected internal override InspectableState Refresh()
  27. {
  28. SliderJoint joint = InspectedObject as SliderJoint;
  29. if (joint == null)
  30. return InspectableState.NotModified;
  31. Refresh(joint);
  32. InspectableState oldState = modifyState;
  33. if (modifyState.HasFlag(InspectableState.Modified))
  34. modifyState = InspectableState.NotModified;
  35. return oldState;
  36. }
  37. /// <summary>
  38. /// Creates GUI elements for fields specific to the slider joint.
  39. /// </summary>
  40. protected void BuildGUI(SliderJoint joint)
  41. {
  42. enableLimitField.OnChanged += x =>
  43. {
  44. joint.SetFlag(SliderJointFlag.Limit, x);
  45. MarkAsModified();
  46. ConfirmModify();
  47. ToggleLimitFields(x);
  48. };
  49. Layout.AddElement(enableLimitField);
  50. limitLayout = Layout.AddLayoutX();
  51. {
  52. limitLayout.AddSpace(10);
  53. GUILayoutY limitContentsLayout = limitLayout.AddLayoutY();
  54. limitGUI = new LimitLinearRangeGUI(joint.Limit, limitContentsLayout, Persistent);
  55. limitGUI.OnChanged += (x, y) =>
  56. {
  57. joint.Limit = x;
  58. joint.Limit.SetBase(y);
  59. MarkAsModified();
  60. };
  61. limitGUI.OnConfirmed += ConfirmModify;
  62. }
  63. ToggleLimitFields(joint.HasFlag(SliderJointFlag.Limit));
  64. base.BuildGUI(joint, true);
  65. }
  66. /// <summary>
  67. /// Updates all GUI elements from current values in the joint.
  68. /// </summary>
  69. /// <param name="joint">Joint to update the GUI from.</param>
  70. protected void Refresh(SliderJoint joint)
  71. {
  72. bool enableLimit = joint.HasFlag(SliderJointFlag.Limit);
  73. if (enableLimitField.Value != enableLimit)
  74. {
  75. enableLimitField.Value = enableLimit;
  76. ToggleLimitFields(enableLimit);
  77. }
  78. limitGUI.Limit = joint.Limit;
  79. base.Refresh(joint);
  80. }
  81. /// <summary>
  82. /// Hides or shows limit property GUI elements.
  83. /// </summary>
  84. /// <param name="enable">True to show, false to hide.</param>
  85. private void ToggleLimitFields(bool enable)
  86. {
  87. limitLayout.Active = enable;
  88. }
  89. }
  90. /** @} */
  91. }