Files
Continentis/Assets/Scripts/MainGame/UI/HUDPage/HUDElements/Icon/HUD_CharacterBuffIcon.cs

139 lines
5.0 KiB
C#
Raw Normal View History

2025-10-03 00:02:43 -04:00
using System;
2025-10-23 00:49:44 -04:00
using System.Collections.Generic;
2025-10-03 00:02:43 -04:00
using Continentis.MainGame.Character;
2025-10-24 09:11:22 -04:00
using DG.Tweening;
2025-10-03 00:02:43 -04:00
using Lean.Pool;
2025-10-23 00:49:44 -04:00
using SLSFramework.General;
2025-10-03 00:02:43 -04:00
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
2025-10-24 09:11:22 -04:00
using UnityEngine.Serialization;
2025-10-03 00:02:43 -04:00
using UnityEngine.UI;
namespace Continentis.MainGame.UI
{
2025-10-24 09:11:22 -04:00
public class HUD_CharacterBuffIcon : HUD_BaseIcon, IPrioritized
2025-10-03 00:02:43 -04:00
{
2025-10-24 09:11:22 -04:00
public int Priority { get; set; }
2025-10-03 00:02:43 -04:00
public CharacterBuffBase buff;
2025-10-23 00:49:44 -04:00
public Image buffTypeBackground;
2025-10-24 09:11:22 -04:00
2025-10-23 00:49:44 -04:00
public Sprite positive;
public Sprite negative;
public Sprite neutral;
2025-10-24 09:11:22 -04:00
public Sprite focusing;
2025-10-03 00:02:43 -04:00
public void Initialize(CharacterBuffBase buff)
{
this.buff = buff;
2025-10-24 09:11:22 -04:00
this.Priority = buff.Priority;
2025-10-23 00:49:44 -04:00
buff.iconSubmodule.buffIcon = this;
icon.sprite = buff.iconSubmodule.icon;
2025-10-31 10:02:30 -04:00
this.infoBox = null;
2025-10-24 09:11:22 -04:00
PlayApplyAnimation();
2025-10-03 00:02:43 -04:00
UpdateIcon();
}
2025-10-24 09:11:22 -04:00
public void PlayApplyAnimation()
{
2025-10-25 07:49:39 -04:00
Image spreadImage = LeanPool.Spawn(MainGameManager.Instance.basePrefabs.customImage, rectTransform).GetComponent<Image>();
2025-10-24 09:11:22 -04:00
spreadImage.sprite = buff.iconSubmodule.icon;
2025-10-25 07:49:39 -04:00
spreadImage.rectTransform.rect.Set(0, 0, rectTransform.rect.width, rectTransform.rect.height);
2025-10-24 09:11:22 -04:00
spreadImage.rectTransform.localScale = Vector3.zero;
spreadImage.color = Color.white;
spreadImage.DOColor(new Color(1f, 1f, 1f, 0f), 1.1f).SetEase(Ease.Linear).Play();
2025-10-31 10:02:30 -04:00
spreadImage.maskable = false;
2025-10-25 07:49:39 -04:00
spreadImage.rectTransform.DOScale(4f, 1.2f).SetEase(Ease.OutQuad).OnComplete(() =>
2025-10-24 09:11:22 -04:00
{
LeanPool.Despawn(spreadImage.gameObject);
}).Play();
}
public void PlayHintAnimation()
{
2025-10-25 07:49:39 -04:00
icon.rectTransform.DOScale(1.25f, 0.2f).SetLoops(2, LoopType.Yoyo).SetEase(Ease.OutQuad).Play();
2025-10-24 09:11:22 -04:00
}
2025-10-03 00:02:43 -04:00
public override void UpdateIcon()
{
int index;
2025-10-23 00:49:44 -04:00
List<string> synchronizedParameters = buff.iconSubmodule.synchronizedParameters;
for (index = 0; index < synchronizedParameters.Count; index++)
2025-10-03 00:02:43 -04:00
{
2025-10-23 00:49:44 -04:00
string paramKey = synchronizedParameters[index];
Func<string> func = buff.contentSubmodule.parameterGetters[paramKey];
2025-11-13 10:42:05 -05:00
//Debug.Log($"Updating buff icon text for parameter {paramKey} with func is {func != null}");
2025-10-03 00:02:43 -04:00
SetText(index, func);
}
if (index < textList.Count)
{
for (int i = index; i < textList.Count; i++)
{
textList[i].gameObject.SetActive(false);
}
}
2025-10-23 00:49:44 -04:00
buffTypeBackground.sprite = buff.buffType switch
{
BuffType.Positive => positive,
BuffType.Negative => negative,
BuffType.Neutral => neutral,
2025-10-24 09:11:22 -04:00
BuffType.Focusing => focusing,
2025-10-23 00:49:44 -04:00
_ => buffTypeBackground.sprite
};
}
public void RemoveIcon()
{
buff.iconSubmodule.buffIcon = null;
LeanPool.Despawn(gameObject);
2025-10-03 00:02:43 -04:00
}
public override void OnPointerEnter(PointerEventData eventData)
{
2025-10-23 00:49:44 -04:00
BuffTextInterpreter.InterpretText(buff);
string dispelThreshold = buff.dispelThreshold switch
{
BuffDispelLevel.Basic => "Buff_DispelThreshold_Basic_Suffix",
BuffDispelLevel.Strong => "Buff_DispelThreshold_Strong_Suffix",
2025-10-25 07:49:39 -04:00
BuffDispelLevel.DeathOnly => "Buff_DispelThreshold_Immune_Suffix",
2025-10-23 00:49:44 -04:00
BuffDispelLevel.Undispellable => "Buff_DispelThreshold_Undispellable_Suffix",
_ => throw new ArgumentOutOfRangeException()
};
dispelThreshold = dispelThreshold.Localize();
2025-10-31 10:02:30 -04:00
2025-10-23 00:49:44 -04:00
string finalDescription = buff.contentSubmodule.interpretedFunctionText + "\n" + dispelThreshold;
2025-10-25 07:49:39 -04:00
2025-12-10 18:22:26 -05:00
RectTransform canvasTransform = CombatUIManager.Instance.hudPage.rectTransform;
Vector2 basePosition = canvasTransform.InverseTransformPoint(rectTransform.position);
InformationBox.Create(canvasTransform, ref infoBox).Initialize(buff.contentSubmodule.displayName, finalDescription, basePosition);
2025-10-03 00:02:43 -04:00
}
2025-10-23 00:49:44 -04:00
2025-10-03 00:02:43 -04:00
public override void OnPointerExit(PointerEventData eventData)
{
if (infoBox != null)
{
LeanPool.Despawn(infoBox.gameObject);
infoBox = null;
}
2025-10-31 10:02:30 -04:00
else
{
Debug.LogWarning("InfoBox is already null on pointer exit.");
}
}
private void OnDisable()
{
if (infoBox != null)
{
Debug.Log("Cleaning up InfoBox from OnDisable.");
LeanPool.Despawn(infoBox.gameObject);
infoBox = null;
}
2025-10-03 00:02:43 -04:00
}
}
}