| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428 |
- 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;
- using Photon.Pun;
- 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))
- {
- handCard.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);
- if (GManager.instance.turnStateMachine.gameContext.TurnPlayer.isYou)
- {
- foreach (HandCard handCard in handCards)
- {
- if (handCard.cardSource.Owner != GManager.instance.turnStateMachine.gameContext.TurnPlayer)
- continue;
- if (handCard.cardSource.CanDeclareSkill)
- {
- handCard.SetOrangeOutline();
- handCard.AddClickTarget(OnClickHandCard);
- }
- }
- }
- }
- public void OnClickHandCard(HandCard handCard)
- {
- if (handCard != null)
- {
- if (handCard.cardSource != null)
- {
- List<CardCommand> FieldUnitCommands = new List<CardCommand>();
- #region Card Effects
- List<ICardEffect> cardEffects = new List<ICardEffect>();
- List<ICardEffect> cardEffects1 = new List<ICardEffect>();
- foreach (ICardEffect cardEffect in handCard.cardSource.EffectList(EffectTiming.OnDeclaration))
- {
- cardEffects1.Add(cardEffect);
- cardEffects.Add(cardEffect);
- }
- cardEffects.Reverse();
- foreach (ICardEffect cardEffect in cardEffects)
- {
- if (cardEffect is ActivateICardEffect)
- {
- CardCommand SkillCommand = new CardCommand(cardEffect.EffectName, OnClick_SetUseSkillUnit_RPC, cardEffect.CanUse(null), DataBase.CommandColor_Skill);
- FieldUnitCommands.Add(SkillCommand);
- void OnClick_SetUseSkillUnit_RPC()
- {
- #region Reset the card on the field
- foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players)
- {
- foreach (FieldPermanentCard fieldPermanentCard in player.FieldPermanentObjects)
- {
- fieldPermanentCard.RemoveSelectEffect();
- fieldPermanentCard.RemoveClickTarget();
- fieldPermanentCard.RemoveDragTarget();
- fieldPermanentCard.Outline_Select.gameObject.SetActive(false);
- fieldPermanentCard.CloseCommandPanel();
- }
- }
- #endregion
- #region Reset the card in hand
- foreach (HandCard handCard1 in GManager.instance.turnStateMachine.gameContext.TurnPlayer.HandCardObjects)
- {
- handCard.Outline_Select.gameObject.SetActive(false);
- handCard1.RemoveSelectEffect();
- handCard1.RemoveClickTarget();
- handCard1.RemoveDragTarget();
- }
- #endregion
- #region Reset the card in trash
- foreach (HandCard trashCard in handCards)
- {
- trashCard.Outline_Select.gameObject.SetActive(false);
- trashCard.RemoveSelectEffect();
- trashCard.RemoveClickTarget();
- trashCard.RemoveDragTarget();
- }
- #endregion
- handCard.GetComponent<Draggable_HandCard>().CanPointerEnterExitAction = true;
- GManager.instance.turnStateMachine.photonView.RPC("SetActCardSkill", RpcTarget.All, handCard.cardSource.CardIndex, cardEffects1.IndexOf(cardEffect));
- CloseSelectCardPanel();
- }
- }
- }
- #endregion
- handCard.handCardCommandPanel.SetUpCommandPanel(FieldUnitCommands, null, handCard);
- handCard.AddClickTarget((_fieldUnitCard) => StartCoroutine(GManager.instance.turnStateMachine.SetMainPhase()));
- handCard.Outline_Select.gameObject.SetActive(true);
- handCard.SetOrangeOutline();
- }
- }
- }
- 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;
- }
- }
|