Files
Continentis/Assets/Scripts/MainGame/UI/HUDPage/HUDElements/Icon/HUD_CharacterBuffIcon.cs
SoulliesOfficial 61a397dd4c MOD!
2025-10-23 00:49:44 -04:00

97 lines
3.3 KiB
C#

using System;
using System.Collections.Generic;
using Continentis.MainGame.Character;
using Lean.Pool;
using SLSFramework.General;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
namespace Continentis.MainGame.UI
{
public class HUD_CharacterBuffIcon : HUD_BaseIcon
{
public CharacterBuffBase buff;
public Image buffTypeBackground;
public Sprite positive;
public Sprite negative;
public Sprite neutral;
public void Initialize(CharacterBuffBase buff)
{
this.buff = buff;
buff.iconSubmodule.buffIcon = this;
icon.sprite = buff.iconSubmodule.icon;
UpdateIcon();
}
public override void UpdateIcon()
{
int index;
List<string> synchronizedParameters = buff.iconSubmodule.synchronizedParameters;
for (index = 0; index < synchronizedParameters.Count; index++)
{
string paramKey = synchronizedParameters[index];
Func<string> func = buff.contentSubmodule.parameterGetters[paramKey];
SetText(index, func);
}
if (index < textList.Count)
{
for (int i = index; i < textList.Count; i++)
{
textList[i].gameObject.SetActive(false);
}
}
buffTypeBackground.sprite = buff.buffType switch
{
BuffType.Positive => positive,
BuffType.Negative => negative,
BuffType.Neutral => neutral,
_ => buffTypeBackground.sprite
};
}
public void RemoveIcon()
{
buff.iconSubmodule.buffIcon = null;
LeanPool.Despawn(gameObject);
}
public override void OnPointerEnter(PointerEventData eventData)
{
GameObject infoBoxPrefab = MainGameManager.Instance.basePrefabs.informationBox;
RectTransform canvasTransform = CombatUIManager.Instance.hudPage.rectTransform;
infoBox = LeanPool.Spawn(infoBoxPrefab, canvasTransform).GetComponent<InformationBox>();
BuffTextInterpreter.InterpretText(buff);
string dispelThreshold = buff.dispelThreshold switch
{
BuffDispelLevel.Basic => "Buff_DispelThreshold_Basic_Suffix",
BuffDispelLevel.Strong => "Buff_DispelThreshold_Strong_Suffix",
BuffDispelLevel.Immune => "Buff_DispelThreshold_Immune_Suffix",
BuffDispelLevel.Undispellable => "Buff_DispelThreshold_Undispellable_Suffix",
_ => throw new ArgumentOutOfRangeException()
};
dispelThreshold = dispelThreshold.Localize();
string finalDescription = buff.contentSubmodule.interpretedFunctionText + "\n" + dispelThreshold;
infoBox.Initialize(buff.contentSubmodule.displayName, finalDescription, canvasTransform.InverseTransformPoint(rectTransform.position));
}
public override void OnPointerExit(PointerEventData eventData)
{
if (infoBox != null)
{
LeanPool.Despawn(infoBox.gameObject);
infoBox = null;
}
}
}
}