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

Allow manually setting a RootElement as CanBeActive

This commit is contained in:
Ell 2022-07-18 15:53:26 +02:00
parent 288b8352af
commit 08e28cb95b
3 changed files with 16 additions and 7 deletions

View file

@ -47,6 +47,7 @@ Improvements
- Don't query a paragraph's text callback in the constructor - Don't query a paragraph's text callback in the constructor
- Allow manually hiding a paragraph without its text overriding the hidden state - Allow manually hiding a paragraph without its text overriding the hidden state
- Added optional isKeybindAllowed parameter to KeybindButton - Added optional isKeybindAllowed parameter to KeybindButton
- Allow manually setting a RootElement as CanBeActive
Fixes Fixes
- Fixed auto-nav tooltip displaying on the selected element even when not in auto-nav mode - Fixed auto-nav tooltip displaying on the selected element even when not in auto-nav mode

View file

@ -57,7 +57,7 @@ namespace MLEM.Ui {
/// <summary> /// <summary>
/// The <see cref="RootElement"/> that is currently active. /// The <see cref="RootElement"/> that is currently active.
/// The active root element is the one with the highest <see cref="RootElement.Priority"/> that whose <see cref="RootElement.CanSelectContent"/> property is true. /// The active root element is the one with the highest <see cref="RootElement.Priority"/> that <see cref="RootElement.CanBeActive"/>.
/// </summary> /// </summary>
public RootElement ActiveRoot { get; protected set; } public RootElement ActiveRoot { get; protected set; }
/// <summary> /// <summary>
@ -155,7 +155,7 @@ namespace MLEM.Ui {
public virtual void Update() { public virtual void Update() {
if (this.IsInputOurs) if (this.IsInputOurs)
this.Input.Update(); this.Input.Update();
this.ActiveRoot = this.System.GetRootElements().FirstOrDefault(root => !root.Element.IsHidden && root.CanSelectContent); this.ActiveRoot = this.System.GetRootElements().FirstOrDefault(root => root.CanBeActive);
// MOUSE INPUT // MOUSE INPUT
if (this.HandleMouse) { if (this.HandleMouse) {

View file

@ -508,7 +508,6 @@ namespace MLEM.Ui {
/// The <see cref="UiSystem"/> that this root element is a part of. /// The <see cref="UiSystem"/> that this root element is a part of.
/// </summary> /// </summary>
public readonly UiSystem System; public readonly UiSystem System;
private float scale = 1;
/// <summary> /// <summary>
/// The scale of this root element. /// The scale of this root element.
/// Note that, to change the scale of every root element, you can use <see cref="UiSystem.GlobalScale"/> /// Note that, to change the scale of every root element, you can use <see cref="UiSystem.GlobalScale"/>
@ -522,7 +521,6 @@ namespace MLEM.Ui {
this.Element.ForceUpdateArea(); this.Element.ForceUpdateArea();
} }
} }
private int priority;
/// <summary> /// <summary>
/// The priority of this root element. /// The priority of this root element.
/// A higher priority means the element will be updated first, as well as rendered on top. /// A higher priority means the element will be updated first, as well as rendered on top.
@ -539,7 +537,6 @@ namespace MLEM.Ui {
/// This is a combination of this root element's <see cref="Scale"/> as well as the ui system's <see cref="UiSystem.GlobalScale"/>. /// This is a combination of this root element's <see cref="Scale"/> as well as the ui system's <see cref="UiSystem.GlobalScale"/>.
/// </summary> /// </summary>
public float ActualScale => this.System.GlobalScale * this.Scale; public float ActualScale => this.System.GlobalScale * this.Scale;
/// <summary> /// <summary>
/// The transformation that this root element (and all of its children) has. /// The transformation that this root element (and all of its children) has.
/// This transform is applied both to input, as well as to rendering. /// This transform is applied both to input, as well as to rendering.
@ -549,7 +546,6 @@ namespace MLEM.Ui {
/// An inversion of <see cref="Transform"/> /// An inversion of <see cref="Transform"/>
/// </summary> /// </summary>
public Matrix InvTransform => Matrix.Invert(this.Transform); public Matrix InvTransform => Matrix.Invert(this.Transform);
/// <summary> /// <summary>
/// The child element of this root element that is currently selected. /// The child element of this root element that is currently selected.
/// If there is no selected element in this root, this value will be <c>null</c>. /// If there is no selected element in this root, this value will be <c>null</c>.
@ -557,9 +553,17 @@ namespace MLEM.Ui {
public Element SelectedElement => this.System.Controls.GetSelectedElement(this); public Element SelectedElement => this.System.Controls.GetSelectedElement(this);
/// <summary> /// <summary>
/// Determines whether this root element contains any children that <see cref="Elements.Element.CanBeSelected"/>. /// Determines whether this root element contains any children that <see cref="Elements.Element.CanBeSelected"/>.
/// This value is automatically calculated. /// This value is automatically calculated, and used in <see cref="CanBeActive"/>.
/// </summary> /// </summary>
public bool CanSelectContent => this.Element.CanBeSelected || this.Element.GetChildren(c => c.CanBeSelected, true).Any(); public bool CanSelectContent => this.Element.CanBeSelected || this.Element.GetChildren(c => c.CanBeSelected, true).Any();
/// <summary>
/// Determines whether this root element can become the <see cref="UiControls.ActiveRoot"/>.
/// This property returns <see langword="true"/> if <see cref="CanSelectContent"/> is <see langword="true"/> and the <see cref="Element"/> is not hidden, or if it has been set to <see langword="true"/> manually.
/// </summary>
public bool CanBeActive {
get => this.canBeActive || (!this.Element.IsHidden && this.CanSelectContent);
set => this.canBeActive = value;
}
/// <summary> /// <summary>
/// Event that is invoked when a <see cref="Element"/> is added to this root element or any of its children. /// Event that is invoked when a <see cref="Element"/> is added to this root element or any of its children.
@ -578,6 +582,10 @@ namespace MLEM.Ui {
/// </summary> /// </summary>
public event Action<UiSystem> OnRemovedFromUi; public event Action<UiSystem> OnRemovedFromUi;
private float scale = 1;
private bool canBeActive;
private int priority;
internal RootElement(string name, Element element, UiSystem system) { internal RootElement(string name, Element element, UiSystem system) {
this.Name = name; this.Name = name;
this.Element = element; this.Element = element;