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.

53 lines
1.3 KiB

public partial class Menu : CenterContainer
{
[Export] public Container SideButtons { get; set; }
[Export] public TabContainer Tabs { get; set; }
public override void _Ready()
{
foreach (var child in SideButtons.GetChildren())
if ((child is BaseButton button) && button.ToggleMode)
button.Pressed += () => {
for (var i = 0; i < Tabs.GetTabCount(); i++)
if (Tabs.GetTabControl(i).Name == button.Name)
Tabs.CurrentTab = i;
// Make sure you can't "detoggle" the button.
button.Disabled = true;
};
}
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 child in SideButtons.GetChildren())
if ((child is BaseButton button) && button.ToggleMode)
button.Disabled = button.ButtonPressed = button.Name == tabName;
}
public void OnReturnPressed()
{
Visible = false;
}
public void OnQuitPressed()
{
GetTree().Quit();
}
}