various menu changes and fixes

This commit is contained in:
orosmatthew 2022-01-25 23:06:48 -05:00
parent a3019beef1
commit dda22a8367
6 changed files with 144 additions and 36 deletions

13
Main.cs
View File

@ -6,8 +6,15 @@ public class Main : Node
{
public int Seed;
private int _nParticles;
public float Zoom;
private int _nParticles;
public override void _Ready()
{
OS.MinWindowSize = new Vector2(1024, 600);
}
public void StartSimulation(int nParticles)
{
_nParticles = nParticles;
@ -15,7 +22,7 @@ public class Main : Node
var particleSimulationScene = particleSimulationPackedScene.Instance<ParticleSimulationScene>();
particleSimulationScene.Name = Seed.ToString();
AddChild(particleSimulationScene);
particleSimulationScene.Initialize(nParticles);
particleSimulationScene.Initialize(Seed, nParticles, Zoom);
GetNode<Control>("MainMenu").Hide();
}
@ -30,7 +37,7 @@ public class Main : Node
{
GetNode<ParticleSimulationScene>(Seed.ToString()).Hide();
GetNode(Seed.ToString()).QueueFree();
Seed = (int) GD.Randi();
Seed = Mathf.Abs((int)GD.Randi());
StartSimulation(_nParticles);
}

View File

@ -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");
}
}

View File

@ -20,12 +20,12 @@ __meta__ = {
[node name="MenuButtons" type="VBoxContainer" parent="."]
anchor_left = 0.5
anchor_top = 0.5
anchor_top = 0.582
anchor_right = 0.5
anchor_bottom = 0.5
margin_left = -259.5
margin_top = -114.0
margin_right = 259.5
anchor_bottom = 0.582
margin_left = -304.0
margin_top = -172.5
margin_right = 304.0
margin_bottom = 172.5
custom_constants/separation = 12
__meta__ = {
@ -33,17 +33,17 @@ __meta__ = {
}
[node name="Inputs" type="HBoxContainer" parent="MenuButtons"]
margin_right = 519.0
margin_right = 608.0
margin_bottom = 150.0
alignment = 1
[node name="Seed" type="VBoxContainer" parent="MenuButtons/Inputs"]
margin_right = 250.946
margin_right = 200.0
margin_bottom = 150.0
rect_min_size = Vector2( 250.946, 0 )
rect_min_size = Vector2( 200, 0 )
[node name="SeedLabel" type="Label" parent="MenuButtons/Inputs/Seed"]
margin_right = 250.0
margin_right = 200.0
margin_bottom = 27.0
text = "Seed Number"
align = 1
@ -53,14 +53,14 @@ __meta__ = {
[node name="SeedText" type="TextEdit" parent="MenuButtons/Inputs/Seed"]
margin_top = 31.0
margin_right = 250.0
margin_right = 200.0
margin_bottom = 95.769
rect_min_size = Vector2( 0, 64.769 )
text = "12345"
[node name="RandomizeButton" type="Button" parent="MenuButtons/Inputs/Seed"]
margin_top = 99.0
margin_right = 250.0
margin_right = 200.0
margin_bottom = 150.251
text = "Randomize!"
__meta__ = {
@ -68,26 +68,55 @@ __meta__ = {
}
[node name="ParticleCount" type="VBoxContainer" parent="MenuButtons/Inputs"]
margin_left = 254.0
margin_right = 519.0
margin_left = 204.0
margin_right = 404.0
margin_bottom = 150.0
rect_min_size = Vector2( 200, 0 )
[node name="ParticleCountLabel" type="Label" parent="MenuButtons/Inputs/ParticleCount"]
margin_right = 265.0
margin_right = 200.0
margin_bottom = 27.0
text = "Number of Particles"
text = "Particle Count"
align = 1
[node name="ParticleCountText" type="TextEdit" parent="MenuButtons/Inputs/ParticleCount"]
margin_top = 31.0
margin_right = 265.0
margin_bottom = 95.769
rect_min_size = Vector2( 0, 64.769 )
margin_right = 200.0
margin_bottom = 96.0
rect_min_size = Vector2( 0, 65 )
text = "1000"
[node name="Zoom" type="VBoxContainer" parent="MenuButtons/Inputs"]
margin_left = 408.0
margin_right = 608.0
margin_bottom = 150.0
rect_min_size = Vector2( 200, 0 )
[node name="ZoomLabel" type="Label" parent="MenuButtons/Inputs/Zoom"]
margin_right = 200.0
margin_bottom = 27.0
text = "Zoom"
align = 1
[node name="ZoomValue" type="Label" parent="MenuButtons/Inputs/Zoom"]
margin_top = 31.0
margin_right = 200.0
margin_bottom = 58.0
text = "1.4"
align = 1
[node name="ZoomSlider" type="HSlider" parent="MenuButtons/Inputs/Zoom"]
margin_top = 62.0
margin_right = 200.0
margin_bottom = 104.0
min_value = 0.5
max_value = 5.0
step = 0.1
value = 1.4
[node name="SimulateButton" type="Button" parent="MenuButtons"]
margin_top = 162.0
margin_right = 519.0
margin_right = 608.0
margin_bottom = 213.251
text = "Simulate!"
__meta__ = {
@ -96,7 +125,7 @@ __meta__ = {
[node name="Warning" type="Label" parent="MenuButtons"]
margin_top = 225.0
margin_right = 519.0
margin_right = 608.0
margin_bottom = 270.0
custom_fonts/font = SubResource( 1 )
text = "Simulation cannot be resized
@ -105,7 +134,7 @@ align = 1
[node name="HBoxContainer" type="HBoxContainer" parent="MenuButtons"]
margin_top = 282.0
margin_right = 519.0
margin_right = 608.0
margin_bottom = 282.0
__meta__ = {
"_edit_use_anchors_": false
@ -113,7 +142,7 @@ __meta__ = {
[node name="ToggleFullscreenButton" type="Button" parent="MenuButtons"]
margin_top = 294.0
margin_right = 519.0
margin_right = 608.0
margin_bottom = 345.251
text = "Toggle Fullscreen!"
@ -131,5 +160,41 @@ rect_scale = Vector2( 0.35, 0.35 )
mouse_filter = 2
texture = ExtResource( 2 )
__meta__ = {
"_edit_lock_": true,
"_edit_use_anchors_": false
}
[node name="Controls" type="Label" parent="."]
anchor_left = 1.0
anchor_top = 1.0
anchor_right = 1.0
anchor_bottom = 1.0
margin_left = -183.0
margin_top = -81.0
margin_right = -10.0
margin_bottom = -12.0
custom_fonts/font = SubResource( 1 )
text = "Controls
R to Restart
Esc to Exit"
align = 1
__meta__ = {
"_edit_use_anchors_": false
}
[node name="InvalidLabel" type="Label" parent="."]
modulate = Color( 1, 1, 1, 0 )
margin_left = 15.0
margin_top = 16.0
margin_right = 226.0
margin_bottom = 43.0
text = "Invalid Inputs!"
uppercase = true
__meta__ = {
"_edit_use_anchors_": false
}
[node name="InvalidTween" type="Tween" parent="."]
[node name="InvalidTimer" type="Timer" parent="."]
one_shot = true

View File

@ -10,15 +10,14 @@ public class ParticleSimulationScene : Node2D
private ParticleSimulation _particleSimulation;
public float PhysicsInterpolationFraction;
public void Initialize(int nParticles)
public void Initialize(int seed, int nParticles, float zoom)
{
_particleNodes = GetNode<Node2D>("ParticleNodes");
var seed = GetParent<Main>().Seed;
GD.Seed((ulong)seed);
GD.Print("Last Seed: " + seed);
var viewSize = GetViewportRect().Size;
var zoom = GetNode<Camera2D>("Camera2D").Zoom;
var spaceSize = new Vector2(viewSize.x * zoom.x, viewSize.y * zoom.y);
GetNode<Camera2D>("Camera2D").Zoom = new Vector2(zoom, zoom);
var spaceSize = viewSize * zoom;
_particleSimulation = new ParticleSimulation
{
SpaceSize = spaceSize

View File

@ -2,7 +2,6 @@
[ext_resource path="res://ParticleSimulation/ParticleSimulationScene.cs" type="Script" id=1]
[node name="ParticleSimulationScene" type="Node2D"]
script = ExtResource( 1 )

View File

@ -283,7 +283,7 @@ TextEdit/colors/bookmark_color = Color( 0.08, 0.49, 0.98, 1 )
TextEdit/colors/brace_mismatch_color = Color( 1, 0.2, 0.2, 1 )
TextEdit/colors/breakpoint_color = Color( 0.8, 0.8, 0.4, 0.2 )
TextEdit/colors/caret_background_color = Color( 0, 0, 0, 1 )
TextEdit/colors/caret_color = Color( 0.88, 0.88, 0.88, 1 )
TextEdit/colors/caret_color = Color( 0, 0, 0, 1 )
TextEdit/colors/code_folding_color = Color( 0.8, 0.8, 0.8, 0.8 )
TextEdit/colors/completion_background_color = Color( 0.17, 0.16, 0.2, 1 )
TextEdit/colors/completion_existing_color = Color( 0.87, 0.87, 0.87, 0.13 )