BallanceStalker/scripts/stages/MenuManager.cs

76 lines
2.3 KiB
C#

using BallanceStalker;
using Godot;
using System;
public class MenuManager : Control {
public enum MenuPage : int {
Main,
LoadLevel,
LoadSky,
Multiplayer,
About
}
//[Signal]
//public delegate void SetMouseCapture();
[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;
}
}
public override void _Input(InputEvent @event) {
if (!this.Visible) return;
if (@event.IsActionPressed("ballance_esc")) {
if (mCurrentPage == MenuPage.Main) {
// we are in main menu, we need switch visible
BallanceStalkerCore.StalkerManager.Singleton.SetEventController(BallanceStalkerCore.EventControllerSource.None);
} else {
// otherwise, back from sub menu
RefreshMenuPage(MenuPage.Main);
}
// mark handled to prevent loop call
GetTree().SetInputAsHandled();
}
}
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);
}
private void Proc_MenuMain_Exit() {
EmitSignal(nameof(ExitGame));
}
}