riversong code showcase

This commit is contained in:
Daniele Marotta
2026-05-21 15:52:18 +02:00
commit 4c9eea1c02
462 changed files with 23406 additions and 0 deletions

View File

@@ -0,0 +1,54 @@
using System;
using Cysharp.Threading.Tasks;
using UnityEngine.UIElements;
namespace DanieleMarotta.RiversongCodeShowcase
{
public class RuntimeTooltipUIController : UIControllerSystem<RuntimeTooltipUIView>, IDisposable
{
private VisualElement _currentSource;
public RuntimeTooltipUIController(IServiceLocator serviceLocator) : base(serviceLocator)
{
}
protected override RuntimeTooltipUIView View => UIRoot.GetView<RuntimeTooltipUIView>();
public override async UniTask InitializeAsync()
{
await base.InitializeAsync();
View.Show(false);
UIRoot.RootVisualElement.RegisterCallback<PointerEnterEvent>(OnPointerEnter, TrickleDown.TrickleDown);
UIRoot.RootVisualElement.RegisterCallback<PointerLeaveEvent>(OnPointerLeave, TrickleDown.TrickleDown);
}
public void Dispose()
{
UIRoot.RootVisualElement.UnregisterCallback<PointerEnterEvent>(OnPointerEnter, TrickleDown.TrickleDown);
UIRoot.RootVisualElement.UnregisterCallback<PointerLeaveEvent>(OnPointerLeave, TrickleDown.TrickleDown);
}
private void OnPointerEnter(PointerEnterEvent evt)
{
if (evt.target is not VisualElement element) return;
var source = element.GetFirstAncestorOrSelf(static candidate => !string.IsNullOrEmpty(candidate.tooltip));
if (source == null || ReferenceEquals(source, _currentSource)) return;
_currentSource = source;
View.Show(true);
View.AnchorTooltip(source, source.tooltip);
}
private void OnPointerLeave(PointerLeaveEvent evt)
{
if (!ReferenceEquals(evt.target, _currentSource)) return;
_currentSource = null;
View.Show(false);
}
}
}