Better tooltip

This commit is contained in:
Braedon 2022-01-17 19:40:23 -05:00
parent 55bb69cffb
commit f7694ba345
11 changed files with 424 additions and 27 deletions

View file

@ -574,6 +574,140 @@ CanvasRenderer:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 129013732}
m_CullTransparentMesh: 1
--- !u!1 &151438063
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 151438064}
- component: {fileID: 151438066}
- component: {fileID: 151438065}
m_Layer: 5
m_Name: Text
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &151438064
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 151438063}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 1090036110}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 4, y: 4}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0, y: 0}
--- !u!114 &151438065
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 151438063}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f4688fdb7df04437aeb418b961361dc5, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 0
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_text: New Text
m_isRightToLeft: 0
m_fontAsset: {fileID: 11400000, guid: 78e7291cdeccdfc4fa61249845605144, type: 2}
m_sharedMaterial: {fileID: 5250768452915780979, guid: 78e7291cdeccdfc4fa61249845605144, type: 2}
m_fontSharedMaterials: []
m_fontMaterial: {fileID: 0}
m_fontMaterials: []
m_fontColor32:
serializedVersion: 2
rgba: 4294967295
m_fontColor: {r: 1, g: 1, b: 1, a: 1}
m_enableVertexGradient: 0
m_colorMode: 3
m_fontColorGradient:
topLeft: {r: 1, g: 1, b: 1, a: 1}
topRight: {r: 1, g: 1, b: 1, a: 1}
bottomLeft: {r: 1, g: 1, b: 1, a: 1}
bottomRight: {r: 1, g: 1, b: 1, a: 1}
m_fontColorGradientPreset: {fileID: 0}
m_spriteAsset: {fileID: 0}
m_tintAllSprites: 0
m_StyleSheet: {fileID: 0}
m_TextStyleHashCode: -1183493901
m_overrideHtmlColors: 0
m_faceColor:
serializedVersion: 2
rgba: 4294967295
m_fontSize: 28
m_fontSizeBase: 28
m_fontWeight: 400
m_enableAutoSizing: 0
m_fontSizeMin: 18
m_fontSizeMax: 72
m_fontStyle: 0
m_HorizontalAlignment: 1
m_VerticalAlignment: 1024
m_textAlignment: 65535
m_characterSpacing: 0
m_wordSpacing: 0
m_lineSpacing: 0
m_lineSpacingMax: 0
m_paragraphSpacing: 0
m_charWidthMaxAdj: 0
m_enableWordWrapping: 0
m_wordWrappingRatios: 0.4
m_overflowMode: 0
m_linkedTextComponent: {fileID: 0}
parentLinkedComponent: {fileID: 0}
m_enableKerning: 1
m_enableExtraPadding: 0
checkPaddingRequired: 0
m_isRichText: 1
m_parseCtrlCharacters: 1
m_isOrthographic: 1
m_isCullingEnabled: 0
m_horizontalMapping: 0
m_verticalMapping: 0
m_uvLineOffset: 0
m_geometrySortingOrder: 0
m_IsTextObjectScaleStatic: 0
m_VertexBufferAutoSizeReduction: 0
m_useMaxVisibleDescender: 1
m_pageToDisplay: 1
m_margin: {x: 0, y: 0, z: 0, w: 0}
m_isUsingLegacyAnimationComponent: 0
m_isVolumetricText: 0
m_hasFontAssetChanged: 0
m_baseMaterial: {fileID: 0}
m_maskOffset: {x: 0, y: 0, z: 0, w: 0}
--- !u!222 &151438066
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 151438063}
m_CullTransparentMesh: 1
--- !u!1 &156962253
GameObject:
m_ObjectHideFlags: 0
@ -1123,7 +1257,7 @@ MonoBehaviour:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 202724641}
m_Enabled: 1
m_Enabled: 0
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
m_Name:
@ -4180,7 +4314,6 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: eb5481d804b2aec42a04ea8f659fdc5a, type: 3}
m_Name:
m_EditorClassIdentifier:
isDragging: 0
PosPreview: {fileID: 0}
PosPreviewRef: {fileID: 2142375787}
Icon: {fileID: 820032006}
@ -4192,6 +4325,7 @@ MonoBehaviour:
mouseHovering: 0
resizable: 0
resizing: 0
moving: 0
NormalCol: {r: 0.8470589, g: 0.8470589, b: 1, a: 1}
--- !u!222 &798021451
CanvasRenderer:
@ -5340,6 +5474,73 @@ MonoBehaviour:
m_EditorClassIdentifier:
m_Padding: {x: 0, y: 0, z: 0, w: 0}
m_Softness: {x: 0, y: 0}
--- !u!1 &1090036109
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1090036110}
- component: {fileID: 1090036111}
- component: {fileID: 1090036112}
m_Layer: 5
m_Name: Tooltip
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &1090036110
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1090036109}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 1585542810}
- {fileID: 151438064}
m_Father: {fileID: 1791483803}
m_RootOrder: 6
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 640, y: 360}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0, y: 0}
--- !u!114 &1090036111
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1090036109}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 6d76a474576f0f04a9d3e0230c58dcb1, type: 3}
m_Name:
m_EditorClassIdentifier:
canvasRect: {fileID: 1791483803}
background: {fileID: 1585542810}
text: {fileID: 151438065}
group: {fileID: 1090036112}
--- !u!225 &1090036112
CanvasGroup:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1090036109}
m_Enabled: 1
m_Alpha: 0
m_Interactable: 0
m_BlocksRaycasts: 0
m_IgnoreParentGroups: 0
--- !u!1 &1110073994
GameObject:
m_ObjectHideFlags: 0
@ -6030,7 +6231,7 @@ RectTransform:
m_AnchorMin: {x: 0, y: 0.5}
m_AnchorMax: {x: 0, y: 0.5}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_SizeDelta: {x: 20, y: 20}
m_Pivot: {x: 0, y: 1}
--- !u!114 &1209651184
MonoBehaviour:
@ -6743,7 +6944,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
m_IsActive: 0
--- !u!224 &1344377689
RectTransform:
m_ObjectHideFlags: 0
@ -7616,6 +7817,81 @@ CanvasRenderer:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1567318395}
m_CullTransparentMesh: 1
--- !u!1 &1585542809
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1585542810}
- component: {fileID: 1585542812}
- component: {fileID: 1585542811}
m_Layer: 5
m_Name: BG
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &1585542810
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1585542809}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 1090036110}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 571.95, y: 87.81}
m_Pivot: {x: 0, y: 0}
--- !u!114 &1585542811
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1585542809}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 0, g: 0, b: 0, a: 0.6117647}
m_RaycastTarget: 0
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_Sprite: {fileID: 0}
m_Type: 0
m_PreserveAspect: 0
m_FillCenter: 1
m_FillMethod: 4
m_FillAmount: 1
m_FillClockwise: 1
m_FillOrigin: 0
m_UseSpriteMesh: 0
m_PixelsPerUnitMultiplier: 1
--- !u!222 &1585542812
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1585542809}
m_CullTransparentMesh: 1
--- !u!1 &1609794606
GameObject:
m_ObjectHideFlags: 0
@ -8606,7 +8882,7 @@ Canvas:
m_SortingBucketNormalizedSize: 0
m_AdditionalShaderChannelsFlag: 25
m_SortingLayerID: 0
m_SortingOrder: 0
m_SortingOrder: 1500
m_TargetDisplay: 0
--- !u!224 &1791483803
RectTransform:
@ -8625,6 +8901,7 @@ RectTransform:
- {fileID: 1861169746}
- {fileID: 703340359}
- {fileID: 1344377689}
- {fileID: 1090036110}
m_Father: {fileID: 0}
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 95230a0832fc45d459b313a5de51a2ff
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,50 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
using TMPro;
using RhythmHeavenMania.Common;
namespace RhythmHeavenMania.Deprecated
{
public class Tooltip : MonoBehaviour
{
public static Tooltip instance { get; private set; }
private void Awake()
{
instance = this;
}
public void OnEnter(string tooltipText)
{
this.GetComponent<Image>().enabled = true;
this.transform.GetChild(0).GetComponent<TMP_Text>().text = tooltipText;
this.transform.GetChild(0).gameObject.SetActive(true);
}
public void OnExit()
{
this.GetComponent<Image>().enabled = false;
this.transform.GetChild(0).gameObject.SetActive(false);
}
public void AddTooltip(GameObject g, string tooltipText)
{
EventTrigger et = g.AddComponent<EventTrigger>();
EventTrigger.Entry pointerEnter = new EventTrigger.Entry();
pointerEnter.eventID = EventTriggerType.PointerEnter;
pointerEnter.callback.AddListener((data) => { OnEnter(tooltipText); });
EventTrigger.Entry pointerExit = new EventTrigger.Entry();
pointerExit.eventID = EventTriggerType.PointerExit;
pointerExit.callback.AddListener((data) => { OnExit(); });
et.triggers.Add(pointerEnter);
et.triggers.Add(pointerExit);
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7e029fba1da3e5d4292b2d0e67333487
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -39,7 +39,7 @@ namespace RhythmHeavenMania
GameObject ui = new GameObject();
ui.AddComponent<SpriteRenderer>().sprite = Resources.Load<Sprite>("tempBuildUI");
ui.GetComponent<SpriteRenderer>().sortingOrder = 32767;
ui.GetComponent<SpriteRenderer>().sortingOrder = 1000;
ui.layer = 5;
ui.name = "tempBuildUI";
}

View file

@ -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()

View file

@ -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);
}

View file

@ -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()

View file

@ -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;

View file

@ -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;
public void OnExit()
if (anchoredPosition.x + background.rect.width > canvasRect.rect.width)
{
this.GetComponent<Image>().enabled = false;
this.transform.GetChild(0).gameObject.SetActive(false);
anchoredPosition.x = canvasRect.rect.width - background.rect.width;
}
if (anchoredPosition.x < 0)
{
anchoredPosition.x = 0;
}
public void AddTooltip(GameObject g, string tooltipText)
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 static void OnEnter(string tooltipText)
{
instance.OnEnterPrivate(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>();

View file

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 7e029fba1da3e5d4292b2d0e67333487
guid: 6d76a474576f0f04a9d3e0230c58dcb1
MonoImporter:
externalObjects: {}
serializedVersion: 2