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.
54 lines
1.3 KiB
54 lines
1.3 KiB
11 months ago
|
public partial class Menu : CenterContainer
|
||
11 months ago
|
{
|
||
|
[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;
|
||
11 months ago
|
// Make sure you can't "detoggle" the button.
|
||
|
button.Disabled = true;
|
||
11 months ago
|
};
|
||
|
}
|
||
|
|
||
|
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)
|
||
11 months ago
|
button.Disabled = button.ButtonPressed = button.Name == tabName;
|
||
11 months ago
|
}
|
||
|
|
||
|
public void OnReturnPressed()
|
||
|
{
|
||
|
Visible = false;
|
||
|
}
|
||
|
|
||
|
public void OnQuitPressed()
|
||
|
{
|
||
|
GetTree().Quit();
|
||
|
}
|
||
|
}
|