93 lines
2.9 KiB
C#
93 lines
2.9 KiB
C#
using NeoModLoader.General;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace IdleSpectator;
|
|
|
|
/// <summary>
|
|
/// Shared canvas / text / panel helpers for compact non-modal HUD cards.
|
|
/// </summary>
|
|
public static class HudCanvas
|
|
{
|
|
public static Canvas Resolve()
|
|
{
|
|
if (CanvasMain.instance != null)
|
|
{
|
|
if (CanvasMain.instance.canvas_ui != null)
|
|
{
|
|
return CanvasMain.instance.canvas_ui;
|
|
}
|
|
|
|
if (CanvasMain.instance.canvas_tooltip != null)
|
|
{
|
|
return CanvasMain.instance.canvas_tooltip;
|
|
}
|
|
}
|
|
|
|
return Object.FindObjectOfType<Canvas>();
|
|
}
|
|
|
|
public static Text MakeText(Transform parent, string name, string value, int size)
|
|
{
|
|
Text text = new GameObject(name, typeof(RectTransform), typeof(Text)).GetComponent<Text>();
|
|
text.transform.SetParent(parent, false);
|
|
try
|
|
{
|
|
OT.InitializeCommonText(text);
|
|
}
|
|
catch
|
|
{
|
|
text.font = Resources.GetBuiltinResource<Font>("Arial.ttf");
|
|
}
|
|
|
|
text.text = value ?? "";
|
|
text.fontSize = size;
|
|
text.resizeTextForBestFit = true;
|
|
text.resizeTextMinSize = 8;
|
|
text.resizeTextMaxSize = size;
|
|
text.color = Color.white;
|
|
text.raycastTarget = false;
|
|
text.horizontalOverflow = HorizontalWrapMode.Wrap;
|
|
text.verticalOverflow = VerticalWrapMode.Truncate;
|
|
return text;
|
|
}
|
|
|
|
public static Image MakeIcon(Transform parent, string name, float size)
|
|
{
|
|
Image image = new GameObject(name, typeof(RectTransform), typeof(Image)).GetComponent<Image>();
|
|
image.transform.SetParent(parent, false);
|
|
RectTransform rt = image.GetComponent<RectTransform>();
|
|
rt.sizeDelta = new Vector2(size, size);
|
|
image.raycastTarget = false;
|
|
image.preserveAspect = true;
|
|
image.color = Color.white;
|
|
image.enabled = false;
|
|
return image;
|
|
}
|
|
|
|
/// <summary>Dark fill + lighter 1px edge so panels read as WorldBox chrome.</summary>
|
|
public static void StylePanel(Image fill, Transform root, Color fillColor)
|
|
{
|
|
if (fill != null)
|
|
{
|
|
fill.color = fillColor;
|
|
}
|
|
|
|
if (root == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
GameObject edge = new GameObject("Edge", typeof(RectTransform), typeof(Image));
|
|
edge.transform.SetParent(root, false);
|
|
edge.transform.SetAsFirstSibling();
|
|
RectTransform edgeRt = edge.GetComponent<RectTransform>();
|
|
edgeRt.anchorMin = Vector2.zero;
|
|
edgeRt.anchorMax = Vector2.one;
|
|
edgeRt.offsetMin = new Vector2(-1f, -1f);
|
|
edgeRt.offsetMax = new Vector2(1f, 1f);
|
|
Image edgeImg = edge.GetComponent<Image>();
|
|
edgeImg.color = new Color(0.42f, 0.45f, 0.5f, 0.55f);
|
|
edgeImg.raycastTarget = false;
|
|
}
|
|
}
|