1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-11-26 06:28:35 +01:00

allow tooltips to appear later

This commit is contained in:
Ell 2020-12-05 16:42:21 +01:00
parent 490a8aab78
commit 56db897c00
2 changed files with 26 additions and 1 deletions

View file

@ -16,10 +16,16 @@ namespace MLEM.Ui.Elements {
/// </summary>
public StyleProp<Vector2> MouseOffset;
/// <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
/// </summary>
public Paragraph Paragraph;
private TimeSpan delayCountdown;
/// <summary>
/// Creates a new tooltip with the given settings
/// </summary>
@ -43,9 +49,16 @@ namespace MLEM.Ui.Elements {
if (this.Children.All(c => c.IsHidden))
return;
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 => {
this.delayCountdown = TimeSpan.Zero;
if (this.System != null)
this.System.Remove(this.Root.Name);
};
@ -56,6 +69,12 @@ namespace MLEM.Ui.Elements {
public override void Update(GameTime time) {
base.Update(time);
this.SnapPositionToMouse();
if (this.IsHidden && this.delayCountdown > TimeSpan.Zero) {
this.delayCountdown -= time.ElapsedGameTime;
if (this.delayCountdown <= TimeSpan.Zero)
this.IsHidden = false;
}
}
/// <inheritdoc />
@ -70,6 +89,7 @@ namespace MLEM.Ui.Elements {
base.InitStyle(style);
this.Texture.SetFromStyle(style.TooltipBackground);
this.MouseOffset.SetFromStyle(style.TooltipOffset);
this.Delay.SetFromStyle(style.TooltipDelay);
// we can't set from style here since it's a different element
this.Paragraph?.TextColor.Set(style.TooltipTextColor);
}

View file

@ -1,3 +1,4 @@
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using MLEM.Font;
@ -108,6 +109,10 @@ namespace MLEM.Ui.Style {
/// </summary>
public Color TooltipTextColor = Color.White;
/// <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
/// </summary>
public NinePatch ProgressBarTexture;