| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688 |
- 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 SelectCardPanel : MonoBehaviour
- {
- [Header("Message Text")]
- public TextMeshProUGUI MessageText;
- [Header("ScrollRect")]
- public ScrollRect scrollRect;
- [Header("Do not select button")]
- public GameObject NoSelectButton;
- [Header("Select Decision button")]
- public GameObject EndSelectButton;
- [Header("BackGround")]
- public GameObject BackGround;
- [Header("Parents other than background")]
- public GameObject Parent;
- [Header("Return to card selection button")]
- public Button ReturnToSelectCardButton;
- [Header("Text of the button not to be selected")]
- public Text NotSelectButtonText;
- [Header("Text of the selection end button")]
- public Text EndSelectButtonText;
- public Text CountText;
- //Selected card list
- public List<CardSource> SelectedList { get; set; } = new List<CardSource>();
- public List<int> SelectedIndex { get; set; } = new List<int>();
- //Eligibility Criteria for Eligible Cards
- Func<CardSource, bool> _canTargetCondition = null;
- //Whether the unit can be selected with the current selection list status
- Func<List<CardSource>, CardSource, bool> _canTargetCondition_ByPreSelecetedList = null;
- //Conditions under which a selection can be terminated (see list of selection termination points)
- Func<List<CardSource>, bool> _canEndSelectCondition = null;
- //Maximum number of cards that can be selected
- int _maxCount = 0;
- //Whether it can be terminated with less than the maximum number of cards
- bool _canEndNotMax = false;
- //Whether you can choose not to choose
- Func<bool> _canNoSelect = () => false;
- //provisional selection card list
- List<HandCard> _preSelectedHandCardList = new List<HandCard>();
- //Whether the selection has been completed or not
- bool _isEndSelection = false;
- //List of cards with scroll view
- List<HandCard> _handCards = new List<HandCard>();
- UnityAction _onClickNotSelectButtonAction;
- UnityAction _onClickEndSelectButtonAction;
- public string _customCountText = null;
- #region Notification that selection has been made
- public void SetIsEndSelection(bool isEndSelection)
- {
- _isEndSelection = isEndSelection;
- }
- #endregion
- //Select cards normally
- public IEnumerator OpenSelectCardPanel(string Message, List<CardSource> RootCardSources, Func<CardSource, bool> _CanTargetCondition, Func<List<CardSource>, CardSource, bool> _CanTargetCondition_ByPreSelecetedList, Func<List<CardSource>, bool> _CanEndSelectCondition, int _MaxCount, bool _CanEndNotMax, Func<bool> _CanNoSelect, bool CanLookReverseCard, List<SkillInfo> skillInfos, SelectCardEffect.Root root, bool isCenter = false, CardSource[][] evoRootsArray = null, List<string> titleStrings = null)
- {
- yield return ContinuousController.instance.StartCoroutine(OpenSelectCardPanel(Message, "No Selection", "End Selection", null, null, RootCardSources, _CanTargetCondition, _CanTargetCondition_ByPreSelecetedList, _CanEndSelectCondition, _MaxCount, _CanEndNotMax, _CanNoSelect, CanLookReverseCard, skillInfos, root, isCenter: isCenter, evoRootsArray: evoRootsArray, titleStrings: titleStrings));
- }
- //Select cards(Custom button text and click handling)
- public IEnumerator OpenSelectCardPanel(string Message, string NotSelectButtonMessage, string EndSelectButtonMessage, UnityAction _OnClickNotSelectButtonAction, UnityAction _OnClickEndSelectButtonAction, List<CardSource> RootCardSources, Func<CardSource, bool> _CanTargetCondition, Func<List<CardSource>, CardSource, bool> _CanTargetCondition_ByPreSelecetedList, Func<List<CardSource>, bool> _CanEndSelectCondition, int _MaxCount, bool _CanEndNotMax, Func<bool> _CanNoSelect, bool CanLookReverseCard, List<SkillInfo> skillInfos, SelectCardEffect.Root root, bool isCenter = false, CardSource[][] evoRootsArray = null, List<string> titleStrings = null)
- {
- #region Initialization
- this.gameObject.SetActive(true);
- _onClickNotSelectButtonAction = _OnClickNotSelectButtonAction;
- _onClickEndSelectButtonAction = _OnClickEndSelectButtonAction;
- NotSelectButtonText.text = NotSelectButtonMessage;
- EndSelectButtonText.text = EndSelectButtonMessage;
- foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players)
- {
- GManager.instance.turnStateMachine.OffFieldCardTarget(player);
- GManager.instance.turnStateMachine.OffHandCardTarget(player);
- }
- GManager.instance.turnStateMachine.IsSelecting = true;
- BackGround.SetActive(true);
- Parent.SetActive(false);
- SetIsEndSelection(false);
- ReturnToSelectCardButton.gameObject.SetActive(false);
- _preSelectedHandCardList = new List<HandCard>();
- SelectedList = new List<CardSource>();
- SelectedIndex = new List<int>();
- _handCards = new List<HandCard>();
- MessageText.text = Message;
- _canTargetCondition = _CanTargetCondition;
- _canTargetCondition_ByPreSelecetedList = _CanTargetCondition_ByPreSelecetedList;
- _canEndSelectCondition = _CanEndSelectCondition;
- _maxCount = _MaxCount;
- _canEndNotMax = _CanEndNotMax;
- _canNoSelect = _CanNoSelect;
- if (!GManager.instance.turnStateMachine.DoneStartGame)
- {
- CountText.text = "";
- }
- else
- {
- if (!string.IsNullOrEmpty(_customCountText))
- {
- CountText.text = _customCountText;
- }
- else
- {
- if (_canEndNotMax)
- {
- CountText.text = $"Select up to {_maxCount} card{Utils.PluralFormSuffix(_maxCount)}.";
- }
- else
- {
- CountText.text = $"Select {_maxCount} card{Utils.PluralFormSuffix(_maxCount)}.";
- }
- }
- }
- #endregion
- yield return StartCoroutine(OpenSelectCardPanelAnimation(root));
- yield return StartCoroutine(OpenSelectCardPanelCoroutine(RootCardSources, CanLookReverseCard, skillInfos, isCenter: isCenter, evoRootsArray: evoRootsArray, titleStrings: titleStrings));
- CheckSelection();
- yield return new WaitWhile(() => !_isEndSelection);
- SetIsEndSelection(false);
- }
- IEnumerator OpenSelectCardPanelAnimation(SelectCardEffect.Root root)
- {
- 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)
- {
- this.transform.localPosition = new Vector3(-580f, -110f, 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;
- }
- #region Open panel to generate card prefab
- IEnumerator OpenSelectCardPanelCoroutine(List<CardSource> RootCardSources, bool CanLookReverseCard, List<SkillInfo> skillInfos, bool isCenter, CardSource[][] evoRootsArray, List<string> titleStrings)
- {
- List<CardSource> root = new List<CardSource>();
- foreach (CardSource cardSource in RootCardSources)
- {
- root.Add(cardSource);
- }
- GridLayoutGroup grid = scrollRect.content.GetComponent<GridLayoutGroup>();
- if (grid != null)
- {
- if (isCenter)
- {
- grid.padding.left = 550;
- grid.spacing = new Vector2(600f, 0);
- }
- else
- {
- grid.padding.left = 248;
- grid.spacing = new Vector2(191.7f, 0);
- }
- }
- yield return new WaitForSeconds(Time.deltaTime);
- #region Do not select button
- NoSelectButton.SetActive(_canNoSelect());
- #endregion
- #region Initialize card list
- while (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 null;
- }
- }
- }
- }
- 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 = $"selectCardPanel_{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);
- 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);
- if (!cardSource.IsFlipped || CanLookReverseCard)
- {
- handCard.SetUpHandCardImage();
- }
- else
- {
- handCard.SetUpReverseCard();
- }
- handCard.AddClickTarget(OnClickHandCard);
- _handCards.Add(handCard);
- }
- yield return new WaitWhile(() => scrollRect.content.childCount < root.Count);
- yield return new WaitWhile(() => scrollRect.content.childCount != _handCards.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
- CheckSelection();
- Parent.SetActive(true);
- ReturnToSelectCardButton.gameObject.SetActive(false);
- scrollRect.horizontalNormalizedPosition = 0;
- yield return new WaitForSeconds(Time.deltaTime * 1f);
- #region 効果名を表示
- if (skillInfos != null)
- {
- List<Permanent> permanents = new List<Permanent>();
- foreach (HandCard handCard in _handCards)
- {
- int index = _handCards.IndexOf(handCard);
- if (0 <= index && index < skillInfos.Count)
- {
- if (skillInfos[index] != null)
- {
- Permanent permanent = handCard.cardSource.PermanentOfThisCard();
- if (permanent != null)
- {
- if (!permanents.Contains(permanent))
- {
- permanents.Add(permanent);
- }
- }
- }
- }
- }
- foreach (HandCard handCard in _handCards)
- {
- int index = _handCards.IndexOf(handCard);
- if (0 <= index && index < skillInfos.Count)
- {
- if (skillInfos[index] != null)
- {
- if (!string.IsNullOrEmpty(skillInfos[index].CardEffect.EffectName))
- {
- handCard.SetSkillName(skillInfos[index].CardEffect);
- handCard.SetUpCardPositionText(permanents);
- }
- if (handCard.cardSource.PermanentOfThisCard() != null)
- {
- foreach (FieldPermanentCard fieldPermanentCard in handCard.cardSource.Owner.FieldPermanentObjects)
- {
- if (fieldPermanentCard.ThisPermanent != null)
- {
- if (fieldPermanentCard.ThisPermanent.cardSources.Contains(handCard.cardSource))
- {
- fieldPermanentCard.SetPermanentIndexText(permanents);
- break;
- }
- }
- }
- }
- }
- }
- }
- }
- #endregion
- #region 進化元画像を表示
- if (evoRootsArray != null)
- {
- for (int i = 0; i < evoRootsArray.Length; i++)
- {
- if (i < _handCards.Count)
- {
- _handCards[i].SetEvoRootCardImages(evoRootsArray[i]);
- }
- }
- }
- #endregion
- #region タイトルテキストを表示
- if (titleStrings != null)
- {
- for (int i = 0; i < titleStrings.Count; i++)
- {
- if (i < _handCards.Count)
- {
- _handCards[i].SetTitleText(titleStrings[i]);
- }
- }
- }
- #endregion
- }
- #endregion
- #region Left-click processing
- public void OnClickHandCard(HandCard handCard)
- {
- if (_canTargetCondition(handCard.cardSource))
- {
- if (_preSelectedHandCardList.Contains(handCard))
- {
- _preSelectedHandCardList.Remove(handCard);
- SelectedIndex.Remove(_handCards.IndexOf(handCard));
- }
- else
- {
- if (_canTargetCondition_ByPreSelecetedList != null)
- {
- List<CardSource> _PreSelectedList = new List<CardSource>();
- for (int i = 0; i < _preSelectedHandCardList.Count; i++)
- {
- if (_preSelectedHandCardList.Count >= _maxCount && i == _preSelectedHandCardList.Count - 1)
- {
- continue;
- }
- _PreSelectedList.Add(_preSelectedHandCardList[i].cardSource);
- }
- if (!_canTargetCondition_ByPreSelecetedList(_PreSelectedList, handCard.cardSource))
- {
- return;
- }
- }
- if (_preSelectedHandCardList.Count < _maxCount)
- {
- _preSelectedHandCardList.Add(handCard);
- SelectedIndex.Add(_handCards.IndexOf(handCard));
- }
- else
- {
- if (_preSelectedHandCardList.Count > 0)
- {
- _preSelectedHandCardList.RemoveAt(_preSelectedHandCardList.Count - 1);
- SelectedIndex.RemoveAt(SelectedIndex.Count - 1);
- _preSelectedHandCardList.Add(handCard);
- SelectedIndex.Add(_handCards.IndexOf(handCard));
- }
- }
- if (!ContinuousController.instance.checkBeforeEndingSelection
- && !_canNoSelect()
- && !_canEndNotMax
- && _maxCount == _preSelectedHandCardList.Count)
- {
- OnClickEndSelectButton();
- return;
- }
- }
- CheckSelection();
- }
- }
- #endregion
- #region UI reflects whether the selection can be terminated.
- public void CheckSelection()
- {
- EndSelectButton.SetActive(CanEndSelection());
- foreach (HandCard handCard in _handCards)
- {
- handCard.RemoveSelectEffect();
- handCard.OffSelectedIndexText();
- if (_canTargetCondition(handCard.cardSource))
- {
- if (_preSelectedHandCardList.Contains(handCard))
- {
- handCard.SetOrangeOutline();
- handCard.OnOutline();
- handCard.SetSelectedIndexText(_preSelectedHandCardList.IndexOf(handCard) + 1);
- }
- else
- {
- handCard.SetBlueOutline();
- handCard.OnOutline();
- if (_canTargetCondition_ByPreSelecetedList != null)
- {
- List<CardSource> _PreSelectedList = new List<CardSource>();
- for (int i = 0; i < _preSelectedHandCardList.Count; i++)
- {
- if (_preSelectedHandCardList.Count >= _maxCount && i == _preSelectedHandCardList.Count - 1)
- {
- continue;
- }
- _PreSelectedList.Add(_preSelectedHandCardList[i].cardSource);
- }
- if (!_canTargetCondition_ByPreSelecetedList(_PreSelectedList, handCard.cardSource))
- {
- handCard.RemoveSelectEffect();
- }
- }
- if (_preSelectedHandCardList.Count >= _maxCount)
- {
- handCard.RemoveSelectEffect();
- }
- }
- }
- }
- if (_preSelectedHandCardList.Count >= _maxCount)
- {
- NoSelectButton.SetActive(false);
- }
- else
- {
- NoSelectButton.SetActive(_canNoSelect());
- }
- }
- #endregion
- #region Determines if selection can be terminated
- bool CanEndSelection()
- {
- if (_maxCount <= 0) return true;
- List<CardSource> _PreSelectedList = new List<CardSource>();
- foreach (HandCard handCard1 in _preSelectedHandCardList)
- {
- _PreSelectedList.Add(handCard1.cardSource);
- }
- if (_canEndSelectCondition != null)
- {
- if (!_canEndSelectCondition(_PreSelectedList))
- {
- return false;
- }
- }
- if (_canEndNotMax)
- {
- return true;
- }
- else
- {
- if (_PreSelectedList.Count == _maxCount)
- {
- return true;
- }
- }
- return false;
- }
- #endregion
- #region Exit card selection
- public void CloseSelectCardPanel()
- {
- this.gameObject.SetActive(false);
- ReturnToSelectCardButton.gameObject.SetActive(false);
- }
- #endregion
- #region Processing when a button is pressed that does not select anything
- public void OnClickNotSelectButton()
- {
- GManager.instance.PlayDecisionSE();
- SelectedList = new List<CardSource>();
- CloseSelectCardPanel();
- SetIsEndSelection(true);
- ContinuousController.instance.StartCoroutine(OnClickButtonActionCoroutine(_onClickNotSelectButtonAction));
- }
- #endregion
- #region Processing when the Select End button is pressed
- public void OnClickEndSelectButton()
- {
- if (CanEndSelection())
- {
- GManager.instance.PlayDecisionSE();
- List<CardSource> _PreSelectedList = new List<CardSource>();
- foreach (HandCard handCard1 in _preSelectedHandCardList)
- {
- _PreSelectedList.Add(handCard1.cardSource);
- }
- SelectedList = new List<CardSource>();
- foreach (CardSource cardSource in _PreSelectedList)
- {
- SelectedList.Add(cardSource);
- }
- foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
- {
- foreach (FieldPermanentCard fieldPermanentCard in player.FieldPermanentObjects)
- {
- fieldPermanentCard.OffPermanentIndexText();
- }
- }
- CloseSelectCardPanel();
- SetIsEndSelection(true);
- ContinuousController.instance.StartCoroutine(OnClickButtonActionCoroutine(_onClickEndSelectButtonAction));
- }
- }
- IEnumerator OnClickButtonActionCoroutine(UnityAction Action)
- {
- yield return new WaitForSeconds(0.1f);
- Action?.Invoke();
- }
- #endregion
- #region Temporarily display/hide panel
- public void OnClickReturnToSelectCardButton()
- {
- this.gameObject.SetActive(true);
- ReturnToSelectCardButton.gameObject.SetActive(false);
- }
- public void OnClickCheckFieldButton()
- {
- this.gameObject.SetActive(false);
- ReturnToSelectCardButton.gameObject.SetActive(true);
- ReturnToSelectCardButton.onClick.RemoveAllListeners();
- ReturnToSelectCardButton.onClick.AddListener(() => OnClickReturnToSelectCardButton());
- }
- #endregion
- }
|