using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BansheeEngine;
namespace BansheeEditor
{
///
/// Displays GUI for a serializable property containing an array. Array contents are displayed as rows of entries
/// that can be shown, hidden or manipulated.
///
public class InspectableArray : InspectableField
{
///
/// Contains GUI elements for a single entry in the array.
///
private class EntryRow
{
public GUILayoutY contentLayout;
private GUILayoutX rowLayout;
private GUILayoutX titleLayout;
private bool ownsTitleLayout;
///
/// Constructs a new entry row object.
///
/// Parent layout that row GUI elements will be added to.
public EntryRow(GUILayout parentLayout)
{
rowLayout = parentLayout.AddLayoutX();
contentLayout = rowLayout.AddLayoutY();
}
///
/// Recreates all row GUI elements.
///
/// Inspectable field of the array entry.
/// Sequential index of the array entry.
/// Parent array object that the entry is contained in.
public void Refresh(InspectableField child, int seqIndex, InspectableArray parent)
{
if (ownsTitleLayout || (titleLayout != null && titleLayout == child.GetTitleLayout()))
return;
titleLayout = child.GetTitleLayout();
if (titleLayout == null)
{
GUILayoutY buttonCenter = rowLayout.AddLayoutY();
buttonCenter.AddFlexibleSpace();
titleLayout = buttonCenter.AddLayoutX();
buttonCenter.AddFlexibleSpace();
ownsTitleLayout = true;
}
GUIContent cloneIcon = new GUIContent(EditorBuiltin.GetInspectorWindowIcon(InspectorWindowIcon.Clone));
GUIContent deleteIcon = new GUIContent(EditorBuiltin.GetInspectorWindowIcon(InspectorWindowIcon.Delete));
GUIContent moveUp = new GUIContent(EditorBuiltin.GetInspectorWindowIcon(InspectorWindowIcon.MoveUp));
GUIContent moveDown = new GUIContent(EditorBuiltin.GetInspectorWindowIcon(InspectorWindowIcon.MoveDown));
GUIButton cloneBtn = new GUIButton(cloneIcon, GUIOption.FixedWidth(30));
GUIButton deleteBtn = new GUIButton(deleteIcon, GUIOption.FixedWidth(30));
GUIButton moveUpBtn = new GUIButton(moveUp, GUIOption.FixedWidth(30));
GUIButton moveDownBtn = new GUIButton(moveDown, GUIOption.FixedWidth(30));
cloneBtn.OnClick += () => parent.OnCloneButtonClicked(seqIndex);
deleteBtn.OnClick += () => parent.OnDeleteButtonClicked(seqIndex);
moveUpBtn.OnClick += () => parent.OnMoveUpButtonClicked(seqIndex);
moveDownBtn.OnClick += () => parent.OnMoveDownButtonClicked(seqIndex);
titleLayout.AddElement(cloneBtn);
titleLayout.AddElement(deleteBtn);
titleLayout.AddElement(moveUpBtn);
titleLayout.AddElement(moveDownBtn);
}
///
/// Destroys all row GUI elements.
///
public void Destroy()
{
rowLayout.Destroy();
}
}
private const int IndentAmount = 5;
private object propertyValue; // TODO - This will unnecessarily hold references to the object
private int numArrayElements;
private List rows = new List();
private GUIIntField guiSizeField;
private GUILayoutX guiChildLayout;
private GUILayoutX guiTitleLayout;
private bool isExpanded;
private bool forceUpdate = true;
///
/// Creates a new inspectable array GUI for the specified property.
///
/// Name of the property, or some other value to set as the title.
/// 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 array whose contents to display.
public InspectableArray(string title, int depth, InspectableFieldLayout layout, SerializableProperty property)
: base(title, depth, layout, property)
{
}
///
public override GUILayoutX GetTitleLayout()
{
return guiTitleLayout;
}
///
protected override bool IsModified()
{
if (forceUpdate)
return true;
object newPropertyValue = property.GetValue