mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-25 05:58:35 +01:00
Compare commits
3 commits
f445f59078
...
be26a2ebc2
Author | SHA1 | Date | |
---|---|---|---|
be26a2ebc2 | |||
45afd9ac79 | |||
ad29b46df3 |
4 changed files with 25 additions and 13 deletions
|
@ -14,8 +14,12 @@ Additions
|
|||
- Added consuming variants of IsPressed methods to InputHandler
|
||||
|
||||
### MLEM.Ui
|
||||
Additions
|
||||
- Added Element.AutoNavGroup which allows forming groups for auto-navigation
|
||||
|
||||
Fixes
|
||||
- Fixed auto-nav tooltip displaying on the selected element even when not in auto-nav mode
|
||||
- Fixed radio buttons not unchecking all other radio buttons with the same root element
|
||||
|
||||
## 5.3.0
|
||||
### MLEM
|
||||
|
|
|
@ -249,6 +249,12 @@ namespace MLEM.Ui.Elements {
|
|||
/// Returns whether this element's <see cref="SetAreaDirty"/> method has been recently called and its area has not been updated since then using <see cref="UpdateAreaIfDirty"/> or <see cref="ForceUpdateArea"/>.
|
||||
/// </summary>
|
||||
public bool AreaDirty { get; private set; }
|
||||
/// <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.
|
||||
/// </summary>
|
||||
public virtual string AutoNavGroup { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// This Element's current <see cref="UiStyle"/>.
|
||||
|
|
|
@ -4,7 +4,7 @@ using MLEM.Ui.Style;
|
|||
namespace MLEM.Ui.Elements {
|
||||
/// <summary>
|
||||
/// A radio button element to use inside of a <see cref="UiSystem"/>.
|
||||
/// A radio button is a variation of a <see cref="Checkbox"/> that causes all other radio buttons in the same <see cref="Group"/> to be deselected upon selection.
|
||||
/// A radio button is a variation of a <see cref="Checkbox"/> that causes all other radio buttons in the same <see cref="RootElement"/> to be deselected upon selection.
|
||||
/// </summary>
|
||||
public class RadioButton : Checkbox {
|
||||
|
||||
|
@ -26,13 +26,13 @@ namespace MLEM.Ui.Elements {
|
|||
base(anchor, size, label, defaultChecked) {
|
||||
this.Group = group;
|
||||
|
||||
// don't += because we want to override the checking + unchecking behavior of Checkbox
|
||||
// don't += because we want to override the checking/unchecking behavior of Checkbox
|
||||
this.OnPressed = element => {
|
||||
this.Checked = true;
|
||||
foreach (var sib in this.GetSiblings()) {
|
||||
if (sib is RadioButton radio && radio.Group == this.Group)
|
||||
radio.Checked = false;
|
||||
}
|
||||
this.Root.Element.AndChildren(e => {
|
||||
if (e != this && e is RadioButton r && r.Group == this.Group)
|
||||
r.Checked = false;
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -353,15 +353,15 @@ namespace MLEM.Ui {
|
|||
protected virtual Element GetTabNextElement(bool backward) {
|
||||
if (this.ActiveRoot == 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) {
|
||||
return backward ? children.LastOrDefault(c => c.CanBeSelected) : children.FirstOrDefault(c => c.CanBeSelected);
|
||||
return backward ? children.LastOrDefault() : children.FirstOrDefault();
|
||||
} else {
|
||||
var foundCurr = false;
|
||||
Element lastFound = null;
|
||||
foreach (var child in children) {
|
||||
if (!child.CanBeSelected)
|
||||
continue;
|
||||
if (child == this.SelectedElement) {
|
||||
// when going backwards, return the last element found before the current one
|
||||
if (backward)
|
||||
|
@ -386,14 +386,16 @@ namespace MLEM.Ui {
|
|||
protected virtual Element GetGamepadNextElement(Direction2 direction) {
|
||||
if (this.ActiveRoot == 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) {
|
||||
return children.FirstOrDefault(c => c.CanBeSelected);
|
||||
return children.FirstOrDefault();
|
||||
} else {
|
||||
Element closest = null;
|
||||
float closestPriority = 0;
|
||||
foreach (var child in children) {
|
||||
if (!child.CanBeSelected || child == this.SelectedElement)
|
||||
if (child == this.SelectedElement)
|
||||
continue;
|
||||
var (xOffset, yOffset) = child.Area.Center - this.SelectedElement.Area.Center;
|
||||
var angle = Math.Abs(direction.Angle() - (float) Math.Atan2(yOffset, xOffset));
|
||||
|
|
Loading…
Reference in a new issue