76 lines
2.4 KiB
C#
76 lines
2.4 KiB
C#
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using SLSFramework.General;
|
||
using UniRx;
|
||
using UnityEngine;
|
||
|
||
namespace Continentis.MainGame.Card
|
||
{
|
||
public class ContentSubmodule : SubmoduleBase<CardInstance>
|
||
{
|
||
public List<string> keywords;
|
||
|
||
public string cardName;
|
||
public Sprite cardSprite;
|
||
public Rarity cardRarity;
|
||
public CardType cardType;
|
||
public string originalFunctionText;
|
||
public string interpretedFunctionText;
|
||
|
||
/// <summary>
|
||
/// 标记:内容已更改,需要刷新
|
||
/// </summary>
|
||
public bool dirtyMark;
|
||
|
||
/// <summary>
|
||
/// 标记:hint shadow 颜色需要刷新,不触发文本重解析
|
||
/// </summary>
|
||
public bool hintDirtyMark;
|
||
|
||
public ContentSubmodule(CardInstance card) : base(card)
|
||
{
|
||
keywords = card.cardData.keywords;
|
||
cardName = card.cardData.displayName.Localize();
|
||
cardSprite = card.cardData.cardSprite ?? MainGameManager.Instance.basePrefabs.defaultCardImage;
|
||
originalFunctionText = card.cardData.functionText.Localize();
|
||
cardRarity = card.cardData.cardRarity;
|
||
cardType = card.cardData.cardType;
|
||
dirtyMark = false;
|
||
hintDirtyMark = false;
|
||
|
||
Observable.EveryLateUpdate().Subscribe(_ =>
|
||
{
|
||
if (dirtyMark)
|
||
{
|
||
RefreshContent();
|
||
dirtyMark = false;
|
||
}
|
||
if (hintDirtyMark)
|
||
{
|
||
RefreshHintShadow();
|
||
hintDirtyMark = false;
|
||
}
|
||
}).AddTo(card.disposables);
|
||
}
|
||
|
||
public void RefreshContent()
|
||
{
|
||
CardTextInterpreter.InterpretText(owner);
|
||
owner.handCardView?.Setup();
|
||
owner.intentionCardView?.Setup();
|
||
|
||
// 文本刷新后,hint 也需要同步更新
|
||
hintDirtyMark = true;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 仅刷新 hint shadow 颜色,不触发文本重解析。
|
||
/// </summary>
|
||
public void RefreshHintShadow()
|
||
{
|
||
if (owner.handCardView == null || owner.handCardView.isSelecting) return;
|
||
Color? hintColor = owner.cardLogic?.GetHintColor();
|
||
owner.handCardView.UpdateHintShadow(hintColor);
|
||
}
|
||
}
|
||
} |