BallanceStalker/scripts/stages/MenuManager.cs

76 lines
2.3 KiB
C#
Raw Normal View History

2022-07-02 21:23:45 +08:00
using BallanceStalker;
using Godot;
using System;
public class MenuManager : Control {
public enum MenuPage : int {
Main,
LoadLevel,
LoadSky,
Multiplayer,
About
}
//[Signal]
//public delegate void SetMouseCapture();
2022-07-02 21:23:45 +08:00
[Signal]
public delegate void ExitGame();
private MenuMain mMenuMain;
private MenuPage mCurrentPage;
// Called when the node enters the scene tree for the first time.
public override void _Ready() {
mCurrentPage = MenuPage.Main;
mMenuMain = GetNode<MenuMain>("MenuMain");
mMenuMain.Connect(nameof(MenuMain.MenuMain_GotoPage), this, nameof(Proc_MenuMain_GotoPage));
mMenuMain.Connect(nameof(MenuMain.MenuMain_Back), this, nameof(Proc_MenuMain_Back));
mMenuMain.Connect(nameof(MenuMain.MenuMain_Exit), this, nameof(Proc_MenuMain_Exit));
BallanceStalkerCore.StalkerManager.Singleton.EventControllerChanged += Proc_StalkerManager_EventControllerChanged;
}
private void Proc_StalkerManager_EventControllerChanged(BallanceStalkerCore.EventControllerSource obj) {
if (obj == BallanceStalkerCore.EventControllerSource.Menu) {
this.Visible = true;
} else {
this.Visible = false;
}
2022-07-02 21:23:45 +08:00
}
public override void _Input(InputEvent @event) {
if (!this.Visible) return;
if (@event.IsActionPressed("ballance_esc")) {
2022-07-02 21:23:45 +08:00
if (mCurrentPage == MenuPage.Main) {
// we are in main menu, we need switch visible
BallanceStalkerCore.StalkerManager.Singleton.SetEventController(BallanceStalkerCore.EventControllerSource.None);
2022-07-02 21:23:45 +08:00
} else {
// otherwise, back from sub menu
RefreshMenuPage(MenuPage.Main);
}
// mark handled to prevent loop call
GetTree().SetInputAsHandled();
2022-07-02 21:23:45 +08:00
}
}
private void RefreshMenuPage(MenuPage page_type) {
;//todo:
//mCurrentPage = page_type;
}
private void Proc_MenuMain_GotoPage(MenuPage menu_type) {
RefreshMenuPage(menu_type);
}
private void Proc_MenuMain_Back() {
BallanceStalkerCore.StalkerManager.Singleton.SetEventController(BallanceStalkerCore.EventControllerSource.None);
2022-07-02 21:23:45 +08:00
}
private void Proc_MenuMain_Exit() {
EmitSignal(nameof(ExitGame));
}
}