123 lines
4.2 KiB
C#
123 lines
4.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.InputSystem;
|
|
using UnityEngine.UI;
|
|
|
|
namespace Continentis.MainGame.Card
|
|
{
|
|
public abstract partial class CardViewBase : UIElementBase, IPointerEnterHandler, IPointerExitHandler
|
|
{
|
|
public CardInstance cardInstance;
|
|
public CardLogicBase cardLogic => cardInstance.cardLogic;
|
|
|
|
public Canvas canvas;
|
|
public RectTransform cardTransform;
|
|
|
|
public TMP_Text cardNameText, cardDescriptionText;
|
|
public TMP_Text staminaCostText;
|
|
public TMP_Text manaCostText;
|
|
public TMP_Text cardTypeText;
|
|
public Image cardBackground;
|
|
public Image cardImage;
|
|
public Image cardRarityMark;
|
|
public CardViewKeywordList keywordList;
|
|
|
|
public Image normalShadow;
|
|
public Image hintShadow;
|
|
public Image selectShadow;
|
|
|
|
public string collectionName;
|
|
}
|
|
|
|
public partial class CardViewBase
|
|
{
|
|
|
|
public bool isOccupied;
|
|
|
|
public bool isHovering;
|
|
|
|
public bool isSelecting;
|
|
|
|
public bool isDuringPlaying;
|
|
|
|
private void Update()
|
|
{
|
|
if (isHovering)
|
|
{
|
|
keywordList.Scroll(Mouse.current.scroll.y.ReadValue());
|
|
}
|
|
}
|
|
|
|
public virtual void OnPointerEnter(PointerEventData eventData)
|
|
{
|
|
if(isDuringPlaying) return;
|
|
|
|
isHovering = true;
|
|
|
|
List<string> allKeywords = new List<string>();
|
|
allKeywords.AddRange(cardLogic.contentSubmodule.keywords);
|
|
allKeywords.AddRange(cardLogic.contentSubmodule.hintKeywords);
|
|
keywordList.Enable(allKeywords);
|
|
}
|
|
|
|
public virtual void OnPointerExit(PointerEventData eventData)
|
|
{
|
|
isHovering = false;
|
|
keywordList.Disable();
|
|
}
|
|
}
|
|
|
|
public partial class CardViewBase
|
|
{
|
|
public virtual void Setup(CardInstance card = null)
|
|
{
|
|
if (card != null)
|
|
{
|
|
cardInstance = card;
|
|
}
|
|
|
|
isOccupied = false;
|
|
isHovering = false;
|
|
isSelecting = false;
|
|
isDuringPlaying = false;
|
|
|
|
cardNameText.text = cardLogic.contentSubmodule.cardName;
|
|
cardDescriptionText.text = cardLogic.contentSubmodule.interpretedFunctionText;
|
|
cardImage.sprite = cardLogic.contentSubmodule.cardSprite;
|
|
|
|
if (cardLogic.contentSubmodule.cardRarity != Rarity.None)
|
|
{
|
|
cardRarityMark.color = MainGameManager.Instance.basePrefabs.GetRarityColor(cardLogic.contentSubmodule.cardRarity);
|
|
}
|
|
else
|
|
{
|
|
cardRarityMark.gameObject.SetActive(false);
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(collectionName)) collectionName = "Basic";
|
|
CardViewCollection collection = MainGameManager.Instance.basePrefabs.cardViewCollections[collectionName];
|
|
List<string> elementTags = cardLogic.GetElementTags();
|
|
string firstElementTag = elementTags.Count > 0 ? elementTags[0] : "Default";
|
|
if (!collection.cardViews.ContainsKey(firstElementTag)) firstElementTag = "Default";
|
|
cardBackground.sprite = collection.cardViews[firstElementTag].background;
|
|
|
|
cardTypeText.text = cardLogic.contentSubmodule.cardType.ToString();
|
|
|
|
staminaCostText.rectTransform.parent.gameObject.SetActive(true);
|
|
staminaCostText.text = cardLogic.attributeSubmodule.GetRoundCurrentAttribute("StaminaCost").ToString();
|
|
|
|
int manaCost = cardLogic.attributeSubmodule.GetRoundCurrentAttribute("ManaCost");
|
|
manaCostText.rectTransform.parent.gameObject.SetActive(manaCost > 0);
|
|
manaCostText.text = manaCost.ToString();
|
|
|
|
if (cardLogic.HasKeyword("Unplayable")) // 如果卡牌不能被打出,则隐藏费用文本
|
|
{
|
|
staminaCostText.rectTransform.parent.gameObject.SetActive(false);
|
|
manaCostText.rectTransform.parent.gameObject.SetActive(false);
|
|
}
|
|
}
|
|
}
|
|
} |