various menu changes and fixes
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using System.Globalization;
|
||||
using Godot;
|
||||
|
||||
public class MainMenu : Control
|
||||
@@ -10,6 +11,10 @@ public class MainMenu : Control
|
||||
private TextEdit _seedText;
|
||||
private TextEdit _particleCountText;
|
||||
private Button _randomizeButton;
|
||||
private Label _zoomValue;
|
||||
private HSlider _zoomSlider;
|
||||
|
||||
private Label _invalidLabel;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
@@ -20,17 +25,27 @@ public class MainMenu : Control
|
||||
_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");
|
||||
_zoomValue = GetNode("MenuButtons").GetNode("Inputs").GetNode("Zoom").GetNode<Label>("ZoomValue");
|
||||
_zoomSlider = GetNode("MenuButtons").GetNode("Inputs").GetNode("Zoom").GetNode<HSlider>("ZoomSlider");
|
||||
_invalidLabel = GetNode<Label>("InvalidLabel");
|
||||
|
||||
// Connect signals
|
||||
_simulateButton.Connect("pressed", this, nameof(_OnSimulatePressed));
|
||||
_toggleFullScreenButton.Connect("pressed", this, nameof(_OnToggleFullscreenPressed));
|
||||
_randomizeButton.Connect("pressed", this, nameof(_OnRandomizePressed));
|
||||
_zoomSlider.Connect("value_changed", this, nameof(_OnZoomSliderChange));
|
||||
|
||||
// Random seed
|
||||
GD.Randomize();
|
||||
var randomSeed = (int)GD.Randi();
|
||||
var randomSeed = Mathf.Abs((int)GD.Randi());
|
||||
_main.Seed = randomSeed;
|
||||
RefreshSeedText();
|
||||
RefreshSeedText();
|
||||
}
|
||||
|
||||
public void _OnZoomSliderChange(float value)
|
||||
{
|
||||
_zoomValue.Text = value.ToString(CultureInfo.InvariantCulture);
|
||||
_main.Zoom = value;
|
||||
}
|
||||
|
||||
public void RefreshSeedText()
|
||||
@@ -41,8 +56,16 @@ public class MainMenu : Control
|
||||
public void _OnSimulatePressed()
|
||||
{
|
||||
// Start simulation with seed and number of particles
|
||||
var nParticles = _particleCountText.Text.ToInt();
|
||||
_main.Seed = _seedText.Text.ToInt();
|
||||
var particleCountCheck = int.TryParse(_particleCountText.Text, out var nParticles);
|
||||
var seedCheck = int.TryParse(_seedText.Text, out var seed);
|
||||
if (!particleCountCheck || !seedCheck)
|
||||
{
|
||||
ShowInvalid();
|
||||
return;
|
||||
}
|
||||
|
||||
_main.Zoom = (float)_zoomSlider.Value;
|
||||
_main.Seed = seed;
|
||||
_main.StartSimulation(nParticles);
|
||||
}
|
||||
|
||||
@@ -53,7 +76,7 @@ public class MainMenu : Control
|
||||
|
||||
public void _OnRandomizePressed()
|
||||
{
|
||||
var randomSeed = (int) GD.Randi();
|
||||
var randomSeed = Mathf.Abs((int)GD.Randi());
|
||||
_main.Seed = randomSeed;
|
||||
RefreshSeedText();
|
||||
}
|
||||
@@ -66,4 +89,19 @@ public class MainMenu : Control
|
||||
GetTree().Quit();
|
||||
}
|
||||
}
|
||||
|
||||
private async void ShowInvalid()
|
||||
{
|
||||
GetNode<Tween>("InvalidTween").ResetAll();
|
||||
GetNode<Timer>("InvalidTimer").Stop();
|
||||
GetNode<Timer>("InvalidTimer").WaitTime = 3.0f;
|
||||
_invalidLabel.Modulate = new Color(1, 1, 1, 1);
|
||||
var invalidTimer = GetNode<Timer>("InvalidTimer");
|
||||
invalidTimer.Start();
|
||||
await ToSignal(invalidTimer, "timeout");
|
||||
var invalidTween = GetNode<Tween>("InvalidTween");
|
||||
invalidTween.InterpolateProperty(_invalidLabel, "modulate:a", 1, 0, 1);
|
||||
invalidTween.Start();
|
||||
await ToSignal(invalidTween, "tween_all_completed");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user