CheckCardPanel.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  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. using Photon.Pun;
  11. public class CheckCardPanel : MonoBehaviour
  12. {
  13. [Header("Message Text")]
  14. public TextMeshProUGUI MessageText;
  15. [Header("ScrollRect")]
  16. public ScrollRect scrollRect;
  17. [Header("Background")]
  18. public GameObject BackGround;
  19. [Header("Parent except background")]
  20. public GameObject Parent;
  21. public List<HandCard> handCards
  22. {
  23. get
  24. {
  25. List<HandCard> handCards = new List<HandCard>();
  26. if (GManager.instance.turnStateMachine.DoneStartGame)
  27. {
  28. for (int i = 0; i < scrollRect.content.childCount; i++)
  29. {
  30. if (scrollRect.content.GetChild(i) != null)
  31. {
  32. if (scrollRect.content.GetChild(i).gameObject != null)
  33. {
  34. if (scrollRect.content.GetChild(i).GetComponent<HandCard>() != null)
  35. {
  36. handCards.Add(scrollRect.content.GetChild(i).GetComponent<HandCard>());
  37. }
  38. }
  39. }
  40. }
  41. }
  42. return handCards;
  43. }
  44. }
  45. #region Check trash cards
  46. public void OnClickCheckTrashButton(bool IsYou)
  47. {
  48. string Message = "";
  49. Player player = null;
  50. if (IsYou)
  51. {
  52. player = GManager.instance.You;
  53. Message = $"Your trash({player.TrashCards.Count}card{Utils.PluralFormSuffix(player.TrashCards.Count)})";
  54. }
  55. else
  56. {
  57. player = GManager.instance.Opponent;
  58. Message = $"The opponent's trash({player.TrashCards.Count}card{Utils.PluralFormSuffix(player.TrashCards.Count)})";
  59. }
  60. OpenSelectCardPanel(Message, player.TrashCards, true, null, SelectCardEffect.Root.Trash, IsYou);
  61. }
  62. #endregion
  63. #region Check security cards
  64. public void OnClickCheckSideButton(bool IsYou)
  65. {
  66. string Message = "";
  67. Player player = null;
  68. if (IsYou)
  69. {
  70. player = GManager.instance.You;
  71. Message = $"Your security({player.SecurityCards.Count}card{Utils.PluralFormSuffix(player.SecurityCards.Count)})";
  72. }
  73. else
  74. {
  75. player = GManager.instance.Opponent;
  76. Message = $"The opponent's security({player.SecurityCards.Count}card{Utils.PluralFormSuffix(player.SecurityCards.Count)})";
  77. }
  78. OpenSelectCardPanel(Message, player.SecurityCards, false, null, SelectCardEffect.Root.Security, IsYou);
  79. }
  80. #endregion
  81. public void OpenSelectCardPanel(string Message, List<CardSource> RootCardSources, bool CanLookReverseCard, Func<UnityAction<HandCard>> OnClickAction, SelectCardEffect.Root root, bool IsYou)
  82. {
  83. #region Initialization
  84. this.gameObject.SetActive(true);
  85. BackGround.SetActive(true);
  86. Parent.SetActive(false);
  87. MessageText.text = Message;
  88. #endregion
  89. StartCoroutine(OpenSelectCardPanelCoroutine(RootCardSources, CanLookReverseCard, OnClickAction, root, IsYou));
  90. }
  91. IEnumerator OpenSelectCardPanelAnimation(SelectCardEffect.Root root, bool IsYou)
  92. {
  93. bool end = false;
  94. var sequence = DOTween.Sequence();
  95. float time = 0.4f;
  96. this.transform.localScale = new Vector3(0.1f, 0.1f, 1f);
  97. if (root == SelectCardEffect.Root.Security)
  98. {
  99. if (IsYou)
  100. {
  101. this.transform.localPosition = new Vector3(-580f, -110f, 0f);
  102. }
  103. else
  104. {
  105. this.transform.localPosition = new Vector3(-580f, 165f, 0f);
  106. }
  107. }
  108. else if (root == SelectCardEffect.Root.Trash || root == SelectCardEffect.Root.DigivolutionCards)
  109. {
  110. if (IsYou)
  111. {
  112. this.transform.localPosition = new Vector3(-580f, -280f, 0f);
  113. }
  114. else
  115. {
  116. this.transform.localPosition = new Vector3(-580f, 340f, 0f);
  117. }
  118. }
  119. else
  120. {
  121. this.transform.localPosition = new Vector3(0f, 0f, 0f);
  122. }
  123. sequence
  124. .Append(this.transform.DOLocalMove(new Vector3(0f, 0f, 0f), time))
  125. .Join(this.transform.DOScale(new Vector3(1f, 1f, 1f), time))
  126. .AppendCallback(() => { end = true; });
  127. sequence.Play();
  128. yield return new WaitWhile(() => !end);
  129. end = false;
  130. }
  131. IEnumerator OpenSelectCardPanelCoroutine(List<CardSource> RootCardSources, bool CanLookReverseCard, Func<UnityAction<HandCard>> OnClickAction, SelectCardEffect.Root root1, bool IsYou)
  132. {
  133. yield return StartCoroutine(OpenSelectCardPanelAnimation(root1, IsYou));
  134. List<CardSource> root = new List<CardSource>();
  135. foreach (CardSource cardSource in RootCardSources)
  136. {
  137. root.Add(cardSource);
  138. }
  139. yield return new WaitForSeconds(Time.deltaTime);
  140. #region Initialize card list
  141. if (scrollRect.content.childCount > 0)
  142. {
  143. for (int i = 0; i < scrollRect.content.childCount; i++)
  144. {
  145. if (scrollRect.content.GetChild(i) != null)
  146. {
  147. if (scrollRect.content.GetChild(i).gameObject != null)
  148. {
  149. Destroy(scrollRect.content.GetChild(i).gameObject);
  150. }
  151. }
  152. }
  153. yield return new WaitWhile(() => scrollRect.content.childCount > 0);
  154. }
  155. #endregion
  156. #region card generation
  157. foreach (CardSource cardSource in root)
  158. {
  159. HandCard handCard = Instantiate(GManager.instance.handCardPrefab, scrollRect.content);
  160. handCard.gameObject.name = $"checkCardPanel_{cardSource.Owner.PlayerName}";
  161. handCard.GetComponent<Draggable_HandCard>().startScale = new Vector3(2.7f, 2.7f, 1);
  162. handCard.GetComponent<Draggable_HandCard>().DefaultY = -292;
  163. EventTrigger eventTrigger = handCard.CardImage.GetComponent<EventTrigger>();
  164. eventTrigger.triggers.Clear();
  165. EventTrigger.Entry entry = new EventTrigger.Entry();
  166. entry.eventID = EventTriggerType.PointerClick;
  167. entry.callback.AddListener((x) => { PointerClick(cardSource); });
  168. #region Processing on click
  169. void PointerClick(CardSource cardSource1)
  170. {
  171. #region right click
  172. if (Input.GetMouseButtonUp(1))
  173. {
  174. if (cardSource1 != null)
  175. {
  176. //If you can't see the face down card
  177. if (!CanLookReverseCard)
  178. {
  179. if (!cardSource1.IsFlipped)
  180. {
  181. GManager.instance.cardDetail.OpenCardDetail(cardSource1, true);
  182. if (GManager.instance != null)
  183. {
  184. GManager.instance.PlayDecisionSE();
  185. }
  186. }
  187. }
  188. //If you can see the card face down
  189. else
  190. {
  191. GManager.instance.cardDetail.OpenCardDetail(cardSource1, true);
  192. GManager.instance.PlayDecisionSE();
  193. }
  194. }
  195. }
  196. #endregion
  197. #region left click
  198. else if (Input.GetMouseButtonUp(0))
  199. {
  200. handCard.OnClickAction?.Invoke(handCard);
  201. }
  202. #endregion
  203. }
  204. #endregion
  205. eventTrigger.triggers.Add(entry);
  206. handCard.SetUpHandCard(cardSource, showCardImage: false);
  207. if (!cardSource.IsFlipped)
  208. {
  209. handCard.SetUpHandCardImage();
  210. }
  211. else
  212. {
  213. handCard.SetUpReverseCard();
  214. }
  215. }
  216. yield return new WaitWhile(() => scrollRect.content.childCount < root.Count);
  217. yield return new WaitForSeconds(Time.deltaTime * 2);
  218. for (int i = 0; i < scrollRect.content.childCount; i++)
  219. {
  220. scrollRect.content.GetChild(i).localScale = new Vector3(2.7f, 2.7f, 1);
  221. }
  222. #endregion
  223. Parent.SetActive(true);
  224. scrollRect.horizontalNormalizedPosition = 0;
  225. yield return new WaitForSeconds(Time.deltaTime * 0.2f);
  226. foreach(HandCard handCard in handCards)
  227. {
  228. if (handCard.cardSource.CanDeclareSkill)
  229. {
  230. handCard.SetOrangeOutline();
  231. handCard.AddClickTarget(OnClickHandCard);
  232. }
  233. }
  234. }
  235. public void OnClickHandCard(HandCard handCard)
  236. {
  237. if (handCard != null)
  238. {
  239. if (handCard.cardSource != null)
  240. {
  241. List<CardCommand> FieldUnitCommands = new List<CardCommand>();
  242. #region Card Effects
  243. List<ICardEffect> cardEffects = new List<ICardEffect>();
  244. List<ICardEffect> cardEffects1 = new List<ICardEffect>();
  245. foreach (ICardEffect cardEffect in handCard.cardSource.EffectList(EffectTiming.OnDeclaration))
  246. {
  247. cardEffects1.Add(cardEffect);
  248. cardEffects.Add(cardEffect);
  249. }
  250. cardEffects.Reverse();
  251. foreach (ICardEffect cardEffect in cardEffects)
  252. {
  253. if (cardEffect is ActivateICardEffect)
  254. {
  255. CardCommand SkillCommand = new CardCommand(cardEffect.EffectName, OnClick_SetUseSkillUnit_RPC, cardEffect.CanUse(null), DataBase.CommandColor_Skill);
  256. FieldUnitCommands.Add(SkillCommand);
  257. void OnClick_SetUseSkillUnit_RPC()
  258. {
  259. #region Reset the card on the field
  260. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players)
  261. {
  262. foreach (FieldPermanentCard fieldPermanentCard in player.FieldPermanentObjects)
  263. {
  264. fieldPermanentCard.RemoveSelectEffect();
  265. fieldPermanentCard.RemoveClickTarget();
  266. fieldPermanentCard.RemoveDragTarget();
  267. fieldPermanentCard.Outline_Select.gameObject.SetActive(false);
  268. fieldPermanentCard.CloseCommandPanel();
  269. }
  270. }
  271. #endregion
  272. #region Reset the card in hand
  273. foreach (HandCard handCard1 in GManager.instance.turnStateMachine.gameContext.TurnPlayer.HandCardObjects)
  274. {
  275. handCard.Outline_Select.gameObject.SetActive(false);
  276. handCard1.RemoveSelectEffect();
  277. handCard1.RemoveClickTarget();
  278. handCard1.RemoveDragTarget();
  279. }
  280. #endregion
  281. #region Reset the card in trash
  282. foreach (HandCard trashCard in handCards)
  283. {
  284. trashCard.Outline_Select.gameObject.SetActive(false);
  285. trashCard.RemoveSelectEffect();
  286. trashCard.RemoveClickTarget();
  287. trashCard.RemoveDragTarget();
  288. }
  289. #endregion
  290. handCard.GetComponent<Draggable_HandCard>().CanPointerEnterExitAction = true;
  291. GManager.instance.turnStateMachine.photonView.RPC("SetActCardSkill", RpcTarget.All, handCard.cardSource.CardIndex, cardEffects1.IndexOf(cardEffect));
  292. CloseSelectCardPanel();
  293. }
  294. }
  295. }
  296. #endregion
  297. handCard.handCardCommandPanel.SetUpCommandPanel(FieldUnitCommands, null, handCard);
  298. handCard.AddClickTarget((_fieldUnitCard) => StartCoroutine(GManager.instance.turnStateMachine.SetMainPhase()));
  299. handCard.Outline_Select.gameObject.SetActive(true);
  300. handCard.SetOrangeOutline();
  301. }
  302. }
  303. }
  304. bool CanClose = true;
  305. public void CloseSelectCardPanel()
  306. {
  307. if (!CanClose)
  308. return;
  309. CanClose = false;
  310. ContinuousController.instance.StartCoroutine(CloseSelectCardPanelCoroutine());
  311. }
  312. bool first = false;
  313. public IEnumerator CloseSelectCardPanelCoroutine()
  314. {
  315. if (first)
  316. {
  317. if (Opening.instance != null)
  318. {
  319. Opening.instance.PlayCancelSE();
  320. }
  321. }
  322. first = true;
  323. this.gameObject.SetActive(false);
  324. if (scrollRect.content.childCount > 0)
  325. {
  326. for (int i = 0; i < scrollRect.content.childCount; i++)
  327. {
  328. if (scrollRect.content.GetChild(i) != null)
  329. {
  330. if (scrollRect.content.GetChild(i).gameObject != null)
  331. {
  332. Destroy(scrollRect.content.GetChild(i).gameObject);
  333. }
  334. }
  335. }
  336. yield return new WaitWhile(() => scrollRect.content.childCount > 0);
  337. }
  338. CanClose = true;
  339. }
  340. }