-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInventory.cs
More file actions
137 lines (116 loc) · 3.58 KB
/
Inventory.cs
File metadata and controls
137 lines (116 loc) · 3.58 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
using FunkEngine;
using Godot;
public partial class Inventory : Control, IFocusableMenu
{
public static readonly string LoadPath = "res://Scenes/UI/Inventory.tscn";
[Export]
private GridContainer _relics;
[Export]
private GridContainer _notes;
[Export]
private Label _description;
[Export]
private TabContainer _tabs;
[Export]
private Label _moneyLabel;
public IFocusableMenu Prev { get; set; }
private static readonly string[] TabNames = new[] { "NOTE", "RELIC" };
private void Display(PlayerStats playerStats)
{
AddDisplayButtons(playerStats.CurRelics, _relics);
AddDisplayButtons(playerStats.CurNotes, _notes);
_moneyLabel.Text = playerStats.Money.ToString();
_tabs.TabChanged += ClearDescription;
}
private void AddDisplayButtons(IDisplayable[] displayables, Node parentNode)
{
foreach (IDisplayable item in displayables)
{
var newButton = GD.Load<PackedScene>(DisplayButton.LoadPath)
.Instantiate<DisplayButton>();
newButton.Display(item.Texture, item.Name, true);
newButton.Pressed += () =>
{
DoDescription(newButton);
};
parentNode.AddChild(newButton);
}
}
public override void _Process(double delta)
{
NoNullFocus();
}
public override void _Input(InputEvent @event)
{
if (ControlSettings.IsOutOfFocus(this))
{
GetViewport().SetInputAsHandled();
return;
}
if (_tabs.CurrentTab == 0) //Godot 4.4 changed neighbor behaviour
{
if (_notes.GetChildCount() > 0)
_tabs.GetTabBar().FocusNeighborBottom = _notes.GetChild(0).GetPath();
else
_tabs.GetTabBar().FocusNeighborBottom = null;
}
else if (_tabs.CurrentTab == 1)
{
if (_relics.GetChildCount() > 0)
_tabs.GetTabBar().FocusNeighborBottom = _relics.GetChild(0).GetPath();
else
_tabs.GetTabBar().FocusNeighborBottom = null;
}
if (
@event.IsActionPressed("ui_cancel")
|| @event.IsActionPressed("WASD_inventory")
|| @event.IsActionPressed("CONTROLLER_inventory")
)
{
ReturnToPrev();
GetViewport().SetInputAsHandled();
}
}
public void ResumeFocus()
{
ProcessMode = ProcessModeEnum.Pausable;
_tabs.GetTabBar().GrabFocus();
}
public void PauseFocus()
{
ProcessMode = ProcessModeEnum.Disabled;
}
public void OpenMenu(IFocusableMenu prev)
{
Display(StageProducer.PlayerStats ?? new PlayerStats());
Prev = prev;
Prev.PauseFocus();
_tabs.GetTabBar().GrabFocus();
}
public void ReturnToPrev()
{
Prev.ResumeFocus();
QueueFree();
}
private void NoNullFocus()
{
var focusedNode = GetViewport().GuiGetFocusOwner();
if (focusedNode != null)
return;
_tabs.GetTabBar().GrabFocus();
ClearDescription(-1);
}
private void DoDescription(DisplayButton dispButton)
{
string itemName = dispButton.DisplayName.ToUpper();
itemName = itemName.Replace(" ", "");
_description.Text =
Tr(TabNames[_tabs.CurrentTab] + "_" + itemName + "_NAME")
+ ": "
+ Tr(TabNames[_tabs.CurrentTab] + "_" + itemName + "_TOOLTIP");
}
private void ClearDescription(long newTab)
{
_description.Text = "";
}
}