DeckListPanel.cs 5.1 KB

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