// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved.
using System.Collections.Generic;
using System.Linq;
using System.Xml;
using FlaxEditor.CustomEditors;
using FlaxEditor.SceneGraph;
using FlaxEditor.Viewport;
using FlaxEngine.GUI;
namespace FlaxEditor.Windows
{
///
/// Window used to present collection of selected object(s) properties in a grid. Supports Undo/Redo operations.
///
///
///
public class PropertiesWindow : SceneEditorWindow, IPresenterOwner
{
private IEnumerable undoRecordObjects;
///
public override bool UseLayoutData => true;
///
/// The editor.
///
public readonly CustomEditorPresenter Presenter;
///
/// Indication of if the scale is locked.
///
public bool ScaleLinked = false;
///
/// Indication of if UI elements should size relative to the pivot point.
///
public bool UIPivotRelative = true;
///
/// Initializes a new instance of the class.
///
/// The editor.
public PropertiesWindow(Editor editor)
: base(editor, true, ScrollBars.Vertical)
{
Title = "Properties";
AutoFocus = true;
Presenter = new CustomEditorPresenter(editor.Undo, null, this);
Presenter.Panel.Parent = this;
Presenter.GetUndoObjects += GetUndoObjects;
Presenter.Features |= FeatureFlags.CacheExpandedGroups;
Editor.SceneEditing.SelectionChanged += OnSelectionChanged;
}
private IEnumerable GetUndoObjects(CustomEditorPresenter customEditorPresenter)
{
return undoRecordObjects;
}
private void OnSelectionChanged()
{
// Update selected objects
// TODO: use cached collection for less memory allocations
undoRecordObjects = Editor.SceneEditing.Selection.ConvertAll(x => x.UndoRecordObject).Distinct();
var objects = Editor.SceneEditing.Selection.ConvertAll(x => x.EditableObject).Distinct();
Presenter.Select(objects);
}
///
public override void OnLayoutSerialize(XmlWriter writer)
{
writer.WriteAttributeString("ScaleLinked", ScaleLinked.ToString());
writer.WriteAttributeString("UIPivotRelative", UIPivotRelative.ToString());
}
///
public override void OnLayoutDeserialize(XmlElement node)
{
if (bool.TryParse(node.GetAttribute("ScaleLinked"), out bool value1))
ScaleLinked = value1;
if (bool.TryParse(node.GetAttribute("UIPivotRelative"), out value1))
UIPivotRelative = value1;
}
///
public EditorViewport PresenterViewport => Editor.Windows.EditWin.Viewport;
///
public void Select(List nodes)
{
Editor.SceneEditing.Select(nodes);
}
}
}