Files
Continentis/Assets/Scripts/MainGame/Card/CardView/CardViewKeywordList.cs

90 lines
2.6 KiB
C#
Raw Normal View History

2025-10-03 00:02:43 -04:00
using System;
using System.Collections.Generic;
2025-10-23 00:49:44 -04:00
using Continentis.MainGame.Combat;
2025-10-03 00:02:43 -04:00
using Continentis.MainGame.UI;
using DG.Tweening;
using Lean.Pool;
2025-10-23 00:49:44 -04:00
using SLSFramework.General;
2025-10-03 00:02:43 -04:00
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);
}
2025-10-23 00:49:44 -04:00
public void SetUp(List<string> keys)
2025-10-03 00:02:43 -04:00
{
keywordsContainer.DespawnAllChildren();
2025-10-23 00:49:44 -04:00
foreach (string key in keys)
2025-10-03 00:02:43 -04:00
{
2025-10-23 00:49:44 -04:00
if (MainGameManager.Instance.keywordData.TryGetLocalizedKeyword(key, out string locName, out string locDesc))
{
InformationBox keywordBox = LeanPool.Spawn(MainGameManager.Instance.basePrefabs.informationBox, keywordsContainer)
.GetComponent<InformationBox>();
keywordBox.Initialize(locName, locDesc);
}
2025-10-03 00:02:43 -04:00
}
}
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();
}
}
}
}