mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-22 20:58:34 +01:00
allow tooltips to appear later
This commit is contained in:
parent
490a8aab78
commit
56db897c00
2 changed files with 26 additions and 1 deletions
|
@ -16,10 +16,16 @@ namespace MLEM.Ui.Elements {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public StyleProp<Vector2> MouseOffset;
|
public StyleProp<Vector2> MouseOffset;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
/// The amount of time that the mouse has to be over an element before it appears
|
||||||
|
/// </summary>
|
||||||
|
public StyleProp<TimeSpan> Delay;
|
||||||
|
/// <summary>
|
||||||
/// The paragraph of text that this tooltip displays
|
/// The paragraph of text that this tooltip displays
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Paragraph Paragraph;
|
public Paragraph Paragraph;
|
||||||
|
|
||||||
|
private TimeSpan delayCountdown;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a new tooltip with the given settings
|
/// Creates a new tooltip with the given settings
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -43,9 +49,16 @@ namespace MLEM.Ui.Elements {
|
||||||
if (this.Children.All(c => c.IsHidden))
|
if (this.Children.All(c => c.IsHidden))
|
||||||
return;
|
return;
|
||||||
element.System.Add(element.GetType().Name + "Tooltip", this);
|
element.System.Add(element.GetType().Name + "Tooltip", this);
|
||||||
this.SnapPositionToMouse();
|
if (this.Delay <= TimeSpan.Zero) {
|
||||||
|
this.IsHidden = false;
|
||||||
|
this.SnapPositionToMouse();
|
||||||
|
} else {
|
||||||
|
this.IsHidden = true;
|
||||||
|
this.delayCountdown = this.Delay;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
elementToHover.OnMouseExit += element => {
|
elementToHover.OnMouseExit += element => {
|
||||||
|
this.delayCountdown = TimeSpan.Zero;
|
||||||
if (this.System != null)
|
if (this.System != null)
|
||||||
this.System.Remove(this.Root.Name);
|
this.System.Remove(this.Root.Name);
|
||||||
};
|
};
|
||||||
|
@ -56,6 +69,12 @@ namespace MLEM.Ui.Elements {
|
||||||
public override void Update(GameTime time) {
|
public override void Update(GameTime time) {
|
||||||
base.Update(time);
|
base.Update(time);
|
||||||
this.SnapPositionToMouse();
|
this.SnapPositionToMouse();
|
||||||
|
|
||||||
|
if (this.IsHidden && this.delayCountdown > TimeSpan.Zero) {
|
||||||
|
this.delayCountdown -= time.ElapsedGameTime;
|
||||||
|
if (this.delayCountdown <= TimeSpan.Zero)
|
||||||
|
this.IsHidden = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
@ -70,6 +89,7 @@ namespace MLEM.Ui.Elements {
|
||||||
base.InitStyle(style);
|
base.InitStyle(style);
|
||||||
this.Texture.SetFromStyle(style.TooltipBackground);
|
this.Texture.SetFromStyle(style.TooltipBackground);
|
||||||
this.MouseOffset.SetFromStyle(style.TooltipOffset);
|
this.MouseOffset.SetFromStyle(style.TooltipOffset);
|
||||||
|
this.Delay.SetFromStyle(style.TooltipDelay);
|
||||||
// we can't set from style here since it's a different element
|
// we can't set from style here since it's a different element
|
||||||
this.Paragraph?.TextColor.Set(style.TooltipTextColor);
|
this.Paragraph?.TextColor.Set(style.TooltipTextColor);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
using System;
|
||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using Microsoft.Xna.Framework.Audio;
|
using Microsoft.Xna.Framework.Audio;
|
||||||
using MLEM.Font;
|
using MLEM.Font;
|
||||||
|
@ -108,6 +109,10 @@ namespace MLEM.Ui.Style {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Color TooltipTextColor = Color.White;
|
public Color TooltipTextColor = Color.White;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
/// The amount of time that the mouse has to be over an element with a <see cref="Tooltip"/> for the tooltip to appear
|
||||||
|
/// </summary>
|
||||||
|
public TimeSpan TooltipDelay = TimeSpan.Zero;
|
||||||
|
/// <summary>
|
||||||
/// The texture that the <see cref="ProgressBar"/> element uses for its background
|
/// The texture that the <see cref="ProgressBar"/> element uses for its background
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public NinePatch ProgressBarTexture;
|
public NinePatch ProgressBarTexture;
|
||||||
|
|
Loading…
Reference in a new issue