DeckListPanel.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using UnityEngine.Events;
  6. public class DeckListPanel : MonoBehaviour
  7. {
  8. private static readonly int OpenHash = Animator.StringToHash("Open");
  9. private static readonly int CloseHash = Animator.StringToHash("Close");
  10. public Animator anim;
  11. public CardPrefab_CreateDeck cardPrefab_CreateDeckPrefab;
  12. public DetailCard_DeckEditor detailCard;
  13. public ScrollRect DeckScroll;
  14. public Text DeckNameText;
  15. public Text DeckCountText;
  16. public GameObject DeckListPanelObject;
  17. public IEnumerator SetUpDeckListPanel(DeckData deckData, UnityAction<CEntity_Base> onClickAction, string CustomMessage)
  18. {
  19. detailCard.OffDetailCard();
  20. for (int i = 0; i < DeckScroll.content.childCount; i++)
  21. {
  22. Destroy(DeckScroll.content.GetChild(i).gameObject);
  23. }
  24. yield return new WaitWhile(() => DeckScroll.content.childCount > 0);
  25. #region デッキ名を表示
  26. DeckNameText.text = deckData.DeckName;
  27. if(!string.IsNullOrEmpty(CustomMessage))
  28. {
  29. DeckNameText.text = CustomMessage;
  30. }
  31. #endregion
  32. #region デッキのカードを取得
  33. List<CEntity_Base> DeckCards = new List<CEntity_Base>();
  34. foreach (CEntity_Base cEntity_Base in deckData.AllDeckCards())
  35. {
  36. DeckCards.Add(cEntity_Base);
  37. }
  38. #endregion
  39. #region デッキのカードを生成
  40. foreach (CEntity_Base cEntity_Base in DeckCards)
  41. {
  42. CardPrefab_CreateDeck _cardPrefab_CreateDeck = null;
  43. _cardPrefab_CreateDeck = Instantiate(cardPrefab_CreateDeckPrefab, DeckScroll.content);
  44. _cardPrefab_CreateDeck.OnEnterAction = (cardPrefab) => { OnDetailCard(cEntity_Base, Vector3.zero); };
  45. //_cardPrefab_CreateDeck.OnExitAction = (cardPrefab) => { OffDetailCard(); };
  46. SetUpDeckCard(_cardPrefab_CreateDeck, cEntity_Base);
  47. _cardPrefab_CreateDeck.HideDeckCardTab();
  48. if(onClickAction != null)
  49. {
  50. _cardPrefab_CreateDeck.OnClickAction = () => onClickAction(_cardPrefab_CreateDeck.cEntity_Base);
  51. }
  52. }
  53. #endregion
  54. SetDeckCountText(deckData);
  55. yield return new WaitWhile(() => DeckScroll.content.childCount < DeckCards.Count);
  56. this.gameObject.SetActive(true);
  57. yield return new WaitForSeconds(Time.deltaTime);
  58. DeckScroll.verticalNormalizedPosition = 1;
  59. yield return ContinuousController.instance.StartCoroutine(OpenCoroutine(deckData));
  60. }
  61. IEnumerator OpenCoroutine(DeckData deckData)
  62. {
  63. yield return new WaitWhile(() => DeckScroll.content.childCount < deckData.AllDeckCards().Count);
  64. yield return new WaitForSeconds(Time.deltaTime);
  65. Open();
  66. yield return new WaitWhile(() => DeckListPanelObject.transform.localScale.y < 0.9f);
  67. DeckScroll.verticalNormalizedPosition = 1;
  68. for (int i = 0; i < DeckScroll.content.childCount; i++)
  69. {
  70. DeckScroll.content.GetChild(i).GetComponent<CardPrefab_CreateDeck>().SetUpCardPrefab_CreateDeck(DeckScroll.content.GetChild(i).GetComponent<CardPrefab_CreateDeck>().cEntity_Base);
  71. DeckScroll.content.GetChild(i).GetComponent<CardPrefab_CreateDeck>().ShowCardImage();
  72. }
  73. }
  74. public void Open()
  75. {
  76. On();
  77. anim.SafeSetInt(OpenHash, 1);
  78. anim.SafeSetInt(CloseHash, 0);
  79. }
  80. public void Close()
  81. {
  82. //OffDetailCard();
  83. anim.SafeSetInt(OpenHash, 0);
  84. anim.SafeSetInt(CloseHash, 1);
  85. }
  86. public void On()
  87. {
  88. this.gameObject.SetActive(true);
  89. }
  90. public void Off()
  91. {
  92. this.gameObject.SetActive(false);
  93. //Close();
  94. }
  95. #region Card Detail View
  96. public void OffDetailCard()
  97. {
  98. //detailCard.GetComponent<DetailCard_DeckEditor>().OffDetailCard();
  99. }
  100. public void OnDetailCard(CEntity_Base cEntity_Base, Vector3 position)
  101. {
  102. detailCard.GetComponent<DetailCard_DeckEditor>().SetUpDetailCard(cEntity_Base);
  103. }
  104. #endregion
  105. public void SetUpDeckCard(CardPrefab_CreateDeck _cardPrefab_CreateDeck, CEntity_Base cEntity_Base)
  106. {
  107. foreach (ScrollRect _scroll in _cardPrefab_CreateDeck.scroll)
  108. {
  109. _scroll.content = DeckScroll.content;
  110. _scroll.viewport = DeckScroll.viewport;
  111. }
  112. _cardPrefab_CreateDeck.SetUpCardPrefab_CreateDeck(cEntity_Base);
  113. _cardPrefab_CreateDeck.ShowCardImage();
  114. _cardPrefab_CreateDeck.Parent.localScale = new Vector3(0.7f, 0.7f, 0.7f);
  115. }
  116. #region Display the number of cards in the deck text
  117. public void SetDeckCountText(DeckData deckData)
  118. {
  119. DeckCountText.text = $"{deckData.DeckCards().Count}+{deckData.DigitamaDeckCards().Count}/50+5";
  120. if (deckData.IsValidDeckData())
  121. {
  122. DeckCountText.color = new Color32(69, 255, 69, 255);
  123. }
  124. else
  125. {
  126. DeckCountText.color = new Color32(255, 64, 64, 255);
  127. }
  128. }
  129. #endregion
  130. }