90 lines
2.6 KiB
C#
90 lines
2.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using Continentis.MainGame.Combat;
|
|
using Continentis.MainGame.UI;
|
|
using DG.Tweening;
|
|
using Lean.Pool;
|
|
using SLSFramework.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> keys)
|
|
{
|
|
keywordsContainer.DespawnAllChildren();
|
|
|
|
foreach (string key in keys)
|
|
{
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
|
|
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();
|
|
}
|
|
}
|
|
}
|
|
} |