cirnogodot/Scripts/UI/DebugMenu.cs

111 lines
2.7 KiB
C#
Raw Normal View History

2025-02-19 13:34:15 +01:00
using Godot;
using System;
2025-06-12 18:03:55 +02:00
using Cirno.Scripts;
2025-02-21 11:39:22 +01:00
using Cirno.Scripts.Resources;
using Cirno.Scripts.Resources.DebugMenu;
using Cirno.Scripts.Utils;
2025-02-19 13:34:15 +01:00
using Godot.Collections;
2025-02-21 11:39:22 +01:00
using DebugMapSelectData = Cirno.Scripts.Resources.DebugMenu.DebugMapSelectData;
2025-02-19 13:34:15 +01:00
2025-02-25 21:21:07 +01:00
public partial class DebugMenu : MenuBase
2025-02-19 13:34:15 +01:00
{
[Export]
public Theme ButtonTheme { get; private set; }
2025-02-27 10:37:10 +01:00
2025-02-19 13:34:15 +01:00
[Export]
2025-02-21 11:39:22 +01:00
public DebugMapSelectData Levels { get; set; }
2025-02-27 10:37:10 +01:00
2025-02-19 13:34:15 +01:00
[Export]
public Container ButtonsContainer { get; private set; }
2025-03-12 15:47:57 +01:00
2025-03-12 16:31:53 +01:00
[Export]
public Container CheatsContainer { get; private set; }
2025-03-12 15:47:57 +01:00
[Export]
public Button DefaultSelectedButton { get; private set; }
2025-02-19 13:34:15 +01:00
// Called when the node enters the scene tree for the first time.
public override void _Ready()
{
if (GameStateManager.Instance is not null)
2025-06-08 16:33:38 +02:00
{
GameStateManager.Instance.GameStateChange += OnGameStateChange;
2025-06-08 16:33:38 +02:00
}
2025-05-20 17:46:35 +02:00
2025-03-12 15:47:57 +01:00
DefaultSelectedButton.GrabFocus();
2025-02-21 11:39:22 +01:00
foreach (var level in Levels.Maps)
2025-02-19 13:34:15 +01:00
{
2025-02-21 11:39:22 +01:00
if (!level.Enabled) continue;
2025-02-27 10:37:10 +01:00
2025-03-12 16:31:53 +01:00
var button = MakeButton(ButtonsContainer, level.DisplayName, level.Icon);
// var button = new Button();
// //button.Text = level.Split("/")[^1].Split(".")[0];
// button.Text = level.DisplayName;
// button.Icon = level.Icon;
// //button.Text = level;
// button.Theme = ButtonTheme;
//
// ButtonsContainer.CallDeferred("add_child", button);
2025-02-27 10:37:10 +01:00
2025-02-19 13:34:15 +01:00
button.Pressed += () => ButtonOnPressed(level);
}
2025-03-12 16:31:53 +01:00
var refillHealthButton = MakeButton(CheatsContainer, "Health", null);
refillHealthButton.Pressed += RefillHealthButtonOnPressed;
var refillShieldButton = MakeButton(CheatsContainer, "Shield", null);
refillShieldButton.Pressed += RefillShieldButtonOnPressed;
}
2025-05-20 17:46:35 +02:00
private void OnGameStateChange(GameState state)
{
if (state is not GameState.Paused)
{
GameStateManager.Instance.GameStateChange -= OnGameStateChange;
2025-05-20 17:46:35 +02:00
CloseMenu();
}
}
2025-03-12 16:31:53 +01:00
private void RefillHealthButtonOnPressed()
{
GameManager.Instance?.Player?.RefillHealth();
}
private void RefillShieldButtonOnPressed()
{
GameManager.Instance?.Player?.RefilleShield();
}
private Button MakeButton(Control parent, string text, Texture2D icon)
{
var button = new Button();
button.Text = text;
button.Icon = icon;
button.Theme = ButtonTheme;
parent.CallDeferred("add_child", button);
return button;
2025-02-19 13:34:15 +01:00
}
2025-02-21 11:39:22 +01:00
private void ButtonOnPressed(DebugMapSelectResource scene)
2025-02-19 13:34:15 +01:00
{
if (GameStateManager.Instance is not null)
2025-02-24 10:58:00 +01:00
{
GameStateManager.Instance.Unpause();
2025-02-24 10:58:00 +01:00
}
2025-04-07 15:58:43 +02:00
GlobalState.Instance.GoToScene(scene.ScenePath, scene.StartData);
2025-02-19 13:34:15 +01:00
}
2025-02-27 08:37:55 +01:00
private void _on_check_box_toggled(bool state)
{
GlobalState.Instance.SessionSettings.SkipDialogues = state;
}
2025-02-19 13:34:15 +01:00
// Called every frame. 'delta' is the elapsed time since the previous frame.
public override void _Process(double delta)
{
}
}