149 lines
5.3 KiB
C#
149 lines
5.3 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 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;
|
|
this.infoBox = null;
|
|
PlayApplyAnimation();
|
|
UpdateIcon();
|
|
}
|
|
|
|
public void PlayApplyAnimation()
|
|
{
|
|
Image spreadImage = LeanPool.Spawn(MainGameManager.Instance.basePrefabs.customImage, rectTransform).GetComponent<Image>();
|
|
spreadImage.sprite = buff.iconSubmodule.icon;
|
|
spreadImage.rectTransform.rect.Set(0, 0, rectTransform.rect.width, rectTransform.rect.height);
|
|
spreadImage.rectTransform.localScale = Vector3.zero;
|
|
spreadImage.color = Color.white;
|
|
spreadImage.DOColor(new Color(1f, 1f, 1f, 0f), 1.1f).SetEase(Ease.Linear).Play();
|
|
spreadImage.maskable = false;
|
|
spreadImage.rectTransform.DOScale(4f, 1.2f).SetEase(Ease.OutQuad).OnComplete(() =>
|
|
{
|
|
LeanPool.Despawn(spreadImage.gameObject);
|
|
}).Play();
|
|
}
|
|
|
|
public void PlayHintAnimation()
|
|
{
|
|
icon.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];
|
|
//Debug.Log($"Updating buff icon text for parameter {paramKey} with func is {func != null}");
|
|
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;
|
|
|
|
if (infoBox == null)
|
|
{
|
|
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.DeathOnly => "Buff_DispelThreshold_Immune_Suffix",
|
|
BuffDispelLevel.Undispellable => "Buff_DispelThreshold_Undispellable_Suffix",
|
|
_ => throw new ArgumentOutOfRangeException()
|
|
};
|
|
dispelThreshold = dispelThreshold.Localize();
|
|
|
|
string finalDescription = buff.contentSubmodule.interpretedFunctionText + "\n" + dispelThreshold;
|
|
Vector2 basePosition = canvasTransform.InverseTransformPoint(rectTransform.position);
|
|
infoBox.Initialize(buff.contentSubmodule.displayName, finalDescription, basePosition);
|
|
|
|
Debug.Log("Pointer Enter Buff Icon");
|
|
}
|
|
|
|
public override void OnPointerExit(PointerEventData eventData)
|
|
{
|
|
Debug.Log("Pointer Exit Buff Icon");
|
|
|
|
if (infoBox != null)
|
|
{
|
|
LeanPool.Despawn(infoBox.gameObject);
|
|
infoBox = null;
|
|
}
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
} |