126 lines
4.3 KiB
C#
126 lines
4.3 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 card;
|
||
|
||
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(card.contentSubmodule.keywords);
|
||
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)
|
||
{
|
||
this.card = card;
|
||
isOccupied = false;
|
||
isHovering = false;
|
||
isSelecting = false;
|
||
isDuringPlaying = false;
|
||
}
|
||
else if (this.card == null)
|
||
{
|
||
Debug.LogError("CardViewBase Setup called with null card!");
|
||
return;
|
||
}
|
||
|
||
cardNameText.text = this.card.contentSubmodule.cardName;
|
||
cardDescriptionText.text = this.card.contentSubmodule.interpretedFunctionText;
|
||
cardImage.sprite = this.card.contentSubmodule.cardSprite;
|
||
|
||
if (this.card.contentSubmodule.cardRarity != Rarity.None)
|
||
{
|
||
cardRarityMark.color = MainGameManager.Instance.basePrefabs.GetRarityColor(this.card.contentSubmodule.cardRarity);
|
||
}
|
||
else
|
||
{
|
||
cardRarityMark.gameObject.SetActive(false);
|
||
}
|
||
|
||
if (string.IsNullOrEmpty(collectionName)) collectionName = "Basic";
|
||
CardViewCollection collection = MainGameManager.Instance.basePrefabs.cardViewCollections[collectionName];
|
||
|
||
List<string> layoutTags = this.card.cardData.cardLayoutTags; //TODO:后续可扩展为动态布局标签
|
||
string firstLayoutTag = layoutTags.Count > 0 ? layoutTags[0] : "Default";
|
||
if (!collection.cardViews.ContainsKey(firstLayoutTag)) firstLayoutTag = "Default";
|
||
cardBackground.sprite = collection.cardViews[firstLayoutTag].background;
|
||
|
||
cardTypeText.text = this.card.contentSubmodule.cardType.ToString();
|
||
|
||
staminaCostText.rectTransform.parent.gameObject.SetActive(true);
|
||
staminaCostText.text = this.card.attributeSubmodule.GetRoundCurrentAttribute("StaminaCost").ToString();
|
||
|
||
int manaCost = this.card.attributeSubmodule.GetRoundCurrentAttribute("ManaCost");
|
||
manaCostText.rectTransform.parent.gameObject.SetActive(manaCost > 0);
|
||
manaCostText.text = manaCost.ToString();
|
||
|
||
if (this.card.HasKeyword("Unplayable")) // 如果卡牌不能被打出,则隐藏费用文本
|
||
{
|
||
staminaCostText.rectTransform.parent.gameObject.SetActive(false);
|
||
manaCostText.rectTransform.parent.gameObject.SetActive(false);
|
||
}
|
||
}
|
||
}
|
||
} |