88 lines
2.9 KiB
C#
88 lines
2.9 KiB
C#
#nullable enable
|
|
|
|
using Godot;
|
|
using SideScrollerGame.Debug.Commands;
|
|
|
|
namespace SideScrollerGame.Debug;
|
|
|
|
public partial class DebugPanelController : PanelContainer
|
|
{
|
|
public override void _Ready()
|
|
{
|
|
ProcessMode = ProcessModeEnum.Always;
|
|
EnsureLayout();
|
|
TryBindFromRoot();
|
|
}
|
|
|
|
public void Bind(DebugCommandNode commandNode)
|
|
{
|
|
m_CommandNode = commandNode;
|
|
}
|
|
|
|
private void EnsureLayout()
|
|
{
|
|
if (m_Container is not null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
m_Container = new VBoxContainer { Name = "Controls" };
|
|
AddChild(m_Container);
|
|
|
|
AddHeader("Time");
|
|
AddButton("Pause", DebugCommandId.TogglePause);
|
|
AddButton("Step", DebugCommandId.FrameStep);
|
|
AddButton("0.25x", DebugCommandId.SetTimeScale, "0.25");
|
|
AddButton("0.5x", DebugCommandId.SetTimeScale, "0.5");
|
|
AddButton("1x", DebugCommandId.SetTimeScale, "1");
|
|
AddButton("2x", DebugCommandId.SetTimeScale, "2");
|
|
AddButton("4x", DebugCommandId.SetTimeScale, "4");
|
|
|
|
AddHeader("Content");
|
|
AddButton("Easy", DebugCommandId.SetDifficulty, "difficulty.easy");
|
|
AddButton("Normal", DebugCommandId.SetDifficulty, "difficulty.normal");
|
|
AddButton("Hard", DebugCommandId.SetDifficulty, "difficulty.hard");
|
|
AddButton("Spawn serial", DebugCommandId.SpawnActor, "enemy.serial");
|
|
AddButton("Spawn parallel", DebugCommandId.SpawnActor, "enemy.parallel");
|
|
AddButton("Intro", DebugCommandId.JumpToMarker, "intro");
|
|
AddButton("Opening", DebugCommandId.JumpToMarker, "cluster.opening");
|
|
|
|
AddHeader("Flags");
|
|
AddButton("Invulnerable", DebugCommandId.ToggleInvulnerability);
|
|
AddButton("Infinite ammo", DebugCommandId.ToggleInfiniteSpecialAmmo);
|
|
AddButton("No enemy fire", DebugCommandId.ToggleNoEnemyFire);
|
|
AddButton("Collisions", DebugCommandId.ToggleCollisionShapes);
|
|
AddButton("Bounds", DebugCommandId.ToggleGameplayBounds);
|
|
|
|
AddHeader("Scene");
|
|
AddButton("Restart", DebugCommandId.RestartMission);
|
|
AddButton("Reload", DebugCommandId.ReloadScene);
|
|
}
|
|
|
|
private void TryBindFromRoot()
|
|
{
|
|
m_CommandNode ??= GetNodeOrNull<DebugCommandNode>("/root/GameRoot/DebugCommandNode");
|
|
}
|
|
|
|
private void AddHeader(string text)
|
|
{
|
|
Label label = new() { Text = text };
|
|
m_Container?.AddChild(label);
|
|
}
|
|
|
|
private void AddButton(string text, DebugCommandId commandId, string? argument = null)
|
|
{
|
|
Button button = new() { Text = text };
|
|
button.Pressed += () => Execute(commandId, argument);
|
|
m_Container?.AddChild(button);
|
|
}
|
|
|
|
private void Execute(DebugCommandId commandId, string? argument = null)
|
|
{
|
|
TryBindFromRoot();
|
|
m_CommandNode?.Execute(commandId, argument);
|
|
}
|
|
|
|
private DebugCommandNode? m_CommandNode;
|
|
private VBoxContainer? m_Container;
|
|
} |