Added random seed and ability to enter a seed. Also added a simple/small tutorial screen and unified the UI with UIStyle.cs

This commit is contained in:
2026-05-09 22:09:15 +02:00
parent 7e70471227
commit fc21c7c8d3
12 changed files with 493 additions and 22 deletions
+72
View File
@@ -0,0 +1,72 @@
using Godot;
using System;
public partial class WorldSetup : Control
{
[Export] LineEdit seedInput;
[Export] RichTextLabel seedPreview;
public override void _Ready()
{
UIStyle.Apply(this);
UpdateSeedPreview();
}
public void OnSeedChanged(string text)
{
UpdateSeedPreview();
}
public void OnStartPressed()
{
GameData.seed = GetSelectedSeed();
GameData.loadSaveOnStart = false;
GameData.showTutorial = true;
GetTree().ChangeSceneToFile("res://Scenes/Game.tscn");
}
public void OnBackPressed()
{
GetTree().ChangeSceneToFile("res://Scenes/MainMenu.tscn");
}
private int GetSelectedSeed()
{
string text = seedInput.Text.Trim();
if (text.Length <= 0)
{
return new Random().Next(1, int.MaxValue);
}
int numericSeed;
if (int.TryParse(text, out numericSeed))
{
return numericSeed;
}
return CreateTextSeed(text);
}
private int CreateTextSeed(string text)
{
int hash = 17;
foreach (char character in text)
{
hash = hash * 31 + character;
}
return Math.Abs(hash);
}
private void UpdateSeedPreview()
{
string text = seedInput.Text.Trim();
if (text.Length <= 0)
{
seedPreview.Text = "No seed entered. B.O.B. will pick one from the ruins.";
return;
}
seedPreview.Text = "Selected seed: " + GetSelectedSeed();
}
}