-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMenuModule.cs
More file actions
93 lines (81 loc) · 2.48 KB
/
MenuModule.cs
File metadata and controls
93 lines (81 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
using FunkEngine;
using Godot;
using GodotSteam;
/**
* <summary>Simple system for any scene which should display pause and inventory screen.</summary>
*/
public partial class MenuModule : CanvasLayer, IFocusableMenu
{
[Export]
private Node CurSceneNode { get; set; }
private Control _lastFocused { get; set; }
public override void _Ready()
{
Input.JoyConnectionChanged += (device, connected) =>
{
if (!connected)
OpenPauseMenu(); //Pause on disconnection
};
GetTree().GetRoot().FocusExited += OpenPauseMenu;
Steam.OverlayToggled += OpenPauseMenu;
}
public override void _ExitTree()
{
Steam.OverlayToggled -= OpenPauseMenu;
}
public void ResumeFocus()
{
CurSceneNode.ProcessMode = ProcessModeEnum.Inherit;
if (CurSceneNode is BattleDirector { HasPlayed: true } bd && !GetTree().IsPaused())
bd.StartCountdown();
_lastFocused?.GrabFocus();
}
public void PauseFocus()
{
_lastFocused = GetViewport().GuiGetFocusOwner();
CurSceneNode.ProcessMode = ProcessModeEnum.Disabled;
}
public IFocusableMenu Prev { get; set; }
public void OpenMenu(IFocusableMenu prev)
{
GD.PushWarning("Undefined behaviour, MenuModule should not be opened!");
}
public void ReturnToPrev()
{
GD.PushWarning("Undefined behaviour, MenuModule should not return to previous menu!");
}
public override void _Input(InputEvent @event)
{
if (ControlSettings.IsOutOfFocus(this))
{
GetViewport().SetInputAsHandled();
return;
}
if (@event.IsActionPressed("Pause"))
{
OpenPauseMenu();
}
if (
@event.IsActionPressed("WASD_inventory")
|| @event.IsActionPressed("CONTROLLER_inventory")
)
{
var invenMenu = GD.Load<PackedScene>(Inventory.LoadPath).Instantiate<Inventory>();
AddChild(invenMenu);
invenMenu.OpenMenu(this);
}
}
private void OpenPauseMenu(bool active, bool initiated = false, uint id = 0)
{
if (active)
OpenPauseMenu();
}
private void OpenPauseMenu()
{
if (CurSceneNode.ProcessMode == ProcessModeEnum.Disabled)
return;
var pauseMenu = GD.Load<PackedScene>(PauseMenu.LoadPath).Instantiate<PauseMenu>();
AddChild(pauseMenu);
pauseMenu.OpenMenu(this);
}
}