|
|
|
[Tool]
|
|
|
|
public partial class TerrainEditingControls
|
|
|
|
: VBoxContainer
|
|
|
|
{
|
|
|
|
public (ToolMode , Button)[] ToolModeButtons { get; private set; }
|
|
|
|
public (ToolShape, Button)[] ToolShapeButtons { get; private set; }
|
|
|
|
public Button[] PaintTextureButtons { get; private set; }
|
|
|
|
public Slider DrawSizeSlider { get; private set; }
|
|
|
|
|
|
|
|
ToolMode _toolMode = ToolMode.Height;
|
|
|
|
ToolShape _toolShape = ToolShape.Circle;
|
|
|
|
int _texture = 1;
|
|
|
|
|
|
|
|
public ToolMode ToolMode { get => _toolMode ; set => SetToolMode (value); }
|
|
|
|
public ToolShape ToolShape { get => _toolShape; set => SetToolShape(value); }
|
|
|
|
public int Texture { get => _texture ; set => SetTexture (value); }
|
|
|
|
|
|
|
|
public int DrawSize {
|
|
|
|
get => RoundToInt(-DrawSizeSlider?.Value ?? 1);
|
|
|
|
set => DrawSizeSlider.Value = -value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void _Ready()
|
|
|
|
{
|
|
|
|
ToolModeButtons = [
|
|
|
|
(ToolMode.Height, GetNode<Button>("Height")),
|
|
|
|
(ToolMode.Paint , GetNode<Button>("Paint" )),
|
|
|
|
];
|
|
|
|
|
|
|
|
ToolShapeButtons = [
|
|
|
|
(ToolShape.Corner, GetNode<Button>("Corner")),
|
|
|
|
(ToolShape.Circle, GetNode<Button>("Circle")),
|
|
|
|
(ToolShape.Square, GetNode<Button>("Square")),
|
|
|
|
];
|
|
|
|
|
|
|
|
PaintTextureButtons = [
|
|
|
|
GetNode<Button>("Grass"),
|
|
|
|
GetNode<Button>("Dirt"),
|
|
|
|
GetNode<Button>("Rock"),
|
|
|
|
GetNode<Button>("Sand"),
|
|
|
|
];
|
|
|
|
|
|
|
|
foreach (var (mode, button) in ToolModeButtons)
|
|
|
|
button.Pressed += () => SetToolMode(mode);
|
|
|
|
foreach (var (shape, button) in ToolShapeButtons)
|
|
|
|
button.Pressed += () => SetToolShape(shape);
|
|
|
|
foreach (var (i, button) in PaintTextureButtons.Select((b, i) => (i, b)))
|
|
|
|
button.Pressed += () => SetTexture(i + 1);
|
|
|
|
|
|
|
|
var drawSizeLabel = GetNode<Label>("SizeLabel");
|
|
|
|
DrawSizeSlider = GetNode<Slider>("SizeSlider");
|
|
|
|
DrawSizeSlider.ValueChanged += (_) => drawSizeLabel.Text = $"{DrawSize}";
|
|
|
|
|
|
|
|
SetToolMode(_toolMode);
|
|
|
|
SetToolShape(_toolShape);
|
|
|
|
SetTexture(_texture);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SetToolMode(ToolMode value)
|
|
|
|
{
|
|
|
|
// Ignore if _Ready hasn't been called yet.
|
|
|
|
if (ToolModeButtons == null) return;
|
|
|
|
|
|
|
|
foreach (var (mode, button) in ToolModeButtons)
|
|
|
|
button.Flat = button.ButtonPressed = value != mode;
|
|
|
|
foreach (var button in PaintTextureButtons)
|
|
|
|
button.Disabled = value != ToolMode.Paint;
|
|
|
|
_toolMode = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetToolShape(ToolShape value)
|
|
|
|
{
|
|
|
|
// Ignore if _Ready hasn't been called yet.
|
|
|
|
if (ToolShapeButtons == null) return;
|
|
|
|
|
|
|
|
foreach (var (shape, button) in ToolShapeButtons)
|
|
|
|
button.Flat = button.ButtonPressed = value != shape;
|
|
|
|
DrawSizeSlider.Editable = value != ToolShape.Corner;
|
|
|
|
_toolShape = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetTexture(int value)
|
|
|
|
{
|
|
|
|
// Ignore if _Ready hasn't been called yet.
|
|
|
|
if (PaintTextureButtons == null) return;
|
|
|
|
|
|
|
|
if ((value < 1) || (value > PaintTextureButtons.Length))
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(value));
|
|
|
|
foreach (var (i, button) in PaintTextureButtons.Select((b, i) => (i, b)))
|
|
|
|
button.Flat = button.ButtonPressed = value != i + 1;
|
|
|
|
_texture = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public enum ToolMode
|
|
|
|
{
|
|
|
|
Height,
|
|
|
|
Paint,
|
|
|
|
}
|
|
|
|
|
|
|
|
public enum ToolShape
|
|
|
|
{
|
|
|
|
Corner,
|
|
|
|
Circle,
|
|
|
|
Square,
|
|
|
|
}
|