Files
Continentis/Assets/Scripts/MainGame/Card/CardView/CardViewKeywordList.cs
SoulliesOfficial 9b1b5ca93f initial
2025-10-03 00:02:43 -04:00

85 lines
2.5 KiB
C#

using System;
using System.Collections.Generic;
using Continentis.MainGame.UI;
using DG.Tweening;
using Lean.Pool;
using SoulliesFramework.General;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.UI;
namespace Continentis.MainGame.Card
{
public class CardViewKeywordList : UIElementBase
{
public CanvasGroup canvasGroup;
public ScrollRect scrollRect;
public RectTransform keywordsContainer;
public Tweener enableTweener, disableTweener;
private bool HasAnyKeyword() => keywordsContainer.childCount > 0;
protected override void Awake()
{
base.Awake();
GetComponent<Canvas>().sortingLayerName = "UI";
enableTweener = canvasGroup.DOFade(1f, 0.2f).SetEase(Ease.OutQuad).SetAutoKill(false);
disableTweener = canvasGroup.DOFade(0f, 0.2f).SetEase(Ease.OutQuad).SetAutoKill(false);
}
public void SetUp(List<string> keywords)
{
keywordsContainer.DespawnAllChildren();
foreach (string keyword in keywords)
{
string desc = CombatMainManager.Instance.keywordCollection.GetKeywordDescription(keyword);
InformationBox keywordBox = LeanPool.Spawn(MainGameManager.Instance.basePrefabs.informationBox, keywordsContainer).GetComponent<InformationBox>();
keywordBox.Initialize(keyword, desc);
}
}
public void Scroll(float scrollAmount)
{
if(!HasAnyKeyword())
{
return;
}
float step = scrollAmount * 50f;
float height = scrollRect.content.rect.height;
float delta = step / height;
scrollRect.verticalNormalizedPosition += delta;
}
public void Enable(List<string> keywords)
{
SetUp(keywords);
if(!HasAnyKeyword())
{
return;
}
disableTweener.Complete();
if (!enableTweener.IsPlaying())
{
enableTweener.Restart();
}
}
public void Disable()
{
if(!HasAnyKeyword())
{
return;
}
enableTweener.Complete();
if (!disableTweener.IsPlaying())
{
disableTweener.Restart();
}
}
}
}