62 lines
1.4 KiB
C#
62 lines
1.4 KiB
C#
using Godot;
|
|
using System;
|
|
|
|
public partial class CYSFocusSetup : Node
|
|
{
|
|
[Export] private GridContainer grid;
|
|
[Export] private Button button;
|
|
[Export] private ScrollContainer textContainer;
|
|
public override void _Ready()
|
|
{
|
|
for (int i = 0; i < grid.GetChildCount(); i++)
|
|
{
|
|
int x = i % grid.Columns;
|
|
int y = i / grid.Columns;
|
|
|
|
Control control = grid.GetChild<Control>(i);
|
|
|
|
// If it isn't leftmost element
|
|
if (x != 0)
|
|
{
|
|
control.FocusNeighborLeft = control.GetPathTo(grid.GetChild(PositionToIndex(x - 1, y)));
|
|
}
|
|
// If it isn't upmost element
|
|
if (y != 0)
|
|
{
|
|
control.FocusNeighborTop = control.GetPathTo(grid.GetChild(PositionToIndex(x, y - 1)));
|
|
}
|
|
else
|
|
{
|
|
control.FocusNeighborTop = control.GetPathTo(textContainer);
|
|
}
|
|
// If it isn't rightmost element
|
|
if (x != grid.Columns - 1 && i != grid.GetChildCount())
|
|
{
|
|
control.FocusNeighborRight = control.GetPathTo(grid.GetChild(PositionToIndex(x + 1, y)));
|
|
}
|
|
else
|
|
{
|
|
if (y != 0)
|
|
{
|
|
control.FocusNeighborRight = control.GetPathTo(grid.GetChild(PositionToIndex(x + 1, y - 1)));
|
|
}
|
|
else
|
|
{
|
|
control.FocusNeighborRight = control.GetPathTo(button);
|
|
}
|
|
}
|
|
if (PositionToIndex(x, y + 1) < grid.GetChildCount())
|
|
{
|
|
control.FocusNeighborBottom = control.GetPathTo(grid.GetChild(PositionToIndex(x, y + 1)));
|
|
}
|
|
|
|
}
|
|
|
|
QueueFree();
|
|
}
|
|
private int PositionToIndex(int x, int y)
|
|
{
|
|
return y * grid.Columns + x;
|
|
}
|
|
|
|
}
|