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