2024-08-24 15:25:30 +02:00
|
|
|
using Godot;
|
|
|
|
|
using System;
|
|
|
|
|
|
|
|
|
|
public partial class MainMenu : Control
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
[Export]
|
2025-02-19 15:45:21 +01:00
|
|
|
public string GameScene { get; set; }
|
2024-08-24 15:25:30 +02:00
|
|
|
|
|
|
|
|
[Export]
|
2024-08-25 17:06:59 +02:00
|
|
|
public string MainMenuScene { get; set; }
|
2025-02-27 10:37:10 +01:00
|
|
|
|
2025-02-19 13:34:15 +01:00
|
|
|
[Export]
|
2025-02-25 21:21:07 +01:00
|
|
|
public Control SubMenuHolder { get; set; } = new Control();
|
|
|
|
|
|
2025-02-27 10:37:10 +01:00
|
|
|
[Export]
|
|
|
|
|
public AudioStreamPlayer2D MusicPlayer { get; private set; }
|
|
|
|
|
|
2025-02-25 21:21:07 +01:00
|
|
|
[ExportCategory("Music Room")]
|
|
|
|
|
[Export]
|
|
|
|
|
public PackedScene MusicRoomTemplate { get; set; }
|
|
|
|
|
|
|
|
|
|
[ExportCategory("Debug Menu")]
|
2025-02-19 13:34:15 +01:00
|
|
|
[Export]
|
2025-02-25 21:21:07 +01:00
|
|
|
public PackedScene DebugMenuTemplate { get; set; }
|
|
|
|
|
|
2025-02-27 10:37:10 +01:00
|
|
|
|
2024-08-24 15:25:30 +02:00
|
|
|
// Called when the node enters the scene tree for the first time.
|
|
|
|
|
public override void _Ready()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
|
|
|
public override void _Process(double delta)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void _on_start_button_pressed()
|
|
|
|
|
{
|
2025-02-27 10:37:10 +01:00
|
|
|
if (GameScene != null)
|
|
|
|
|
{
|
2025-02-21 12:09:42 +01:00
|
|
|
GlobalState.Instance.GotoScene(GameScene);
|
|
|
|
|
//GetTree().ChangeSceneToFile(GameScene);
|
2024-08-24 15:25:30 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void _on_debug_button_pressed()
|
|
|
|
|
{
|
2025-02-25 21:21:07 +01:00
|
|
|
SpawnMenu<DebugMenu>(DebugMenuTemplate, SubMenuHolder);
|
|
|
|
|
|
|
|
|
|
// if (DebugMenuTemplate is null || DebugMenuHolder is null) return;
|
|
|
|
|
// DebugMenuHolder.Visible = true;
|
2025-02-27 10:37:10 +01:00
|
|
|
|
2025-02-25 21:21:07 +01:00
|
|
|
// var children = DebugMenuHolder.GetChildren();
|
|
|
|
|
// foreach (var child in children)
|
|
|
|
|
// {
|
|
|
|
|
// child.QueueFree();
|
|
|
|
|
// }
|
2025-02-27 10:37:10 +01:00
|
|
|
|
2025-02-25 21:21:07 +01:00
|
|
|
// var menu = DebugMenuTemplate.Instantiate<DebugMenu>();
|
2025-02-27 10:37:10 +01:00
|
|
|
|
2025-02-25 21:21:07 +01:00
|
|
|
// DebugMenuHolder.CallDeferred("add_child", menu);
|
|
|
|
|
|
|
|
|
|
// menu.DebugMenuClosed += () =>
|
|
|
|
|
// {
|
|
|
|
|
// DebugMenuHolder.Visible = false;
|
|
|
|
|
// };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void _on_music_room_button_pressed()
|
|
|
|
|
{
|
|
|
|
|
SpawnMenu<MusicRoom>(MusicRoomTemplate, SubMenuHolder);
|
2025-02-27 10:37:10 +01:00
|
|
|
MusicPlayer?.Stop();
|
2025-02-25 21:21:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SpawnMenu<T>(PackedScene template, Control holder) where T : MenuBase
|
|
|
|
|
{
|
|
|
|
|
if (template is null || holder is null) return;
|
|
|
|
|
holder.Visible = true;
|
2025-02-27 10:37:10 +01:00
|
|
|
|
2025-02-25 21:21:07 +01:00
|
|
|
var children = holder.GetChildren();
|
2025-02-19 15:45:21 +01:00
|
|
|
foreach (var child in children)
|
|
|
|
|
{
|
|
|
|
|
child.QueueFree();
|
|
|
|
|
}
|
2025-02-27 10:37:10 +01:00
|
|
|
|
2025-02-25 21:21:07 +01:00
|
|
|
var menu = template.Instantiate<T>();
|
2025-02-27 10:37:10 +01:00
|
|
|
|
2025-02-25 21:21:07 +01:00
|
|
|
holder.CallDeferred("add_child", menu);
|
2025-02-19 13:34:15 +01:00
|
|
|
|
2025-02-25 21:21:07 +01:00
|
|
|
menu.MenuClosed += () =>
|
2025-02-19 15:45:21 +01:00
|
|
|
{
|
2025-02-25 21:21:07 +01:00
|
|
|
holder.Visible = false;
|
2025-02-27 10:37:10 +01:00
|
|
|
if (!MusicPlayer.Playing)
|
|
|
|
|
{
|
|
|
|
|
MusicPlayer.Play();
|
|
|
|
|
}
|
2025-02-19 15:45:21 +01:00
|
|
|
};
|
2024-08-24 15:25:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void _on_mainmenu_button_pressed()
|
|
|
|
|
{
|
2025-02-27 10:37:10 +01:00
|
|
|
if (MainMenuScene != null)
|
|
|
|
|
{
|
2025-02-21 11:39:22 +01:00
|
|
|
GlobalState.Instance.GotoScene(MainMenuScene);
|
|
|
|
|
//GetTree().ChangeSceneToFile(MainMenuScene);
|
2024-08-24 15:25:30 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void _on_exit_button_pressed()
|
|
|
|
|
{
|
|
|
|
|
GetTree().Quit();
|
|
|
|
|
}
|
|
|
|
|
}
|