Files
Continentis/Assets/Scripts/MainGame/UI/HUDPage/HUDElements/Icon/HUD_CharacterBuffIcon.cs
SoulliesOfficial 76157e3cb1 继续
2025-10-24 09:11:22 -04:00

123 lines
4.4 KiB
C#

using System;
using System.Collections.Generic;
using Continentis.MainGame.Character;
using DG.Tweening;
using Lean.Pool;
using SLSFramework.General;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Serialization;
using UnityEngine.UI;
namespace Continentis.MainGame.UI
{
public class HUD_CharacterBuffIcon : HUD_BaseIcon, IPrioritized
{
public int Priority { get; set; }
public CharacterBuffBase buff;
public Image buffTypeBackground;
public Image mainIcon;
public Sprite positive;
public Sprite negative;
public Sprite neutral;
public Sprite focusing;
public void Initialize(CharacterBuffBase buff)
{
this.buff = buff;
this.Priority = buff.Priority;
buff.iconSubmodule.buffIcon = this;
icon.sprite = buff.iconSubmodule.icon;
PlayApplyAnimation();
UpdateIcon();
}
public void PlayApplyAnimation()
{
Image spreadImage = LeanPool.Spawn(mainIcon.gameObject, rectTransform).GetComponent<Image>();
spreadImage.sprite = buff.iconSubmodule.icon;
spreadImage.rectTransform.localScale = Vector3.zero;
spreadImage.color = Color.white;
spreadImage.DOColor(new Color(1f, 1f, 1f, 0f), 1.1f).SetEase(Ease.Linear).Play();
spreadImage.rectTransform.DOScale(5f, 1.2f).SetEase(Ease.OutQuad).OnComplete(() =>
{
LeanPool.Despawn(spreadImage.gameObject);
}).Play();
}
public void PlayHintAnimation()
{
mainIcon.rectTransform.DOScale(1.25f, 0.2f).SetLoops(2, LoopType.Yoyo).SetEase(Ease.OutQuad).Play();
}
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,
BuffType.Focusing => focusing,
_ => 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;
}
}
}
}