1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-11-22 12:58:33 +01:00

made the new AutoNavGroup also work for gamepad controls

This commit is contained in:
Ell 2022-04-14 18:01:30 +02:00
parent 45afd9ac79
commit be26a2ebc2

View file

@ -386,14 +386,16 @@ namespace MLEM.Ui {
protected virtual Element GetGamepadNextElement(Direction2 direction) { protected virtual Element GetGamepadNextElement(Direction2 direction) {
if (this.ActiveRoot == null) if (this.ActiveRoot == null)
return null; return null;
var children = this.ActiveRoot.Element.GetChildren(c => !c.IsHidden, true, true).Append(this.ActiveRoot.Element); var children = this.ActiveRoot.Element.GetChildren(c => !c.IsHidden, true, true).Append(this.ActiveRoot.Element)
// we can't add these checks to GetChildren because it ignores false grandchildren
.Where(c => c.CanBeSelected && c.AutoNavGroup == this.SelectedElement?.AutoNavGroup);
if (this.SelectedElement?.Root != this.ActiveRoot) { if (this.SelectedElement?.Root != this.ActiveRoot) {
return children.FirstOrDefault(c => c.CanBeSelected); return children.FirstOrDefault();
} else { } else {
Element closest = null; Element closest = null;
float closestPriority = 0; float closestPriority = 0;
foreach (var child in children) { foreach (var child in children) {
if (!child.CanBeSelected || child == this.SelectedElement) if (child == this.SelectedElement)
continue; continue;
var (xOffset, yOffset) = child.Area.Center - this.SelectedElement.Area.Center; var (xOffset, yOffset) = child.Area.Center - this.SelectedElement.Area.Center;
var angle = Math.Abs(direction.Angle() - (float) Math.Atan2(yOffset, xOffset)); var angle = Math.Abs(direction.Angle() - (float) Math.Atan2(yOffset, xOffset));