EditDeck.cs 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351
  1. using DG.Tweening;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using UnityEngine;
  6. using UnityEngine.Events;
  7. using UnityEngine.EventSystems;
  8. using UnityEngine.UI;
  9. public class EditDeck : MonoBehaviour
  10. {
  11. [Header("Deck creation object")]
  12. public GameObject CreateDeckObject;
  13. [Header("card prefab")]
  14. public CardPrefab_CreateDeck cardPrefab_CreateDeck;
  15. [Header("card pool scroll rect")]
  16. public ScrollRect CardPoolScroll;
  17. [Header("Deck card scroll rect")]
  18. public ScrollRect DeckScroll;
  19. [Header("Deck card number display text")]
  20. public Text DeckCountText;
  21. [Header("loading object")]
  22. public LoadingObject LoadingObjec;
  23. [Header("Card details display")]
  24. public DetailCard_DeckEditor DetailCard;
  25. [Header("filter")]
  26. public FilterCardList filterCardList;
  27. /*
  28. [Header("フィルターパネル")]
  29. public FilterPanel filterPanel;
  30. */
  31. [Header("Deck name input field")]
  32. public InputField DeckNameInputField;
  33. //Deck data being edited
  34. public DeckData EdittingDeckData { get; set; }
  35. bool _isFromSelectDeck = false;
  36. public UnityAction EndEditAction;
  37. public int DisplayPageIndex = 0;
  38. public Button UpDisplayPageIndexButton;
  39. public Button DownDisplayPageIndexButton;
  40. public Text ShowDisplayPageIndexText;
  41. public LoadingObject isSearchingObject;
  42. [Header("Page switching SE")]
  43. public AudioClip SwitchPageSE;
  44. [Header("Card classification display")]
  45. [SerializeField] CardDistribution cardDistribution;
  46. int _maxDisplayPageIndex;
  47. string _oldDeckName = "";
  48. List<CEntity_Base> _oldDeckCards = new List<CEntity_Base>();
  49. List<CEntity_Base> _oldDigitamaDeckCards = new List<CEntity_Base>();
  50. int _oldKeyCardId = -1;
  51. bool _isFromClipboard = false;
  52. private void Start()
  53. {
  54. #if !UNITY_EDITOR && UNITY_ANDROID
  55. CardPoolScroll.content.GetComponent<GridLayoutGroup>().constraintCount = 5;
  56. #endif
  57. }
  58. void CheckButtonEnabled()
  59. {
  60. UpDisplayPageIndexButton.interactable = DisplayPageIndex < _maxDisplayPageIndex;
  61. UpDisplayPageIndexButton.transform.GetChild(0).gameObject.SetActive(DisplayPageIndex < _maxDisplayPageIndex);
  62. DownDisplayPageIndexButton.interactable = DisplayPageIndex > 0;
  63. DownDisplayPageIndexButton.transform.GetChild(0).gameObject.SetActive(DisplayPageIndex > 0);
  64. ShowDisplayPageIndexText.text = $"{DisplayPageIndex + 1}/{_maxDisplayPageIndex + 1}";
  65. CardPoolScroll.verticalNormalizedPosition = 1;
  66. }
  67. public void UpDisplayPageIndex()
  68. {
  69. ContinuousController.instance.PlaySE(SwitchPageSE);
  70. DisplayPageIndex++;
  71. if (DisplayPageIndex > _maxDisplayPageIndex)
  72. {
  73. DisplayPageIndex = _maxDisplayPageIndex;
  74. }
  75. SetCardData();
  76. CheckButtonEnabled();
  77. ReflectDeckData();
  78. }
  79. public void DownDisplayPageIndex()
  80. {
  81. ContinuousController.instance.PlaySE(SwitchPageSE);
  82. DisplayPageIndex--;
  83. if (DisplayPageIndex < 0)
  84. {
  85. DisplayPageIndex = 0;
  86. }
  87. SetCardData();
  88. CheckButtonEnabled();
  89. ReflectDeckData();
  90. }
  91. List<List<CEntity_Base>> SprittedCardLists = new List<List<CEntity_Base>>();
  92. //List<CEntity_Base> ActiveCardList = new List<CEntity_Base>();
  93. IEnumerator SetSprittedCardLists()
  94. {
  95. SprittedCardLists = new List<List<CEntity_Base>>();
  96. for (int i = 0; i < _maxDisplayPageIndex + 1; i++)
  97. {
  98. SprittedCardLists.Add(new List<CEntity_Base>());
  99. }
  100. List<CEntity_Base> cEntity_Bases = new List<CEntity_Base>();
  101. foreach (CEntity_Base cEntity_Base in ContinuousController.instance.CardList)
  102. {
  103. if (MatchCondition(cEntity_Base))
  104. {
  105. cEntity_Bases.Add(cEntity_Base);
  106. }
  107. }
  108. for (int i = 0; i < cEntity_Bases.Count; i++)
  109. {
  110. CEntity_Base cEntity_Base = cEntity_Bases[i];
  111. int Quotient = i / _cardPoolPrefabs.Count;
  112. if (0 <= Quotient && Quotient < SprittedCardLists.Count)
  113. {
  114. SprittedCardLists[Quotient].Add(cEntity_Base);
  115. }
  116. }
  117. yield return null;
  118. }
  119. void SetCardData()
  120. {
  121. for (int i = 0; i < _cardPoolPrefabs.Count; i++)
  122. {
  123. if (i < SprittedCardLists[DisplayPageIndex].Count)
  124. {
  125. _cardPoolPrefabs[i].isActive = true;
  126. _cardPoolPrefabs[i].SetUpCardPrefab_CreateDeck(SprittedCardLists[DisplayPageIndex][i]);
  127. }
  128. else
  129. {
  130. _cardPoolPrefabs[i].isActive = false;
  131. }
  132. }
  133. }
  134. #region Card details display
  135. public void OffDetailCard()
  136. {
  137. DetailCard.OffDetailCard();
  138. }
  139. public void OnDetailCard(CEntity_Base cEntity_Base)
  140. {
  141. if (isDragging)
  142. {
  143. return;
  144. }
  145. DetailCard.SetUpDetailCard(cEntity_Base);
  146. }
  147. #endregion
  148. int _frameCount = 0;
  149. int _updateFrame = 3;
  150. private void Update()
  151. {
  152. #region Updates only once every few frames
  153. _frameCount++;
  154. if (_frameCount < _updateFrame)
  155. {
  156. return;
  157. }
  158. else
  159. {
  160. _frameCount = 0;
  161. }
  162. #endregion
  163. //TODO: need to find a better way, this shouldn't happen every 3rd frame, should only happen on changes. MikeB
  164. ShowOnlyVisibleObjects();
  165. if (EdittingDeckData != null)
  166. {
  167. TrialDrawButton.gameObject.SetActive(EdittingDeckData.DeckCards().Count >= 1);
  168. ClearDeckButton.gameObject.SetActive(EdittingDeckData.AllDeckCards().Count >= 1);
  169. }
  170. }
  171. #region Show only visible cards
  172. public void ShowOnlyVisibleObjects()
  173. {
  174. if (DoneSetUp)
  175. {
  176. foreach (CardPrefab_CreateDeck cardPrefab_CreateDeck in _cardPoolPrefabs)
  177. {
  178. if (!cardPrefab_CreateDeck.isActive)
  179. {
  180. cardPrefab_CreateDeck.gameObject.SetActive(false);
  181. }
  182. else
  183. {
  184. cardPrefab_CreateDeck.gameObject.SetActive(true);
  185. if (!((RectTransform)cardPrefab_CreateDeck.transform).IsVisibleFrom(Opening.instance.MainCamera))
  186. {
  187. cardPrefab_CreateDeck.CardImage.transform.parent.gameObject.SetActive(false);
  188. }
  189. else
  190. {
  191. cardPrefab_CreateDeck.CardImage.transform.parent.gameObject.SetActive(true);
  192. if (cardPrefab_CreateDeck.cEntity_Base != null)
  193. {
  194. //if (cardPrefab_CreateDeck.cEntity_Base.CardSprite != null)
  195. {
  196. cardPrefab_CreateDeck.ShowCardImage();
  197. }
  198. }
  199. }
  200. }
  201. }
  202. }
  203. }
  204. #endregion
  205. public bool isEditting { get; set; } = false;
  206. #region Close deck editing screen
  207. public void OnClickCompleteEditButton()
  208. {
  209. ContinuousController.instance.PlaySE(Opening.instance.DecisionSE);
  210. ContinuousController.instance.StartCoroutine(CloseCreateDeckCoroutine(false));
  211. }
  212. public void OnClickCancelEditButton()
  213. {
  214. ContinuousController.instance.PlaySE(Opening.instance.CancelSE);
  215. ContinuousController.instance.StartCoroutine(CloseCreateDeckCoroutine(true));
  216. }
  217. public IEnumerator CloseCreateDeckCoroutine(bool Canceled)
  218. {
  219. isEditting = false;
  220. yield return ContinuousController.instance.StartCoroutine(LoadingObjec.StartLoading("Now Loading"));
  221. Opening.instance.OffYesNoObjects();
  222. Opening.instance.deck.trialDraw.Close();
  223. Opening.instance.deck.deckListPanel.Close();
  224. for (int i = 0; i < Opening.instance.deck.selectDeck.deckInfoPrefabParentScroll.content.childCount; i++)
  225. {
  226. CreateNewDeckButton createNewDeckButton = Opening.instance.deck.selectDeck.deckInfoPrefabParentScroll.content.GetChild(i).GetComponent<CreateNewDeckButton>();
  227. if (createNewDeckButton != null)
  228. {
  229. createNewDeckButton.CreateNewDeckWayObject.Close_(false);
  230. break;
  231. }
  232. }
  233. if (Canceled)
  234. {
  235. EdittingDeckData.DeckCardIDs = DeckData.GetDeckCardCodes(DeckData.SortedDeckCardsList(_oldDeckCards));
  236. EdittingDeckData.DigitamaDeckCardIDs = DeckData.GetDeckCardCodes(DeckData.SortedDeckCardsList(_oldDigitamaDeckCards));
  237. EdittingDeckData.DeckName = _oldDeckName;
  238. EdittingDeckData.KeyCardId = _oldKeyCardId;
  239. }
  240. if (!EdittingDeckData.AllDeckCards().Contains(EdittingDeckData.KeyCard))
  241. {
  242. EdittingDeckData.KeyCardId = -1;
  243. }
  244. #region not save if deck is empty or canceled when importing from clipboard
  245. if (EdittingDeckData != null && (EdittingDeckData.DeckCards().Count == 0 && EdittingDeckData.DigitamaDeckCards().Count == 0 || (Canceled && _isFromClipboard)))
  246. {
  247. ContinuousController.instance.DeckDatas.Remove(EdittingDeckData);
  248. }
  249. #endregion
  250. ContinuousController.instance.SaveDeckDatas();
  251. ContinuousController.instance.SaveDeckData(EdittingDeckData);
  252. for (int i = 0; i < DeckScroll.content.childCount; i++)
  253. {
  254. Destroy(DeckScroll.content.GetChild(i).gameObject);
  255. }
  256. if (!Canceled)
  257. {
  258. EdittingDeckData.DeckCardIDs = DeckData.GetDeckCardCodes(DeckData.SortedDeckCardsList(EdittingDeckData.DeckCards()));
  259. EdittingDeckData.DigitamaDeckCardIDs = DeckData.GetDeckCardCodes(DeckData.SortedDeckCardsList(EdittingDeckData.DigitamaDeckCards()));
  260. }
  261. foreach (CardPrefab_CreateDeck cardPrefab_CreateDeck in _cardPoolPrefabs)
  262. {
  263. if (cardPrefab_CreateDeck._OnEnterCoroutine != null)
  264. {
  265. cardPrefab_CreateDeck.StopCoroutine(cardPrefab_CreateDeck._OnEnterCoroutine);
  266. cardPrefab_CreateDeck._OnEnterCoroutine = null;
  267. }
  268. cardPrefab_CreateDeck.StopAllCoroutines();
  269. cardPrefab_CreateDeck.gameObject.SetActive(false);
  270. }
  271. yield return new WaitUntil(() => DeckScroll.content.childCount == 0);
  272. yield return new WaitForSeconds(0.1f);
  273. CreateDeckObject.SetActive(false);
  274. #region Set up previous screen
  275. if (_isFromSelectDeck)
  276. {
  277. Opening.instance.deck.selectDeck.ResetDeckInfoPanel();
  278. yield return ContinuousController.instance.StartCoroutine(Opening.instance.deck.selectDeck.SetDeckList(false));
  279. for (int i = 0; i < Opening.instance.deck.selectDeck.deckInfoPrefabParentScroll.content.childCount; i++)
  280. {
  281. if (Opening.instance.deck.selectDeck.deckInfoPrefabParentScroll.content.GetChild(i).GetComponent<DeckInfoPrefab>() != null)
  282. {
  283. if (Opening.instance.deck.selectDeck.deckInfoPrefabParentScroll.content.GetChild(i).GetComponent<DeckInfoPrefab>().thisDeckData == EdittingDeckData)
  284. {
  285. if (Opening.instance.deck.selectDeck.deckInfoPrefabParentScroll.content.GetChild(i).GetComponent<DeckInfoPrefab>().thisDeckData != null)
  286. {
  287. if (Opening.instance.deck.selectDeck.deckInfoPrefabParentScroll.content.GetChild(i).GetComponent<DeckInfoPrefab>().thisDeckData.DeckCards().Count > 0)
  288. {
  289. Opening.instance.deck.selectDeck.deckInfoPrefabParentScroll.content.GetChild(i).GetComponent<DeckInfoPrefab>().OnClick_DeckInfoPrefab(false);
  290. }
  291. }
  292. }
  293. }
  294. }
  295. if (EdittingDeckData != null)
  296. {
  297. ContinuousController.instance.BattleDeckData = EdittingDeckData;
  298. }
  299. }
  300. else
  301. {
  302. Opening.instance.battle.selectBattleDeck.ResetDeckInfoPanel();
  303. yield return ContinuousController.instance.StartCoroutine(Opening.instance.battle.selectBattleDeck.SetDeckList(false));
  304. for (int i = 0; i < Opening.instance.battle.selectBattleDeck.deckInfoPrefabParentScroll.content.childCount; i++)
  305. {
  306. if (Opening.instance.battle.selectBattleDeck.deckInfoPrefabParentScroll.content.GetChild(i).GetComponent<DeckInfoPrefab>() != null)
  307. {
  308. if (Opening.instance.battle.selectBattleDeck.deckInfoPrefabParentScroll.content.GetChild(i).GetComponent<DeckInfoPrefab>().thisDeckData == EdittingDeckData)
  309. {
  310. Opening.instance.battle.selectBattleDeck.deckInfoPrefabParentScroll.content.GetChild(i).GetComponent<DeckInfoPrefab>().OnClick_DeckInfoPrefab(false);
  311. }
  312. }
  313. }
  314. }
  315. #endregion
  316. EndEditAction?.Invoke();
  317. EndEditAction = null;
  318. yield return ContinuousController.instance.StartCoroutine(LoadingObjec.EndLoading());
  319. }
  320. #endregion
  321. #region Open deck editing screen
  322. public void SetUpCreateDeck(DeckData deckData, bool isFromSelectDeck, bool isFromClipboard = false)
  323. {
  324. if (deckData == null)
  325. {
  326. return;
  327. }
  328. _isFromClipboard = isFromClipboard;
  329. Opening.instance.OffYesNoObjects();
  330. Opening.instance.deck.trialDraw.Close();
  331. Opening.instance.deck.deckListPanel.Close();
  332. _oldDeckName = deckData.DeckName;
  333. _oldDeckCards = new List<CEntity_Base>();
  334. foreach (CEntity_Base cEntity_Base in deckData.DeckCards())
  335. {
  336. _oldDeckCards.Add(cEntity_Base);
  337. }
  338. _oldDigitamaDeckCards = new List<CEntity_Base>();
  339. foreach (CEntity_Base cEntity_Base in deckData.DigitamaDeckCards())
  340. {
  341. _oldDigitamaDeckCards.Add(cEntity_Base);
  342. }
  343. _oldKeyCardId = deckData.KeyCardId;
  344. _checkCoverCoroutine = null;
  345. this._isFromSelectDeck = isFromSelectDeck;
  346. DisplayPageIndex = 0;
  347. SetCardData();
  348. CheckButtonEnabled();
  349. isSearchingObject.Off();
  350. ContinuousController.instance.StartCoroutine(SetUpCreateDeckCoroutine(deckData));
  351. }
  352. public IEnumerator SetUpCreateDeckCoroutine(DeckData deckData)
  353. {
  354. yield return ContinuousController.instance.StartCoroutine(LoadingObjec.StartLoading("Now Loading"));
  355. yield return new WaitForSeconds(0.1f);
  356. for (int i = 0; i < draggable_CardParent.childCount; i++)
  357. {
  358. Destroy(draggable_CardParent.GetChild(i).gameObject);
  359. }
  360. DraggingCover.SetActive(false);
  361. CardPoolScroll.verticalNormalizedPosition = 1;
  362. DeckScroll.verticalNormalizedPosition = 1;
  363. deckData.DeckCardIDs = DeckData.GetDeckCardCodes(DeckData.SortedDeckCardsList(deckData.DeckCards()));
  364. deckData.DigitamaDeckCardIDs = DeckData.GetDeckCardCodes(DeckData.SortedDeckCardsList(deckData.DigitamaDeckCards()));
  365. EdittingDeckData = deckData;
  366. ContinuousController.instance.SaveDeckDatas();
  367. //ContinuousController.instance.SaveDeckData(EdittingDeckData);
  368. OffDetailCard();
  369. for (int i = 0; i < DeckScroll.content.childCount; i++)
  370. {
  371. Destroy(DeckScroll.content.GetChild(i).gameObject);
  372. }
  373. yield return new WaitUntil(() => DeckScroll.content.childCount == 0);
  374. for (int i = 0; i < DeckScroll.viewport.childCount; i++)
  375. {
  376. if (i != 0)
  377. {
  378. Destroy(DeckScroll.viewport.GetChild(i).gameObject);
  379. }
  380. }
  381. yield return new WaitUntil(() => DeckScroll.viewport.childCount == 1);
  382. _maxDisplayPageIndex = (ContinuousController.instance.CardList.Length - 1) / _cardPoolPrefabs.Count;
  383. if (deckData != null)
  384. {
  385. List<CEntity_Base> DeckCards = new List<CEntity_Base>();
  386. foreach (CEntity_Base cEntity_Base in deckData.AllDeckCards())
  387. {
  388. DeckCards.Add(cEntity_Base);
  389. }
  390. foreach (CEntity_Base cEntity_Base in DeckCards)
  391. {
  392. CreateDeckCard(cEntity_Base);
  393. }
  394. }
  395. CreateDeckObject.SetActive(true);
  396. foreach (CardPrefab_CreateDeck _CardPrefab_CreateDeck in _cardPoolPrefabs)
  397. {
  398. _CardPrefab_CreateDeck.isActive = true;
  399. if (_CardPrefab_CreateDeck._OnEnterCoroutine != null)
  400. {
  401. _CardPrefab_CreateDeck.StopCoroutine(_CardPrefab_CreateDeck._OnEnterCoroutine);
  402. _CardPrefab_CreateDeck._OnEnterCoroutine = null;
  403. }
  404. }
  405. filterCardList.Init(() => ContinuousController.instance.StartCoroutine(ShowPoolCard_MatchCondition()));
  406. DeckNameInputField.onEndEdit.RemoveAllListeners();
  407. DeckNameInputField.text = EdittingDeckData.DeckName;
  408. DeckNameInputField.onEndEdit.AddListener(OnEndEdit);
  409. yield return ContinuousController.instance.StartCoroutine(SetSprittedCardLists());
  410. SetCardData();
  411. CheckButtonEnabled();
  412. ReflectDeckData();
  413. cardDistribution.SetCardDistribution(EdittingDeckData);
  414. yield return new WaitForSeconds(0.1f);
  415. for (int i = 0; i < DeckScroll.content.childCount; i++)
  416. {
  417. DeckScroll.content.GetChild(i).GetComponent<CardPrefab_CreateDeck>().ShowCardImage();
  418. }
  419. yield return StartCoroutine(LoadingObjec.EndLoading());
  420. isEditting = true;
  421. }
  422. public void OnEndEdit(string text)
  423. {
  424. ContinuousController.instance.RenameDeck(EdittingDeckData, text);
  425. DeckNameInputField.onEndEdit.RemoveAllListeners();
  426. DeckNameInputField.text = text;
  427. DeckNameInputField.onEndEdit.AddListener(OnEndEdit);
  428. }
  429. #endregion
  430. public List<CardPrefab_CreateDeck> CardPoolCardPrefabs_CreateDeck = new List<CardPrefab_CreateDeck>();
  431. #region Initialize the deck editing screen at the start of the game
  432. public List<CardPrefab_CreateDeck> cardPoolPrefabs_all = new List<CardPrefab_CreateDeck>();
  433. List<CardPrefab_CreateDeck> _cardPoolPrefabs = new List<CardPrefab_CreateDeck>();
  434. bool DoneSetUp { get; set; } = false;
  435. public IEnumerator InitEditDeck()
  436. {
  437. cardDistribution.Init();
  438. for (int i = 0; i < CardPoolScroll.content.childCount; i++)
  439. {
  440. CardPrefab_CreateDeck cardPrefab_CreateDeck = CardPoolScroll.content.GetChild(i).GetComponent<CardPrefab_CreateDeck>();
  441. if (cardPrefab_CreateDeck != null)
  442. {
  443. CardPoolCardPrefabs_CreateDeck.Add(cardPrefab_CreateDeck);
  444. }
  445. }
  446. for (int i = 0; i < DeckScroll.content.childCount; i++)
  447. {
  448. Destroy(DeckScroll.content.GetChild(i).gameObject);
  449. }
  450. foreach (CardPrefab_CreateDeck cardPrefab_CreateDeck in cardPoolPrefabs_all)
  451. {
  452. if (cardPrefab_CreateDeck.gameObject.activeSelf)
  453. {
  454. cardPrefab_CreateDeck.gameObject.SetActive(false);
  455. }
  456. }
  457. for (int i = 0; i < cardPoolPrefabs_all.Count; i++)
  458. {
  459. if (i < ContinuousController.instance.CardList.Length)
  460. {
  461. CardPrefab_CreateDeck _cardPrefab_CreateDeck = cardPoolPrefabs_all[i];
  462. _cardPoolPrefabs.Add(_cardPrefab_CreateDeck);
  463. CEntity_Base cEntity_Base = ContinuousController.instance.CardList[i];
  464. foreach (ScrollRect _scroll in _cardPrefab_CreateDeck.scroll)
  465. {
  466. _scroll.content = CardPoolScroll.content;
  467. _scroll.viewport = CardPoolScroll.viewport;
  468. _scroll.enabled = false;
  469. }
  470. _cardPrefab_CreateDeck.OnClickAction = () =>
  471. {
  472. StartCoroutine(AddDeckCardCoroutine_OnClick(_cardPrefab_CreateDeck));
  473. };
  474. _cardPrefab_CreateDeck.OnBeginDragAction = (cardPrefab_CreateDeck) => { StartCoroutine(OnBeginDrag(cardPrefab_CreateDeck)); };
  475. _cardPrefab_CreateDeck.OnEnterAction = (cardPrefab) =>
  476. {
  477. OnDetailCard(_cardPrefab_CreateDeck.cEntity_Base);
  478. };
  479. }
  480. }
  481. yield return ContinuousController.instance.StartCoroutine(SetSprittedCardLists());
  482. yield return new WaitForSeconds(0.1f);
  483. DoneSetUp = true;
  484. }
  485. #endregion
  486. #region Changed deck content changes to UI
  487. public void ReflectDeckData()
  488. {
  489. if (EdittingDeckData != null)
  490. {
  491. //Turn on covers for cards that cannot be included in the deck
  492. if (_checkCoverCoroutine != null)
  493. {
  494. StopCoroutine(_checkCoverCoroutine);
  495. }
  496. _checkCoverCoroutine = StartCoroutine(CheckCoverIEnumerator());
  497. SetDeckCountText();
  498. }
  499. }
  500. Coroutine _checkCoverCoroutine = null;
  501. IEnumerator CheckCoverIEnumerator()
  502. {
  503. foreach (CardPrefab_CreateDeck cardPrefab_CreateDeck in _cardPoolPrefabs)
  504. {
  505. yield return null;
  506. cardPrefab_CreateDeck.CheckCover(EdittingDeckData);
  507. }
  508. }
  509. #endregion
  510. #region Show deck number text
  511. public void SetDeckCountText()
  512. {
  513. DeckCountText.text = $"{EdittingDeckData.DeckCards().Count}+{EdittingDeckData.DigitamaDeckCards().Count}/50+5";
  514. if (EdittingDeckData.IsValidDeckData())
  515. {
  516. DeckCountText.color = new Color32(69, 255, 69, 255);
  517. }
  518. else
  519. {
  520. DeckCountText.color = new Color32(255, 64, 64, 255);
  521. }
  522. }
  523. #endregion
  524. #region Generate cards for deck
  525. public CardPrefab_CreateDeck CreateDeckCard(CEntity_Base cEntity_Base)
  526. {
  527. CardPrefab_CreateDeck _cardPrefab_CreateDeck = Instantiate(cardPrefab_CreateDeck, DeckScroll.content);
  528. SetUpDeckCard(_cardPrefab_CreateDeck, cEntity_Base);
  529. return _cardPrefab_CreateDeck;
  530. }
  531. public void SetUpDeckCard(CardPrefab_CreateDeck _cardPrefab_CreateDeck, CEntity_Base cEntity_Base)
  532. {
  533. foreach (ScrollRect _scroll in _cardPrefab_CreateDeck.scroll)
  534. {
  535. _scroll.content = DeckScroll.content;
  536. _scroll.viewport = DeckScroll.viewport;
  537. }
  538. _cardPrefab_CreateDeck.SetUpCardPrefab_CreateDeck(cEntity_Base);
  539. _cardPrefab_CreateDeck.ShowCardImage();
  540. _cardPrefab_CreateDeck.OnClickAction = () =>
  541. {
  542. StartCoroutine(RemoveDeckCardCoroutine_OnClick(_cardPrefab_CreateDeck));
  543. };
  544. _cardPrefab_CreateDeck.OnBeginDragAction = (cardPrefab_CreateDeck) => { StartCoroutine(OnBeginDrag(cardPrefab_CreateDeck)); };
  545. _cardPrefab_CreateDeck.OnEnterAction = (cardPrefab) =>
  546. {
  547. OnDetailCard(cEntity_Base);
  548. cardPrefab.SetupAddRemoveButton(EdittingDeckData);
  549. };
  550. _cardPrefab_CreateDeck.OnExitAction = (cardPrefab) =>
  551. {
  552. cardPrefab.OffAddRemoveButton();
  553. };
  554. _cardPrefab_CreateDeck.Parent.localScale = new Vector3(0.76f, 0.76f, 0.76f);
  555. _cardPrefab_CreateDeck.OnClickAddButtonAction = (cardPrefab) => StartCoroutine(AddDeckCardCoroutine_OnClick(cardPrefab));
  556. _cardPrefab_CreateDeck.OnClickRemoveButtonAction = (cardPrefab) => StartCoroutine(RemoveDeckCardCoroutine_OnClick(cardPrefab));
  557. }
  558. #endregion
  559. #region Display only cards that meet search/filter conditions
  560. bool MatchCondition(CEntity_Base cEntity_Base)
  561. {
  562. if (!filterCardList.OnlyContainsName()(cEntity_Base))
  563. {
  564. return false;
  565. }
  566. if (!filterCardList.OnlyContainsColor()(cEntity_Base))
  567. {
  568. return false;
  569. }
  570. if (!filterCardList.OnlyMatchRarity()(cEntity_Base))
  571. {
  572. return false;
  573. }
  574. if (!filterCardList.OnlyMatchCardKind()(cEntity_Base))
  575. {
  576. return false;
  577. }
  578. if (!filterCardList.OnlyMatchCardSet()(cEntity_Base))
  579. {
  580. return false;
  581. }
  582. if (!filterCardList.OnlyMatchPlayCost()(cEntity_Base))
  583. {
  584. return false;
  585. }
  586. if (!filterCardList.OnlyMatchLevel()(cEntity_Base))
  587. {
  588. return false;
  589. }
  590. if (!filterCardList.OnlyMatchSpecialCardKind()(cEntity_Base))
  591. {
  592. return false;
  593. }
  594. if (!filterCardList.OnlyMatchParallelCondition()(cEntity_Base))
  595. {
  596. return false;
  597. }
  598. return true;
  599. }
  600. public IEnumerator ShowPoolCard_MatchCondition()
  601. {
  602. DraggingCover.SetActive(true);
  603. DisplayPageIndex = 0;
  604. _maxDisplayPageIndex = (ContinuousController.instance.CardList.Count((cEntity_Base) => MatchCondition(cEntity_Base)) - 1) / _cardPoolPrefabs.Count;
  605. yield return ContinuousController.instance.StartCoroutine(SetSprittedCardLists());
  606. SetCardData();
  607. CheckButtonEnabled();
  608. ReflectDeckData();
  609. DraggingCover.SetActive(false);
  610. for (int i = 0; i < CardPoolCardPrefabs_CreateDeck.Count; i++)
  611. {
  612. CardPrefab_CreateDeck cardPrefab_CreateDeck = CardPoolCardPrefabs_CreateDeck[i];
  613. if (cardPrefab_CreateDeck != null)
  614. {
  615. cardPrefab_CreateDeck.uIShiny.enabled = false;
  616. if (cardPrefab_CreateDeck._OnEnterCoroutine != null)
  617. {
  618. cardPrefab_CreateDeck.StopCoroutine(cardPrefab_CreateDeck._OnEnterCoroutine);
  619. cardPrefab_CreateDeck._OnEnterCoroutine = null;
  620. }
  621. cardPrefab_CreateDeck.StopAllCoroutines();
  622. }
  623. }
  624. }
  625. #endregion
  626. #region Manipulating card objects
  627. [Header("draggable card object")]
  628. public Draggable_Card draggable_CardPrefab;
  629. [Header("draggable card object parent")]
  630. public Transform draggable_CardParent;
  631. [Header("Deck card dropArea")]
  632. public DropArea DeckCardsDropArea;
  633. [Header("card pool dropArea")]
  634. public DropArea CardPoolDropArea;
  635. [Header("Cover while dragging")]
  636. public GameObject DraggingCover;
  637. [Header("Coordinates of the disappearing deck card")]
  638. public Transform DisappearDeckCardTransform;
  639. //Is it draggable?
  640. public bool CanDrag { get; set; } = true;
  641. //Whether you are dragging
  642. public bool isDragging { get; set; } = false;
  643. #region Generate draggable objects
  644. public Draggable_Card CreateDraggable_Card()
  645. {
  646. Draggable_Card draggable_Card = Instantiate(draggable_CardPrefab, draggable_CardParent);
  647. draggable_Card.DefaultParent = draggable_CardParent;
  648. draggable_Card.transform.localScale = new Vector3(1, 1, 1);
  649. draggable_Card.CardImage.color = new Color(1, 1, 1, 1);
  650. return draggable_Card;
  651. }
  652. #endregion
  653. #region At the start of drag
  654. public IEnumerator OnBeginDrag(CardPrefab_CreateDeck _cardPrefab_CreateDeck)
  655. {
  656. if (_cardPrefab_CreateDeck.transform.parent == CardPoolScroll.content)
  657. {
  658. if (!DeckBuildingRule.CanAddCard(_cardPrefab_CreateDeck.cEntity_Base, EdittingDeckData))
  659. {
  660. yield break;
  661. }
  662. }
  663. if (Input.GetMouseButton(1))
  664. {
  665. yield break;
  666. }
  667. if (!isDragging && CanDrag)
  668. {
  669. Draggable_Card draggable_Card = CreateDraggable_Card();
  670. SetStartDrag(_cardPrefab_CreateDeck, draggable_Card);
  671. draggable_Card.OnDropAction = (dropAreas) => { OnEndDrag(dropAreas, _cardPrefab_CreateDeck, draggable_Card); };
  672. draggable_Card.OnDragAction = (dropAreas) =>
  673. {
  674. DeckCardsDropArea.OnPointerExit();
  675. CardPoolDropArea.OnPointerExit();
  676. if (_cardPrefab_CreateDeck.transform.parent == DeckScroll.content)
  677. {
  678. if (dropAreas.Count((dropArea) => dropArea == CardPoolDropArea) > 0)
  679. {
  680. CardPoolDropArea.OnPointerEnter();
  681. }
  682. }
  683. else if (_cardPrefab_CreateDeck.transform.parent == CardPoolScroll.content)
  684. {
  685. if (dropAreas.Count((dropArea) => dropArea == DeckCardsDropArea) > 0)
  686. {
  687. DeckCardsDropArea.OnPointerEnter();
  688. }
  689. }
  690. };
  691. if (_cardPrefab_CreateDeck.transform.parent == DeckScroll.content)
  692. {
  693. DeckCardsDropArea.OffDropPanel();
  694. CardPoolDropArea.OnDropPanel();
  695. _cardPrefab_CreateDeck.HideDeckCardTab();
  696. _cardPrefab_CreateDeck.OffAddRemoveButton();
  697. }
  698. else if (_cardPrefab_CreateDeck.transform.parent == CardPoolScroll.content)
  699. {
  700. DeckCardsDropArea.OnDropPanel();
  701. CardPoolDropArea.OffDropPanel();
  702. }
  703. DeckScroll.enabled = false;
  704. for (int i = 0; i < DeckScroll.content.childCount; i++)
  705. {
  706. foreach (ScrollRect scroll in DeckScroll.content.GetChild(i).GetComponent<CardPrefab_CreateDeck>().scroll)
  707. {
  708. scroll.enabled = false;
  709. }
  710. }
  711. CardPoolScroll.enabled = false;
  712. for (int i = 0; i < _cardPoolPrefabs.Count; i++)
  713. {
  714. foreach (ScrollRect scroll in _cardPoolPrefabs[i].scroll)
  715. {
  716. scroll.enabled = false;
  717. }
  718. }
  719. }
  720. }
  721. public void SetStartDrag(CardPrefab_CreateDeck _cardPrefab_CreateDeck, Draggable_Card draggable_Card)
  722. {
  723. isDragging = true;
  724. CanDrag = false;
  725. DraggingCover.SetActive(true);
  726. draggable_Card.SetUpDraggable_Card(_cardPrefab_CreateDeck.cEntity_Base, _cardPrefab_CreateDeck.transform.position);
  727. }
  728. #endregion
  729. #region At the end of dragging
  730. public void OnEndDrag(List<DropArea> dropAreas, CardPrefab_CreateDeck _cardPrefab_CreateDeck, Draggable_Card draggable_Card)
  731. {
  732. DeckCardsDropArea.OffDropPanel();
  733. CardPoolDropArea.OffDropPanel();
  734. StartCoroutine(OnEndDragCoroutine(dropAreas, _cardPrefab_CreateDeck, draggable_Card));
  735. DeckScroll.enabled = true;
  736. for (int i = 0; i < DeckScroll.content.childCount; i++)
  737. {
  738. foreach (ScrollRect scroll in DeckScroll.content.GetChild(i).GetComponent<CardPrefab_CreateDeck>().scroll)
  739. {
  740. scroll.enabled = true;
  741. }
  742. }
  743. CardPoolScroll.enabled = true;
  744. for (int i = 0; i < _cardPoolPrefabs.Count; i++)
  745. {
  746. foreach (ScrollRect scroll in _cardPoolPrefabs[i].scroll)
  747. {
  748. scroll.enabled = true;
  749. }
  750. }
  751. }
  752. IEnumerator OnEndDragCoroutine(List<DropArea> dropAreas, CardPrefab_CreateDeck _cardPrefab_CreateDeck, Draggable_Card draggable_Card)
  753. {
  754. if (_cardPrefab_CreateDeck.transform.parent == DeckScroll.content)
  755. {
  756. if (dropAreas.Count((dropArea) => dropArea == CardPoolDropArea) > 0)
  757. {
  758. yield return StartCoroutine(RemoveDeckCardCoroutine(_cardPrefab_CreateDeck, draggable_Card));
  759. }
  760. else
  761. {
  762. _cardPrefab_CreateDeck.ShowCardImage();
  763. }
  764. }
  765. else if (_cardPrefab_CreateDeck.transform.parent == CardPoolScroll.content)
  766. {
  767. if (dropAreas.Count((dropArea) => dropArea == DeckCardsDropArea) > 0)
  768. {
  769. yield return StartCoroutine(AddDeckCardCoroutine(_cardPrefab_CreateDeck, draggable_Card));
  770. }
  771. }
  772. Reset_EndDrag(draggable_Card);
  773. }
  774. public void Reset_EndDrag(Draggable_Card draggable_Card)
  775. {
  776. isDragging = false;
  777. DestroyImmediate(draggable_Card.gameObject);
  778. CanDrag = true;
  779. DraggingCover.SetActive(false);
  780. }
  781. #endregion
  782. float _addCardAnimationTime = 0.01f;
  783. #region Animation to add cards to deck when dropped
  784. IEnumerator AddDeckCardCoroutine(CardPrefab_CreateDeck _cardPrefab_CreateDeck, Draggable_Card draggable_Card)
  785. {
  786. if (!DeckBuildingRule.CanAddCard(_cardPrefab_CreateDeck.cEntity_Base, EdittingDeckData))
  787. {
  788. yield break;
  789. }
  790. ContinuousController.instance.PlaySE(Opening.instance.DrawSE);
  791. for (int i = 0; i < CardPoolCardPrefabs_CreateDeck.Count; i++)
  792. {
  793. CardPrefab_CreateDeck cardPrefab_CreateDeck = CardPoolCardPrefabs_CreateDeck[i];
  794. if (cardPrefab_CreateDeck != null)
  795. {
  796. cardPrefab_CreateDeck.uIShiny.enabled = false;
  797. cardPrefab_CreateDeck.OffAddRemoveButton();
  798. }
  799. }
  800. Debug.Log($"CARD TO ADD: {_cardPrefab_CreateDeck.cEntity_Base}");
  801. yield return StartCoroutine(AddDeckCards(_cardPrefab_CreateDeck.cEntity_Base));
  802. List<CEntity_Base> DeckCards = new List<CEntity_Base>();
  803. foreach (CEntity_Base cEntity_Base in EdittingDeckData.AllDeckCards())
  804. {
  805. //Debug.Log($"ADD: {cEntity_Base.CardIndex} || {cEntity_Base.CardID}");
  806. DeckCards.Add(cEntity_Base);
  807. }
  808. Debug.Log($"ADDED EDITTING DECK DATA ENTITIES TO DECK CARDS LIST: {DeckCards.Count} || {DeckCards.IndexOf(_cardPrefab_CreateDeck.cEntity_Base)} || {DeckCards.Count((cEntity_Base) => cEntity_Base == _cardPrefab_CreateDeck.cEntity_Base)}");
  809. int index = DeckCards.IndexOf(_cardPrefab_CreateDeck.cEntity_Base) + DeckCards.Count((cEntity_Base) => cEntity_Base == _cardPrefab_CreateDeck.cEntity_Base) - 1;
  810. Debug.Log("GETTING INDEX OF LAST ADDED CARD: " + index);
  811. CardPrefab_CreateDeck newCardPrefab = CreateDeckCard(_cardPrefab_CreateDeck.cEntity_Base);
  812. newCardPrefab.HideDeckCardTab();
  813. newCardPrefab.transform.SetSiblingIndex(index);
  814. List<CardPrefab_CreateDeck> cardPrefabs = new List<CardPrefab_CreateDeck>();
  815. for (int i = 0; i < DeckScroll.content.childCount; i++)
  816. {
  817. CardPrefab_CreateDeck cardPrefab = DeckScroll.content.GetChild(i).GetComponent<CardPrefab_CreateDeck>();
  818. if (cardPrefab != null)
  819. {
  820. cardPrefabs.Add(cardPrefab);
  821. if (cardPrefab.AddRemoveButtonParent.activeSelf)
  822. {
  823. cardPrefab.OffAddRemoveButton();
  824. cardPrefab.SetupAddRemoveButton(EdittingDeckData);
  825. }
  826. }
  827. }
  828. foreach (CardPrefab_CreateDeck cardPrefab in cardPrefabs)
  829. {
  830. cardPrefab.transform.SetParent(null);
  831. }
  832. foreach (CEntity_Base cEntity_Base in EdittingDeckData.AllDeckCards())
  833. {
  834. for (int i = 0; i < cardPrefabs.Count; i++)
  835. {
  836. if (cardPrefabs[i].cEntity_Base == cEntity_Base)
  837. {
  838. cardPrefabs[i].transform.SetParent(DeckScroll.content);
  839. cardPrefabs.Remove(cardPrefabs[i]);
  840. break;
  841. }
  842. }
  843. }
  844. yield return new WaitForSeconds(Time.deltaTime);
  845. bool end = false;
  846. var sequence = DOTween.Sequence();
  847. sequence
  848. .Append(draggable_Card.transform.DOMove(newCardPrefab.transform.position, _addCardAnimationTime))
  849. .Join(draggable_Card.transform.DOScale(new Vector3(0.5f, 0.5f, 0.5f), _addCardAnimationTime))
  850. .AppendCallback(() => end = true);
  851. sequence.Play();
  852. yield return new WaitWhile(() => !end);
  853. end = false;
  854. yield return new WaitForSeconds(_addCardAnimationTime);
  855. newCardPrefab.ShowCardImage();
  856. draggable_Card.gameObject.SetActive(false);
  857. }
  858. #endregion
  859. #region Animation to remove cards on drop
  860. IEnumerator RemoveDeckCardCoroutine(CardPrefab_CreateDeck _cardPrefab_CreateDeck, Draggable_Card draggable_Card)
  861. {
  862. ContinuousController.instance.PlaySE(Opening.instance.DrawSE);
  863. bool end = false;
  864. yield return StartCoroutine(RemoveDeckCards(_cardPrefab_CreateDeck.cEntity_Base));
  865. var sequence = DOTween.Sequence();
  866. sequence
  867. .Append(draggable_Card.transform.DOMove(DisappearDeckCardTransform.position, _addCardAnimationTime))
  868. .Join(draggable_Card.transform.DOScale(new Vector3(0.5f, 0.5f, 0.5f), _addCardAnimationTime))
  869. .AppendCallback(() => end = true);
  870. sequence.Play();
  871. yield return new WaitWhile(() => !end);
  872. end = false;
  873. yield return new WaitForSeconds(_addCardAnimationTime);
  874. draggable_Card.gameObject.SetActive(false);
  875. if (_cardPrefab_CreateDeck.transform.parent != CardPoolScroll.content)
  876. {
  877. DestroyImmediate(_cardPrefab_CreateDeck.gameObject);
  878. }
  879. }
  880. #endregion
  881. #region Add card to deck animation when right-clicking
  882. public IEnumerator AddDeckCardCoroutine_OnClick(CardPrefab_CreateDeck _cardPrefab_CreateDeck)
  883. {
  884. if (!DeckBuildingRule.CanAddCard(_cardPrefab_CreateDeck.cEntity_Base, EdittingDeckData))
  885. {
  886. yield break;
  887. }
  888. Draggable_Card draggable_Card = CreateDraggable_Card();
  889. SetStartDrag(_cardPrefab_CreateDeck, draggable_Card);
  890. draggable_Card.IsDragging = false;
  891. yield return StartCoroutine(AddDeckCardCoroutine(_cardPrefab_CreateDeck, draggable_Card));
  892. Reset_EndDrag(draggable_Card);
  893. }
  894. #endregion
  895. #region Animation to remove cards from deck when right-clicking
  896. public IEnumerator RemoveDeckCardCoroutine_OnClick(CardPrefab_CreateDeck _cardPrefab_CreateDeck)
  897. {
  898. Draggable_Card draggable_Card = CreateDraggable_Card();
  899. _cardPrefab_CreateDeck.HideDeckCardTab();
  900. SetStartDrag(_cardPrefab_CreateDeck, draggable_Card);
  901. draggable_Card.IsDragging = false;
  902. yield return StartCoroutine(RemoveDeckCardCoroutine(_cardPrefab_CreateDeck, draggable_Card));
  903. Reset_EndDrag(draggable_Card);
  904. }
  905. #endregion
  906. #region add cards to deck
  907. public IEnumerator AddDeckCards(CEntity_Base cEntity_Base)
  908. {
  909. Debug.Log($"ADD DECK CARD: {cEntity_Base.CardID}: {DeckBuildingRule.CanAddCard(cEntity_Base, EdittingDeckData)}");
  910. if (!DeckBuildingRule.CanAddCard(cEntity_Base, EdittingDeckData))
  911. {
  912. yield break;
  913. }
  914. Debug.Log($"ADD DECK CARD: {EdittingDeckData.DeckCardIDs.Count}");
  915. EdittingDeckData.AddCard(cEntity_Base);
  916. Debug.Log($"ADD DECK CARD: {EdittingDeckData.DeckCardIDs.Count}");
  917. Debug.Log($"ADD DECK CARD: {EdittingDeckData.DeckCards().Count}");
  918. EdittingDeckData.DeckCardIDs = DeckData.GetDeckCardCodes(DeckData.SortedDeckCardsList(EdittingDeckData.DeckCards()));
  919. EdittingDeckData.DigitamaDeckCardIDs = DeckData.GetDeckCardCodes(DeckData.SortedDeckCardsList(EdittingDeckData.DigitamaDeckCards()));
  920. ReflectDeckData();
  921. cardDistribution.SetCardDistribution(EdittingDeckData);
  922. }
  923. #endregion
  924. #region remove cards from deck
  925. public IEnumerator RemoveDeckCards(CEntity_Base cEntity_Base)
  926. {
  927. if (cEntity_Base.cardKind.Contains(CardKind.DigiEgg))
  928. {
  929. if (EdittingDeckData.DigitamaDeckCards().Count((cardData) => cardData.CardID == cEntity_Base.CardID) <= 0)
  930. {
  931. yield break;
  932. }
  933. }
  934. else
  935. {
  936. if (EdittingDeckData.DeckCards().Count((cardData) => cardData.CardID == cEntity_Base.CardID) <= 0)
  937. {
  938. yield break;
  939. }
  940. }
  941. EdittingDeckData.RemoveCard(cEntity_Base);
  942. EdittingDeckData.DeckCardIDs = DeckData.GetDeckCardCodes(DeckData.SortedDeckCardsList(EdittingDeckData.DeckCards()));
  943. EdittingDeckData.DigitamaDeckCardIDs = DeckData.GetDeckCardCodes(DeckData.SortedDeckCardsList(EdittingDeckData.DigitamaDeckCards()));
  944. ReflectDeckData();
  945. cardDistribution.SetCardDistribution(EdittingDeckData);
  946. }
  947. #endregion
  948. #endregion
  949. public void OnPointerEnterBackground()
  950. {
  951. List<CardPrefab_CreateDeck> cardPrefabs = new List<CardPrefab_CreateDeck>();
  952. for (int i = 0; i < DeckScroll.content.childCount; i++)
  953. {
  954. CardPrefab_CreateDeck cardPrefab = DeckScroll.content.GetChild(i).GetComponent<CardPrefab_CreateDeck>();
  955. if (cardPrefab != null)
  956. {
  957. cardPrefabs.Add(cardPrefab);
  958. }
  959. }
  960. foreach (CardPrefab_CreateDeck cardPrefab in cardPrefabs)
  961. {
  962. if (cardPrefab != null)
  963. {
  964. cardPrefab._OnExit();
  965. }
  966. }
  967. }
  968. public Button TrialDrawButton;
  969. public void OnClickTrial5DrawButton()
  970. {
  971. Opening.instance.deck.trialDraw.Off();
  972. ContinuousController.instance.PlaySE(Opening.instance.DecisionSE);
  973. ContinuousController.instance.StartCoroutine(Opening.instance.deck.trialDraw.SetUpTrialDraw(EdittingDeckData.DeckCards()));
  974. }
  975. public Button ClearDeckButton;
  976. public void OnClickClearDeckButton()
  977. {
  978. List<UnityAction> Commands = new List<UnityAction>()
  979. {
  980. () =>
  981. {
  982. ContinuousController.instance.StartCoroutine(ClearDeckCoroutine());
  983. IEnumerator ClearDeckCoroutine()
  984. {
  985. DraggingCover.SetActive(true);
  986. List<CEntity_Base> cEntity_Bases = new List<CEntity_Base>();
  987. foreach(CEntity_Base cEntity_Base in EdittingDeckData.DeckCards())
  988. {
  989. cEntity_Bases.Add(cEntity_Base);
  990. }
  991. foreach(CEntity_Base cEntity_Base in EdittingDeckData.DigitamaDeckCards())
  992. {
  993. cEntity_Bases.Add(cEntity_Base);
  994. }
  995. foreach(CEntity_Base cEntity_Base in cEntity_Bases)
  996. {
  997. yield return ContinuousController.instance.StartCoroutine(RemoveDeckCards(cEntity_Base));
  998. }
  999. for (int i = 0; i < DeckScroll.content.childCount; i++)
  1000. {
  1001. Destroy(DeckScroll.content.GetChild(i).gameObject);
  1002. }
  1003. yield return new WaitWhile(() => DeckScroll.content.childCount >= 1);
  1004. DraggingCover.SetActive(false);
  1005. }
  1006. },
  1007. null,
  1008. };
  1009. List<string> CommandTexts = new List<string>()
  1010. {
  1011. LocalizeUtility.GetLocalizedString(
  1012. EngMessage: "Yes",
  1013. JpnMessage: "はい"
  1014. ),
  1015. LocalizeUtility.GetLocalizedString(
  1016. EngMessage: "No",
  1017. JpnMessage: "いいえ"
  1018. ),
  1019. };
  1020. Opening.instance.SetUpActiveYesNoObject(
  1021. Commands,
  1022. CommandTexts,
  1023. LocalizeUtility.GetLocalizedString(
  1024. EngMessage: "Remove all cards from the deck?",
  1025. JpnMessage: "全てのカードをデッキから除きますか?"
  1026. ),
  1027. true);
  1028. }
  1029. public void OnClickSetDeckIconButton()
  1030. {
  1031. ContinuousController.instance.StartCoroutine(Opening.instance.deck.deckListPanel.SetUpDeckListPanel(
  1032. EdittingDeckData,
  1033. OnClick,
  1034. LocalizeUtility.GetLocalizedString(
  1035. EngMessage: "Choose a deck icon card.",
  1036. JpnMessage: "デッキアイコン選択"
  1037. )));
  1038. void OnClick(CEntity_Base cEntity_Base)
  1039. {
  1040. EdittingDeckData.KeyCardId = cEntity_Base.CardIndex;
  1041. Opening.instance.deck.deckListPanel.Close();
  1042. Opening.instance.PlayDecisionSE();
  1043. }
  1044. }
  1045. }