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

Allow specifying a custom position for a tooltip to snap to

This commit is contained in:
Ell 2022-03-14 14:20:12 +01:00
parent f166c3d256
commit b77edd80d5
2 changed files with 10 additions and 1 deletions

View file

@ -49,6 +49,7 @@ Improvements
- Automatically select the first element when a dropdown is opened in auto nav mode - Automatically select the first element when a dropdown is opened in auto nav mode
- Improved gamepad navigation by employing angles between elements - Improved gamepad navigation by employing angles between elements
- Prefer elements that have the same parent as the currently selected element when using gamepad navigation - Prefer elements that have the same parent as the currently selected element when using gamepad navigation
- Allow specifying a custom position for a tooltip to snap to
Fixes Fixes
- Fixed paragraph links having incorrect hover locations when using special text alignments - Fixed paragraph links having incorrect hover locations when using special text alignments

View file

@ -1,5 +1,6 @@
using System; using System;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using MLEM.Input;
using MLEM.Ui.Style; using MLEM.Ui.Style;
namespace MLEM.Ui.Elements { namespace MLEM.Ui.Elements {
@ -22,6 +23,12 @@ namespace MLEM.Ui.Elements {
/// The paragraph of text that this tooltip displays /// The paragraph of text that this tooltip displays
/// </summary> /// </summary>
public Paragraph Paragraph; public Paragraph Paragraph;
/// <summary>
/// The position that this tooltip should be following (or snapped to) instead of the <see cref="InputHandler.ViewportMousePosition"/>.
/// If this value is unset, <see cref="InputHandler.ViewportMousePosition"/> will be used as the snap position.
/// Note that <see cref="MouseOffset"/> is still applied with this value set.
/// </summary>
public virtual Vector2? SnapPosition { get; set; }
private TimeSpan delayCountdown; private TimeSpan delayCountdown;
private bool autoHidden; private bool autoHidden;
@ -91,7 +98,8 @@ namespace MLEM.Ui.Elements {
/// </summary> /// </summary>
public void SnapPositionToMouse() { public void SnapPositionToMouse() {
var viewport = this.System.Viewport; var viewport = this.System.Viewport;
var offset = (this.Input.ViewportMousePosition.ToVector2() + this.MouseOffset.Value) / this.Scale; var snapPosition = this.SnapPosition ?? this.Input.ViewportMousePosition.ToVector2();
var offset = (snapPosition + this.MouseOffset.Value) / this.Scale;
if (offset.X < viewport.X) if (offset.X < viewport.X)
offset.X = viewport.X; offset.X = viewport.X;
if (offset.Y < viewport.Y) if (offset.Y < viewport.Y)