| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using System;
- using UnityEngine.EventSystems;
- using UnityEngine.Events;
- using DG.Tweening;
- using TMPro;
- public class CheckCardPanel : MonoBehaviour
- {
- [Header("Message Text")]
- public TextMeshProUGUI MessageText;
- [Header("ScrollRect")]
- public ScrollRect scrollRect;
- [Header("Background")]
- public GameObject BackGround;
- [Header("Parent except background")]
- public GameObject Parent;
- public List<HandCard> handCards
- {
- get
- {
- List<HandCard> handCards = new List<HandCard>();
- if (GManager.instance.turnStateMachine.DoneStartGame)
- {
- for (int i = 0; i < scrollRect.content.childCount; i++)
- {
- if (scrollRect.content.GetChild(i) != null)
- {
- if (scrollRect.content.GetChild(i).gameObject != null)
- {
- if (scrollRect.content.GetChild(i).GetComponent<HandCard>() != null)
- {
- handCards.Add(scrollRect.content.GetChild(i).GetComponent<HandCard>());
- }
- }
- }
- }
- }
- return handCards;
- }
- }
- #region Check trash cards
- public void OnClickCheckTrashButton(bool IsYou)
- {
- string Message = "";
- Player player = null;
- if (IsYou)
- {
- player = GManager.instance.You;
- Message = $"Your trash({player.TrashCards.Count}card{Utils.PluralFormSuffix(player.TrashCards.Count)})";
- }
- else
- {
- player = GManager.instance.Opponent;
- Message = $"The opponent's trash({player.TrashCards.Count}card{Utils.PluralFormSuffix(player.TrashCards.Count)})";
- }
- OpenSelectCardPanel(Message, player.TrashCards, true, null, SelectCardEffect.Root.Trash, IsYou);
- }
- #endregion
- #region Check security cards
- public void OnClickCheckSideButton(bool IsYou)
- {
- string Message = "";
- Player player = null;
- if (IsYou)
- {
- player = GManager.instance.You;
- Message = $"Your security({player.SecurityCards.Count}card{Utils.PluralFormSuffix(player.SecurityCards.Count)})";
- }
- else
- {
- player = GManager.instance.Opponent;
- Message = $"The opponent's security({player.SecurityCards.Count}card{Utils.PluralFormSuffix(player.SecurityCards.Count)})";
- }
- OpenSelectCardPanel(Message, player.SecurityCards, false, null, SelectCardEffect.Root.Security, IsYou);
- }
- #endregion
- public void OpenSelectCardPanel(string Message, List<CardSource> RootCardSources, bool CanLookReverseCard, Func<UnityAction<HandCard>> OnClickAction, SelectCardEffect.Root root, bool IsYou)
- {
- #region Initialization
- this.gameObject.SetActive(true);
- BackGround.SetActive(true);
- Parent.SetActive(false);
- MessageText.text = Message;
- #endregion
- StartCoroutine(OpenSelectCardPanelCoroutine(RootCardSources, CanLookReverseCard, OnClickAction, root, IsYou));
- }
- IEnumerator OpenSelectCardPanelAnimation(SelectCardEffect.Root root, bool IsYou)
- {
- bool end = false;
- var sequence = DOTween.Sequence();
- float time = 0.4f;
- this.transform.localScale = new Vector3(0.1f, 0.1f, 1f);
- if (root == SelectCardEffect.Root.Security)
- {
- if (IsYou)
- {
- this.transform.localPosition = new Vector3(-580f, -110f, 0f);
- }
- else
- {
- this.transform.localPosition = new Vector3(-580f, 165f, 0f);
- }
- }
- else if (root == SelectCardEffect.Root.Trash || root == SelectCardEffect.Root.DigivolutionCards)
- {
- if (IsYou)
- {
- this.transform.localPosition = new Vector3(-580f, -280f, 0f);
- }
- else
- {
- this.transform.localPosition = new Vector3(-580f, 340f, 0f);
- }
- }
- else
- {
- this.transform.localPosition = new Vector3(0f, 0f, 0f);
- }
- sequence
- .Append(this.transform.DOLocalMove(new Vector3(0f, 0f, 0f), time))
- .Join(this.transform.DOScale(new Vector3(1f, 1f, 1f), time))
- .AppendCallback(() => { end = true; });
- sequence.Play();
- yield return new WaitWhile(() => !end);
- end = false;
- }
- IEnumerator OpenSelectCardPanelCoroutine(List<CardSource> RootCardSources, bool CanLookReverseCard, Func<UnityAction<HandCard>> OnClickAction, SelectCardEffect.Root root1, bool IsYou)
- {
- yield return StartCoroutine(OpenSelectCardPanelAnimation(root1, IsYou));
- List<CardSource> root = new List<CardSource>();
- foreach (CardSource cardSource in RootCardSources)
- {
- root.Add(cardSource);
- }
- yield return new WaitForSeconds(Time.deltaTime);
- #region Initialize card list
- if (scrollRect.content.childCount > 0)
- {
- for (int i = 0; i < scrollRect.content.childCount; i++)
- {
- if (scrollRect.content.GetChild(i) != null)
- {
- if (scrollRect.content.GetChild(i).gameObject != null)
- {
- Destroy(scrollRect.content.GetChild(i).gameObject);
- }
- }
- }
- yield return new WaitWhile(() => scrollRect.content.childCount > 0);
- }
- #endregion
- #region card generation
- foreach (CardSource cardSource in root)
- {
- HandCard handCard = Instantiate(GManager.instance.handCardPrefab, scrollRect.content);
- handCard.gameObject.name = $"checkCardPanel_{cardSource.Owner.PlayerName}";
- handCard.GetComponent<Draggable_HandCard>().startScale = new Vector3(2.7f, 2.7f, 1);
- handCard.GetComponent<Draggable_HandCard>().DefaultY = -292;
- EventTrigger eventTrigger = handCard.CardImage.GetComponent<EventTrigger>();
- eventTrigger.triggers.Clear();
- EventTrigger.Entry entry = new EventTrigger.Entry();
- entry.eventID = EventTriggerType.PointerClick;
- entry.callback.AddListener((x) => { PointerClick(cardSource); });
- #region Processing on click
- void PointerClick(CardSource cardSource1)
- {
- #region right click
- if (Input.GetMouseButtonUp(1))
- {
- if (cardSource1 != null)
- {
- //If you can't see the face down card
- if (!CanLookReverseCard)
- {
- if (!cardSource1.IsFlipped)
- {
- GManager.instance.cardDetail.OpenCardDetail(cardSource1, true);
- if (GManager.instance != null)
- {
- GManager.instance.PlayDecisionSE();
- }
- }
- }
- //If you can see the card face down
- else
- {
- GManager.instance.cardDetail.OpenCardDetail(cardSource1, true);
- GManager.instance.PlayDecisionSE();
- }
- }
- }
- #endregion
- #region left click
- else if (Input.GetMouseButtonUp(0))
- {
- if (OnClickAction != null)
- {
- OnClickAction()?.Invoke(handCard);
- }
- }
- #endregion
- }
- #endregion
- eventTrigger.triggers.Add(entry);
- handCard.SetUpHandCard(cardSource, showCardImage: false);
- if (!cardSource.IsFlipped)
- {
- handCard.SetUpHandCardImage();
- }
- else
- {
- handCard.SetUpReverseCard();
- }
- }
- yield return new WaitWhile(() => scrollRect.content.childCount < root.Count);
- yield return new WaitForSeconds(Time.deltaTime * 2);
- for (int i = 0; i < scrollRect.content.childCount; i++)
- {
- scrollRect.content.GetChild(i).localScale = new Vector3(2.7f, 2.7f, 1);
- }
- #endregion
- Parent.SetActive(true);
- scrollRect.horizontalNormalizedPosition = 0;
- yield return new WaitForSeconds(Time.deltaTime * 0.2f);
- //GManager.instance.turnStateMachine.OpenTrashCardPanelAction?.Invoke();
- }
- bool CanClose = true;
- public void CloseSelectCardPanel()
- {
- if (!CanClose)
- {
- return;
- }
- CanClose = false;
- ContinuousController.instance.StartCoroutine(CloseSelectCardPanelCoroutine());
- }
- bool first = false;
- public IEnumerator CloseSelectCardPanelCoroutine()
- {
- if (first)
- {
- if (Opening.instance != null)
- {
- Opening.instance.PlayCancelSE();
- }
- }
- first = true;
- this.gameObject.SetActive(false);
- if (scrollRect.content.childCount > 0)
- {
- for (int i = 0; i < scrollRect.content.childCount; i++)
- {
- if (scrollRect.content.GetChild(i) != null)
- {
- if (scrollRect.content.GetChild(i).gameObject != null)
- {
- Destroy(scrollRect.content.GetChild(i).gameObject);
- }
- }
- }
- yield return new WaitWhile(() => scrollRect.content.childCount > 0);
- }
- CanClose = true;
- }
- }
|