full gamepad support

This commit is contained in:
Rendo 2025-07-28 18:03:26 +05:00
commit a57d79e84a
21 changed files with 213 additions and 46 deletions

View file

@ -0,0 +1,62 @@
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;
}
}