Max amount of card remain, Max amount of cards in hand.

pull/6/head
SherlockShiYL 2022-03-20 20:22:40 -07:00
parent 5f1965667e
commit deea0a218e
2 changed files with 913 additions and 307 deletions

File diff suppressed because it is too large Load Diff

View File

@ -2,30 +2,19 @@ using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using UnityEngine.UI; using UnityEngine.UI;
using TMPro;
public class Deck : MonoBehaviour public class Deck : MonoBehaviour
{ {
public List<CardData> cardDataList; public List<CardData> cardDataList;
//public List<CardData> drawList;
public List<GameObject> drawDisplayList;
//public List<CardData> handList;
//public List<GameObject> handDisplayList;
//public List<CardData> discardList;
public List<GameObject> discardDisplayList;
public List<CardData> wasteList;
public int randomSeed; public int randomSeed;
public GameObject handCardTemplate; private GameObject cardTemplate;
public GameObject cardDisplayTemplate;
public GameObject drawListContent; private GameObject handListContent;
public GameObject discardListContent; private GameObject drawListContent;
private GameObject discardListContent;
private int cardInHandAmount = 0;
// Card Limit // Card Limit
public int maxCardinHandLimit = 10; public int maxCardinHandLimit = 10;
public int maxCardRemainLimit = 5; public int maxCardRemainLimit = 5;
@ -34,25 +23,35 @@ public class Deck : MonoBehaviour
private float warningDisplayCountDown; private float warningDisplayCountDown;
private float warningDisplayTime = 1.0f; private float warningDisplayTime = 1.0f;
private GameObject discardHoldingListContent;
private TextMeshProUGUI discardWarningDisplayText;
// Start is called before the first frame update // Start is called before the first frame update
void Start() void Start()
{ {
drawListContent = transform.Find("DrawListContent/Viewport/Content").gameObject;
drawListContent.transform.parent.parent.gameObject.SetActive(false);
discardListContent = transform.Find("DiscardListContent/Viewport/Content").gameObject;
discardListContent.transform.parent.parent.gameObject.SetActive(false);
handListContent = transform.Find("Content/HandListContent").gameObject;
cardTemplate = transform.Find("CardTemplate").gameObject;
reachCardinHandLimitWarningDisplay = transform.Find("Content/LimitWarning").gameObject; reachCardinHandLimitWarningDisplay = transform.Find("Content/LimitWarning").gameObject;
reachCardinHandLimitWarningDisplay.SetActive(false); reachCardinHandLimitWarningDisplay.SetActive(false);
discardHoldingListContent = transform.Find("Content/DiscardHoldingListContent/Viewport/HoldingListContent").gameObject;
discardHoldingListContent.transform.parent.parent.gameObject.SetActive(false);
discardWarningDisplayText = transform.Find("Content/DiscardHoldingListContent/Viewport/DiscardWarning/Text").gameObject.GetComponent<TextMeshProUGUI>();
randomSeed = 200; randomSeed = 200;
Random.InitState(randomSeed); Random.InitState(randomSeed);
for (int i = 0; i < cardDataList.Count; i++) for (int i = 0; i < cardDataList.Count; i++)
{ {
//drawList.Add(cardDataList[i]); GameObject tempDrawDisplay = Instantiate(cardTemplate.gameObject, transform.Find("DrawListContent/Viewport/Content"));
GameObject tempDrawDisplay = Instantiate(cardDisplayTemplate.gameObject, transform.Find("DrawListContent/Viewport/Content"));
tempDrawDisplay.transform.Find("Card").gameObject.GetComponent<CardDisplay>().SetCardData(cardDataList[i]); tempDrawDisplay.transform.Find("Card").gameObject.GetComponent<CardDisplay>().SetCardData(cardDataList[i]);
tempDrawDisplay.transform.Find("Button").gameObject.GetComponent<Image>().sprite = cardDataList[i].artwork; tempDrawDisplay.transform.Find("Button").gameObject.GetComponent<Image>().sprite = cardDataList[i].artwork;
tempDrawDisplay.SetActive(true); tempDrawDisplay.SetActive(true);
drawDisplayList.Add(tempDrawDisplay);
} }
drawListContent.SetActive(false);
discardListContent.SetActive(false);
} }
// Update is called once per frame // Update is called once per frame
@ -77,30 +76,21 @@ public class Deck : MonoBehaviour
{ {
for (int i = 0; i < amount; i++) for (int i = 0; i < amount; i++)
{ {
if (cardInHandAmount > maxCardinHandLimit - 1) if (handListContent.transform.childCount > maxCardinHandLimit - 1)
{ {
ActivateCardInHandLimitWarning(); ActivateCardInHandLimitWarning();
return; return;
} }
if (drawDisplayList.Count == 0) if (drawListContent.transform.childCount == 0)
{ {
Shuffle(); Shuffle();
} }
if (drawDisplayList.Count == 0) if (drawListContent.transform.childCount == 0)
{ {
return; return;
} }
int randomIndex = Random.Range(0, drawDisplayList.Count); int randomIndex = Random.Range(0, drawListContent.transform.childCount);
GameObject cardObj = Instantiate(handCardTemplate.gameObject, transform.Find("Content/HandList")); drawListContent.transform.GetChild(randomIndex).transform.SetParent(handListContent.transform);
var tempCardData = drawDisplayList[randomIndex].transform.Find("Card").gameObject.GetComponent<CardDisplay>().cardData;
cardObj.transform.Find("Card").gameObject.GetComponent<CardDisplay>().SetCardData(tempCardData);
cardObj.transform.Find("Button").gameObject.GetComponent<Image>().sprite = tempCardData.artwork;
cardObj.SetActive(true);
cardInHandAmount++;
//handDisplayList.Add(cardObj);
//handList.Add(drawList[randomIndex]);
Destroy(drawDisplayList[randomIndex]);
drawDisplayList.RemoveAt(randomIndex);
} }
} }
@ -120,15 +110,21 @@ public class Deck : MonoBehaviour
public void UseThisCard(GameObject card) public void UseThisCard(GameObject card)
{ {
GameObject tempDiscardDisplay = Instantiate(cardDisplayTemplate.gameObject, transform.Find("DiscardListContent/Viewport/Content")); if (!discardHoldingListContent.transform.parent.parent.gameObject.activeSelf)
tempDiscardDisplay.SetActive(true); {
tempDiscardDisplay.transform.Find("Card").gameObject.GetComponent<CardDisplay>().SetCardData(card.transform.Find("Card").GetComponent<CardDisplay>().cardData); card.transform.SetParent(discardListContent.transform);
tempDiscardDisplay.transform.Find("Button").gameObject.GetComponent<Image>().sprite = card.transform.Find("Card").GetComponent<CardDisplay>().cardData.artwork; }
discardDisplayList.Add(tempDiscardDisplay); else
//discardList.Add(card.transform.Find("Card").gameObject.gameObject.GetComponent<CardDisplay>().cardData); {
//handDisplayList.Find(card); if (card.transform.parent == discardHoldingListContent.transform)
Destroy(card); {
cardInHandAmount--; card.transform.SetParent(handListContent.transform);
}
else if (handListContent.transform.childCount > maxCardRemainLimit)
{
card.transform.SetParent(discardHoldingListContent.transform);
}
}
} }
// When unit dead // When unit dead
@ -139,60 +135,36 @@ public class Deck : MonoBehaviour
public void Shuffle() public void Shuffle()
{ {
// Put all cards in drawList into discardList while (drawListContent.transform.childCount != 0)
List<CardData> tempCardDataList = new List<CardData>();
for (int i = 0; i < drawDisplayList.Count; i++)
{ {
tempCardDataList.Add(drawDisplayList[i].transform.Find("Card").GetComponent<CardDisplay>().cardData); drawListContent.transform.GetChild(drawListContent.transform.childCount - 1).SetParent(discardListContent.transform);
Destroy(drawDisplayList[i]);
} }
drawDisplayList.Clear();
//drawList.Clear();
for (int i = 0; i < tempCardDataList.Count; i++) while (discardListContent.transform.childCount != 0)
{ {
GameObject tempCardDisplay = Instantiate(cardDisplayTemplate.gameObject,transform.Find("DrawListContent/Viewport/Content")); int index = Random.Range(0, discardListContent.transform.childCount);
tempCardDisplay.transform.Find("Card").gameObject.GetComponent<CardDisplay>().SetCardData(tempCardDataList[i]); discardListContent.transform.GetChild(index).transform.SetParent(drawListContent.transform);
tempCardDisplay.transform.Find("Button").gameObject.GetComponent<Image>().sprite = tempCardDataList[i].artwork;
tempCardDisplay.SetActive(true);
drawDisplayList.Add(tempCardDisplay);
}
tempCardDataList.Clear();
while (discardDisplayList.Count != 0)
{
int index = Random.Range(0, discardDisplayList.Count);
GameObject tempCardDisplay = Instantiate(cardDisplayTemplate.gameObject, transform.Find("DrawListContent/Viewport/Content"));
CardData tempCardData = discardDisplayList[index].transform.Find("Card").GetComponent<CardDisplay>().cardData;
tempCardDisplay.transform.Find("Card").gameObject.GetComponent<CardDisplay>().SetCardData(tempCardData);
tempCardDisplay.transform.Find("Button").gameObject.GetComponent<Image>().sprite = tempCardData.artwork;
tempCardDisplay.SetActive(true);
drawDisplayList.Add(tempCardDisplay);
Destroy(discardDisplayList[index]);
discardDisplayList.RemoveAt(index);
}; };
Debug.LogError(discardDisplayList.Count);
discardDisplayList.Clear();
} }
public void ActivateDisplayDrawList() public void ActivateDisplayDrawList()
{ {
drawListContent.SetActive(true); drawListContent.transform.parent.parent.gameObject.SetActive(true);
} }
public void DeactivateDisplayDrawList() public void DeactivateDisplayDrawList()
{ {
drawListContent.SetActive(false); drawListContent.transform.parent.parent.gameObject.SetActive(false);
} }
public void ActivateDisplayDiscardList() public void ActivateDisplayDiscardList()
{ {
discardListContent.SetActive(true); discardListContent.transform.parent.parent.gameObject.SetActive(true);
} }
public void DeactivateDisplayDiscardList() public void DeactivateDisplayDiscardList()
{ {
discardListContent.SetActive(false); discardListContent.transform.parent.parent.gameObject.SetActive(false);
} }
private void ActivateCardInHandLimitWarning() private void ActivateCardInHandLimitWarning()
@ -208,9 +180,27 @@ public class Deck : MonoBehaviour
public void EndRound() public void EndRound()
{ {
if (cardInHandAmount > maxCardRemainLimit) if (handListContent.transform.childCount > maxCardRemainLimit)
{ {
ActivateDiscardWarning();
}
}
private void ActivateDiscardWarning()
{
discardHoldingListContent.transform.parent.parent.gameObject.SetActive(true);
discardWarningDisplayText.text = string.Format("Choose {0} Card(s) to Discard", handListContent.transform.childCount - maxCardRemainLimit);
}
public void DiscardHoldingListCards()
{
while (discardHoldingListContent.transform.childCount != 0)
{
discardHoldingListContent.transform.GetChild(discardHoldingListContent.transform.childCount - 1).SetParent(discardListContent.transform);
}
if (handListContent.transform.childCount <= maxCardRemainLimit)
{
discardHoldingListContent.transform.parent.parent.gameObject.SetActive(false);
} }
} }
} }