mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-25 14:08:34 +01:00
Compare commits
No commits in common. "58b716aabb0aa92df4d4c430b6dd1a331229769a" and "4c24284a3f126da7f7319868d37d4887970d4de9" have entirely different histories.
58b716aabb
...
4c24284a3f
5 changed files with 25 additions and 140 deletions
|
@ -23,11 +23,6 @@ Improvements
|
||||||
- Ensure that Element.IsMouseOver is always accurate by making it an auto-property
|
- Ensure that Element.IsMouseOver is always accurate by making it an auto-property
|
||||||
- Started using SpriteBatchContext for Draw and DrawTransformed methods
|
- Started using SpriteBatchContext for Draw and DrawTransformed methods
|
||||||
- Make use of the new consuming variants in InputHandler and Keybind to consume UiControls inputs
|
- Make use of the new consuming variants in InputHandler and Keybind to consume UiControls inputs
|
||||||
- Allow Tooltip to manage more than one paragraph and make it easier to add new lines
|
|
||||||
- Allow adding dropdown elements at a specified index
|
|
||||||
- Turned Tooltip paragraph styling into style properties
|
|
||||||
- Improved ElementHelper.AddTooltip overloads
|
|
||||||
- Don't query a paragraph's text callback in the constructor
|
|
||||||
|
|
||||||
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
|
||||||
|
@ -36,7 +31,6 @@ Fixes
|
||||||
|
|
||||||
Removals
|
Removals
|
||||||
- Marked old Draw and DrawTransformed overloads as obsolete in favor of SpriteBatchContext ones
|
- Marked old Draw and DrawTransformed overloads as obsolete in favor of SpriteBatchContext ones
|
||||||
- Marked Tooltip.Paragraph as obsolete in favor of new Paragraphs collection
|
|
||||||
|
|
||||||
## 5.3.0
|
## 5.3.0
|
||||||
### MLEM
|
### MLEM
|
||||||
|
|
|
@ -55,9 +55,8 @@ namespace MLEM.Ui.Elements {
|
||||||
/// Adds an element to this dropdown's <see cref="Panel"/>
|
/// Adds an element to this dropdown's <see cref="Panel"/>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="element">The element to add</param>
|
/// <param name="element">The element to add</param>
|
||||||
/// <param name="index">The index to add the child at, or -1 to add it to the end of the <see cref="Element.Children"/> list</param>
|
public void AddElement(Element element) {
|
||||||
public void AddElement(Element element, int index = -1) {
|
this.Panel.AddChild(element);
|
||||||
this.Panel.AddChild(element, index);
|
|
||||||
// Since the dropdown causes elements to be over each other,
|
// Since the dropdown causes elements to be over each other,
|
||||||
// usual gamepad code doesn't apply
|
// usual gamepad code doesn't apply
|
||||||
element.GetGamepadNextElement = (dir, usualNext) => {
|
element.GetGamepadNextElement = (dir, usualNext) => {
|
||||||
|
@ -78,9 +77,8 @@ namespace MLEM.Ui.Elements {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="text">The text to display</param>
|
/// <param name="text">The text to display</param>
|
||||||
/// <param name="pressed">The resulting paragraph's <see cref="Element.OnPressed"/> event</param>
|
/// <param name="pressed">The resulting paragraph's <see cref="Element.OnPressed"/> event</param>
|
||||||
/// <param name="index">The index to add the child at, or -1 to add it to the end of the <see cref="Element.Children"/> list</param>
|
public Element AddElement(string text, GenericCallback pressed = null) {
|
||||||
public Element AddElement(string text, GenericCallback pressed = null, int index = -1) {
|
return this.AddElement(p => text, pressed);
|
||||||
return this.AddElement(p => text, pressed, index);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -89,8 +87,7 @@ namespace MLEM.Ui.Elements {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="text">The text to display</param>
|
/// <param name="text">The text to display</param>
|
||||||
/// <param name="pressed">The resulting paragraph's <see cref="Element.OnPressed"/> event</param>
|
/// <param name="pressed">The resulting paragraph's <see cref="Element.OnPressed"/> event</param>
|
||||||
/// <param name="index">The index to add the child at, or -1 to add it to the end of the <see cref="Element.Children"/> list</param>
|
public Element AddElement(Paragraph.TextCallback text, GenericCallback pressed = null) {
|
||||||
public Element AddElement(Paragraph.TextCallback text, GenericCallback pressed = null, int index = -1) {
|
|
||||||
var paragraph = new Paragraph(Anchor.AutoLeft, 1, text) {
|
var paragraph = new Paragraph(Anchor.AutoLeft, 1, text) {
|
||||||
CanBeMoused = true,
|
CanBeMoused = true,
|
||||||
CanBeSelected = true,
|
CanBeSelected = true,
|
||||||
|
@ -100,7 +97,7 @@ namespace MLEM.Ui.Elements {
|
||||||
paragraph.OnPressed += pressed;
|
paragraph.OnPressed += pressed;
|
||||||
paragraph.OnMouseEnter += e => paragraph.TextColor = Color.LightGray;
|
paragraph.OnMouseEnter += e => paragraph.TextColor = Color.LightGray;
|
||||||
paragraph.OnMouseExit += e => paragraph.TextColor = Color.White;
|
paragraph.OnMouseExit += e => paragraph.TextColor = Color.White;
|
||||||
this.AddElement(paragraph, index);
|
this.AddElement(paragraph);
|
||||||
return paragraph;
|
return paragraph;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -184,7 +184,7 @@ namespace MLEM.Ui.Elements {
|
||||||
/// <param name="textCallback">The text to display on the tooltip</param>
|
/// <param name="textCallback">The text to display on the tooltip</param>
|
||||||
/// <returns>The created tooltip instance</returns>
|
/// <returns>The created tooltip instance</returns>
|
||||||
public static Tooltip AddTooltip(this Element element, Paragraph.TextCallback textCallback) {
|
public static Tooltip AddTooltip(this Element element, Paragraph.TextCallback textCallback) {
|
||||||
return element.AddTooltip(new Tooltip(textCallback));
|
return new Tooltip(textCallback, element);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -194,18 +194,7 @@ namespace MLEM.Ui.Elements {
|
||||||
/// <param name="text">The text to display on the tooltip</param>
|
/// <param name="text">The text to display on the tooltip</param>
|
||||||
/// <returns>The created tooltip instance</returns>
|
/// <returns>The created tooltip instance</returns>
|
||||||
public static Tooltip AddTooltip(this Element element, string text) {
|
public static Tooltip AddTooltip(this Element element, string text) {
|
||||||
return element.AddTooltip(new Tooltip(text));
|
return new Tooltip(text, element);
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Adds the given <see cref="Tooltip"/> to the given element
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="element">The element to add the tooltip to</param>
|
|
||||||
/// <param name="tooltip">The tooltip to add</param>
|
|
||||||
/// <returns>The passed tooltip, for chaining</returns>
|
|
||||||
public static Tooltip AddTooltip(this Element element, Tooltip tooltip) {
|
|
||||||
tooltip.AddToElement(element);
|
|
||||||
return tooltip;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -110,15 +110,19 @@ namespace MLEM.Ui.Elements {
|
||||||
/// <param name="width">The paragraph's width. Note that its height is automatically calculated.</param>
|
/// <param name="width">The paragraph's width. Note that its height is automatically calculated.</param>
|
||||||
/// <param name="textCallback">The paragraph's text</param>
|
/// <param name="textCallback">The paragraph's text</param>
|
||||||
/// <param name="autoAdjustWidth">Whether the paragraph's width should automatically be calculated based on the text within it.</param>
|
/// <param name="autoAdjustWidth">Whether the paragraph's width should automatically be calculated based on the text within it.</param>
|
||||||
public Paragraph(Anchor anchor, float width, TextCallback textCallback, bool autoAdjustWidth = false) : this(anchor, width, "", autoAdjustWidth) {
|
public Paragraph(Anchor anchor, float width, TextCallback textCallback, bool autoAdjustWidth = false)
|
||||||
this.IsHidden = true;
|
: this(anchor, width, "", autoAdjustWidth) {
|
||||||
this.GetTextCallback = textCallback;
|
this.GetTextCallback = textCallback;
|
||||||
|
this.Text = textCallback(this);
|
||||||
|
if (this.Text == null)
|
||||||
|
this.IsHidden = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="Paragraph(Anchor,float,TextCallback,bool)"/>
|
/// <inheritdoc cref="Paragraph(Anchor,float,TextCallback,bool)"/>
|
||||||
public Paragraph(Anchor anchor, float width, string text, bool autoAdjustWidth = false) : base(anchor, new Vector2(width, 0)) {
|
public Paragraph(Anchor anchor, float width, string text, bool autoAdjustWidth = false) : base(anchor, new Vector2(width, 0)) {
|
||||||
this.IsHidden = true;
|
|
||||||
this.Text = text;
|
this.Text = text;
|
||||||
|
if (this.Text == null)
|
||||||
|
this.IsHidden = true;
|
||||||
this.AutoAdjustWidth = autoAdjustWidth;
|
this.AutoAdjustWidth = autoAdjustWidth;
|
||||||
this.CanBeSelected = false;
|
this.CanBeSelected = false;
|
||||||
this.CanBeMoused = false;
|
this.CanBeMoused = false;
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using MLEM.Input;
|
using MLEM.Input;
|
||||||
using MLEM.Ui.Style;
|
using MLEM.Ui.Style;
|
||||||
|
@ -12,13 +11,6 @@ namespace MLEM.Ui.Elements {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Tooltip : Panel {
|
public class Tooltip : Panel {
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// A list of <see cref="Elements.Paragraph"/> objects that this tooltip automatically manages.
|
|
||||||
/// A paragraph that is contained in this list will automatically have the <see cref="UiStyle.TooltipTextWidth"/> and <see cref="UiStyle.TooltipTextColor"/> applied.
|
|
||||||
/// To add a paragraph to both this list and to <see cref="Element.Children"/>, use <see cref="AddParagraph(Elements.Paragraph,int)"/>.
|
|
||||||
/// </summary>
|
|
||||||
public readonly List<Paragraph> Paragraphs = new List<Paragraph>();
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The offset that this tooltip's top left corner should have from the mouse position
|
/// The offset that this tooltip's top left corner should have from the mouse position
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -31,41 +23,9 @@ namespace MLEM.Ui.Elements {
|
||||||
/// The amount of time that the mouse has to be over an element before it appears
|
/// The amount of time that the mouse has to be over an element before it appears
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public StyleProp<TimeSpan> Delay;
|
public StyleProp<TimeSpan> Delay;
|
||||||
/// <summary>
|
|
||||||
/// The <see cref="Elements.Paragraph.TextColor"/> that this tooltip's <see cref="Paragraphs"/> should have
|
|
||||||
/// </summary>
|
|
||||||
public StyleProp<Color> ParagraphTextColor {
|
|
||||||
get => this.paragraphTextColor;
|
|
||||||
set {
|
|
||||||
this.paragraphTextColor = value;
|
|
||||||
this.UpdateParagraphsStyles();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// The <see cref="Elements.Paragraph.TextScale"/> that this tooltip's <see cref="Paragraphs"/> should have
|
|
||||||
/// </summary>
|
|
||||||
public StyleProp<float> ParagraphTextScale {
|
|
||||||
get => this.paragraphTextScale;
|
|
||||||
set {
|
|
||||||
this.paragraphTextScale = value;
|
|
||||||
this.UpdateParagraphsStyles();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// The width that this tooltip's <see cref="Paragraphs"/> should have
|
|
||||||
/// </summary>
|
|
||||||
public StyleProp<float> ParagraphWidth {
|
|
||||||
get => this.paragraphWidth;
|
|
||||||
set {
|
|
||||||
this.paragraphWidth = value;
|
|
||||||
this.UpdateParagraphsStyles();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The paragraph of text that this tooltip displays
|
/// The paragraph of text that this tooltip displays
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Obsolete("Use Paragraphs instead, which allows for multiple paragraphs to be managed by one tooltip")]
|
|
||||||
public Paragraph Paragraph;
|
public Paragraph Paragraph;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Determines whether this tooltip should display when <see cref="UiControls.IsAutoNavMode"/> is true, which is when the UI is being controlled using a keyboard or gamepad.
|
/// Determines whether this tooltip should display when <see cref="UiControls.IsAutoNavMode"/> is true, which is when the UI is being controlled using a keyboard or gamepad.
|
||||||
|
@ -85,9 +45,6 @@ namespace MLEM.Ui.Elements {
|
||||||
private TimeSpan delayCountdown;
|
private TimeSpan delayCountdown;
|
||||||
private bool autoHidden;
|
private bool autoHidden;
|
||||||
private Element snapElement;
|
private Element snapElement;
|
||||||
private StyleProp<float> paragraphWidth;
|
|
||||||
private StyleProp<float> paragraphTextScale;
|
|
||||||
private StyleProp<Color> paragraphTextColor;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a new tooltip with the given settings
|
/// Creates a new tooltip with the given settings
|
||||||
|
@ -96,11 +53,8 @@ namespace MLEM.Ui.Elements {
|
||||||
/// <param name="elementToHover">The element that should automatically cause the tooltip to appear and disappear when hovered and not hovered, respectively</param>
|
/// <param name="elementToHover">The element that should automatically cause the tooltip to appear and disappear when hovered and not hovered, respectively</param>
|
||||||
public Tooltip(string text = null, Element elementToHover = null) :
|
public Tooltip(string text = null, Element elementToHover = null) :
|
||||||
base(Anchor.TopLeft, Vector2.One, Vector2.Zero) {
|
base(Anchor.TopLeft, Vector2.One, Vector2.Zero) {
|
||||||
if (text != null) {
|
if (text != null)
|
||||||
#pragma warning disable CS0618
|
this.Paragraph = this.AddChild(new Paragraph(Anchor.TopLeft, 0, text));
|
||||||
this.Paragraph = this.AddParagraph(text);
|
|
||||||
#pragma warning restore CS0618
|
|
||||||
}
|
|
||||||
this.Init(elementToHover);
|
this.Init(elementToHover);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,9 +65,7 @@ namespace MLEM.Ui.Elements {
|
||||||
/// <param name="elementToHover">The element that should automatically cause the tooltip to appear and disappear when hovered and not hovered, respectively</param>
|
/// <param name="elementToHover">The element that should automatically cause the tooltip to appear and disappear when hovered and not hovered, respectively</param>
|
||||||
public Tooltip(Paragraph.TextCallback textCallback, Element elementToHover = null) :
|
public Tooltip(Paragraph.TextCallback textCallback, Element elementToHover = null) :
|
||||||
base(Anchor.TopLeft, Vector2.One, Vector2.Zero) {
|
base(Anchor.TopLeft, Vector2.One, Vector2.Zero) {
|
||||||
#pragma warning disable CS0618
|
this.Paragraph = this.AddChild(new Paragraph(Anchor.TopLeft, 0, textCallback));
|
||||||
this.Paragraph = this.AddParagraph(textCallback);
|
|
||||||
#pragma warning restore CS0618
|
|
||||||
this.Init(elementToHover);
|
this.Init(elementToHover);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -149,47 +101,11 @@ namespace MLEM.Ui.Elements {
|
||||||
this.MouseOffset = this.MouseOffset.OrStyle(style.TooltipOffset);
|
this.MouseOffset = this.MouseOffset.OrStyle(style.TooltipOffset);
|
||||||
this.AutoNavOffset = this.AutoNavOffset.OrStyle(style.TooltipAutoNavOffset);
|
this.AutoNavOffset = this.AutoNavOffset.OrStyle(style.TooltipAutoNavOffset);
|
||||||
this.Delay = this.Delay.OrStyle(style.TooltipDelay);
|
this.Delay = this.Delay.OrStyle(style.TooltipDelay);
|
||||||
this.ParagraphTextColor = this.ParagraphTextColor.OrStyle(style.TooltipTextColor);
|
|
||||||
this.ParagraphTextScale = this.ParagraphTextScale.OrStyle(style.TextScale);
|
|
||||||
this.ParagraphWidth = this.ParagraphWidth.OrStyle(style.TooltipTextWidth);
|
|
||||||
this.ChildPadding = this.ChildPadding.OrStyle(style.TooltipChildPadding);
|
this.ChildPadding = this.ChildPadding.OrStyle(style.TooltipChildPadding);
|
||||||
this.UpdateParagraphsStyles();
|
if (this.Paragraph != null) {
|
||||||
|
this.Paragraph.TextColor = this.Paragraph.TextColor.OrStyle(style.TooltipTextColor, 1);
|
||||||
|
this.Paragraph.Size = new Vector2(style.TooltipTextWidth, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Adds the given paragraph to this tooltip's managed <see cref="Paragraphs"/> list, as well as to its children using <see cref="Element.AddChild{T}"/>.
|
|
||||||
/// A paragraph that is contained in the <see cref="Paragraphs"/> list will automatically have the <see cref="UiStyle.TooltipTextWidth"/> and <see cref="UiStyle.TooltipTextColor"/> applied.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="paragraph">The paragraph to add</param>
|
|
||||||
/// <returns>The added paragraph, for chaining</returns>
|
|
||||||
/// <param name="index">The index to add the child at, or -1 to add it to the end of the <see cref="Element.Children"/> list</param>
|
|
||||||
public Paragraph AddParagraph(Paragraph paragraph, int index = -1) {
|
|
||||||
this.Paragraphs.Add(paragraph);
|
|
||||||
this.AddChild(paragraph, index);
|
|
||||||
this.UpdateParagraphStyle(paragraph);
|
|
||||||
return paragraph;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Adds a new paragraph with the given text callback to this tooltip's managed <see cref="Paragraphs"/> list, as well as to its children using <see cref="Element.AddChild{T}"/>.
|
|
||||||
/// A paragraph that is contained in the <see cref="Paragraphs"/> list will automatically have the <see cref="UiStyle.TooltipTextWidth"/> and <see cref="UiStyle.TooltipTextColor"/> applied.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="text">The text that the paragraph should display</param>
|
|
||||||
/// <returns>The created paragraph, for chaining</returns>
|
|
||||||
/// <param name="index">The index to add the child at, or -1 to add it to the end of the <see cref="Element.Children"/> list</param>
|
|
||||||
public Paragraph AddParagraph(Paragraph.TextCallback text, int index = -1) {
|
|
||||||
return this.AddParagraph(new Paragraph(Anchor.AutoLeft, 0, text), index);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Adds a new paragraph with the given text to this tooltip's managed <see cref="Paragraphs"/> list, as well as to its children using <see cref="Element.AddChild{T}"/>.
|
|
||||||
/// A paragraph that is contained in the <see cref="Paragraphs"/> list will automatically have the <see cref="UiStyle.TooltipTextWidth"/> and <see cref="UiStyle.TooltipTextColor"/> applied.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="text">The text that the paragraph should display</param>
|
|
||||||
/// <returns>The created paragraph, for chaining</returns>
|
|
||||||
/// <param name="index">The index to add the child at, or -1 to add it to the end of the <see cref="Element.Children"/> list</param>
|
|
||||||
public Paragraph AddParagraph(string text, int index = -1) {
|
|
||||||
return this.AddParagraph(p => text, index);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -269,6 +185,9 @@ namespace MLEM.Ui.Elements {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Init(Element elementToHover) {
|
private void Init(Element elementToHover) {
|
||||||
|
if (this.Paragraph != null)
|
||||||
|
this.Paragraph.AutoAdjustWidth = true;
|
||||||
|
|
||||||
this.SetWidthBasedOnChildren = true;
|
this.SetWidthBasedOnChildren = true;
|
||||||
this.SetHeightBasedOnChildren = true;
|
this.SetHeightBasedOnChildren = true;
|
||||||
this.CanBeMoused = false;
|
this.CanBeMoused = false;
|
||||||
|
@ -291,23 +210,5 @@ namespace MLEM.Ui.Elements {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateParagraphsStyles() {
|
|
||||||
foreach (var paragraph in this.Paragraphs)
|
|
||||||
this.UpdateParagraphStyle(paragraph);
|
|
||||||
|
|
||||||
#pragma warning disable CS0618
|
|
||||||
// still set style here in case someone changed the paragraph field manually
|
|
||||||
if (this.Paragraph != null)
|
|
||||||
this.UpdateParagraphStyle(this.Paragraph);
|
|
||||||
#pragma warning restore CS0618
|
|
||||||
}
|
|
||||||
|
|
||||||
private void UpdateParagraphStyle(Paragraph paragraph) {
|
|
||||||
paragraph.TextColor = paragraph.TextColor.OrStyle(this.ParagraphTextColor, 1);
|
|
||||||
paragraph.TextScale = paragraph.TextScale.OrStyle(this.ParagraphTextScale, 1);
|
|
||||||
paragraph.Size = new Vector2(this.ParagraphWidth, 0);
|
|
||||||
paragraph.AutoAdjustWidth = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue