randomize seed for menu

This commit is contained in:
2022-01-25 12:33:18 -05:00
parent 17017d631e
commit a3019beef1
4 changed files with 104 additions and 53 deletions

View File

@@ -1,5 +1,4 @@
using Godot;
using System;
public class MainMenu : Control
{
@@ -10,6 +9,7 @@ public class MainMenu : Control
private Button _toggleFullScreenButton;
private TextEdit _seedText;
private TextEdit _particleCountText;
private Button _randomizeButton;
public override void _Ready()
{
@@ -17,25 +17,33 @@ public class MainMenu : Control
_main = GetTree().Root.GetNode<Main>("Main");
_simulateButton = GetNode("MenuButtons").GetNode<Button>("SimulateButton");
_toggleFullScreenButton = GetNode("MenuButtons").GetNode<Button>("ToggleFullscreenButton");
_seedText = GetNode("MenuButtons").GetNode<TextEdit>("SeedText");
_particleCountText = GetNode("MenuButtons").GetNode<TextEdit>("ParticleCountText");
_seedText = GetNode("MenuButtons").GetNode("Inputs").GetNode("Seed").GetNode<TextEdit>("SeedText");
_particleCountText = GetNode("MenuButtons").GetNode("Inputs").GetNode("ParticleCount").GetNode<TextEdit>("ParticleCountText");
_randomizeButton = GetNode("MenuButtons").GetNode("Inputs").GetNode("Seed").GetNode<Button>("RandomizeButton");
// Connect signals
_simulateButton.Connect("pressed", this, nameof(_OnSimulatePressed));
_toggleFullScreenButton.Connect("pressed", this, nameof(_OnToggleFullscreenPressed));
_randomizeButton.Connect("pressed", this, nameof(_OnRandomizePressed));
// Random seed
GD.Randomize();
var randomSeed = (int)GD.Randi();
_seedText.Text = randomSeed.ToString();
_main.Seed = randomSeed;
RefreshSeedText();
}
public void RefreshSeedText()
{
_seedText.Text = _main.Seed.ToString();
}
public void _OnSimulatePressed()
{
// Start simulation with seed and number of particles
var nParticles = _particleCountText.Text.ToInt();
var seed = _seedText.Text.ToInt();
_main.StartSimulation(seed, nParticles);
_main.Seed = _seedText.Text.ToInt();
_main.StartSimulation(nParticles);
}
public void _OnToggleFullscreenPressed()
@@ -43,6 +51,13 @@ public class MainMenu : Control
OS.WindowFullscreen = !OS.WindowFullscreen;
}
public void _OnRandomizePressed()
{
var randomSeed = (int) GD.Randi();
_main.Seed = randomSeed;
RefreshSeedText();
}
public override void _Input(InputEvent @event)
{
// Quit only if menu is visible