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

126 lines
4.3 KiB
C#
Raw Normal View History

2025-10-03 00:02:43 -04:00
using System;
2025-10-23 00:49:44 -04:00
using System.Collections.Generic;
2025-10-03 00:02:43 -04:00
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
{
2025-11-15 12:17:34 -05:00
public CardInstance card;
2025-10-03 00:02:43 -04:00
public Canvas canvas;
public RectTransform cardTransform;
public TMP_Text cardNameText, cardDescriptionText;
public TMP_Text staminaCostText;
public TMP_Text manaCostText;
public TMP_Text cardTypeText;
2025-10-23 00:49:44 -04:00
public Image cardBackground;
2025-10-03 00:02:43 -04:00
public Image cardImage;
public Image cardRarityMark;
public CardViewKeywordList keywordList;
2025-10-23 00:49:44 -04:00
public Image normalShadow;
public Image hintShadow;
public Image selectShadow;
public string collectionName;
2025-10-03 00:02:43 -04:00
}
public partial class CardViewBase
{
2025-10-23 00:49:44 -04:00
2025-10-03 00:02:43 -04:00
public bool isOccupied;
2025-10-23 00:49:44 -04:00
2025-10-03 00:02:43 -04:00
public bool isHovering;
2025-10-23 00:49:44 -04:00
2025-10-03 00:02:43 -04:00
public bool isSelecting;
2025-10-23 00:49:44 -04:00
2025-10-03 00:02:43 -04:00
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;
2025-10-23 00:49:44 -04:00
List<string> allKeywords = new List<string>();
2025-11-15 12:17:34 -05:00
allKeywords.AddRange(card.contentSubmodule.keywords);
2025-10-23 00:49:44 -04:00
keywordList.Enable(allKeywords);
2025-10-03 00:02:43 -04:00
}
public virtual void OnPointerExit(PointerEventData eventData)
{
isHovering = false;
keywordList.Disable();
}
}
public partial class CardViewBase
{
public virtual void Setup(CardInstance card = null)
{
if (card != null)
{
2025-11-15 12:17:34 -05:00
this.card = card;
2025-11-08 09:50:55 -05:00
isOccupied = false;
isHovering = false;
isSelecting = false;
isDuringPlaying = false;
2025-10-03 00:02:43 -04:00
}
2025-11-15 12:17:34 -05:00
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;
2025-10-03 00:02:43 -04:00
2025-11-15 12:17:34 -05:00
if (this.card.contentSubmodule.cardRarity != Rarity.None)
2025-10-03 00:02:43 -04:00
{
2025-11-15 12:17:34 -05:00
cardRarityMark.color = MainGameManager.Instance.basePrefabs.GetRarityColor(this.card.contentSubmodule.cardRarity);
2025-10-03 00:02:43 -04:00
}
else
{
cardRarityMark.gameObject.SetActive(false);
}
2025-10-23 00:49:44 -04:00
if (string.IsNullOrEmpty(collectionName)) collectionName = "Basic";
CardViewCollection collection = MainGameManager.Instance.basePrefabs.cardViewCollections[collectionName];
2025-10-27 07:04:34 -04:00
2025-11-15 12:17:34 -05:00
List<string> layoutTags = this.card.cardData.cardLayoutTags; //TODO后续可扩展为动态布局标签
2025-10-27 07:04:34 -04:00
string firstLayoutTag = layoutTags.Count > 0 ? layoutTags[0] : "Default";
if (!collection.cardViews.ContainsKey(firstLayoutTag)) firstLayoutTag = "Default";
cardBackground.sprite = collection.cardViews[firstLayoutTag].background;
2025-10-23 00:49:44 -04:00
2025-11-15 12:17:34 -05:00
cardTypeText.text = this.card.contentSubmodule.cardType.ToString();
2025-10-23 00:49:44 -04:00
staminaCostText.rectTransform.parent.gameObject.SetActive(true);
2025-11-15 12:17:34 -05:00
staminaCostText.text = this.card.attributeSubmodule.GetRoundCurrentAttribute("StaminaCost").ToString();
2025-10-03 00:02:43 -04:00
2025-11-15 12:17:34 -05:00
int manaCost = this.card.attributeSubmodule.GetRoundCurrentAttribute("ManaCost");
2025-10-03 00:02:43 -04:00
manaCostText.rectTransform.parent.gameObject.SetActive(manaCost > 0);
manaCostText.text = manaCost.ToString();
2025-11-15 12:17:34 -05:00
if (this.card.HasKeyword("Unplayable")) // 如果卡牌不能被打出,则隐藏费用文本
2025-10-03 00:02:43 -04:00
{
staminaCostText.rectTransform.parent.gameObject.SetActive(false);
manaCostText.rectTransform.parent.gameObject.SetActive(false);
}
}
}
}