better menu

This commit is contained in:
2022-01-25 12:02:24 -05:00
parent d2ebbdef62
commit 17017d631e
7 changed files with 554 additions and 42 deletions

View File

@@ -4,24 +4,51 @@ using System;
public class MainMenu : Control
{
// Nodes for menu items
private Main _main;
private Button _simulateButton;
private Button _toggleFullScreenButton;
private TextEdit _seedText;
private TextEdit _particleCountText;
public override void _Ready()
{
// Init nodes
_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");
// Connect signals
_simulateButton.Connect("pressed", this, nameof(_OnSimulatePressed));
_toggleFullScreenButton.Connect("pressed", this, nameof(_OnToggleFullscreenPressed));
// Random seed
GD.Randomize();
var randomSeed = (int)GD.Randi();
_seedText.Text = randomSeed.ToString();
}
public void _on_Button_pressed()
public void _OnSimulatePressed()
{
var nParticles = GetNode<VBoxContainer>("MenuButtons").GetNode<TextEdit>("TextEdit").Text.ToInt();
_main.StartSimulation(nParticles);
// Start simulation with seed and number of particles
var nParticles = _particleCountText.Text.ToInt();
var seed = _seedText.Text.ToInt();
_main.StartSimulation(seed, nParticles);
}
public void _on_ToggleFullscreen_pressed()
public void _OnToggleFullscreenPressed()
{
if (OS.WindowFullscreen)
OS.WindowFullscreen = false;
else
OS.WindowFullscreen = true;
OS.WindowFullscreen = !OS.WindowFullscreen;
}
public override void _Input(InputEvent @event)
{
// Quit only if menu is visible
if (Visible && @event.IsActionPressed("quit"))
{
GetTree().Quit();
}
}
}

View File

@@ -24,57 +24,74 @@ anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
margin_left = -150.0
margin_top = -105.315
margin_top = -132.0
margin_right = 150.0
margin_bottom = 192.685
margin_bottom = 337.685
custom_constants/separation = 12
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Label" type="Label" parent="MenuButtons"]
[node name="ParticleCountLabel" type="Label" parent="MenuButtons"]
margin_right = 300.0
margin_bottom = 27.0
text = "Number of Particles"
align = 1
[node name="TextEdit" type="TextEdit" parent="MenuButtons"]
[node name="ParticleCountText" type="TextEdit" parent="MenuButtons"]
margin_top = 39.0
margin_right = 300.0
margin_bottom = 103.769
rect_min_size = Vector2( 0, 64.769 )
text = "1000"
[node name="Button" type="Button" parent="MenuButtons"]
[node name="SeedLabel" type="Label" parent="MenuButtons"]
margin_top = 115.0
margin_right = 300.0
margin_bottom = 166.251
margin_bottom = 142.0
text = "Optional Seed Number"
align = 1
__meta__ = {
"_edit_use_anchors_": false
}
[node name="SeedText" type="TextEdit" parent="MenuButtons"]
margin_top = 154.0
margin_right = 300.0
margin_bottom = 218.769
rect_min_size = Vector2( 0, 64.769 )
text = "12345"
[node name="SimulateButton" type="Button" parent="MenuButtons"]
margin_top = 230.0
margin_right = 300.0
margin_bottom = 281.251
text = "Simulate!"
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Warning" type="Label" parent="MenuButtons"]
margin_top = 178.0
margin_top = 293.0
margin_right = 300.0
margin_bottom = 223.0
margin_bottom = 338.0
custom_fonts/font = SubResource( 1 )
text = "Simulation cannot be resized
once simulation starts!"
align = 1
[node name="HBoxContainer" type="HBoxContainer" parent="MenuButtons"]
margin_top = 235.0
margin_top = 350.0
margin_right = 300.0
margin_bottom = 235.0
margin_bottom = 350.0
__meta__ = {
"_edit_use_anchors_": false
}
[node name="ToggleFullscreen" type="Button" parent="MenuButtons"]
margin_top = 247.0
[node name="ToggleFullscreenButton" type="Button" parent="MenuButtons"]
margin_top = 362.0
margin_right = 300.0
margin_bottom = 298.251
margin_bottom = 413.251
text = "Toggle Fullscreen"
[node name="Logo" type="TextureRect" parent="."]
@@ -83,10 +100,10 @@ anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
margin_left = -342.0
margin_top = -357.183
margin_right = 1578.0
margin_bottom = 726.817
margin_left = -339.0
margin_top = -384.0
margin_right = 1581.0
margin_bottom = 700.0
rect_scale = Vector2( 0.35, 0.35 )
mouse_filter = 2
texture = ExtResource( 2 )
@@ -94,5 +111,4 @@ __meta__ = {
"_edit_use_anchors_": false
}
[connection signal="pressed" from="MenuButtons/Button" to="." method="_on_Button_pressed"]
[connection signal="pressed" from="MenuButtons/ToggleFullscreen" to="." method="_on_ToggleFullscreen_pressed"]
[connection signal="pressed" from="MenuButtons/ToggleFullscreenButton" to="." method="_on_ToggleFullscreen_pressed"]

View File

@@ -22,14 +22,25 @@ public class MenuBackground : Node2D
int addCount = nParticles - currentCount;
for (int i = 0; i < addCount; i++)
{
CreateParticle();
}
}
// TODO pick random particles to delete
}
//TODO add private method to add particles
public override void _Process(float delta)
private void CreateParticle()
{
var particlePackedScene = GD.Load<PackedScene>("res://ParticleSimulation/ParticleNode.tscn");
var particleNode = particlePackedScene.Instance<ParticleNode>();
_particleNodes.AddChild(particleNode);
var screenSize = GetViewportRect().Size;
var position = new Vector2(
(float) GD.RandRange(0, screenSize.x),
(float) GD.RandRange(0, screenSize.y));
particleNode.Position = position;
}
public override void _Process(float delta)
{
//var particleNodesArray = _particleNodes.GetChildren();
//foreach (ParticleNode particle in particleNodesArray)