| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501 |
- //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
- //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
- using System;
- using BansheeEngine;
- namespace BansheeEditor
- {
- /** @addtogroup Inspectors
- * @{
- */
- /// <summary>
- /// Draws GUI elements for inspecting an <see cref="Spring"/> object.
- /// </summary>
- internal class SpringGUI
- {
- private Spring spring;
- private GUIFloatField stiffnessField = new GUIFloatField(new LocEdString("Stiffness"));
- private GUIFloatField dampingField = new GUIFloatField(new LocEdString("Damping"));
- public Action<Spring> OnChanged;
- public Action OnConfirmed;
- /// <summary>
- /// Current value of the spring object.
- /// </summary>
- public Spring Spring
- {
- get { return spring; }
- set
- {
- spring = value;
- stiffnessField.Value = value.stiffness;
- dampingField.Value = value.damping;
- }
- }
- /// <summary>
- /// Constructs a new set of GUI elements for inspecting the spring object.
- /// </summary>
- /// <param name="spring">Initial values to assign to the GUI elements.</param>
- /// <param name="layout">Layout to append the GUI elements to.</param>
- public SpringGUI(Spring spring, GUILayout layout)
- {
- this.spring = spring;
- stiffnessField.OnChanged += x => { this.spring.stiffness = x; MarkAsModified(); };
- stiffnessField.OnFocusLost += ConfirmModify;
- stiffnessField.OnConfirmed += ConfirmModify;
- dampingField.OnChanged += x => { this.spring.damping = x; MarkAsModified(); };
- dampingField.OnFocusLost += ConfirmModify;
- dampingField.OnConfirmed += ConfirmModify;
- layout.AddElement(stiffnessField);
- layout.AddElement(dampingField);
- }
- /// <summary>
- /// Marks the contents of the inspector as modified.
- /// </summary>
- private void MarkAsModified()
- {
- if (OnChanged != null)
- OnChanged(spring);
- }
- /// <summary>
- /// Confirms any queued modifications.
- /// </summary>
- private void ConfirmModify()
- {
- if (OnConfirmed != null)
- OnConfirmed();
- }
- }
- /// <summary>
- /// Draws GUI elements for inspecting an <see cref="LimitCommon"/> object.
- /// </summary>
- internal class LimitCommonGUI
- {
- private LimitCommon limitData;
- private SerializableProperties properties;
- private string prefix;
- private GUIToggle hardFoldout = new GUIToggle(new LocEdString("Hard"), EditorStyles.Foldout);
- private GUIFloatField contactDistanceField = new GUIFloatField(new LocEdString("Contact distance"));
- private GUIToggle softFoldout = new GUIToggle(new LocEdString("Soft"), EditorStyles.Foldout);
- private GUISliderField restitutionField = new GUISliderField(0, 1, new LocEdString("Restitution"));
- private GUIToggle springFoldout = new GUIToggle(new LocEdString("Spring"), EditorStyles.Foldout);
- private SpringGUI springGUI;
- private GUILayoutX hardLimitLayout;
- private GUILayoutX softLimitLayout;
- private GUILayoutX springLayout;
- public Action<LimitCommon> OnChanged;
- public Action OnConfirmed;
- /// <summary>
- /// Current limit properties.
- /// </summary>
- public LimitCommon LimitData
- {
- get { return limitData; }
- set
- {
- limitData = value;
- contactDistanceField.Value = value.contactDist;
- restitutionField.Value = value.restitution;
- springGUI.Spring = value.spring;
- }
- }
- /// <summary>
- /// Constructs a new set of GUI elements for inspecting the limit object.
- /// </summary>
- /// <param name="prefix">Prefix that identifies the exact type of the limit type.</param>
- /// <param name="limitData">Initial values to assign to the GUI elements.</param>
- /// <param name="layout">Layout to append the GUI elements to.</param>
- /// <param name="properties">A set of properties that are persisted by the parent inspector. Used for saving state.
- /// </param>
- public LimitCommonGUI(string prefix, LimitCommon limitData, GUILayout layout, SerializableProperties properties)
- {
- this.limitData = limitData;
- this.properties = properties;
- this.prefix = prefix;
- hardFoldout.AcceptsKeyFocus = false;
- hardFoldout.OnToggled += x =>
- {
- properties.SetBool(prefix + "_hardLimit_Expanded", x);
- ToggleLimitFields();
- };
- contactDistanceField.OnChanged += x => { this.limitData.contactDist = x; MarkAsModified(); };
- contactDistanceField.OnFocusLost += ConfirmModify;
- contactDistanceField.OnConfirmed += ConfirmModify;
- softFoldout.AcceptsKeyFocus = false;
- softFoldout.OnToggled += x =>
- {
- properties.SetBool(prefix + "_softLimit_Expanded", x);
- ToggleLimitFields();
- };
- restitutionField.OnChanged += x => { this.limitData.restitution = x; MarkAsModified(); };
- restitutionField.OnFocusLost += ConfirmModify;
- springFoldout.AcceptsKeyFocus = false;
- springFoldout.OnToggled += x =>
- {
- properties.SetBool(prefix + "_spring_Expanded", x);
- ToggleLimitFields();
- };
- hardLimitLayout = layout.AddLayoutX();
- {
- hardLimitLayout.AddSpace(10);
- GUILayoutY hardLimitContentsLayout = hardLimitLayout.AddLayoutY();
- hardLimitContentsLayout.AddElement(contactDistanceField);
- }
- softLimitLayout = layout.AddLayoutX();
- layout.AddElement(softFoldout);
- {
- softLimitLayout.AddSpace(10);
- GUILayoutY softLimitContentsLayout = softLimitLayout.AddLayoutY();
- softLimitContentsLayout.AddElement(restitutionField);
- softLimitContentsLayout.AddElement(springFoldout);
- springLayout = softLimitContentsLayout.AddLayoutX();
- {
- springLayout.AddSpace(10);
- GUILayoutY springContentsLayout = springLayout.AddLayoutY();
- springGUI = new SpringGUI(limitData.spring, springContentsLayout);
- springGUI.OnChanged += x => { this.limitData.spring = x; MarkAsModified(); };
- springGUI.OnConfirmed += ConfirmModify;
- }
- }
- }
- /// <summary>
- /// Marks the contents of the inspector as modified.
- /// </summary>
- private void MarkAsModified()
- {
- if (OnChanged != null)
- OnChanged(limitData);
- }
- /// <summary>
- /// Confirms any queued modifications.
- /// </summary>
- private void ConfirmModify()
- {
- if (OnConfirmed != null)
- OnConfirmed();
- }
- /// <summary>
- /// Hides or shows limit property GUI elements depending on set properties.
- /// </summary>
- private void ToggleLimitFields()
- {
- hardLimitLayout.Active = properties.GetBool(prefix + "_hardLimit_Expanded");
- softLimitLayout.Active = properties.GetBool(prefix + "_softLimit_Expanded");
- springLayout.Active = properties.GetBool(prefix + "_spring_Expanded");
- }
- }
- /// <summary>
- /// Draws GUI elements for inspecting an <see cref="LimitLinear"/> object.
- /// </summary>
- internal class LimitLinearGUI
- {
- private LimitLinear limitData;
- private GUIFloatField limitExtentField = new GUIFloatField(new LocEdString("Extent"));
- private LimitCommonGUI limitCommonGUI;
- public Action<LimitLinear, LimitCommon> OnChanged;
- public Action OnConfirmed;
- /// <summary>
- /// Current limit properties.
- /// </summary>
- public LimitLinear Limit
- {
- set
- {
- limitData = value;
- limitExtentField.Value = limitData.extent;
- limitCommonGUI.LimitData = value.GetBase();
- }
- }
- /// <summary>
- /// Constructs a new set of GUI elements for inspecting the limit object.
- /// </summary>
- /// <param name="limit">Initial values to assign to the GUI elements.</param>
- /// <param name="layout">Layout to append the GUI elements to.</param>
- /// <param name="properties">A set of properties that are persisted by the parent inspector. Used for saving state.
- /// </param>
- public LimitLinearGUI(LimitLinear limit, GUILayout layout, SerializableProperties properties)
- {
- limitData = limit;
- limitExtentField.OnChanged += x => { limitData.extent = x; MarkAsModified(); };
- limitExtentField.OnFocusLost += ConfirmModify;
- layout.AddElement(limitExtentField);
- limitCommonGUI = new LimitCommonGUI("linear", limit.GetBase(), layout, properties);
- limitCommonGUI.OnChanged += x => MarkAsModified();
- limitCommonGUI.OnConfirmed += ConfirmModify;
- }
- /// <summary>
- /// Marks the contents of the inspector as modified.
- /// </summary>
- private void MarkAsModified()
- {
- if (OnChanged != null)
- OnChanged(limitData, limitCommonGUI.LimitData);
- }
- /// <summary>
- /// Confirms any queued modifications.
- /// </summary>
- private void ConfirmModify()
- {
- if (OnConfirmed != null)
- OnConfirmed();
- }
- }
- /// <summary>
- /// Draws GUI elements for inspecting an <see cref="LimitLinearRange"/> object.
- /// </summary>
- internal class LimitLinearRangeGUI
- {
- private LimitLinearRange limitData;
- private GUIFloatField limitLowerField = new GUIFloatField(new LocEdString("Lower"));
- private GUIFloatField limitUpperField = new GUIFloatField(new LocEdString("Upper"));
- private LimitCommonGUI limitCommonGUI;
- public Action<LimitLinearRange, LimitCommon> OnChanged;
- public Action OnConfirmed;
- /// <summary>
- /// Current limit properties.
- /// </summary>
- public LimitLinearRange Limit
- {
- set
- {
- limitData = value;
- limitLowerField.Value = limitData.lower;
- limitUpperField.Value = limitData.upper;
- limitCommonGUI.LimitData = value.GetBase();
- }
- }
- /// <summary>
- /// Constructs a new set of GUI elements for inspecting the limit object.
- /// </summary>
- /// <param name="limit">Initial values to assign to the GUI elements.</param>
- /// <param name="layout">Layout to append the GUI elements to.</param>
- /// <param name="properties">A set of properties that are persisted by the parent inspector. Used for saving state.
- /// </param>
- public LimitLinearRangeGUI(LimitLinearRange limit, GUILayout layout, SerializableProperties properties)
- {
- this.limitData = limit;
- limitLowerField.OnChanged += x => { limitData.lower = x; MarkAsModified(); };
- limitLowerField.OnFocusLost += ConfirmModify;
- limitUpperField.OnChanged += x => { limitData.upper = x; MarkAsModified(); };
- limitUpperField.OnFocusLost += ConfirmModify;
- layout.AddElement(limitLowerField);
- layout.AddElement(limitUpperField);
- limitCommonGUI = new LimitCommonGUI("linearRange", limit.GetBase(), layout, properties);
- limitCommonGUI.OnChanged += x => MarkAsModified();
- limitCommonGUI.OnConfirmed += ConfirmModify;
- }
- /// <summary>
- /// Marks the contents of the inspector as modified.
- /// </summary>
- private void MarkAsModified()
- {
- if (OnChanged != null)
- OnChanged(limitData, limitCommonGUI.LimitData);
- }
- /// <summary>
- /// Confirms any queued modifications.
- /// </summary>
- private void ConfirmModify()
- {
- if (OnConfirmed != null)
- OnConfirmed();
- }
- }
- /// <summary>
- /// Draws GUI elements for inspecting an <see cref="LimitAngularRange"/> object.
- /// </summary>
- internal class LimitAngularRangeGUI
- {
- private LimitAngularRange limitData;
- private GUISliderField limitLowerField = new GUISliderField(0, 359, new LocEdString("Lower"));
- private GUISliderField limitUpperField = new GUISliderField(0, 359, new LocEdString("Upper"));
- private LimitCommonGUI limitCommonGUI;
- public Action<LimitAngularRange, LimitCommon> OnChanged;
- public Action OnConfirmed;
- /// <summary>
- /// Current limit properties.
- /// </summary>
- public LimitAngularRange Limit
- {
- set
- {
- limitData = value;
- limitLowerField.Value = limitData.lower.Degrees;
- limitUpperField.Value = limitData.upper.Degrees;
- limitCommonGUI.LimitData = value.GetBase();
- }
- }
- /// <summary>
- /// Constructs a new set of GUI elements for inspecting the limit object.
- /// </summary>
- /// <param name="limit">Initial values to assign to the GUI elements.</param>
- /// <param name="layout">Layout to append the GUI elements to.</param>
- /// <param name="properties">A set of properties that are persisted by the parent inspector. Used for saving state.
- /// </param>
- public LimitAngularRangeGUI(LimitAngularRange limit, GUILayout layout, SerializableProperties properties)
- {
- this.limitData = limit;
- limitLowerField.OnChanged += x => { limitData.lower = new Degree(x); MarkAsModified(); };
- limitLowerField.OnFocusLost += ConfirmModify;
- limitUpperField.OnChanged += x => { limitData.upper = new Degree(x); MarkAsModified(); };
- limitUpperField.OnFocusLost += ConfirmModify;
- layout.AddElement(limitLowerField);
- layout.AddElement(limitUpperField);
- limitCommonGUI = new LimitCommonGUI("angularRange", limit.GetBase(), layout, properties);
- limitCommonGUI.OnChanged += x => MarkAsModified();
- limitCommonGUI.OnConfirmed += ConfirmModify;
- }
- /// <summary>
- /// Marks the contents of the inspector as modified.
- /// </summary>
- private void MarkAsModified()
- {
- if (OnChanged != null)
- OnChanged(limitData, limitCommonGUI.LimitData);
- }
- /// <summary>
- /// Confirms any queued modifications.
- /// </summary>
- private void ConfirmModify()
- {
- if (OnConfirmed != null)
- OnConfirmed();
- }
- }
- /// <summary>
- /// Draws GUI elements for inspecting an <see cref="LimitConeRange"/> object.
- /// </summary>
- internal class LimitConeRangeGUI
- {
- private LimitConeRange limitData;
- private GUISliderField yLimitAngleField = new GUISliderField(0, 180, new LocEdString("Y limit"));
- private GUISliderField zLimitAngleField = new GUISliderField(0, 180, new LocEdString("Z limit"));
- private LimitCommonGUI limitCommonGUI;
- public Action<LimitConeRange, LimitCommon> OnChanged;
- public Action OnConfirmed;
- /// <summary>
- /// Current limit properties.
- /// </summary>
- public LimitConeRange Limit
- {
- set
- {
- limitData = value;
- yLimitAngleField.Value = limitData.yLimitAngle.Degrees;
- zLimitAngleField.Value = limitData.zLimitAngle.Degrees;
- limitCommonGUI.LimitData = value.GetBase();
- }
- }
- /// <summary>
- /// Constructs a new set of GUI elements for inspecting the limit object.
- /// </summary>
- /// <param name="limit">Initial values to assign to the GUI elements.</param>
- /// <param name="layout">Layout to append the GUI elements to.</param>
- /// <param name="properties">A set of properties that are persisted by the parent inspector. Used for saving state.
- /// </param>
- public LimitConeRangeGUI(LimitConeRange limit, GUILayout layout, SerializableProperties properties)
- {
- this.limitData = limit;
- yLimitAngleField.OnChanged += x => { limitData.yLimitAngle = new Degree(x); MarkAsModified(); };
- yLimitAngleField.OnFocusLost += ConfirmModify;
- zLimitAngleField.OnChanged += x => { limitData.zLimitAngle = new Degree(x); MarkAsModified(); };
- zLimitAngleField.OnFocusLost += ConfirmModify;
- layout.AddElement(yLimitAngleField);
- layout.AddElement(zLimitAngleField);
- limitCommonGUI = new LimitCommonGUI("coneRange", limit.GetBase(), layout, properties);
- limitCommonGUI.OnChanged += x => MarkAsModified();
- limitCommonGUI.OnConfirmed += ConfirmModify;
- }
- /// <summary>
- /// Marks the contents of the inspector as modified.
- /// </summary>
- private void MarkAsModified()
- {
- if (OnChanged != null)
- OnChanged(limitData, limitCommonGUI.LimitData);
- }
- /// <summary>
- /// Confirms any queued modifications.
- /// </summary>
- private void ConfirmModify()
- {
- if (OnConfirmed != null)
- OnConfirmed();
- }
- }
- /** @} */
- }
|