blob: 769fdf8b632de2ea95ec68bec0d07f3d8898f4a3 (
plain)
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
|
using System.Linq;
using Godot;
using Godot.Collections;
using Texty.Scripts.GodotExtensions;
namespace Texty.Scripts.Terminal
{
[Tool]
public abstract class ButtonBlock : MarginContainer
{
private VBoxContainer Buttons => GetNodeOrNull<VBoxContainer>($"%{nameof(Buttons)}");
public override void _Ready()
{
ConnectButtons();
Buttons.GetChildren<Button>().ForEach(button => button.MouseFilter = MouseFilterEnum.Ignore);
Buttons.GetChildren<Button>().FirstOrDefault()?.GrabFocus();
}
protected abstract void OnButtonPressed(int index);
private void ConnectButtons()
{
foreach (var (button, index) in Buttons.GetChildren<Button>().Select((button, index) => (button, index)))
button.Connect("pressed", this, nameof(OnButtonPressed), new Array(index));
}
}
}
|