added simple ui

This commit is contained in:
2024-03-23 17:17:44 +01:00
parent 6308195224
commit 015f86cec1
4 changed files with 103 additions and 3 deletions

11
Scenes/FPSLabel.cs Normal file
View File

@@ -0,0 +1,11 @@
using Godot;
public partial class FPSLabel : Label
{
bool ShowFPS = true;
// Called every frame. 'delta' is the elapsed time since the previous frame.
public override void _Process(double delta) {
Text = ShowFPS ? $"FPS: {Engine.GetFramesPerSecond()}" : "";
}
}

View File

@@ -0,0 +1,30 @@
using Godot;
public partial class SettingsController : VBoxContainer
{
private Main main;
private Slider slSize;
private Slider slRain;
// Called when the node enters the scene tree for the first time.
public override void _Ready()
{
main = GetNode<Main>("/root/Main");
slSize = GetNode<Slider>("brushSettings/slSize");
slRain = GetNode<Slider>("weatherSettings/slRain");
slSize.ValueChanged += OnSizeValueChanged;
OnSizeValueChanged(main.BrushSize);
slRain.ValueChanged += OnRainValueChanged;
OnRainValueChanged(main.RainAmount);
}
private void OnSizeValueChanged(double value) {
main.BrushSize = (int)value;
}
private void OnRainValueChanged(double value) {
main.RainAmount = (float)value;
}
}

View File

@@ -1,11 +1,12 @@
[gd_scene load_steps=2 format=3 uid="uid://cf34vk5r055dx"]
[gd_scene load_steps=4 format=3 uid="uid://cf34vk5r055dx"]
[ext_resource type="Script" path="res://Scripts/Main.cs" id="1_k1i8e"]
[ext_resource type="Script" path="res://Scenes/FPSLabel.cs" id="2_8cb7y"]
[ext_resource type="Script" path="res://Scenes/SettingsController.cs" id="3_a4w6m"]
[node name="Main" type="Node2D"]
script = ExtResource("1_k1i8e")
BrushSize = 1
TextureResolution = 0.25
RainAmount = 1.0
[node name="CanvasLayer" type="CanvasLayer" parent="."]
@@ -17,3 +18,62 @@ anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
expand_mode = 2
[node name="TopUI" type="Control" parent="CanvasLayer"]
layout_mode = 3
anchors_preset = 10
anchor_right = 1.0
grow_horizontal = 2
[node name="FpsLabel" type="Label" parent="CanvasLayer/TopUI"]
layout_mode = 0
offset_right = 76.0
offset_bottom = 37.0
text = "FPS: 0
"
script = ExtResource("2_8cb7y")
[node name="Settings" type="VBoxContainer" parent="CanvasLayer/TopUI"]
layout_mode = 1
anchors_preset = 1
anchor_left = 1.0
anchor_right = 1.0
offset_left = -275.0
offset_bottom = 46.0
grow_horizontal = 0
script = ExtResource("3_a4w6m")
[node name="brushSettings" type="HBoxContainer" parent="CanvasLayer/TopUI/Settings"]
layout_mode = 2
alignment = 2
[node name="lblBrushSize" type="Label" parent="CanvasLayer/TopUI/Settings/brushSettings"]
layout_mode = 2
text = "Brush Size:"
[node name="slSize" type="HSlider" parent="CanvasLayer/TopUI/Settings/brushSettings"]
custom_minimum_size = Vector2(150, 0)
layout_mode = 2
size_flags_horizontal = 8
size_flags_vertical = 1
min_value = 1.0
value = 1.0
rounded = true
[node name="weatherSettings" type="HBoxContainer" parent="CanvasLayer/TopUI/Settings"]
layout_mode = 2
alignment = 2
[node name="lblRainAmt" type="Label" parent="CanvasLayer/TopUI/Settings/weatherSettings"]
layout_mode = 2
text = "Rain Amount:
"
[node name="slRain" type="HSlider" parent="CanvasLayer/TopUI/Settings/weatherSettings"]
custom_minimum_size = Vector2(150, 0)
layout_mode = 2
size_flags_horizontal = 8
size_flags_vertical = 1
max_value = 1.0
step = 0.01
value = 1.0

View File

@@ -31,7 +31,6 @@ public partial class Main : Node2D {
float mappedX = mouse.X / GetViewportRect().Size.X * mLevel.SizeX;
float mappedY = mouse.Y / GetViewportRect().Size.Y * mLevel.SizeY;
GD.Print($"click: {mouse}");
mLevel.WritePixel<Dirt>((int)mappedX, (int)mappedY, BrushSize);
}
}