fixed issue #1
This commit is contained in:
parent
dda22a8367
commit
005e34498e
@ -16,6 +16,9 @@ public class MainMenu : Control
|
|||||||
|
|
||||||
private Label _invalidLabel;
|
private Label _invalidLabel;
|
||||||
|
|
||||||
|
private string _prevSeedText;
|
||||||
|
private string _prevParticleCountText;
|
||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
// Init nodes
|
// Init nodes
|
||||||
@ -34,12 +37,46 @@ public class MainMenu : Control
|
|||||||
_toggleFullScreenButton.Connect("pressed", this, nameof(_OnToggleFullscreenPressed));
|
_toggleFullScreenButton.Connect("pressed", this, nameof(_OnToggleFullscreenPressed));
|
||||||
_randomizeButton.Connect("pressed", this, nameof(_OnRandomizePressed));
|
_randomizeButton.Connect("pressed", this, nameof(_OnRandomizePressed));
|
||||||
_zoomSlider.Connect("value_changed", this, nameof(_OnZoomSliderChange));
|
_zoomSlider.Connect("value_changed", this, nameof(_OnZoomSliderChange));
|
||||||
|
_seedText.Connect("text_changed", this, nameof(_OnSeedTextChange));
|
||||||
|
_particleCountText.Connect("text_changed", this, nameof(_OnParticleCountTextChange));
|
||||||
|
|
||||||
// Random seed
|
// Random seed
|
||||||
GD.Randomize();
|
GD.Randomize();
|
||||||
var randomSeed = Mathf.Abs((int)GD.Randi());
|
var randomSeed = Mathf.Abs((int)GD.Randi());
|
||||||
_main.Seed = randomSeed;
|
_main.Seed = randomSeed;
|
||||||
RefreshSeedText();
|
RefreshSeedText();
|
||||||
|
|
||||||
|
// Set default previous values
|
||||||
|
_prevSeedText = _seedText.Text;
|
||||||
|
_prevParticleCountText = _particleCountText.Text;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void _OnParticleCountTextChange()
|
||||||
|
{
|
||||||
|
var particleCountCheck = int.TryParse(_particleCountText.Text, out var nParticles);
|
||||||
|
if (!particleCountCheck && !_particleCountText.Text.Empty())
|
||||||
|
{
|
||||||
|
ShowInvalid();
|
||||||
|
_particleCountText.Text = _prevParticleCountText;
|
||||||
|
}
|
||||||
|
else if (!_particleCountText.Text.Empty())
|
||||||
|
{
|
||||||
|
_prevParticleCountText = _particleCountText.Text;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void _OnSeedTextChange()
|
||||||
|
{
|
||||||
|
var seedCheck = int.TryParse(_seedText.Text, out var seed);
|
||||||
|
if (!seedCheck && !_seedText.Text.Empty())
|
||||||
|
{
|
||||||
|
ShowInvalid();
|
||||||
|
_seedText.Text = _prevSeedText;
|
||||||
|
}
|
||||||
|
else if (!_seedText.Text.Empty())
|
||||||
|
{
|
||||||
|
_prevSeedText = _seedText.Text;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void _OnZoomSliderChange(float value)
|
public void _OnZoomSliderChange(float value)
|
||||||
@ -51,22 +88,20 @@ public class MainMenu : Control
|
|||||||
public void RefreshSeedText()
|
public void RefreshSeedText()
|
||||||
{
|
{
|
||||||
_seedText.Text = _main.Seed.ToString();
|
_seedText.Text = _main.Seed.ToString();
|
||||||
|
_prevSeedText = _seedText.Text;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void _OnSimulatePressed()
|
public void _OnSimulatePressed()
|
||||||
{
|
{
|
||||||
// Start simulation with seed and number of particles
|
// Start simulation with seed and number of particles
|
||||||
var particleCountCheck = int.TryParse(_particleCountText.Text, out var nParticles);
|
if (_seedText.Text.Empty() || _particleCountText.Text.Empty())
|
||||||
var seedCheck = int.TryParse(_seedText.Text, out var seed);
|
|
||||||
if (!particleCountCheck || !seedCheck)
|
|
||||||
{
|
{
|
||||||
ShowInvalid();
|
ShowInvalid();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_main.Zoom = (float)_zoomSlider.Value;
|
_main.Zoom = (float)_zoomSlider.Value;
|
||||||
_main.Seed = seed;
|
_main.Seed = int.Parse(_seedText.Text);
|
||||||
_main.StartSimulation(nParticles);
|
_main.StartSimulation(int.Parse(_particleCountText.Text));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void _OnToggleFullscreenPressed()
|
public void _OnToggleFullscreenPressed()
|
||||||
|
Loading…
Reference in New Issue
Block a user