Debug menu

This commit is contained in:
Marco 2025-02-19 13:34:15 +01:00
commit 778dc10d9a
7 changed files with 143 additions and 6 deletions

53
Scripts/UI/DebugMenu.cs Normal file
View file

@ -0,0 +1,53 @@
using Godot;
using System;
using Godot.Collections;
public partial class DebugMenu : Control
{
[Export]
public Theme ButtonTheme { get; private set; }
[Export]
public Array<PackedScene> Levels { get; private set; }
[Export]
public Container ButtonsContainer { get; private set; }
[Signal]
public delegate void DebugMenuClosedEventHandler();
// Called when the node enters the scene tree for the first time.
public override void _Ready()
{
foreach (var level in Levels)
{
var button = new Button();
button.Text = level.ResourcePath.Split("/")[^1].Split(".")[0];
button.Theme = ButtonTheme;
ButtonsContainer.CallDeferred("add_child", button);
button.Pressed += () => ButtonOnPressed(level);
}
}
private void ButtonOnPressed(PackedScene scene)
{
GD.Print("Button was pressed, now what");
GetTree().ChangeSceneToFile(scene.ResourcePath);
}
private void _on_back_button_pressed()
{
this.QueueFree();
EmitSignal(SignalName.DebugMenuClosed);
}
// Called every frame. 'delta' is the elapsed time since the previous frame.
public override void _Process(double delta)
{
}
}