using BepInEx;
using UnityEngine;
using UnityEngine.UI;
namespace KKAPI.Maker.UI
{
///
/// Custom control that displays a simple text
///
public class MakerText : BaseGuiEntry
{
///
/// Light gray color best used for text explaining another setting
///
public static Color ExplanationGray => new Color(0.7f, 0.7f, 0.7f);
private static Transform _textCopy;
private string _text;
private Text _instance;
///
/// Create a new custom control. Create and register it in .
///
/// Displayed text
/// Category the control will be created under
/// Plugin that owns the control
public MakerText(string text, MakerCategory category, BaseUnityPlugin owner) : base(category, owner)
{
Text = text;
}
///
/// Displayed text
///
public string Text
{
get => _text;
set
{
_text = value;
if (_instance != null)
_instance.text = value;
}
}
private static Transform TextCopy
{
get
{
if (_textCopy == null)
MakeCopy();
return _textCopy;
}
}
private static void MakeCopy()
{
_textCopy = Object.Instantiate(GameObject.Find("SettingWindow/WinFace/F_FaceType/Setting/Setting01/title"), GuiCacheTransfrom).transform;
_textCopy.gameObject.SetActive(false);
_textCopy.name = "txtCustom";
_textCopy.gameObject.AddComponent().minHeight = 40;
var textCmp = _textCopy.GetComponentInChildren();
textCmp.lineSpacing = 0.75f;
textCmp.fontSize = 24;
SetTextAutosize(textCmp);
RemoveLocalisation(_textCopy.gameObject);
}
///
protected internal override void Initialize()
{
if (_textCopy == null)
MakeCopy();
}
///
protected override GameObject OnCreateControl(Transform subCategoryList)
{
var tr = Object.Instantiate(TextCopy, subCategoryList, false);
_instance = tr.GetComponentInChildren();
_instance.text = Text;
_instance.color = TextColor;
return tr.gameObject;
}
}
}