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:
parent
45afd9ac79
commit
be26a2ebc2
1 changed files with 5 additions and 3 deletions
|
@ -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));
|
||||||
|
|
Loading…
Reference in a new issue