You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
108 lines
3.0 KiB
108 lines
3.0 KiB
1 month ago
|
[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; }
|
||
1 month ago
|
public Slider DrawSizeSlider { get; private set; }
|
||
1 month ago
|
|
||
1 month ago
|
ToolMode _toolMode = ToolMode.Height;
|
||
|
ToolShape _toolShape = ToolShape.Circle;
|
||
|
int _texture = 1;
|
||
1 month ago
|
|
||
|
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}";
|
||
|
|
||
1 month ago
|
SetToolMode(_toolMode);
|
||
|
SetToolShape(_toolShape);
|
||
|
SetTexture(_texture);
|
||
1 month ago
|
}
|
||
|
|
||
|
|
||
|
void SetToolMode(ToolMode value)
|
||
|
{
|
||
1 month ago
|
// Ignore if _Ready hasn't been called yet.
|
||
|
if (ToolModeButtons == null) return;
|
||
|
|
||
1 month ago
|
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)
|
||
|
{
|
||
1 month ago
|
// Ignore if _Ready hasn't been called yet.
|
||
|
if (ToolShapeButtons == null) return;
|
||
|
|
||
1 month ago
|
foreach (var (shape, button) in ToolShapeButtons)
|
||
|
button.Flat = button.ButtonPressed = value != shape;
|
||
|
DrawSizeSlider.Editable = value != ToolShape.Corner;
|
||
|
_toolShape = value;
|
||
|
}
|
||
|
|
||
|
void SetTexture(int value)
|
||
|
{
|
||
1 month ago
|
// Ignore if _Ready hasn't been called yet.
|
||
|
if (PaintTextureButtons == null) return;
|
||
|
|
||
1 month ago
|
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,
|
||
|
}
|