//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
//**************** Copyright (c) 2018 Marko Pintera (marko.pintera@gmail.com). All rights reserved. **********************//
using BansheeEngine;
namespace BansheeEditor
{
/** @addtogroup Inspector
* @{
*/
///
/// Displays GUI for a serializable property containing a floating point distribution. GUI elements will switch between
/// floating point and curve input depending on the distribution type.
///
public class InspectableFloatDistribution : InspectableField
{
private GUIFloatDistributionField guiDistributionField;
private InspectableState state;
///
/// Creates a new inspectable float distribution GUI for the specified property.
///
/// Parent Inspector this field belongs to.
/// Name of the property, or some other value to set as the title.
/// Full path to this property (includes name of this property and all parent properties).
/// Determines how deep within the inspector nesting hierarchy is this field. Some fields may
/// contain other fields, in which case you should increase this value by one.
/// Parent layout that all the field elements will be added to.
/// Serializable property referencing the field whose contents to display.
public InspectableFloatDistribution(Inspector parent, string title, string path, int depth,
InspectableFieldLayout layout, SerializableProperty property)
: base(parent, title, path, SerializableProperty.FieldType.FloatDistribution, depth, layout, property)
{ }
///
protected internal override void Initialize(int layoutIndex)
{
if (property != null)
{
guiDistributionField = new GUIFloatDistributionField(new GUIContent(title));
guiDistributionField.OnChanged += OnFieldValueChanged;
guiDistributionField.OnConfirmed += OnFieldValueConfirm;
guiDistributionField.OnFocusLost += OnFieldValueConfirm;
layout.AddElement(layoutIndex, guiDistributionField);
}
}
///
public override InspectableState Refresh(int layoutIndex)
{
if (guiDistributionField != null && !guiDistributionField.HasInputFocus)
guiDistributionField.Value = property.GetValue();
InspectableState oldState = state;
if (state.HasFlag(InspectableState.Modified))
state = InspectableState.NotModified;
return oldState;
}
///
/// Triggered when the user edits the distribution.
///
private void OnFieldValueChanged()
{
property.SetValue(guiDistributionField.Value);
state |= InspectableState.ModifyInProgress;
}
///
/// Triggered when the user confirms input in the float fields used for displaying the non-curve distribution.
///
private void OnFieldValueConfirm()
{
if (state.HasFlag(InspectableState.ModifyInProgress))
state |= InspectableState.Modified;
}
}
/** @} */
}