More terrain editing controls tweaking

main
copygirl 2 months ago
parent ac0d3f12bb
commit 49e1112ec2
  1. 56
      terrain/editing/TerrainEditingControls.cs
  2. 24
      terrain/editing/TerrainEditingControls.tscn

@ -7,18 +7,10 @@ public partial class TerrainEditingControls
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 ToolMode ToolMode { get => GetToolMode (); set => SetToolMode (value); }
public ToolShape ToolShape { get => GetToolShape(); set => SetToolShape(value); }
public int DrawSize { get => GetDrawSize (); set => SetDrawSize (value); }
public int Texture { get => GetTexture (); set => SetTexture (value); }
public override void _Ready()
{
@ -26,13 +18,11 @@ public partial class TerrainEditingControls
(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"),
@ -50,46 +40,48 @@ public partial class TerrainEditingControls
var drawSizeLabel = GetNode<Label>("SizeLabel");
DrawSizeSlider = GetNode<Slider>("SizeSlider");
DrawSizeSlider.ValueChanged += (_) => drawSizeLabel.Text = $"{DrawSize}";
SetToolMode(_toolMode);
SetToolShape(_toolShape);
SetTexture(_texture);
}
ToolMode GetToolMode()
=> ToolModeButtons?.First(x => x.Item2.ButtonPressed).Item1 ?? ToolMode.Height;
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;
button.Flat = !(button.ButtonPressed = value == mode);
foreach (var button in PaintTextureButtons)
button.Disabled = value != ToolMode.Paint;
_toolMode = value;
}
ToolShape GetToolShape()
=> ToolShapeButtons?.First(x => x.Item2.ButtonPressed).Item1 ?? ToolShape.Circle;
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;
button.Flat = !(button.ButtonPressed = value == shape);
DrawSizeSlider.Editable = value != ToolShape.Corner;
_toolShape = value;
}
int GetDrawSize()
=> RoundToInt(-DrawSizeSlider?.Value ?? 1);
void SetDrawSize(int value)
{
if (DrawSizeSlider == null) return;
DrawSizeSlider.Value = -value;
}
int GetTexture()
=> PaintTextureButtons?
.Select((b, i) => (Index: i + 1, Button: b))
.First(x => x.Button.ButtonPressed).Index ?? 1;
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;
foreach (var (index, button) in PaintTextureButtons.Select((b, i) => (i, b)))
button.Flat = !(button.ButtonPressed = value == index + 1);
}
}

@ -24,24 +24,17 @@ image = ExtResource("Image_x8cdn")
image = ExtResource("Image_sb66e")
[node name="TerrainEditingControls" type="VBoxContainer"]
anchors_preset = 11
anchor_left = 1.0
anchor_right = 1.0
anchor_bottom = 1.0
offset_left = -20.0
grow_horizontal = 0
grow_vertical = 2
script = ExtResource("1_fklx3")
[node name="Height" type="Button" parent="."]
layout_mode = 2
toggle_mode = true
button_pressed = true
icon = ExtResource("2_hrmm4")
[node name="Paint" type="Button" parent="."]
layout_mode = 2
toggle_mode = true
button_pressed = true
icon = ExtResource("3_5x55r")
flat = true
@ -51,19 +44,18 @@ layout_mode = 2
[node name="Corner" type="Button" parent="."]
layout_mode = 2
toggle_mode = true
button_pressed = true
icon = ExtResource("1_w5qr7")
flat = true
[node name="Circle" type="Button" parent="."]
layout_mode = 2
toggle_mode = true
button_pressed = true
icon = ExtResource("2_yvc34")
[node name="Square" type="Button" parent="."]
layout_mode = 2
toggle_mode = true
button_pressed = true
icon = ExtResource("3_aaaoe")
flat = true
@ -86,7 +78,7 @@ layout_mode = 2
[node name="Grass" type="Button" parent="."]
layout_mode = 2
theme_override_colors/icon_normal_color = Color(1, 1, 1, 1)
theme_override_colors/icon_normal_color = Color(0.752941, 0.752941, 0.752941, 1)
theme_override_colors/icon_focus_color = Color(1, 1, 1, 1)
theme_override_colors/icon_pressed_color = Color(1, 1, 1, 1)
theme_override_colors/icon_hover_color = Color(1, 1, 1, 1)
@ -95,11 +87,12 @@ theme_override_colors/icon_disabled_color = Color(0.753984, 0.753984, 0.753984,
theme_override_constants/icon_max_width = 16
disabled = true
toggle_mode = true
button_pressed = true
icon = SubResource("ImageTexture_btyvd")
[node name="Dirt" type="Button" parent="."]
layout_mode = 2
theme_override_colors/icon_normal_color = Color(1, 1, 1, 1)
theme_override_colors/icon_normal_color = Color(0.752941, 0.752941, 0.752941, 1)
theme_override_colors/icon_focus_color = Color(1, 1, 1, 1)
theme_override_colors/icon_pressed_color = Color(1, 1, 1, 1)
theme_override_colors/icon_hover_color = Color(1, 1, 1, 1)
@ -108,13 +101,12 @@ theme_override_colors/icon_disabled_color = Color(0.753984, 0.753984, 0.753984,
theme_override_constants/icon_max_width = 16
disabled = true
toggle_mode = true
button_pressed = true
icon = SubResource("ImageTexture_wk5vj")
flat = true
[node name="Rock" type="Button" parent="."]
layout_mode = 2
theme_override_colors/icon_normal_color = Color(1, 1, 1, 1)
theme_override_colors/icon_normal_color = Color(0.752941, 0.752941, 0.752941, 1)
theme_override_colors/icon_focus_color = Color(1, 1, 1, 1)
theme_override_colors/icon_pressed_color = Color(1, 1, 1, 1)
theme_override_colors/icon_hover_color = Color(1, 1, 1, 1)
@ -123,13 +115,12 @@ theme_override_colors/icon_disabled_color = Color(0.753984, 0.753984, 0.753984,
theme_override_constants/icon_max_width = 16
disabled = true
toggle_mode = true
button_pressed = true
icon = SubResource("ImageTexture_mfste")
flat = true
[node name="Sand" type="Button" parent="."]
layout_mode = 2
theme_override_colors/icon_normal_color = Color(1, 1, 1, 1)
theme_override_colors/icon_normal_color = Color(0.752941, 0.752941, 0.752941, 1)
theme_override_colors/icon_focus_color = Color(1, 1, 1, 1)
theme_override_colors/icon_pressed_color = Color(1, 1, 1, 1)
theme_override_colors/icon_hover_color = Color(1, 1, 1, 1)
@ -138,6 +129,5 @@ theme_override_colors/icon_disabled_color = Color(0.753984, 0.753984, 0.753984,
theme_override_constants/icon_max_width = 16
disabled = true
toggle_mode = true
button_pressed = true
icon = SubResource("ImageTexture_2hv1j")
flat = true

Loading…
Cancel
Save