mirror of
https://gitgud.io/AbstractConcept/rimworld-animation-studio.git
synced 2024-08-15 00:43:27 +00:00
UI 2.0
This commit is contained in:
parent
c3c0a05ac0
commit
3d859555ad
324 changed files with 13886 additions and 7446 deletions
79
Assets/Scripts/Tooltip.cs
Normal file
79
Assets/Scripts/Tooltip.cs
Normal file
|
@ -0,0 +1,79 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace RimWorldAnimationStudio
|
||||
{
|
||||
public class Tooltip : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
|
||||
{
|
||||
public string message = "Undefined";
|
||||
public string executedCommand;
|
||||
public float delay = 0f;
|
||||
|
||||
private GameObject tooltip;
|
||||
private Text tooltipText;
|
||||
private bool isActive;
|
||||
private bool isDisplayed;
|
||||
private float activeTime = -1f;
|
||||
|
||||
public void Start()
|
||||
{
|
||||
tooltip = Workspace.Instance.transform.Find("TooltipMessage")?.gameObject;
|
||||
tooltipText = tooltip?.GetComponentInChildren<Text>();
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
if (tooltip == null || isActive == false || (activeTime + delay) > Time.unscaledTime) return;
|
||||
|
||||
if (isDisplayed == false)
|
||||
{
|
||||
tooltipText.text = message;
|
||||
|
||||
if (executedCommand != null && executedCommand != "")
|
||||
{ tooltipText.text += " (" + KeybindConfig.Instance.GetKeybindLabel(executedCommand) + ")"; }
|
||||
|
||||
tooltip.transform.position = (Vector2)transform.position + new Vector2(5f, -15f);
|
||||
tooltip.gameObject.SetActive(true);
|
||||
|
||||
LayoutRebuilder.ForceRebuildLayoutImmediate(tooltip.GetComponent<RectTransform>());
|
||||
|
||||
isDisplayed = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnDisable()
|
||||
{
|
||||
if (isActive)
|
||||
{ OnPointerExit(new PointerEventData(EventSystem.current)); }
|
||||
}
|
||||
|
||||
public void OnPointerEnter(PointerEventData pointerEventData)
|
||||
{
|
||||
isActive = true;
|
||||
activeTime = Time.unscaledTime;
|
||||
}
|
||||
|
||||
public void OnPointerExit(PointerEventData pointerEventData)
|
||||
{
|
||||
isActive = false;
|
||||
isDisplayed = false;
|
||||
tooltip.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
public void CalculateLayoutInputHorizontal()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void CalculateLayoutInputVertical()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue