Inventory management focused game written in Godot / C#
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.1 KiB

public partial class Menu : CenterContainer
{
[Export] public Container SideButtons { get; set; }
[Export] public TabContainer Tabs { get; set; }
public override void _Ready()
{
foreach (var button in SideButtons.GetChildren().OfType<Button>())
button.Pressed += () => {
for (var i = 0; i < Tabs.GetTabCount(); i++)
if (Tabs.GetTabControl(i).Name == button.Name)
Tabs.CurrentTab = i;
};
}
public override void _Input(InputEvent @event)
{
if (!Visible) {
var isMouseCaptured = Input.MouseMode == Input.MouseModeEnum.Captured;
if (!isMouseCaptured && @event.IsActionPressed("ui_cancel")) {
Visible = true;
GetViewport().SetInputAsHandled();
}
return;
}
if (@event.IsActionPressed("ui_cancel")) {
OnReturnPressed();
GetViewport().SetInputAsHandled();
}
}
public void OnTabChanged(int tabIndex)
{
var tabName = Tabs.GetTabControl(tabIndex).Name;
foreach (var button in SideButtons.GetChildren().OfType<Button>())
button.Disabled = button.Name == tabName;
}
public void OnReturnPressed()
{
Visible = false;
}
public void OnQuitPressed()
{
GetTree().Quit();
}
}