From 015f86cec1259b4c57b4e7855bb3fa1c73ff7152 Mon Sep 17 00:00:00 2001 From: rogo Date: Sat, 23 Mar 2024 17:17:44 +0100 Subject: [PATCH] added simple ui --- Scenes/FPSLabel.cs | 11 +++++++ Scenes/SettingsController.cs | 30 +++++++++++++++++ Scenes/main.tscn | 64 ++++++++++++++++++++++++++++++++++-- Scripts/Main.cs | 1 - 4 files changed, 103 insertions(+), 3 deletions(-) create mode 100644 Scenes/FPSLabel.cs create mode 100644 Scenes/SettingsController.cs diff --git a/Scenes/FPSLabel.cs b/Scenes/FPSLabel.cs new file mode 100644 index 0000000..a204847 --- /dev/null +++ b/Scenes/FPSLabel.cs @@ -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()}" : ""; + } +} diff --git a/Scenes/SettingsController.cs b/Scenes/SettingsController.cs new file mode 100644 index 0000000..f4964df --- /dev/null +++ b/Scenes/SettingsController.cs @@ -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
("/root/Main"); + slSize = GetNode("brushSettings/slSize"); + slRain = GetNode("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; + } +} diff --git a/Scenes/main.tscn b/Scenes/main.tscn index 46fcbc7..6059423 100644 --- a/Scenes/main.tscn +++ b/Scenes/main.tscn @@ -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 diff --git a/Scripts/Main.cs b/Scripts/Main.cs index a14edc8..8132101 100644 --- a/Scripts/Main.cs +++ b/Scripts/Main.cs @@ -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((int)mappedX, (int)mappedY, BrushSize); } }