EditDeck.cs 43 KB

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