// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved.
using FlaxEditor.CustomEditors;
using FlaxEditor.GUI.Tabs;
using FlaxEngine;
using FlaxEngine.GUI;
namespace FlaxEditor.Tools.Terrain
{
///
/// Carve tab related to terrain painting. Allows to modify terrain splatmap using brush.
///
///
[HideInEditor]
public class PaintTab : Tab
{
///
/// The object for paint mode settings adjusting via Custom Editor.
///
private sealed class ProxyObject
{
private readonly PaintTerrainGizmoMode _mode;
private object _currentMode, _currentBrush;
public ProxyObject(PaintTerrainGizmoMode mode)
{
_mode = mode;
SyncData();
}
public void SyncData()
{
_currentMode = _mode.CurrentMode;
_currentBrush = _mode.CurrentBrush;
}
[EditorOrder(0), EditorDisplay("Tool"), Tooltip("Paint tool mode to use.")]
public PaintTerrainGizmoMode.ModeTypes ToolMode
{
get => _mode.ToolModeType;
set => _mode.ToolModeType = value;
}
[EditorOrder(100), EditorDisplay("Tool", EditorDisplayAttribute.InlineStyle)]
public object Mode
{
get => _currentMode;
set { }
}
[EditorOrder(1000), EditorDisplay("Brush"), Tooltip("Paint brush type to use.")]
public PaintTerrainGizmoMode.BrushTypes BrushTypeType
{
get => _mode.ToolBrushType;
set => _mode.ToolBrushType = value;
}
[EditorOrder(1100), EditorDisplay("Brush", EditorDisplayAttribute.InlineStyle)]
public object Brush
{
get => _currentBrush;
set { }
}
}
private readonly ProxyObject _proxy;
private readonly CustomEditorPresenter _presenter;
///
/// The parent carve tab.
///
public readonly CarveTab CarveTab;
///
/// The related sculp terrain gizmo.
///
public readonly PaintTerrainGizmoMode Gizmo;
///
/// Initializes a new instance of the class.
///
/// The parent tab.
/// The related gizmo.
public PaintTab(CarveTab tab, PaintTerrainGizmoMode gizmo)
: base("Paint")
{
CarveTab = tab;
Gizmo = gizmo;
Gizmo.ToolModeChanged += OnToolModeChanged;
_proxy = new ProxyObject(gizmo);
// Main panel
var panel = new Panel(ScrollBars.Both)
{
AnchorPreset = AnchorPresets.StretchAll,
Offsets = Margin.Zero,
Parent = this
};
// Options editor
// TODO: use editor undo for changing brush options
var editor = new CustomEditorPresenter(null);
editor.Panel.Parent = panel;
editor.Select(_proxy);
_presenter = editor;
}
private void OnToolModeChanged()
{
_presenter.BuildLayoutOnUpdate();
}
///
public override void Update(float deltaTime)
{
if (_presenter.BuildOnUpdate)
{
_proxy.SyncData();
}
base.Update(deltaTime);
}
}
}