Skip to content

Commit

Permalink
Tooltip param: change anchoredPosition to worldPosition
Browse files Browse the repository at this point in the history
  • Loading branch information
AnhPham committed Feb 4, 2025
1 parent d0b1fd7 commit 33fb71a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
2 changes: 1 addition & 1 deletion SSv5/Assets/Scripts/Screen2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void OnAddScreen1ButtonTap()

public void OnShowTooltipButtonTap(Button button)
{
ScreenManager.ShowTooltip(text: "This is a long tooltip to test overflowing the screen", anchoredPosition: button.GetComponent<RectTransform>().anchoredPosition, targetY:Random.Range(100f, 300f));
ScreenManager.ShowTooltip(text: "This is a long tooltip to test overflowing the screen", worldPosition: button.transform.position, targetY:Random.Range(100f, 300f));
}

private IEnumerator ShowLoadingASecond()
Expand Down
18 changes: 9 additions & 9 deletions SSv5/Assets/ThirdParties/SS/Screen/Scripts/ScreenManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -454,15 +454,15 @@ public static bool IsNoMoreScreen()
/// Show tooltip
/// </summary>
/// <param name="text">Tooltip content</param>
/// <param name="anchoredPosition">Tooltip position</param>
/// <param name="worldPosition">Tooltip position</param>
/// <param name="tooltipName">Tooltip prefab name</param>
/// <param name="targetY">Target Y</param>
public static void ShowTooltip(string text, Vector2 anchoredPosition, float targetY = 100f)
public static void ShowTooltip(string text, Vector3 worldPosition, float targetY = 100f)
{
if (m_Instance == null)
return;

m_Instance.LoadAndShowTooltip(text, anchoredPosition, targetY);
m_Instance.LoadAndShowTooltip(text, worldPosition, targetY);
}
#endregion

Expand Down Expand Up @@ -1179,26 +1179,26 @@ private void RemoveScreenFromList(Component screen)
}
}

private void CreateAndShowTooltip(GameObject tooltipPrefab, string text, Vector2 anchoredPosition, float targetY)
private void CreateAndShowTooltip(GameObject tooltipPrefab, string text, Vector3 worldPosition, float targetY)
{
var tooltip = Instantiate(tooltipPrefab, Top);
m_Tooltip = tooltip.GetComponent<TooltipBaseController>();

if (m_Tooltip != null)
{
m_Tooltip.ShowTooltip(text, anchoredPosition, targetY);
m_Tooltip.ShowTooltip(text, worldPosition, targetY);
}
}

private void LoadAndShowTooltip(string text, Vector2 anchoredPosition, float targetY = 100f)
private void LoadAndShowTooltip(string text, Vector3 worldPosition, float targetY = 100f)
{
if (string.IsNullOrEmpty(m_TooltipName))
return;

if (m_Tooltip != null)
{
m_Tooltip.transform.SetParent(Top, true);
m_Tooltip.ShowTooltip(text, anchoredPosition, targetY);
m_Tooltip.ShowTooltip(text, worldPosition, targetY);
return;
}

Expand All @@ -1207,12 +1207,12 @@ private void LoadAndShowTooltip(string text, Vector2 anchoredPosition, float tar
async.Completed += (a => {
if (a.Status == UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationStatus.Succeeded)
{
CreateAndShowTooltip(async.Result, text, anchoredPosition, targetY);
CreateAndShowTooltip(async.Result, text, worldPosition, targetY);
}
});
#else
var tooltipPrefab = Resources.Load<GameObject>(Path.Combine(m_ScreenPath, m_TooltipName));
CreateAndShowTooltip(tooltipPrefab, text, anchoredPosition, targetY);
CreateAndShowTooltip(tooltipPrefab, text, worldPosition, targetY);
#endif
}
#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,20 @@ public void ShowTooltip(string text, Vector2 anchoredPosition, float targetY = 1
m_Animation.Play("Tooltip", OnAnimationEnd);
}

public void ShowTooltip(string text, Vector3 worldPosition, float targetY = 100f)
{
// Canvas
var canvas = GetComponentInParent<Canvas>();
if (canvas == null)
{
return;
}

var localPosition = canvas.transform.InverseTransformPoint(worldPosition);

ShowTooltip(text, new Vector2(localPosition.x, localPosition.y), targetY);
}

protected virtual void SetText(string text)
{
}
Expand Down

0 comments on commit 33fb71a

Please sign in to comment.