From bec2accd9fc45c72adc39d19dcc93c158a5a7903 Mon Sep 17 00:00:00 2001 From: kesac Date: Tue, 11 Jun 2024 21:45:27 -0600 Subject: [PATCH] New node ShiftingLabel for visualizing consonant/vowel pools --- .../Syllabore.Visualizer/ShiftingLabel.cs | 30 +++++++++++++++++++ .../Syllabore.Visualizer/ShiftingLabel.tscn | 21 +++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 Syllabore/Syllabore.Visualizer/ShiftingLabel.cs create mode 100644 Syllabore/Syllabore.Visualizer/ShiftingLabel.tscn diff --git a/Syllabore/Syllabore.Visualizer/ShiftingLabel.cs b/Syllabore/Syllabore.Visualizer/ShiftingLabel.cs new file mode 100644 index 0000000..f5bc610 --- /dev/null +++ b/Syllabore/Syllabore.Visualizer/ShiftingLabel.cs @@ -0,0 +1,30 @@ +using Godot; +using System; +using System.Collections.Generic; + +public partial class ShiftingLabel : Label +{ + private Random _random; + + // Strings to shift through + public List Values; + + public override void _Ready() + { + _random = new Random(); + this.Values = new List(); + this.GetNode("Timer").Start(); + } + + // Randomly select a value from the list + // and set the value of this label + public void Shift() + { + if (this.Values.Count > 0) + { + var index = _random.Next(0, this.Values.Count); + this.Text = this.Values[index].ToUpper(); + } + } + +} diff --git a/Syllabore/Syllabore.Visualizer/ShiftingLabel.tscn b/Syllabore/Syllabore.Visualizer/ShiftingLabel.tscn new file mode 100644 index 0000000..d1bdb65 --- /dev/null +++ b/Syllabore/Syllabore.Visualizer/ShiftingLabel.tscn @@ -0,0 +1,21 @@ +[gd_scene load_steps=3 format=3 uid="uid://cr4njnftd3faq"] + +[ext_resource type="Script" path="res://ShiftingLabel.cs" id="1_53b72"] + +[sub_resource type="LabelSettings" id="LabelSettings_0r5f7"] +font_size = 35 + +[node name="ShiftingLabel" type="Label"] +offset_right = 40.0 +offset_bottom = 23.0 +text = "X" +label_settings = SubResource("LabelSettings_0r5f7") +horizontal_alignment = 1 +vertical_alignment = 1 +script = ExtResource("1_53b72") + +[node name="Timer" type="Timer" parent="."] +wait_time = 0.2 +autostart = true + +[connection signal="timeout" from="Timer" to="." method="Shift"]