| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350 |
- using DG.Tweening;
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- using UnityEngine;
- using UnityEngine.Events;
- using UnityEngine.EventSystems;
- using UnityEngine.UI;
- public class EditDeck : MonoBehaviour
- {
- [Header("Deck creation object")]
- public GameObject CreateDeckObject;
- [Header("card prefab")]
- public CardPrefab_CreateDeck cardPrefab_CreateDeck;
- [Header("card pool scroll rect")]
- public ScrollRect CardPoolScroll;
- [Header("Deck card scroll rect")]
- public ScrollRect DeckScroll;
- [Header("Deck card number display text")]
- public Text DeckCountText;
- [Header("loading object")]
- public LoadingObject LoadingObjec;
- [Header("Card details display")]
- public DetailCard_DeckEditor DetailCard;
- [Header("filter")]
- public FilterCardList filterCardList;
- /*
- [Header("フィルターパネル")]
- public FilterPanel filterPanel;
- */
- [Header("Deck name input field")]
- public InputField DeckNameInputField;
- //Deck data being edited
- public DeckData EdittingDeckData { get; set; }
- bool _isFromSelectDeck = false;
- public UnityAction EndEditAction;
- public int DisplayPageIndex = 0;
- public Button UpDisplayPageIndexButton;
- public Button DownDisplayPageIndexButton;
- public Text ShowDisplayPageIndexText;
- public LoadingObject isSearchingObject;
- [Header("Page switching SE")]
- public AudioClip SwitchPageSE;
- [Header("Card classification display")]
- [SerializeField] CardDistribution cardDistribution;
- int _maxDisplayPageIndex;
- string _oldDeckName = "";
- List<CEntity_Base> _oldDeckCards = new List<CEntity_Base>();
- List<CEntity_Base> _oldDigitamaDeckCards = new List<CEntity_Base>();
- int _oldKeyCardId = -1;
- bool _isFromClipboard = false;
- private void Start()
- {
- #if !UNITY_EDITOR && UNITY_ANDROID
- CardPoolScroll.content.GetComponent<GridLayoutGroup>().constraintCount = 5;
- #endif
- }
- void CheckButtonEnabled()
- {
- UpDisplayPageIndexButton.interactable = DisplayPageIndex < _maxDisplayPageIndex;
- UpDisplayPageIndexButton.transform.GetChild(0).gameObject.SetActive(DisplayPageIndex < _maxDisplayPageIndex);
- DownDisplayPageIndexButton.interactable = DisplayPageIndex > 0;
- DownDisplayPageIndexButton.transform.GetChild(0).gameObject.SetActive(DisplayPageIndex > 0);
- ShowDisplayPageIndexText.text = $"{DisplayPageIndex + 1}/{_maxDisplayPageIndex + 1}";
- CardPoolScroll.verticalNormalizedPosition = 1;
- }
- public void UpDisplayPageIndex()
- {
- ContinuousController.instance.PlaySE(SwitchPageSE);
- DisplayPageIndex++;
- if (DisplayPageIndex > _maxDisplayPageIndex)
- {
- DisplayPageIndex = _maxDisplayPageIndex;
- }
- SetCardData();
- CheckButtonEnabled();
- ReflectDeckData();
- }
- public void DownDisplayPageIndex()
- {
- ContinuousController.instance.PlaySE(SwitchPageSE);
- DisplayPageIndex--;
- if (DisplayPageIndex < 0)
- {
- DisplayPageIndex = 0;
- }
- SetCardData();
- CheckButtonEnabled();
- ReflectDeckData();
- }
- List<List<CEntity_Base>> SprittedCardLists = new List<List<CEntity_Base>>();
- //List<CEntity_Base> ActiveCardList = new List<CEntity_Base>();
- IEnumerator SetSprittedCardLists()
- {
- SprittedCardLists = new List<List<CEntity_Base>>();
- for (int i = 0; i < _maxDisplayPageIndex + 1; i++)
- {
- SprittedCardLists.Add(new List<CEntity_Base>());
- }
- List<CEntity_Base> cEntity_Bases = new List<CEntity_Base>();
- foreach (CEntity_Base cEntity_Base in ContinuousController.instance.CardList)
- {
- if (MatchCondition(cEntity_Base))
- {
- cEntity_Bases.Add(cEntity_Base);
- }
- }
- for (int i = 0; i < cEntity_Bases.Count; i++)
- {
- CEntity_Base cEntity_Base = cEntity_Bases[i];
- int Quotient = i / _cardPoolPrefabs.Count;
- if (0 <= Quotient && Quotient < SprittedCardLists.Count)
- {
- SprittedCardLists[Quotient].Add(cEntity_Base);
- }
- }
- yield return null;
- }
- void SetCardData()
- {
- for (int i = 0; i < _cardPoolPrefabs.Count; i++)
- {
- if (i < SprittedCardLists[DisplayPageIndex].Count)
- {
- _cardPoolPrefabs[i].isActive = true;
- _cardPoolPrefabs[i].SetUpCardPrefab_CreateDeck(SprittedCardLists[DisplayPageIndex][i]);
- }
- else
- {
- _cardPoolPrefabs[i].isActive = false;
- }
- }
- }
- #region Card details display
- public void OffDetailCard()
- {
- DetailCard.OffDetailCard();
- }
- public void OnDetailCard(CEntity_Base cEntity_Base)
- {
- if (isDragging)
- {
- return;
- }
- DetailCard.SetUpDetailCard(cEntity_Base);
- }
- #endregion
- int _frameCount = 0;
- int _updateFrame = 3;
- private void Update()
- {
- #region Updates only once every few frames
- _frameCount++;
- if (_frameCount < _updateFrame)
- {
- return;
- }
- else
- {
- _frameCount = 0;
- }
- #endregion
- ShowOnlyVisibleObjects();
- if (EdittingDeckData != null)
- {
- TrialDrawButton.gameObject.SetActive(EdittingDeckData.DeckCards().Count >= 1);
- ClearDeckButton.gameObject.SetActive(EdittingDeckData.AllDeckCards().Count >= 1);
- }
- }
- #region Show only visible cards
- public void ShowOnlyVisibleObjects()
- {
- if (DoneSetUp)
- {
- foreach (CardPrefab_CreateDeck cardPrefab_CreateDeck in _cardPoolPrefabs)
- {
- if (!cardPrefab_CreateDeck.isActive)
- {
- cardPrefab_CreateDeck.gameObject.SetActive(false);
- }
- else
- {
- cardPrefab_CreateDeck.gameObject.SetActive(true);
- if (!((RectTransform)cardPrefab_CreateDeck.transform).IsVisibleFrom(Opening.instance.MainCamera))
- {
- cardPrefab_CreateDeck.CardImage.transform.parent.gameObject.SetActive(false);
- }
- else
- {
- cardPrefab_CreateDeck.CardImage.transform.parent.gameObject.SetActive(true);
- if (cardPrefab_CreateDeck.cEntity_Base != null)
- {
- //if (cardPrefab_CreateDeck.cEntity_Base.CardSprite != null)
- {
- cardPrefab_CreateDeck.ShowCardImage();
- }
- }
- }
- }
- }
- }
- }
- #endregion
- public bool isEditting { get; set; } = false;
- #region Close deck editing screen
- public void OnClickCompleteEditButton()
- {
- ContinuousController.instance.PlaySE(Opening.instance.DecisionSE);
- ContinuousController.instance.StartCoroutine(CloseCreateDeckCoroutine(false));
- }
- public void OnClickCancelEditButton()
- {
- ContinuousController.instance.PlaySE(Opening.instance.CancelSE);
- ContinuousController.instance.StartCoroutine(CloseCreateDeckCoroutine(true));
- }
- public IEnumerator CloseCreateDeckCoroutine(bool Canceled)
- {
- isEditting = false;
- yield return ContinuousController.instance.StartCoroutine(LoadingObjec.StartLoading("Now Loading"));
- Opening.instance.OffYesNoObjects();
- Opening.instance.deck.trialDraw.Close();
- Opening.instance.deck.deckListPanel.Close();
- for (int i = 0; i < Opening.instance.deck.selectDeck.deckInfoPrefabParentScroll.content.childCount; i++)
- {
- CreateNewDeckButton createNewDeckButton = Opening.instance.deck.selectDeck.deckInfoPrefabParentScroll.content.GetChild(i).GetComponent<CreateNewDeckButton>();
- if (createNewDeckButton != null)
- {
- createNewDeckButton.CreateNewDeckWayObject.Close_(false);
- break;
- }
- }
- if (Canceled)
- {
- EdittingDeckData.DeckCardIDs = DeckData.GetDeckCardCodes(DeckData.SortedDeckCardsList(_oldDeckCards));
- EdittingDeckData.DigitamaDeckCardIDs = DeckData.GetDeckCardCodes(DeckData.SortedDeckCardsList(_oldDigitamaDeckCards));
- EdittingDeckData.DeckName = _oldDeckName;
- EdittingDeckData.KeyCardId = _oldKeyCardId;
- }
- if (!EdittingDeckData.AllDeckCards().Contains(EdittingDeckData.KeyCard))
- {
- EdittingDeckData.KeyCardId = -1;
- }
- #region not save if deck is empty or canceled when importing from clipboard
- if (EdittingDeckData != null && (EdittingDeckData.DeckCards().Count == 0 && EdittingDeckData.DigitamaDeckCards().Count == 0 || (Canceled && _isFromClipboard)))
- {
- ContinuousController.instance.DeckDatas.Remove(EdittingDeckData);
- }
- #endregion
- ContinuousController.instance.SaveDeckDatas();
- ContinuousController.instance.SaveDeckData(EdittingDeckData);
- for (int i = 0; i < DeckScroll.content.childCount; i++)
- {
- Destroy(DeckScroll.content.GetChild(i).gameObject);
- }
- if (!Canceled)
- {
- EdittingDeckData.DeckCardIDs = DeckData.GetDeckCardCodes(DeckData.SortedDeckCardsList(EdittingDeckData.DeckCards()));
- EdittingDeckData.DigitamaDeckCardIDs = DeckData.GetDeckCardCodes(DeckData.SortedDeckCardsList(EdittingDeckData.DigitamaDeckCards()));
- }
- foreach (CardPrefab_CreateDeck cardPrefab_CreateDeck in _cardPoolPrefabs)
- {
- if (cardPrefab_CreateDeck._OnEnterCoroutine != null)
- {
- cardPrefab_CreateDeck.StopCoroutine(cardPrefab_CreateDeck._OnEnterCoroutine);
- cardPrefab_CreateDeck._OnEnterCoroutine = null;
- }
- cardPrefab_CreateDeck.StopAllCoroutines();
- cardPrefab_CreateDeck.gameObject.SetActive(false);
- }
- yield return new WaitUntil(() => DeckScroll.content.childCount == 0);
- yield return new WaitForSeconds(0.1f);
- CreateDeckObject.SetActive(false);
- #region ひとつ前の画面をセットアップ
- if (_isFromSelectDeck)
- {
- Opening.instance.deck.selectDeck.ResetDeckInfoPanel();
- yield return ContinuousController.instance.StartCoroutine(Opening.instance.deck.selectDeck.SetDeckList(false));
- for (int i = 0; i < Opening.instance.deck.selectDeck.deckInfoPrefabParentScroll.content.childCount; i++)
- {
- if (Opening.instance.deck.selectDeck.deckInfoPrefabParentScroll.content.GetChild(i).GetComponent<DeckInfoPrefab>() != null)
- {
- if (Opening.instance.deck.selectDeck.deckInfoPrefabParentScroll.content.GetChild(i).GetComponent<DeckInfoPrefab>().thisDeckData == EdittingDeckData)
- {
- if (Opening.instance.deck.selectDeck.deckInfoPrefabParentScroll.content.GetChild(i).GetComponent<DeckInfoPrefab>().thisDeckData != null)
- {
- if (Opening.instance.deck.selectDeck.deckInfoPrefabParentScroll.content.GetChild(i).GetComponent<DeckInfoPrefab>().thisDeckData.DeckCards().Count > 0)
- {
- Opening.instance.deck.selectDeck.deckInfoPrefabParentScroll.content.GetChild(i).GetComponent<DeckInfoPrefab>().OnClick_DeckInfoPrefab(false);
- }
- }
- }
- }
- }
- if (EdittingDeckData != null)
- {
- ContinuousController.instance.BattleDeckData = EdittingDeckData;
- }
- }
- else
- {
- Opening.instance.battle.selectBattleDeck.ResetDeckInfoPanel();
- yield return ContinuousController.instance.StartCoroutine(Opening.instance.battle.selectBattleDeck.SetDeckList(false));
- for (int i = 0; i < Opening.instance.battle.selectBattleDeck.deckInfoPrefabParentScroll.content.childCount; i++)
- {
- if (Opening.instance.battle.selectBattleDeck.deckInfoPrefabParentScroll.content.GetChild(i).GetComponent<DeckInfoPrefab>() != null)
- {
- if (Opening.instance.battle.selectBattleDeck.deckInfoPrefabParentScroll.content.GetChild(i).GetComponent<DeckInfoPrefab>().thisDeckData == EdittingDeckData)
- {
- Opening.instance.battle.selectBattleDeck.deckInfoPrefabParentScroll.content.GetChild(i).GetComponent<DeckInfoPrefab>().OnClick_DeckInfoPrefab(false);
- }
- }
- }
- }
- #endregion
- EndEditAction?.Invoke();
- EndEditAction = null;
- yield return ContinuousController.instance.StartCoroutine(LoadingObjec.EndLoading());
- }
- #endregion
- #region Open deck editing screen
- public void SetUpCreateDeck(DeckData deckData, bool isFromSelectDeck, bool isFromClipboard = false)
- {
- if (deckData == null)
- {
- return;
- }
- _isFromClipboard = isFromClipboard;
- Opening.instance.OffYesNoObjects();
- Opening.instance.deck.trialDraw.Close();
- Opening.instance.deck.deckListPanel.Close();
- _oldDeckName = deckData.DeckName;
- _oldDeckCards = new List<CEntity_Base>();
- foreach (CEntity_Base cEntity_Base in deckData.DeckCards())
- {
- _oldDeckCards.Add(cEntity_Base);
- }
- _oldDigitamaDeckCards = new List<CEntity_Base>();
- foreach (CEntity_Base cEntity_Base in deckData.DigitamaDeckCards())
- {
- _oldDigitamaDeckCards.Add(cEntity_Base);
- }
- _oldKeyCardId = deckData.KeyCardId;
- _checkCoverCoroutine = null;
- this._isFromSelectDeck = isFromSelectDeck;
- DisplayPageIndex = 0;
- SetCardData();
- CheckButtonEnabled();
- isSearchingObject.Off();
- ContinuousController.instance.StartCoroutine(SetUpCreateDeckCoroutine(deckData));
- }
- public IEnumerator SetUpCreateDeckCoroutine(DeckData deckData)
- {
- yield return ContinuousController.instance.StartCoroutine(LoadingObjec.StartLoading("Now Loading"));
- yield return new WaitForSeconds(0.1f);
- for (int i = 0; i < draggable_CardParent.childCount; i++)
- {
- Destroy(draggable_CardParent.GetChild(i).gameObject);
- }
- DraggingCover.SetActive(false);
- CardPoolScroll.verticalNormalizedPosition = 1;
- DeckScroll.verticalNormalizedPosition = 1;
- deckData.DeckCardIDs = DeckData.GetDeckCardCodes(DeckData.SortedDeckCardsList(deckData.DeckCards()));
- deckData.DigitamaDeckCardIDs = DeckData.GetDeckCardCodes(DeckData.SortedDeckCardsList(deckData.DigitamaDeckCards()));
- EdittingDeckData = deckData;
- ContinuousController.instance.SaveDeckDatas();
- //ContinuousController.instance.SaveDeckData(EdittingDeckData);
- OffDetailCard();
- for (int i = 0; i < DeckScroll.content.childCount; i++)
- {
- Destroy(DeckScroll.content.GetChild(i).gameObject);
- }
- yield return new WaitUntil(() => DeckScroll.content.childCount == 0);
- for (int i = 0; i < DeckScroll.viewport.childCount; i++)
- {
- if (i != 0)
- {
- Destroy(DeckScroll.viewport.GetChild(i).gameObject);
- }
- }
- yield return new WaitUntil(() => DeckScroll.viewport.childCount == 1);
- _maxDisplayPageIndex = (ContinuousController.instance.CardList.Length - 1) / _cardPoolPrefabs.Count;
- if (deckData != null)
- {
- List<CEntity_Base> DeckCards = new List<CEntity_Base>();
- foreach (CEntity_Base cEntity_Base in deckData.AllDeckCards())
- {
- DeckCards.Add(cEntity_Base);
- }
- foreach (CEntity_Base cEntity_Base in DeckCards)
- {
- CreateDeckCard(cEntity_Base);
- }
- }
- CreateDeckObject.SetActive(true);
- foreach (CardPrefab_CreateDeck _CardPrefab_CreateDeck in _cardPoolPrefabs)
- {
- _CardPrefab_CreateDeck.isActive = true;
- if (_CardPrefab_CreateDeck._OnEnterCoroutine != null)
- {
- _CardPrefab_CreateDeck.StopCoroutine(_CardPrefab_CreateDeck._OnEnterCoroutine);
- _CardPrefab_CreateDeck._OnEnterCoroutine = null;
- }
- }
- filterCardList.Init(() => ContinuousController.instance.StartCoroutine(ShowPoolCard_MatchCondition()));
- DeckNameInputField.onEndEdit.RemoveAllListeners();
- DeckNameInputField.text = EdittingDeckData.DeckName;
- DeckNameInputField.onEndEdit.AddListener(OnEndEdit);
- yield return ContinuousController.instance.StartCoroutine(SetSprittedCardLists());
- SetCardData();
- CheckButtonEnabled();
- ReflectDeckData();
- cardDistribution.SetCardDistribution(EdittingDeckData);
- yield return new WaitForSeconds(0.1f);
- for (int i = 0; i < DeckScroll.content.childCount; i++)
- {
- DeckScroll.content.GetChild(i).GetComponent<CardPrefab_CreateDeck>().ShowCardImage();
- }
- yield return StartCoroutine(LoadingObjec.EndLoading());
- isEditting = true;
- }
- public void OnEndEdit(string text)
- {
- string deckName = text;
- deckName = DeckData.ValidateDeckName(deckName);
- EdittingDeckData.DeckName = deckName;
- DeckNameInputField.onEndEdit.RemoveAllListeners();
- DeckNameInputField.text = deckName;
- DeckNameInputField.onEndEdit.AddListener(OnEndEdit);
- }
- #endregion
- public List<CardPrefab_CreateDeck> CardPoolCardPrefabs_CreateDeck = new List<CardPrefab_CreateDeck>();
- #region Initialize the deck editing screen at the start of the game
- public List<CardPrefab_CreateDeck> cardPoolPrefabs_all = new List<CardPrefab_CreateDeck>();
- List<CardPrefab_CreateDeck> _cardPoolPrefabs = new List<CardPrefab_CreateDeck>();
- bool DoneSetUp { get; set; } = false;
- public IEnumerator InitEditDeck()
- {
- cardDistribution.Init();
- for (int i = 0; i < CardPoolScroll.content.childCount; i++)
- {
- CardPrefab_CreateDeck cardPrefab_CreateDeck = CardPoolScroll.content.GetChild(i).GetComponent<CardPrefab_CreateDeck>();
- if (cardPrefab_CreateDeck != null)
- {
- CardPoolCardPrefabs_CreateDeck.Add(cardPrefab_CreateDeck);
- }
- }
- for (int i = 0; i < DeckScroll.content.childCount; i++)
- {
- Destroy(DeckScroll.content.GetChild(i).gameObject);
- }
- foreach (CardPrefab_CreateDeck cardPrefab_CreateDeck in cardPoolPrefabs_all)
- {
- if (cardPrefab_CreateDeck.gameObject.activeSelf)
- {
- cardPrefab_CreateDeck.gameObject.SetActive(false);
- }
- }
- for (int i = 0; i < cardPoolPrefabs_all.Count; i++)
- {
- if (i < ContinuousController.instance.CardList.Length)
- {
- CardPrefab_CreateDeck _cardPrefab_CreateDeck = cardPoolPrefabs_all[i];
- _cardPoolPrefabs.Add(_cardPrefab_CreateDeck);
- CEntity_Base cEntity_Base = ContinuousController.instance.CardList[i];
- foreach (ScrollRect _scroll in _cardPrefab_CreateDeck.scroll)
- {
- _scroll.content = CardPoolScroll.content;
- _scroll.viewport = CardPoolScroll.viewport;
- _scroll.enabled = false;
- }
- _cardPrefab_CreateDeck.OnClickAction = () =>
- {
- StartCoroutine(AddDeckCardCoroutine_OnClick(_cardPrefab_CreateDeck));
- };
- _cardPrefab_CreateDeck.OnBeginDragAction = (cardPrefab_CreateDeck) => { StartCoroutine(OnBeginDrag(cardPrefab_CreateDeck)); };
- _cardPrefab_CreateDeck.OnEnterAction = (cardPrefab) =>
- {
- OnDetailCard(_cardPrefab_CreateDeck.cEntity_Base);
- };
- }
- }
- yield return ContinuousController.instance.StartCoroutine(SetSprittedCardLists());
- yield return new WaitForSeconds(0.1f);
- DoneSetUp = true;
- }
- #endregion
- #region Changed deck content changes to UI
- public void ReflectDeckData()
- {
- if (EdittingDeckData != null)
- {
- //Turn on covers for cards that cannot be included in the deck
- if (_checkCoverCoroutine != null)
- {
- StopCoroutine(_checkCoverCoroutine);
- }
- _checkCoverCoroutine = StartCoroutine(CheckCoverIEnumerator());
- SetDeckCountText();
- }
- }
- Coroutine _checkCoverCoroutine = null;
- IEnumerator CheckCoverIEnumerator()
- {
- foreach (CardPrefab_CreateDeck cardPrefab_CreateDeck in _cardPoolPrefabs)
- {
- yield return null;
- cardPrefab_CreateDeck.CheckCover(EdittingDeckData);
- }
- }
- #endregion
- #region Show deck number text
- public void SetDeckCountText()
- {
- DeckCountText.text = $"{EdittingDeckData.DeckCards().Count}+{EdittingDeckData.DigitamaDeckCards().Count}/50+5";
- if (EdittingDeckData.IsValidDeckData())
- {
- DeckCountText.color = new Color32(69, 255, 69, 255);
- }
- else
- {
- DeckCountText.color = new Color32(255, 64, 64, 255);
- }
- }
- #endregion
- #region Generate cards for deck
- public CardPrefab_CreateDeck CreateDeckCard(CEntity_Base cEntity_Base)
- {
- CardPrefab_CreateDeck _cardPrefab_CreateDeck = Instantiate(cardPrefab_CreateDeck, DeckScroll.content);
- SetUpDeckCard(_cardPrefab_CreateDeck, cEntity_Base);
- return _cardPrefab_CreateDeck;
- }
- public void SetUpDeckCard(CardPrefab_CreateDeck _cardPrefab_CreateDeck, CEntity_Base cEntity_Base)
- {
- foreach (ScrollRect _scroll in _cardPrefab_CreateDeck.scroll)
- {
- _scroll.content = DeckScroll.content;
- _scroll.viewport = DeckScroll.viewport;
- }
- _cardPrefab_CreateDeck.SetUpCardPrefab_CreateDeck(cEntity_Base);
- _cardPrefab_CreateDeck.ShowCardImage();
- _cardPrefab_CreateDeck.OnClickAction = () =>
- {
- StartCoroutine(RemoveDeckCardCoroutine_OnClick(_cardPrefab_CreateDeck));
- };
- _cardPrefab_CreateDeck.OnBeginDragAction = (cardPrefab_CreateDeck) => { StartCoroutine(OnBeginDrag(cardPrefab_CreateDeck)); };
- _cardPrefab_CreateDeck.OnEnterAction = (cardPrefab) =>
- {
- OnDetailCard(cEntity_Base);
- cardPrefab.SetupAddRemoveButton(EdittingDeckData);
- };
- _cardPrefab_CreateDeck.OnExitAction = (cardPrefab) =>
- {
- cardPrefab.OffAddRemoveButton();
- };
- _cardPrefab_CreateDeck.Parent.localScale = new Vector3(0.76f, 0.76f, 0.76f);
- _cardPrefab_CreateDeck.OnClickAddButtonAction = (cardPrefab) => StartCoroutine(AddDeckCardCoroutine_OnClick(cardPrefab));
- _cardPrefab_CreateDeck.OnClickRemoveButtonAction = (cardPrefab) => StartCoroutine(RemoveDeckCardCoroutine_OnClick(cardPrefab));
- }
- #endregion
- #region Display only cards that meet search/filter conditions
- bool MatchCondition(CEntity_Base cEntity_Base)
- {
- if (!filterCardList.OnlyContainsName()(cEntity_Base))
- {
- return false;
- }
- if (!filterCardList.OnlyContainsColor()(cEntity_Base))
- {
- return false;
- }
- if (!filterCardList.OnlyMatchRarity()(cEntity_Base))
- {
- return false;
- }
- if (!filterCardList.OnlyMatchCardKind()(cEntity_Base))
- {
- return false;
- }
- if (!filterCardList.OnlyMatchCardSet()(cEntity_Base))
- {
- return false;
- }
- if (!filterCardList.OnlyMatchPlayCost()(cEntity_Base))
- {
- return false;
- }
- if (!filterCardList.OnlyMatchLevel()(cEntity_Base))
- {
- return false;
- }
- if (!filterCardList.OnlyMatchSpecialCardKind()(cEntity_Base))
- {
- return false;
- }
- if (!filterCardList.OnlyMatchParallelCondition()(cEntity_Base))
- {
- return false;
- }
- return true;
- }
- public IEnumerator ShowPoolCard_MatchCondition()
- {
- DraggingCover.SetActive(true);
- DisplayPageIndex = 0;
- _maxDisplayPageIndex = (ContinuousController.instance.CardList.Count((cEntity_Base) => MatchCondition(cEntity_Base)) - 1) / _cardPoolPrefabs.Count;
- yield return ContinuousController.instance.StartCoroutine(SetSprittedCardLists());
- SetCardData();
- CheckButtonEnabled();
- ReflectDeckData();
- DraggingCover.SetActive(false);
- for (int i = 0; i < CardPoolCardPrefabs_CreateDeck.Count; i++)
- {
- CardPrefab_CreateDeck cardPrefab_CreateDeck = CardPoolCardPrefabs_CreateDeck[i];
- if (cardPrefab_CreateDeck != null)
- {
- cardPrefab_CreateDeck.uIShiny.enabled = false;
- if (cardPrefab_CreateDeck._OnEnterCoroutine != null)
- {
- cardPrefab_CreateDeck.StopCoroutine(cardPrefab_CreateDeck._OnEnterCoroutine);
- cardPrefab_CreateDeck._OnEnterCoroutine = null;
- }
- cardPrefab_CreateDeck.StopAllCoroutines();
- }
- }
- }
- #endregion
- #region Manipulating card objects
- [Header("draggable card object")]
- public Draggable_Card draggable_CardPrefab;
- [Header("draggable card object parent")]
- public Transform draggable_CardParent;
- [Header("Deck card dropArea")]
- public DropArea DeckCardsDropArea;
- [Header("card pool dropArea")]
- public DropArea CardPoolDropArea;
- [Header("Cover while dragging")]
- public GameObject DraggingCover;
- [Header("Coordinates of the disappearing deck card")]
- public Transform DisappearDeckCardTransform;
- //Is it draggable?
- public bool CanDrag { get; set; } = true;
- //Whether you are dragging
- public bool isDragging { get; set; } = false;
- #region Generate draggable objects
- public Draggable_Card CreateDraggable_Card()
- {
- Draggable_Card draggable_Card = Instantiate(draggable_CardPrefab, draggable_CardParent);
- draggable_Card.DefaultParent = draggable_CardParent;
- draggable_Card.transform.localScale = new Vector3(1, 1, 1);
- draggable_Card.CardImage.color = new Color(1, 1, 1, 1);
- return draggable_Card;
- }
- #endregion
- #region At the start of drag
- public IEnumerator OnBeginDrag(CardPrefab_CreateDeck _cardPrefab_CreateDeck)
- {
- if (_cardPrefab_CreateDeck.transform.parent == CardPoolScroll.content)
- {
- if (!DeckBuildingRule.CanAddCard(_cardPrefab_CreateDeck.cEntity_Base, EdittingDeckData))
- {
- yield break;
- }
- }
- if (Input.GetMouseButton(1))
- {
- yield break;
- }
- if (!isDragging && CanDrag)
- {
- Draggable_Card draggable_Card = CreateDraggable_Card();
- SetStartDrag(_cardPrefab_CreateDeck, draggable_Card);
- draggable_Card.OnDropAction = (dropAreas) => { OnEndDrag(dropAreas, _cardPrefab_CreateDeck, draggable_Card); };
- draggable_Card.OnDragAction = (dropAreas) =>
- {
- DeckCardsDropArea.OnPointerExit();
- CardPoolDropArea.OnPointerExit();
- if (_cardPrefab_CreateDeck.transform.parent == DeckScroll.content)
- {
- if (dropAreas.Count((dropArea) => dropArea == CardPoolDropArea) > 0)
- {
- CardPoolDropArea.OnPointerEnter();
- }
- }
- else if (_cardPrefab_CreateDeck.transform.parent == CardPoolScroll.content)
- {
- if (dropAreas.Count((dropArea) => dropArea == DeckCardsDropArea) > 0)
- {
- DeckCardsDropArea.OnPointerEnter();
- }
- }
- };
- if (_cardPrefab_CreateDeck.transform.parent == DeckScroll.content)
- {
- DeckCardsDropArea.OffDropPanel();
- CardPoolDropArea.OnDropPanel();
- _cardPrefab_CreateDeck.HideDeckCardTab();
- _cardPrefab_CreateDeck.OffAddRemoveButton();
- }
- else if (_cardPrefab_CreateDeck.transform.parent == CardPoolScroll.content)
- {
- DeckCardsDropArea.OnDropPanel();
- CardPoolDropArea.OffDropPanel();
- }
- DeckScroll.enabled = false;
- for (int i = 0; i < DeckScroll.content.childCount; i++)
- {
- foreach (ScrollRect scroll in DeckScroll.content.GetChild(i).GetComponent<CardPrefab_CreateDeck>().scroll)
- {
- scroll.enabled = false;
- }
- }
- CardPoolScroll.enabled = false;
- for (int i = 0; i < _cardPoolPrefabs.Count; i++)
- {
- foreach (ScrollRect scroll in _cardPoolPrefabs[i].scroll)
- {
- scroll.enabled = false;
- }
- }
- }
- }
- public void SetStartDrag(CardPrefab_CreateDeck _cardPrefab_CreateDeck, Draggable_Card draggable_Card)
- {
- isDragging = true;
- CanDrag = false;
- DraggingCover.SetActive(true);
- draggable_Card.SetUpDraggable_Card(_cardPrefab_CreateDeck.cEntity_Base, _cardPrefab_CreateDeck.transform.position);
- }
- #endregion
- #region At the end of dragging
- public void OnEndDrag(List<DropArea> dropAreas, CardPrefab_CreateDeck _cardPrefab_CreateDeck, Draggable_Card draggable_Card)
- {
- DeckCardsDropArea.OffDropPanel();
- CardPoolDropArea.OffDropPanel();
- StartCoroutine(OnEndDragCoroutine(dropAreas, _cardPrefab_CreateDeck, draggable_Card));
- DeckScroll.enabled = true;
- for (int i = 0; i < DeckScroll.content.childCount; i++)
- {
- foreach (ScrollRect scroll in DeckScroll.content.GetChild(i).GetComponent<CardPrefab_CreateDeck>().scroll)
- {
- scroll.enabled = true;
- }
- }
- CardPoolScroll.enabled = true;
- for (int i = 0; i < _cardPoolPrefabs.Count; i++)
- {
- foreach (ScrollRect scroll in _cardPoolPrefabs[i].scroll)
- {
- scroll.enabled = true;
- }
- }
- }
- IEnumerator OnEndDragCoroutine(List<DropArea> dropAreas, CardPrefab_CreateDeck _cardPrefab_CreateDeck, Draggable_Card draggable_Card)
- {
- if (_cardPrefab_CreateDeck.transform.parent == DeckScroll.content)
- {
- if (dropAreas.Count((dropArea) => dropArea == CardPoolDropArea) > 0)
- {
- yield return StartCoroutine(RemoveDeckCardCoroutine(_cardPrefab_CreateDeck, draggable_Card));
- }
- else
- {
- _cardPrefab_CreateDeck.ShowCardImage();
- }
- }
- else if (_cardPrefab_CreateDeck.transform.parent == CardPoolScroll.content)
- {
- if (dropAreas.Count((dropArea) => dropArea == DeckCardsDropArea) > 0)
- {
- yield return StartCoroutine(AddDeckCardCoroutine(_cardPrefab_CreateDeck, draggable_Card));
- }
- }
- Reset_EndDrag(draggable_Card);
- }
- public void Reset_EndDrag(Draggable_Card draggable_Card)
- {
- isDragging = false;
- DestroyImmediate(draggable_Card.gameObject);
- CanDrag = true;
- DraggingCover.SetActive(false);
- }
- #endregion
- float _addCardAnimationTime = 0.01f;
- #region Animation to add cards to deck when dropped
- IEnumerator AddDeckCardCoroutine(CardPrefab_CreateDeck _cardPrefab_CreateDeck, Draggable_Card draggable_Card)
- {
- if (!DeckBuildingRule.CanAddCard(_cardPrefab_CreateDeck.cEntity_Base, EdittingDeckData))
- {
- yield break;
- }
- ContinuousController.instance.PlaySE(Opening.instance.DrawSE);
- for (int i = 0; i < CardPoolCardPrefabs_CreateDeck.Count; i++)
- {
- CardPrefab_CreateDeck cardPrefab_CreateDeck = CardPoolCardPrefabs_CreateDeck[i];
- if (cardPrefab_CreateDeck != null)
- {
- cardPrefab_CreateDeck.uIShiny.enabled = false;
- cardPrefab_CreateDeck.OffAddRemoveButton();
- }
- }
- yield return StartCoroutine(AddDeckCards(_cardPrefab_CreateDeck.cEntity_Base));
- List<CEntity_Base> DeckCards = new List<CEntity_Base>();
- foreach (CEntity_Base cEntity_Base in EdittingDeckData.AllDeckCards())
- {
- DeckCards.Add(cEntity_Base);
- }
- Debug.Log("ADDED EDITTING DECK DATA ENTITIES TO DECK CARDS LIST: " + DeckCards.Count);
- int index = DeckCards.IndexOf(_cardPrefab_CreateDeck.cEntity_Base) + DeckCards.Count((cEntity_Base) => cEntity_Base == _cardPrefab_CreateDeck.cEntity_Base) - 1;
- Debug.Log("GETTING INDEX OF LAST ADDED CARD: " + index);
- CardPrefab_CreateDeck newCardPrefab = CreateDeckCard(_cardPrefab_CreateDeck.cEntity_Base);
- newCardPrefab.HideDeckCardTab();
- newCardPrefab.transform.SetSiblingIndex(index);
- List<CardPrefab_CreateDeck> cardPrefabs = new List<CardPrefab_CreateDeck>();
- for (int i = 0; i < DeckScroll.content.childCount; i++)
- {
- CardPrefab_CreateDeck cardPrefab = DeckScroll.content.GetChild(i).GetComponent<CardPrefab_CreateDeck>();
- if (cardPrefab != null)
- {
- cardPrefabs.Add(cardPrefab);
- if (cardPrefab.AddRemoveButtonParent.activeSelf)
- {
- cardPrefab.OffAddRemoveButton();
- cardPrefab.SetupAddRemoveButton(EdittingDeckData);
- }
- }
- }
- foreach (CardPrefab_CreateDeck cardPrefab in cardPrefabs)
- {
- cardPrefab.transform.SetParent(null);
- }
- foreach (CEntity_Base cEntity_Base in EdittingDeckData.AllDeckCards())
- {
- for (int i = 0; i < cardPrefabs.Count; i++)
- {
- if (cardPrefabs[i].cEntity_Base == cEntity_Base)
- {
- cardPrefabs[i].transform.SetParent(DeckScroll.content);
- cardPrefabs.Remove(cardPrefabs[i]);
- break;
- }
- }
- }
- yield return new WaitForSeconds(Time.deltaTime);
- bool end = false;
- var sequence = DOTween.Sequence();
- sequence
- .Append(draggable_Card.transform.DOMove(newCardPrefab.transform.position, _addCardAnimationTime))
- .Join(draggable_Card.transform.DOScale(new Vector3(0.5f, 0.5f, 0.5f), _addCardAnimationTime))
- .AppendCallback(() => end = true);
- sequence.Play();
- yield return new WaitWhile(() => !end);
- end = false;
- yield return new WaitForSeconds(_addCardAnimationTime);
- newCardPrefab.ShowCardImage();
- draggable_Card.gameObject.SetActive(false);
- }
- #endregion
- #region Animation to remove cards on drop
- IEnumerator RemoveDeckCardCoroutine(CardPrefab_CreateDeck _cardPrefab_CreateDeck, Draggable_Card draggable_Card)
- {
- ContinuousController.instance.PlaySE(Opening.instance.DrawSE);
- bool end = false;
- yield return StartCoroutine(RemoveDeckCards(_cardPrefab_CreateDeck.cEntity_Base));
- var sequence = DOTween.Sequence();
- sequence
- .Append(draggable_Card.transform.DOMove(DisappearDeckCardTransform.position, _addCardAnimationTime))
- .Join(draggable_Card.transform.DOScale(new Vector3(0.5f, 0.5f, 0.5f), _addCardAnimationTime))
- .AppendCallback(() => end = true);
- sequence.Play();
- yield return new WaitWhile(() => !end);
- end = false;
- yield return new WaitForSeconds(_addCardAnimationTime);
- draggable_Card.gameObject.SetActive(false);
- if (_cardPrefab_CreateDeck.transform.parent != CardPoolScroll.content)
- {
- DestroyImmediate(_cardPrefab_CreateDeck.gameObject);
- }
- }
- #endregion
- #region Add card to deck animation when right-clicking
- public IEnumerator AddDeckCardCoroutine_OnClick(CardPrefab_CreateDeck _cardPrefab_CreateDeck)
- {
- if (!DeckBuildingRule.CanAddCard(_cardPrefab_CreateDeck.cEntity_Base, EdittingDeckData))
- {
- yield break;
- }
- Draggable_Card draggable_Card = CreateDraggable_Card();
- SetStartDrag(_cardPrefab_CreateDeck, draggable_Card);
- draggable_Card.IsDragging = false;
- yield return StartCoroutine(AddDeckCardCoroutine(_cardPrefab_CreateDeck, draggable_Card));
- Reset_EndDrag(draggable_Card);
- }
- #endregion
- #region Animation to remove cards from deck when right-clicking
- public IEnumerator RemoveDeckCardCoroutine_OnClick(CardPrefab_CreateDeck _cardPrefab_CreateDeck)
- {
- Draggable_Card draggable_Card = CreateDraggable_Card();
- _cardPrefab_CreateDeck.HideDeckCardTab();
- SetStartDrag(_cardPrefab_CreateDeck, draggable_Card);
- draggable_Card.IsDragging = false;
- yield return StartCoroutine(RemoveDeckCardCoroutine(_cardPrefab_CreateDeck, draggable_Card));
- Reset_EndDrag(draggable_Card);
- }
- #endregion
- #region add cards to deck
- public IEnumerator AddDeckCards(CEntity_Base cEntity_Base)
- {
- if (!DeckBuildingRule.CanAddCard(cEntity_Base, EdittingDeckData))
- {
- yield break;
- }
- EdittingDeckData.AddCard(cEntity_Base);
- EdittingDeckData.DeckCardIDs = DeckData.GetDeckCardCodes(DeckData.SortedDeckCardsList(EdittingDeckData.DeckCards()));
- EdittingDeckData.DigitamaDeckCardIDs = DeckData.GetDeckCardCodes(DeckData.SortedDeckCardsList(EdittingDeckData.DigitamaDeckCards()));
- ReflectDeckData();
- cardDistribution.SetCardDistribution(EdittingDeckData);
- }
- #endregion
- #region remove cards from deck
- public IEnumerator RemoveDeckCards(CEntity_Base cEntity_Base)
- {
- if (cEntity_Base.cardKind == CardKind.DigiEgg)
- {
- if (EdittingDeckData.DigitamaDeckCards().Count((cardData) => cardData.CardID == cEntity_Base.CardID) <= 0)
- {
- yield break;
- }
- }
- else
- {
- if (EdittingDeckData.DeckCards().Count((cardData) => cardData.CardID == cEntity_Base.CardID) <= 0)
- {
- yield break;
- }
- }
- EdittingDeckData.RemoveCard(cEntity_Base);
- EdittingDeckData.DeckCardIDs = DeckData.GetDeckCardCodes(DeckData.SortedDeckCardsList(EdittingDeckData.DeckCards()));
- EdittingDeckData.DigitamaDeckCardIDs = DeckData.GetDeckCardCodes(DeckData.SortedDeckCardsList(EdittingDeckData.DigitamaDeckCards()));
- ReflectDeckData();
- cardDistribution.SetCardDistribution(EdittingDeckData);
- }
- #endregion
- #endregion
- public void OnPointerEnterBackground()
- {
- List<CardPrefab_CreateDeck> cardPrefabs = new List<CardPrefab_CreateDeck>();
- for (int i = 0; i < DeckScroll.content.childCount; i++)
- {
- CardPrefab_CreateDeck cardPrefab = DeckScroll.content.GetChild(i).GetComponent<CardPrefab_CreateDeck>();
- if (cardPrefab != null)
- {
- cardPrefabs.Add(cardPrefab);
- }
- }
- foreach (CardPrefab_CreateDeck cardPrefab in cardPrefabs)
- {
- if (cardPrefab != null)
- {
- cardPrefab._OnExit();
- }
- }
- }
- public Button TrialDrawButton;
- public void OnClickTrial5DrawButton()
- {
- Opening.instance.deck.trialDraw.Off();
- ContinuousController.instance.PlaySE(Opening.instance.DecisionSE);
- ContinuousController.instance.StartCoroutine(Opening.instance.deck.trialDraw.SetUpTrialDraw(EdittingDeckData.DeckCards()));
- }
- public Button ClearDeckButton;
- public void OnClickClearDeckButton()
- {
- List<UnityAction> Commands = new List<UnityAction>()
- {
- () =>
- {
- ContinuousController.instance.StartCoroutine(ClearDeckCoroutine());
- IEnumerator ClearDeckCoroutine()
- {
- DraggingCover.SetActive(true);
- List<CEntity_Base> cEntity_Bases = new List<CEntity_Base>();
- foreach(CEntity_Base cEntity_Base in EdittingDeckData.DeckCards())
- {
- cEntity_Bases.Add(cEntity_Base);
- }
- foreach(CEntity_Base cEntity_Base in EdittingDeckData.DigitamaDeckCards())
- {
- cEntity_Bases.Add(cEntity_Base);
- }
- foreach(CEntity_Base cEntity_Base in cEntity_Bases)
- {
- yield return ContinuousController.instance.StartCoroutine(RemoveDeckCards(cEntity_Base));
- }
- for (int i = 0; i < DeckScroll.content.childCount; i++)
- {
- Destroy(DeckScroll.content.GetChild(i).gameObject);
- }
- yield return new WaitWhile(() => DeckScroll.content.childCount >= 1);
- DraggingCover.SetActive(false);
- }
- },
- null,
- };
- List<string> CommandTexts = new List<string>()
- {
- LocalizeUtility.GetLocalizedString(
- EngMessage: "Yes",
- JpnMessage: "はい"
- ),
- LocalizeUtility.GetLocalizedString(
- EngMessage: "No",
- JpnMessage: "いいえ"
- ),
- };
- Opening.instance.SetUpActiveYesNoObject(
- Commands,
- CommandTexts,
- LocalizeUtility.GetLocalizedString(
- EngMessage: "Remove all cards from the deck?",
- JpnMessage: "全てのカードをデッキから除きますか?"
- ),
- true);
- }
- public void OnClickSetDeckIconButton()
- {
- ContinuousController.instance.StartCoroutine(Opening.instance.deck.deckListPanel.SetUpDeckListPanel(
- EdittingDeckData,
- OnClick,
- LocalizeUtility.GetLocalizedString(
- EngMessage: "Choose a deck icon card.",
- JpnMessage: "デッキアイコン選択"
- )));
- void OnClick(CEntity_Base cEntity_Base)
- {
- EdittingDeckData.KeyCardId = cEntity_Base.CardIndex;
- Opening.instance.deck.deckListPanel.Close();
- Opening.instance.PlayDecisionSE();
- }
- }
- }
|