mirror of
https://github.com/RHeavenStudio/HeavenStudio.git
synced 2025-06-13 06:57:39 +02:00
Delayed Property Tooltips (#886)
* add dropdown yes im really making a pr for something as tiny as this * can now turn on/off now for the hard part * can turn on and off much better now i can ACTUALLY get the delay working * it works!!! currently waits for 400 frames regardless of fps, should probably be changed in the future but it works well enough rn * Timer waits 1.5 seconds much better, thanks astrl
This commit is contained in:
@ -32,7 +32,7 @@ namespace HeavenStudio.Editor
|
||||
public bool active;
|
||||
|
||||
private int childCountAtStart;
|
||||
|
||||
|
||||
public Dictionary<string, EventPropertyPrefab> currentProperties = new();
|
||||
|
||||
public bool canDisable = true;
|
||||
@ -43,7 +43,8 @@ namespace HeavenStudio.Editor
|
||||
{
|
||||
instance = this;
|
||||
|
||||
if (PropertyPrefabs == null) {
|
||||
if (PropertyPrefabs == null)
|
||||
{
|
||||
PropertyPrefabs = new() {
|
||||
{ typeof(Integer), IntegerP },
|
||||
{ typeof(Float), FloatP },
|
||||
@ -131,11 +132,11 @@ namespace HeavenStudio.Editor
|
||||
}
|
||||
input.SetCollapses(p.parameter);
|
||||
}
|
||||
|
||||
|
||||
foreach (var p in action.parameters)
|
||||
{
|
||||
EventPropertyPrefab prop = currentProperties[p.propertyName];
|
||||
|
||||
|
||||
prop.PostLoadProperties(p.parameter);
|
||||
}
|
||||
|
||||
@ -151,7 +152,8 @@ namespace HeavenStudio.Editor
|
||||
{
|
||||
Type typeType = type.GetType();
|
||||
GameObject propertyPrefab = DropdownP; // enum check is hardcoded because enums are awesome (lying)
|
||||
if (!typeType.IsEnum && !PropertyPrefabs.TryGetValue(typeType, out propertyPrefab)) {
|
||||
if (!typeType.IsEnum && !PropertyPrefabs.TryGetValue(typeType, out propertyPrefab))
|
||||
{
|
||||
Debug.LogError("Can't make property interface of type: " + typeType);
|
||||
return null;
|
||||
}
|
||||
@ -160,14 +162,12 @@ namespace HeavenStudio.Editor
|
||||
input.SetActive(true);
|
||||
input.transform.localScale = Vector3.one;
|
||||
|
||||
if (tooltip != string.Empty) {
|
||||
if (PersistentDataManager.gameSettings.showParamTooltips) {
|
||||
Tooltip.AddTooltip(input, tooltip);
|
||||
} else {
|
||||
Tooltip.AddTooltip(input, "", tooltip);
|
||||
}
|
||||
if (tooltip != string.Empty)
|
||||
{
|
||||
Tooltip.AddTooltip(input, tooltip, null, PersistentDataManager.gameSettings.showParamTooltips);
|
||||
|
||||
}
|
||||
|
||||
|
||||
EventPropertyPrefab property = input.GetComponent<EventPropertyPrefab>();
|
||||
property.SetProperties(propertyName, type, caption);
|
||||
|
||||
@ -182,7 +182,7 @@ namespace HeavenStudio.Editor
|
||||
{
|
||||
Destroy(transform.GetChild(i).gameObject);
|
||||
}
|
||||
|
||||
|
||||
currentProperties.Clear();
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,8 @@ namespace HeavenStudio.Editor
|
||||
[SerializeField] private RectTransform background;
|
||||
[SerializeField] private TMP_Text text;
|
||||
[SerializeField] private CanvasGroup group;
|
||||
[SerializeField] private float timer = 0f;
|
||||
[SerializeField] private bool timerActive = false;
|
||||
|
||||
public static Tooltip instance { get; private set; }
|
||||
|
||||
@ -27,6 +29,14 @@ namespace HeavenStudio.Editor
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (timerActive)
|
||||
{
|
||||
timer += Time.deltaTime;
|
||||
if (timer >= 1.5f)
|
||||
{
|
||||
group.alpha = 1;
|
||||
}
|
||||
}
|
||||
Vector3 anchoredPosition = Input.mousePosition;
|
||||
Camera camera = Editor.instance.EditorCamera;
|
||||
Vector3 canvasScale = Editor.instance.MainCanvas.transform.localScale;
|
||||
@ -56,9 +66,9 @@ namespace HeavenStudio.Editor
|
||||
rectTransform.anchoredPosition = anchoredPosition / scale;
|
||||
}
|
||||
|
||||
public static void OnEnter(string tooltipText, string altTooltipText)
|
||||
public static void OnEnter(string tooltipText, string altTooltipText, int type)
|
||||
{
|
||||
instance.OnEnterPrivate(tooltipText, altTooltipText);
|
||||
instance.OnEnterPrivate(tooltipText, altTooltipText, type);
|
||||
}
|
||||
|
||||
public static void OnExit()
|
||||
@ -68,24 +78,64 @@ namespace HeavenStudio.Editor
|
||||
Editor.instance.tooltipText.ForceMeshUpdate();
|
||||
}
|
||||
|
||||
private void OnEnterPrivate(string tooltipText, string altTooltipText)
|
||||
private void OnEnterPrivate(string tooltipText, string altTooltipText, int type)
|
||||
{
|
||||
group.alpha = 1;
|
||||
Vector2 textSize;
|
||||
Vector2 paddingSize;
|
||||
|
||||
text.text = tooltipText;
|
||||
text.ForceMeshUpdate();
|
||||
// tooltip types: 0 = only corner, 1 = delayed on mouse, 2 = instant on mouse
|
||||
// idk the best place to put this comment so i'm putting it everywhere lmao
|
||||
switch (type)
|
||||
{
|
||||
case 0:
|
||||
group.alpha = 0;
|
||||
|
||||
Vector2 textSize = text.GetRenderedValues(false);
|
||||
Vector2 paddingSize = new Vector2(8, 8);
|
||||
text.text = tooltipText;
|
||||
text.ForceMeshUpdate();
|
||||
|
||||
background.sizeDelta = textSize + paddingSize;
|
||||
Editor.instance.tooltipText.text = altTooltipText.Replace("\n", "");
|
||||
Editor.instance.tooltipText.ForceMeshUpdate();
|
||||
textSize = text.GetRenderedValues(false);
|
||||
paddingSize = new Vector2(8, 8);
|
||||
|
||||
background.sizeDelta = textSize + paddingSize;
|
||||
Editor.instance.tooltipText.text = altTooltipText.Replace("\n", "");
|
||||
Editor.instance.tooltipText.ForceMeshUpdate();
|
||||
break;
|
||||
case 1:
|
||||
group.alpha = 0;
|
||||
|
||||
text.text = tooltipText;
|
||||
text.ForceMeshUpdate();
|
||||
|
||||
textSize = text.GetRenderedValues(false);
|
||||
paddingSize = new Vector2(8, 8);
|
||||
|
||||
background.sizeDelta = textSize + paddingSize;
|
||||
Editor.instance.tooltipText.text = altTooltipText.Replace("\n", "");
|
||||
Editor.instance.tooltipText.ForceMeshUpdate();
|
||||
|
||||
timerActive = true;
|
||||
break;
|
||||
case 2:
|
||||
group.alpha = 1;
|
||||
|
||||
text.text = tooltipText;
|
||||
text.ForceMeshUpdate();
|
||||
|
||||
textSize = text.GetRenderedValues(false);
|
||||
paddingSize = new Vector2(8, 8);
|
||||
|
||||
background.sizeDelta = textSize + paddingSize;
|
||||
Editor.instance.tooltipText.text = altTooltipText.Replace("\n", "");
|
||||
Editor.instance.tooltipText.ForceMeshUpdate();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnExitPrivate()
|
||||
{
|
||||
group.alpha = 0;
|
||||
timerActive = false;
|
||||
timer = 0;
|
||||
}
|
||||
|
||||
private void SetText(string tooltipText)
|
||||
@ -99,15 +149,16 @@ namespace HeavenStudio.Editor
|
||||
background.sizeDelta = textSize + paddingSize;
|
||||
}
|
||||
|
||||
public static void AddTooltip(GameObject g, string tooltipText, string altTooltipText = null)
|
||||
public static void AddTooltip(GameObject g, string tooltipText, string altTooltipText = null, int type = 2)
|
||||
{
|
||||
// tooltip types: 0 = only corner, 1 = delayed on mouse, 2 = instant on mouse
|
||||
altTooltipText ??= tooltipText;
|
||||
|
||||
EventTrigger et = g.AddComponent<EventTrigger>();
|
||||
|
||||
EventTrigger.Entry pointerEnter = new EventTrigger.Entry();
|
||||
pointerEnter.eventID = EventTriggerType.PointerEnter;
|
||||
pointerEnter.callback.AddListener((data) => { OnEnter(tooltipText, altTooltipText); });
|
||||
pointerEnter.callback.AddListener((data) => { OnEnter(tooltipText, altTooltipText, type); });
|
||||
|
||||
EventTrigger.Entry pointerExit = new EventTrigger.Entry();
|
||||
pointerExit.eventID = EventTriggerType.PointerExit;
|
||||
|
@ -132,7 +132,7 @@ namespace HeavenStudio.Common
|
||||
bool letterboxFxEnable = true,
|
||||
int editorScale = 0,
|
||||
bool scaleWScreenSize = false,
|
||||
bool showParamTooltips = true,
|
||||
int showParamTooltips = 1,
|
||||
bool previewNoteSounds = true
|
||||
)
|
||||
{
|
||||
@ -195,7 +195,7 @@ namespace HeavenStudio.Common
|
||||
public bool discordRPCEnable;
|
||||
public int editorScale;
|
||||
public bool scaleWScreenSize;
|
||||
public bool showParamTooltips;
|
||||
public int showParamTooltips;
|
||||
public bool previewNoteSounds;
|
||||
// public bool showCornerTooltips;
|
||||
|
||||
|
@ -3,6 +3,7 @@ using UnityEngine.UI;
|
||||
using TMPro;
|
||||
|
||||
using HeavenStudio.Common;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace HeavenStudio.Editor
|
||||
{
|
||||
@ -12,7 +13,7 @@ namespace HeavenStudio.Editor
|
||||
[SerializeField] Toggle discordRPCCheckbox;
|
||||
[SerializeField] Button editorScaleDecre, editorScaleIncre;
|
||||
[SerializeField] Toggle scaleWSS;
|
||||
[SerializeField] Toggle paramTooltipsToggle;
|
||||
[SerializeField] TMP_Dropdown paramTooltipsDropdown;
|
||||
[SerializeField] Toggle previewNoteSoundsToggle;
|
||||
// [SerializeField] Toggle cornerTooltipsToggle;
|
||||
|
||||
@ -21,7 +22,7 @@ namespace HeavenStudio.Editor
|
||||
cursorCheckbox.isOn = PersistentDataManager.gameSettings.editorCursorEnable;
|
||||
discordRPCCheckbox.isOn = PersistentDataManager.gameSettings.discordRPCEnable;
|
||||
scaleWSS.isOn = PersistentDataManager.gameSettings.scaleWScreenSize;
|
||||
paramTooltipsToggle.isOn = PersistentDataManager.gameSettings.showParamTooltips;
|
||||
paramTooltipsDropdown.value = PersistentDataManager.gameSettings.showParamTooltips;
|
||||
previewNoteSoundsToggle.isOn = PersistentDataManager.gameSettings.previewNoteSounds;
|
||||
|
||||
SetDecreIncreInteractable();
|
||||
@ -60,7 +61,8 @@ namespace HeavenStudio.Editor
|
||||
|
||||
public void OnParamTooltipsChanged()
|
||||
{
|
||||
PersistentDataManager.gameSettings.showParamTooltips = paramTooltipsToggle.isOn;
|
||||
// tooltip types: 0 = only corner, 1 = delayed on mouse, 2 = instant on mouse
|
||||
PersistentDataManager.gameSettings.showParamTooltips = paramTooltipsDropdown.value;
|
||||
}
|
||||
|
||||
public void OnPreviewNoteSoundsChanged()
|
||||
|
Reference in New Issue
Block a user