CheckCardPanel.cs 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using System;
  6. using UnityEngine.EventSystems;
  7. using UnityEngine.Events;
  8. using DG.Tweening;
  9. using TMPro;
  10. public class CheckCardPanel : MonoBehaviour
  11. {
  12. [Header("Message Text")]
  13. public TextMeshProUGUI MessageText;
  14. [Header("ScrollRect")]
  15. public ScrollRect scrollRect;
  16. [Header("Background")]
  17. public GameObject BackGround;
  18. [Header("Parent except background")]
  19. public GameObject Parent;
  20. public List<HandCard> handCards
  21. {
  22. get
  23. {
  24. List<HandCard> handCards = new List<HandCard>();
  25. if (GManager.instance.turnStateMachine.DoneStartGame)
  26. {
  27. for (int i = 0; i < scrollRect.content.childCount; i++)
  28. {
  29. if (scrollRect.content.GetChild(i) != null)
  30. {
  31. if (scrollRect.content.GetChild(i).gameObject != null)
  32. {
  33. if (scrollRect.content.GetChild(i).GetComponent<HandCard>() != null)
  34. {
  35. handCards.Add(scrollRect.content.GetChild(i).GetComponent<HandCard>());
  36. }
  37. }
  38. }
  39. }
  40. }
  41. return handCards;
  42. }
  43. }
  44. #region Check trash cards
  45. public void OnClickCheckTrashButton(bool IsYou)
  46. {
  47. string Message = "";
  48. Player player = null;
  49. if (IsYou)
  50. {
  51. player = GManager.instance.You;
  52. Message = $"Your trash({player.TrashCards.Count}card{Utils.PluralFormSuffix(player.TrashCards.Count)})";
  53. }
  54. else
  55. {
  56. player = GManager.instance.Opponent;
  57. Message = $"The opponent's trash({player.TrashCards.Count}card{Utils.PluralFormSuffix(player.TrashCards.Count)})";
  58. }
  59. OpenSelectCardPanel(Message, player.TrashCards, true, null, SelectCardEffect.Root.Trash, IsYou);
  60. }
  61. #endregion
  62. #region Check security cards
  63. public void OnClickCheckSideButton(bool IsYou)
  64. {
  65. string Message = "";
  66. Player player = null;
  67. if (IsYou)
  68. {
  69. player = GManager.instance.You;
  70. Message = $"Your security({player.SecurityCards.Count}card{Utils.PluralFormSuffix(player.SecurityCards.Count)})";
  71. }
  72. else
  73. {
  74. player = GManager.instance.Opponent;
  75. Message = $"The opponent's security({player.SecurityCards.Count}card{Utils.PluralFormSuffix(player.SecurityCards.Count)})";
  76. }
  77. OpenSelectCardPanel(Message, player.SecurityCards, false, null, SelectCardEffect.Root.Security, IsYou);
  78. }
  79. #endregion
  80. public void OpenSelectCardPanel(string Message, List<CardSource> RootCardSources, bool CanLookReverseCard, Func<UnityAction<HandCard>> OnClickAction, SelectCardEffect.Root root, bool IsYou)
  81. {
  82. #region Initialization
  83. this.gameObject.SetActive(true);
  84. BackGround.SetActive(true);
  85. Parent.SetActive(false);
  86. MessageText.text = Message;
  87. #endregion
  88. StartCoroutine(OpenSelectCardPanelCoroutine(RootCardSources, CanLookReverseCard, OnClickAction, root, IsYou));
  89. }
  90. IEnumerator OpenSelectCardPanelAnimation(SelectCardEffect.Root root, bool IsYou)
  91. {
  92. bool end = false;
  93. var sequence = DOTween.Sequence();
  94. float time = 0.4f;
  95. this.transform.localScale = new Vector3(0.1f, 0.1f, 1f);
  96. if (root == SelectCardEffect.Root.Security)
  97. {
  98. if (IsYou)
  99. {
  100. this.transform.localPosition = new Vector3(-580f, -110f, 0f);
  101. }
  102. else
  103. {
  104. this.transform.localPosition = new Vector3(-580f, 165f, 0f);
  105. }
  106. }
  107. else if (root == SelectCardEffect.Root.Trash || root == SelectCardEffect.Root.DigivolutionCards)
  108. {
  109. if (IsYou)
  110. {
  111. this.transform.localPosition = new Vector3(-580f, -280f, 0f);
  112. }
  113. else
  114. {
  115. this.transform.localPosition = new Vector3(-580f, 340f, 0f);
  116. }
  117. }
  118. else
  119. {
  120. this.transform.localPosition = new Vector3(0f, 0f, 0f);
  121. }
  122. sequence
  123. .Append(this.transform.DOLocalMove(new Vector3(0f, 0f, 0f), time))
  124. .Join(this.transform.DOScale(new Vector3(1f, 1f, 1f), time))
  125. .AppendCallback(() => { end = true; });
  126. sequence.Play();
  127. yield return new WaitWhile(() => !end);
  128. end = false;
  129. }
  130. IEnumerator OpenSelectCardPanelCoroutine(List<CardSource> RootCardSources, bool CanLookReverseCard, Func<UnityAction<HandCard>> OnClickAction, SelectCardEffect.Root root1, bool IsYou)
  131. {
  132. yield return StartCoroutine(OpenSelectCardPanelAnimation(root1, IsYou));
  133. List<CardSource> root = new List<CardSource>();
  134. foreach (CardSource cardSource in RootCardSources)
  135. {
  136. root.Add(cardSource);
  137. }
  138. yield return new WaitForSeconds(Time.deltaTime);
  139. #region Initialize card list
  140. if (scrollRect.content.childCount > 0)
  141. {
  142. for (int i = 0; i < scrollRect.content.childCount; i++)
  143. {
  144. if (scrollRect.content.GetChild(i) != null)
  145. {
  146. if (scrollRect.content.GetChild(i).gameObject != null)
  147. {
  148. Destroy(scrollRect.content.GetChild(i).gameObject);
  149. }
  150. }
  151. }
  152. yield return new WaitWhile(() => scrollRect.content.childCount > 0);
  153. }
  154. #endregion
  155. #region card generation
  156. foreach (CardSource cardSource in root)
  157. {
  158. HandCard handCard = Instantiate(GManager.instance.handCardPrefab, scrollRect.content);
  159. handCard.gameObject.name = $"checkCardPanel_{cardSource.Owner.PlayerName}";
  160. handCard.GetComponent<Draggable_HandCard>().startScale = new Vector3(2.7f, 2.7f, 1);
  161. handCard.GetComponent<Draggable_HandCard>().DefaultY = -292;
  162. EventTrigger eventTrigger = handCard.CardImage.GetComponent<EventTrigger>();
  163. eventTrigger.triggers.Clear();
  164. EventTrigger.Entry entry = new EventTrigger.Entry();
  165. entry.eventID = EventTriggerType.PointerClick;
  166. entry.callback.AddListener((x) => { PointerClick(cardSource); });
  167. #region Processing on click
  168. void PointerClick(CardSource cardSource1)
  169. {
  170. #region right click
  171. if (Input.GetMouseButtonUp(1))
  172. {
  173. if (cardSource1 != null)
  174. {
  175. //If you can't see the face down card
  176. if (!CanLookReverseCard)
  177. {
  178. if (!cardSource1.IsFlipped)
  179. {
  180. GManager.instance.cardDetail.OpenCardDetail(cardSource1, true);
  181. if (GManager.instance != null)
  182. {
  183. GManager.instance.PlayDecisionSE();
  184. }
  185. }
  186. }
  187. //If you can see the card face down
  188. else
  189. {
  190. GManager.instance.cardDetail.OpenCardDetail(cardSource1, true);
  191. GManager.instance.PlayDecisionSE();
  192. }
  193. }
  194. }
  195. #endregion
  196. #region left click
  197. else if (Input.GetMouseButtonUp(0))
  198. {
  199. if (OnClickAction != null)
  200. {
  201. OnClickAction()?.Invoke(handCard);
  202. }
  203. }
  204. #endregion
  205. }
  206. #endregion
  207. eventTrigger.triggers.Add(entry);
  208. handCard.SetUpHandCard(cardSource, showCardImage: false);
  209. if (!cardSource.IsFlipped)
  210. {
  211. handCard.SetUpHandCardImage();
  212. }
  213. else
  214. {
  215. handCard.SetUpReverseCard();
  216. }
  217. }
  218. yield return new WaitWhile(() => scrollRect.content.childCount < root.Count);
  219. yield return new WaitForSeconds(Time.deltaTime * 2);
  220. for (int i = 0; i < scrollRect.content.childCount; i++)
  221. {
  222. scrollRect.content.GetChild(i).localScale = new Vector3(2.7f, 2.7f, 1);
  223. }
  224. #endregion
  225. Parent.SetActive(true);
  226. scrollRect.horizontalNormalizedPosition = 0;
  227. yield return new WaitForSeconds(Time.deltaTime * 0.2f);
  228. //GManager.instance.turnStateMachine.OpenTrashCardPanelAction?.Invoke();
  229. }
  230. bool CanClose = true;
  231. public void CloseSelectCardPanel()
  232. {
  233. if (!CanClose)
  234. {
  235. return;
  236. }
  237. CanClose = false;
  238. ContinuousController.instance.StartCoroutine(CloseSelectCardPanelCoroutine());
  239. }
  240. bool first = false;
  241. public IEnumerator CloseSelectCardPanelCoroutine()
  242. {
  243. if (first)
  244. {
  245. if (Opening.instance != null)
  246. {
  247. Opening.instance.PlayCancelSE();
  248. }
  249. }
  250. first = true;
  251. this.gameObject.SetActive(false);
  252. if (scrollRect.content.childCount > 0)
  253. {
  254. for (int i = 0; i < scrollRect.content.childCount; i++)
  255. {
  256. if (scrollRect.content.GetChild(i) != null)
  257. {
  258. if (scrollRect.content.GetChild(i).gameObject != null)
  259. {
  260. Destroy(scrollRect.content.GetChild(i).gameObject);
  261. }
  262. }
  263. }
  264. yield return new WaitWhile(() => scrollRect.content.childCount > 0);
  265. }
  266. CanClose = true;
  267. }
  268. }