DeckListPanel.cs 5.0 KB

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