1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-05-24 09:33:37 +02:00

modify AutoNavGroup behavior to disallow new selections

This commit is contained in:
Ell 2022-05-17 16:06:22 +02:00
parent 5ba550619d
commit 03accff6ae
2 changed files with 6 additions and 3 deletions

View file

@ -253,7 +253,7 @@ namespace MLEM.Ui.Elements {
/// <summary>
/// An optional string that represents a group of elements for automatic (keyboard and gamepad) navigation.
/// All elements that share the same auto-nav group will be able to be navigated between, and all other elements will not be reachable from elements of other groups.
/// Note that, if no element is previously selected and auto-navigation is invoked, this element can always be navigated to if it is the first one chosen by auto-navigation.
/// Note that, if no element is previously selected and auto-navigation is invoked, this element cannot be chosen as the first element to navigate to if its auto-nav group is non-null.
/// </summary>
public virtual string AutoNavGroup { get; set; }

View file

@ -373,7 +373,9 @@ namespace MLEM.Ui {
// 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) {
return backward ? children.LastOrDefault() : children.FirstOrDefault();
// if we don't have an element selected in this root, navigate to the first one without a group
var allowed = children.Where(c => c.AutoNavGroup == null);
return backward ? allowed.LastOrDefault() : allowed.FirstOrDefault();
} else {
var foundCurr = false;
Element lastFound = null;
@ -406,7 +408,8 @@ namespace MLEM.Ui {
// 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) {
return children.FirstOrDefault();
// if we don't have an element selected in this root, navigate to the first one without a group
return children.FirstOrDefault(c => c.AutoNavGroup == null);
} else {
Element closest = null;
float closestPriority = 0;