diff --git a/MLEM.Ui/Elements/Tooltip.cs b/MLEM.Ui/Elements/Tooltip.cs index 928d4d7..b56868a 100644 --- a/MLEM.Ui/Elements/Tooltip.cs +++ b/MLEM.Ui/Elements/Tooltip.cs @@ -16,10 +16,16 @@ namespace MLEM.Ui.Elements { /// public StyleProp MouseOffset; /// + /// The amount of time that the mouse has to be over an element before it appears + /// + public StyleProp Delay; + /// /// The paragraph of text that this tooltip displays /// public Paragraph Paragraph; + private TimeSpan delayCountdown; + /// /// Creates a new tooltip with the given settings /// @@ -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; + } } /// @@ -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); } diff --git a/MLEM.Ui/Style/UiStyle.cs b/MLEM.Ui/Style/UiStyle.cs index 601ad89..6585b8f 100644 --- a/MLEM.Ui/Style/UiStyle.cs +++ b/MLEM.Ui/Style/UiStyle.cs @@ -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 { /// public Color TooltipTextColor = Color.White; /// + /// The amount of time that the mouse has to be over an element with a for the tooltip to appear + /// + public TimeSpan TooltipDelay = TimeSpan.Zero; + /// /// The texture that the element uses for its background /// public NinePatch ProgressBarTexture;