mirror of
https://github.com/RHeavenStudio/HeavenStudio.git
synced 2025-06-12 08:37:37 +02:00
Better tooltip
This commit is contained in:
@ -57,9 +57,9 @@ namespace RhythmHeavenMania.Editor
|
||||
GameIcon_.name = EventCaller.instance.minigames[i].displayName;
|
||||
}
|
||||
|
||||
Tooltip.instance.AddTooltip(NewBTN.gameObject, "New");
|
||||
Tooltip.instance.AddTooltip(OpenBTN.gameObject, "Open");
|
||||
Tooltip.instance.AddTooltip(SaveBTN.gameObject, "Save");
|
||||
Tooltip.AddTooltip(NewBTN.gameObject, "New");
|
||||
Tooltip.AddTooltip(OpenBTN.gameObject, "Open");
|
||||
Tooltip.AddTooltip(SaveBTN.gameObject, "Save");
|
||||
}
|
||||
|
||||
public void Update()
|
||||
|
@ -29,8 +29,8 @@ namespace RhythmHeavenMania.Editor
|
||||
{
|
||||
tempoLayer.GetComponent<Image>().color = theme.properties.TempoLayerCol.Hex2RGB();
|
||||
musicLayer.GetComponent<Image>().color = theme.properties.MusicLayerCol.Hex2RGB();
|
||||
Tooltip.instance.AddTooltip(tempoLayer.gameObject, $"Tempo Track");
|
||||
Tooltip.instance.AddTooltip(musicLayer.gameObject, $"Music Volume Track");
|
||||
Tooltip.AddTooltip(tempoLayer.gameObject, $"Tempo Track");
|
||||
Tooltip.AddTooltip(musicLayer.gameObject, $"Music Volume Track");
|
||||
|
||||
|
||||
layer.gameObject.SetActive(false);
|
||||
@ -60,7 +60,7 @@ namespace RhythmHeavenMania.Editor
|
||||
}
|
||||
|
||||
layer.GetComponent<Image>().color = c;
|
||||
Tooltip.instance.AddTooltip(layer, $"Track {i + 1}");
|
||||
Tooltip.AddTooltip(layer, $"Track {i + 1}");
|
||||
}
|
||||
Destroy(layer);
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ namespace RhythmHeavenMania.Editor
|
||||
|
||||
private void Start()
|
||||
{
|
||||
Tooltip.instance.AddTooltip(this.gameObject, this.gameObject.name);
|
||||
Tooltip.AddTooltip(this.gameObject, this.gameObject.name);
|
||||
}
|
||||
|
||||
public void OnClick()
|
||||
|
@ -92,10 +92,10 @@ namespace RhythmHeavenMania.Editor
|
||||
}
|
||||
});
|
||||
|
||||
Tooltip.instance.AddTooltip(PlayBTN.gameObject, "Play <color=#adadad>[Space]</color>");
|
||||
Tooltip.instance.AddTooltip(PauseBTN.gameObject, "Pause <color=#adadad>[Shift + Space]</color>");
|
||||
Tooltip.instance.AddTooltip(StopBTN.gameObject, "Stop <color=#adadad>[Space]</color>");
|
||||
Tooltip.instance.AddTooltip(MetronomeBTN.gameObject, "Metronome");
|
||||
Tooltip.AddTooltip(PlayBTN.gameObject, "Play <color=#adadad>[Space]</color>");
|
||||
Tooltip.AddTooltip(PauseBTN.gameObject, "Pause <color=#adadad>[Shift + Space]</color>");
|
||||
Tooltip.AddTooltip(StopBTN.gameObject, "Stop <color=#adadad>[Space]</color>");
|
||||
Tooltip.AddTooltip(MetronomeBTN.gameObject, "Metronome");
|
||||
|
||||
SetTimeButtonColors(true, false, false);
|
||||
MetronomeBTN.transform.GetChild(0).GetComponent<Image>().color = Color.gray;
|
||||
|
@ -5,33 +5,84 @@ using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
using TMPro;
|
||||
using RhythmHeavenMania.Common;
|
||||
|
||||
namespace RhythmHeavenMania.Editor
|
||||
{
|
||||
public class Tooltip : MonoBehaviour
|
||||
{
|
||||
private RectTransform rectTransform;
|
||||
[SerializeField] private RectTransform canvasRect;
|
||||
[SerializeField] private RectTransform background;
|
||||
[SerializeField] private TMP_Text text;
|
||||
[SerializeField] private CanvasGroup group;
|
||||
|
||||
public static Tooltip instance { get; private set; }
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
instance = this;
|
||||
rectTransform = GetComponent<RectTransform>();
|
||||
group.alpha = 0;
|
||||
}
|
||||
|
||||
public void OnEnter(string tooltipText)
|
||||
private void Update()
|
||||
{
|
||||
this.GetComponent<Image>().enabled = true;
|
||||
this.transform.GetChild(0).GetComponent<TMP_Text>().text = tooltipText;
|
||||
this.transform.GetChild(0).gameObject.SetActive(true);
|
||||
Vector2 anchoredPosition = Input.mousePosition;
|
||||
|
||||
if (anchoredPosition.x + background.rect.width > canvasRect.rect.width)
|
||||
{
|
||||
anchoredPosition.x = canvasRect.rect.width - background.rect.width;
|
||||
}
|
||||
if (anchoredPosition.x < 0)
|
||||
{
|
||||
anchoredPosition.x = 0;
|
||||
}
|
||||
|
||||
if (anchoredPosition.y + background.rect.height > canvasRect.rect.height)
|
||||
{
|
||||
anchoredPosition.y = canvasRect.rect.height - background.rect.height;
|
||||
}
|
||||
if (anchoredPosition.y < 0)
|
||||
{
|
||||
anchoredPosition.y = 0;
|
||||
}
|
||||
|
||||
rectTransform.anchoredPosition = anchoredPosition;
|
||||
}
|
||||
|
||||
public void OnExit()
|
||||
public static void OnEnter(string tooltipText)
|
||||
{
|
||||
this.GetComponent<Image>().enabled = false;
|
||||
this.transform.GetChild(0).gameObject.SetActive(false);
|
||||
instance.OnEnterPrivate(tooltipText);
|
||||
}
|
||||
|
||||
public void AddTooltip(GameObject g, string tooltipText)
|
||||
public static void OnExit()
|
||||
{
|
||||
instance.OnExitPrivate();
|
||||
}
|
||||
|
||||
private void OnEnterPrivate(string tooltipText)
|
||||
{
|
||||
group.alpha = 1;
|
||||
SetText(tooltipText);
|
||||
}
|
||||
|
||||
private void OnExitPrivate()
|
||||
{
|
||||
group.alpha = 0;
|
||||
}
|
||||
|
||||
private void SetText(string tooltipText)
|
||||
{
|
||||
text.text = tooltipText;
|
||||
text.ForceMeshUpdate();
|
||||
|
||||
Vector2 textSize = text.GetRenderedValues(false);
|
||||
Vector2 paddingSize = new Vector2(8, 8);
|
||||
|
||||
background.sizeDelta = textSize + paddingSize;
|
||||
}
|
||||
|
||||
public static void AddTooltip(GameObject g, string tooltipText)
|
||||
{
|
||||
EventTrigger et = g.AddComponent<EventTrigger>();
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7e029fba1da3e5d4292b2d0e67333487
|
||||
guid: 6d76a474576f0f04a9d3e0230c58dcb1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
|
Reference in New Issue
Block a user