EditDeck.cs 43 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. string deckName = text;
  425. deckName = DeckData.ValidateDeckName(deckName);
  426. ContinuousController.instance.RenameDeck(EdittingDeckData, text);
  427. DeckNameInputField.onEndEdit.RemoveAllListeners();
  428. DeckNameInputField.text = deckName;
  429. DeckNameInputField.onEndEdit.AddListener(OnEndEdit);
  430. }
  431. #endregion
  432. public List<CardPrefab_CreateDeck> CardPoolCardPrefabs_CreateDeck = new List<CardPrefab_CreateDeck>();
  433. #region Initialize the deck editing screen at the start of the game
  434. public List<CardPrefab_CreateDeck> cardPoolPrefabs_all = new List<CardPrefab_CreateDeck>();
  435. List<CardPrefab_CreateDeck> _cardPoolPrefabs = new List<CardPrefab_CreateDeck>();
  436. bool DoneSetUp { get; set; } = false;
  437. public IEnumerator InitEditDeck()
  438. {
  439. cardDistribution.Init();
  440. for (int i = 0; i < CardPoolScroll.content.childCount; i++)
  441. {
  442. CardPrefab_CreateDeck cardPrefab_CreateDeck = CardPoolScroll.content.GetChild(i).GetComponent<CardPrefab_CreateDeck>();
  443. if (cardPrefab_CreateDeck != null)
  444. {
  445. CardPoolCardPrefabs_CreateDeck.Add(cardPrefab_CreateDeck);
  446. }
  447. }
  448. for (int i = 0; i < DeckScroll.content.childCount; i++)
  449. {
  450. Destroy(DeckScroll.content.GetChild(i).gameObject);
  451. }
  452. foreach (CardPrefab_CreateDeck cardPrefab_CreateDeck in cardPoolPrefabs_all)
  453. {
  454. if (cardPrefab_CreateDeck.gameObject.activeSelf)
  455. {
  456. cardPrefab_CreateDeck.gameObject.SetActive(false);
  457. }
  458. }
  459. for (int i = 0; i < cardPoolPrefabs_all.Count; i++)
  460. {
  461. if (i < ContinuousController.instance.CardList.Length)
  462. {
  463. CardPrefab_CreateDeck _cardPrefab_CreateDeck = cardPoolPrefabs_all[i];
  464. _cardPoolPrefabs.Add(_cardPrefab_CreateDeck);
  465. CEntity_Base cEntity_Base = ContinuousController.instance.CardList[i];
  466. foreach (ScrollRect _scroll in _cardPrefab_CreateDeck.scroll)
  467. {
  468. _scroll.content = CardPoolScroll.content;
  469. _scroll.viewport = CardPoolScroll.viewport;
  470. _scroll.enabled = false;
  471. }
  472. _cardPrefab_CreateDeck.OnClickAction = () =>
  473. {
  474. StartCoroutine(AddDeckCardCoroutine_OnClick(_cardPrefab_CreateDeck));
  475. };
  476. _cardPrefab_CreateDeck.OnBeginDragAction = (cardPrefab_CreateDeck) => { StartCoroutine(OnBeginDrag(cardPrefab_CreateDeck)); };
  477. _cardPrefab_CreateDeck.OnEnterAction = (cardPrefab) =>
  478. {
  479. OnDetailCard(_cardPrefab_CreateDeck.cEntity_Base);
  480. };
  481. }
  482. }
  483. yield return ContinuousController.instance.StartCoroutine(SetSprittedCardLists());
  484. yield return new WaitForSeconds(0.1f);
  485. DoneSetUp = true;
  486. }
  487. #endregion
  488. #region Changed deck content changes to UI
  489. public void ReflectDeckData()
  490. {
  491. if (EdittingDeckData != null)
  492. {
  493. //Turn on covers for cards that cannot be included in the deck
  494. if (_checkCoverCoroutine != null)
  495. {
  496. StopCoroutine(_checkCoverCoroutine);
  497. }
  498. _checkCoverCoroutine = StartCoroutine(CheckCoverIEnumerator());
  499. SetDeckCountText();
  500. }
  501. }
  502. Coroutine _checkCoverCoroutine = null;
  503. IEnumerator CheckCoverIEnumerator()
  504. {
  505. foreach (CardPrefab_CreateDeck cardPrefab_CreateDeck in _cardPoolPrefabs)
  506. {
  507. yield return null;
  508. cardPrefab_CreateDeck.CheckCover(EdittingDeckData);
  509. }
  510. }
  511. #endregion
  512. #region Show deck number text
  513. public void SetDeckCountText()
  514. {
  515. DeckCountText.text = $"{EdittingDeckData.DeckCards().Count}+{EdittingDeckData.DigitamaDeckCards().Count}/50+5";
  516. if (EdittingDeckData.IsValidDeckData())
  517. {
  518. DeckCountText.color = new Color32(69, 255, 69, 255);
  519. }
  520. else
  521. {
  522. DeckCountText.color = new Color32(255, 64, 64, 255);
  523. }
  524. }
  525. #endregion
  526. #region Generate cards for deck
  527. public CardPrefab_CreateDeck CreateDeckCard(CEntity_Base cEntity_Base)
  528. {
  529. CardPrefab_CreateDeck _cardPrefab_CreateDeck = Instantiate(cardPrefab_CreateDeck, DeckScroll.content);
  530. SetUpDeckCard(_cardPrefab_CreateDeck, cEntity_Base);
  531. return _cardPrefab_CreateDeck;
  532. }
  533. public void SetUpDeckCard(CardPrefab_CreateDeck _cardPrefab_CreateDeck, CEntity_Base cEntity_Base)
  534. {
  535. foreach (ScrollRect _scroll in _cardPrefab_CreateDeck.scroll)
  536. {
  537. _scroll.content = DeckScroll.content;
  538. _scroll.viewport = DeckScroll.viewport;
  539. }
  540. _cardPrefab_CreateDeck.SetUpCardPrefab_CreateDeck(cEntity_Base);
  541. _cardPrefab_CreateDeck.ShowCardImage();
  542. _cardPrefab_CreateDeck.OnClickAction = () =>
  543. {
  544. StartCoroutine(RemoveDeckCardCoroutine_OnClick(_cardPrefab_CreateDeck));
  545. };
  546. _cardPrefab_CreateDeck.OnBeginDragAction = (cardPrefab_CreateDeck) => { StartCoroutine(OnBeginDrag(cardPrefab_CreateDeck)); };
  547. _cardPrefab_CreateDeck.OnEnterAction = (cardPrefab) =>
  548. {
  549. OnDetailCard(cEntity_Base);
  550. cardPrefab.SetupAddRemoveButton(EdittingDeckData);
  551. };
  552. _cardPrefab_CreateDeck.OnExitAction = (cardPrefab) =>
  553. {
  554. cardPrefab.OffAddRemoveButton();
  555. };
  556. _cardPrefab_CreateDeck.Parent.localScale = new Vector3(0.76f, 0.76f, 0.76f);
  557. _cardPrefab_CreateDeck.OnClickAddButtonAction = (cardPrefab) => StartCoroutine(AddDeckCardCoroutine_OnClick(cardPrefab));
  558. _cardPrefab_CreateDeck.OnClickRemoveButtonAction = (cardPrefab) => StartCoroutine(RemoveDeckCardCoroutine_OnClick(cardPrefab));
  559. }
  560. #endregion
  561. #region Display only cards that meet search/filter conditions
  562. bool MatchCondition(CEntity_Base cEntity_Base)
  563. {
  564. if (!filterCardList.OnlyContainsName()(cEntity_Base))
  565. {
  566. return false;
  567. }
  568. if (!filterCardList.OnlyContainsColor()(cEntity_Base))
  569. {
  570. return false;
  571. }
  572. if (!filterCardList.OnlyMatchRarity()(cEntity_Base))
  573. {
  574. return false;
  575. }
  576. if (!filterCardList.OnlyMatchCardKind()(cEntity_Base))
  577. {
  578. return false;
  579. }
  580. if (!filterCardList.OnlyMatchCardSet()(cEntity_Base))
  581. {
  582. return false;
  583. }
  584. if (!filterCardList.OnlyMatchPlayCost()(cEntity_Base))
  585. {
  586. return false;
  587. }
  588. if (!filterCardList.OnlyMatchLevel()(cEntity_Base))
  589. {
  590. return false;
  591. }
  592. if (!filterCardList.OnlyMatchSpecialCardKind()(cEntity_Base))
  593. {
  594. return false;
  595. }
  596. if (!filterCardList.OnlyMatchParallelCondition()(cEntity_Base))
  597. {
  598. return false;
  599. }
  600. return true;
  601. }
  602. public IEnumerator ShowPoolCard_MatchCondition()
  603. {
  604. DraggingCover.SetActive(true);
  605. DisplayPageIndex = 0;
  606. _maxDisplayPageIndex = (ContinuousController.instance.CardList.Count((cEntity_Base) => MatchCondition(cEntity_Base)) - 1) / _cardPoolPrefabs.Count;
  607. yield return ContinuousController.instance.StartCoroutine(SetSprittedCardLists());
  608. SetCardData();
  609. CheckButtonEnabled();
  610. ReflectDeckData();
  611. DraggingCover.SetActive(false);
  612. for (int i = 0; i < CardPoolCardPrefabs_CreateDeck.Count; i++)
  613. {
  614. CardPrefab_CreateDeck cardPrefab_CreateDeck = CardPoolCardPrefabs_CreateDeck[i];
  615. if (cardPrefab_CreateDeck != null)
  616. {
  617. cardPrefab_CreateDeck.uIShiny.enabled = false;
  618. if (cardPrefab_CreateDeck._OnEnterCoroutine != null)
  619. {
  620. cardPrefab_CreateDeck.StopCoroutine(cardPrefab_CreateDeck._OnEnterCoroutine);
  621. cardPrefab_CreateDeck._OnEnterCoroutine = null;
  622. }
  623. cardPrefab_CreateDeck.StopAllCoroutines();
  624. }
  625. }
  626. }
  627. #endregion
  628. #region Manipulating card objects
  629. [Header("draggable card object")]
  630. public Draggable_Card draggable_CardPrefab;
  631. [Header("draggable card object parent")]
  632. public Transform draggable_CardParent;
  633. [Header("Deck card dropArea")]
  634. public DropArea DeckCardsDropArea;
  635. [Header("card pool dropArea")]
  636. public DropArea CardPoolDropArea;
  637. [Header("Cover while dragging")]
  638. public GameObject DraggingCover;
  639. [Header("Coordinates of the disappearing deck card")]
  640. public Transform DisappearDeckCardTransform;
  641. //Is it draggable?
  642. public bool CanDrag { get; set; } = true;
  643. //Whether you are dragging
  644. public bool isDragging { get; set; } = false;
  645. #region Generate draggable objects
  646. public Draggable_Card CreateDraggable_Card()
  647. {
  648. Draggable_Card draggable_Card = Instantiate(draggable_CardPrefab, draggable_CardParent);
  649. draggable_Card.DefaultParent = draggable_CardParent;
  650. draggable_Card.transform.localScale = new Vector3(1, 1, 1);
  651. draggable_Card.CardImage.color = new Color(1, 1, 1, 1);
  652. return draggable_Card;
  653. }
  654. #endregion
  655. #region At the start of drag
  656. public IEnumerator OnBeginDrag(CardPrefab_CreateDeck _cardPrefab_CreateDeck)
  657. {
  658. if (_cardPrefab_CreateDeck.transform.parent == CardPoolScroll.content)
  659. {
  660. if (!DeckBuildingRule.CanAddCard(_cardPrefab_CreateDeck.cEntity_Base, EdittingDeckData))
  661. {
  662. yield break;
  663. }
  664. }
  665. if (Input.GetMouseButton(1))
  666. {
  667. yield break;
  668. }
  669. if (!isDragging && CanDrag)
  670. {
  671. Draggable_Card draggable_Card = CreateDraggable_Card();
  672. SetStartDrag(_cardPrefab_CreateDeck, draggable_Card);
  673. draggable_Card.OnDropAction = (dropAreas) => { OnEndDrag(dropAreas, _cardPrefab_CreateDeck, draggable_Card); };
  674. draggable_Card.OnDragAction = (dropAreas) =>
  675. {
  676. DeckCardsDropArea.OnPointerExit();
  677. CardPoolDropArea.OnPointerExit();
  678. if (_cardPrefab_CreateDeck.transform.parent == DeckScroll.content)
  679. {
  680. if (dropAreas.Count((dropArea) => dropArea == CardPoolDropArea) > 0)
  681. {
  682. CardPoolDropArea.OnPointerEnter();
  683. }
  684. }
  685. else if (_cardPrefab_CreateDeck.transform.parent == CardPoolScroll.content)
  686. {
  687. if (dropAreas.Count((dropArea) => dropArea == DeckCardsDropArea) > 0)
  688. {
  689. DeckCardsDropArea.OnPointerEnter();
  690. }
  691. }
  692. };
  693. if (_cardPrefab_CreateDeck.transform.parent == DeckScroll.content)
  694. {
  695. DeckCardsDropArea.OffDropPanel();
  696. CardPoolDropArea.OnDropPanel();
  697. _cardPrefab_CreateDeck.HideDeckCardTab();
  698. _cardPrefab_CreateDeck.OffAddRemoveButton();
  699. }
  700. else if (_cardPrefab_CreateDeck.transform.parent == CardPoolScroll.content)
  701. {
  702. DeckCardsDropArea.OnDropPanel();
  703. CardPoolDropArea.OffDropPanel();
  704. }
  705. DeckScroll.enabled = false;
  706. for (int i = 0; i < DeckScroll.content.childCount; i++)
  707. {
  708. foreach (ScrollRect scroll in DeckScroll.content.GetChild(i).GetComponent<CardPrefab_CreateDeck>().scroll)
  709. {
  710. scroll.enabled = false;
  711. }
  712. }
  713. CardPoolScroll.enabled = false;
  714. for (int i = 0; i < _cardPoolPrefabs.Count; i++)
  715. {
  716. foreach (ScrollRect scroll in _cardPoolPrefabs[i].scroll)
  717. {
  718. scroll.enabled = false;
  719. }
  720. }
  721. }
  722. }
  723. public void SetStartDrag(CardPrefab_CreateDeck _cardPrefab_CreateDeck, Draggable_Card draggable_Card)
  724. {
  725. isDragging = true;
  726. CanDrag = false;
  727. DraggingCover.SetActive(true);
  728. draggable_Card.SetUpDraggable_Card(_cardPrefab_CreateDeck.cEntity_Base, _cardPrefab_CreateDeck.transform.position);
  729. }
  730. #endregion
  731. #region At the end of dragging
  732. public void OnEndDrag(List<DropArea> dropAreas, CardPrefab_CreateDeck _cardPrefab_CreateDeck, Draggable_Card draggable_Card)
  733. {
  734. DeckCardsDropArea.OffDropPanel();
  735. CardPoolDropArea.OffDropPanel();
  736. StartCoroutine(OnEndDragCoroutine(dropAreas, _cardPrefab_CreateDeck, draggable_Card));
  737. DeckScroll.enabled = true;
  738. for (int i = 0; i < DeckScroll.content.childCount; i++)
  739. {
  740. foreach (ScrollRect scroll in DeckScroll.content.GetChild(i).GetComponent<CardPrefab_CreateDeck>().scroll)
  741. {
  742. scroll.enabled = true;
  743. }
  744. }
  745. CardPoolScroll.enabled = true;
  746. for (int i = 0; i < _cardPoolPrefabs.Count; i++)
  747. {
  748. foreach (ScrollRect scroll in _cardPoolPrefabs[i].scroll)
  749. {
  750. scroll.enabled = true;
  751. }
  752. }
  753. }
  754. IEnumerator OnEndDragCoroutine(List<DropArea> dropAreas, CardPrefab_CreateDeck _cardPrefab_CreateDeck, Draggable_Card draggable_Card)
  755. {
  756. if (_cardPrefab_CreateDeck.transform.parent == DeckScroll.content)
  757. {
  758. if (dropAreas.Count((dropArea) => dropArea == CardPoolDropArea) > 0)
  759. {
  760. yield return StartCoroutine(RemoveDeckCardCoroutine(_cardPrefab_CreateDeck, draggable_Card));
  761. }
  762. else
  763. {
  764. _cardPrefab_CreateDeck.ShowCardImage();
  765. }
  766. }
  767. else if (_cardPrefab_CreateDeck.transform.parent == CardPoolScroll.content)
  768. {
  769. if (dropAreas.Count((dropArea) => dropArea == DeckCardsDropArea) > 0)
  770. {
  771. yield return StartCoroutine(AddDeckCardCoroutine(_cardPrefab_CreateDeck, draggable_Card));
  772. }
  773. }
  774. Reset_EndDrag(draggable_Card);
  775. }
  776. public void Reset_EndDrag(Draggable_Card draggable_Card)
  777. {
  778. isDragging = false;
  779. DestroyImmediate(draggable_Card.gameObject);
  780. CanDrag = true;
  781. DraggingCover.SetActive(false);
  782. }
  783. #endregion
  784. float _addCardAnimationTime = 0.01f;
  785. #region Animation to add cards to deck when dropped
  786. IEnumerator AddDeckCardCoroutine(CardPrefab_CreateDeck _cardPrefab_CreateDeck, Draggable_Card draggable_Card)
  787. {
  788. if (!DeckBuildingRule.CanAddCard(_cardPrefab_CreateDeck.cEntity_Base, EdittingDeckData))
  789. {
  790. yield break;
  791. }
  792. ContinuousController.instance.PlaySE(Opening.instance.DrawSE);
  793. for (int i = 0; i < CardPoolCardPrefabs_CreateDeck.Count; i++)
  794. {
  795. CardPrefab_CreateDeck cardPrefab_CreateDeck = CardPoolCardPrefabs_CreateDeck[i];
  796. if (cardPrefab_CreateDeck != null)
  797. {
  798. cardPrefab_CreateDeck.uIShiny.enabled = false;
  799. cardPrefab_CreateDeck.OffAddRemoveButton();
  800. }
  801. }
  802. yield return StartCoroutine(AddDeckCards(_cardPrefab_CreateDeck.cEntity_Base));
  803. List<CEntity_Base> DeckCards = new List<CEntity_Base>();
  804. foreach (CEntity_Base cEntity_Base in EdittingDeckData.AllDeckCards())
  805. {
  806. DeckCards.Add(cEntity_Base);
  807. }
  808. Debug.Log("ADDED EDITTING DECK DATA ENTITIES TO DECK CARDS LIST: " + DeckCards.Count);
  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. if (!DeckBuildingRule.CanAddCard(cEntity_Base, EdittingDeckData))
  910. {
  911. yield break;
  912. }
  913. EdittingDeckData.AddCard(cEntity_Base);
  914. EdittingDeckData.DeckCardIDs = DeckData.GetDeckCardCodes(DeckData.SortedDeckCardsList(EdittingDeckData.DeckCards()));
  915. EdittingDeckData.DigitamaDeckCardIDs = DeckData.GetDeckCardCodes(DeckData.SortedDeckCardsList(EdittingDeckData.DigitamaDeckCards()));
  916. ReflectDeckData();
  917. cardDistribution.SetCardDistribution(EdittingDeckData);
  918. }
  919. #endregion
  920. #region remove cards from deck
  921. public IEnumerator RemoveDeckCards(CEntity_Base cEntity_Base)
  922. {
  923. if (cEntity_Base.cardKind == CardKind.DigiEgg)
  924. {
  925. if (EdittingDeckData.DigitamaDeckCards().Count((cardData) => cardData.CardID == cEntity_Base.CardID) <= 0)
  926. {
  927. yield break;
  928. }
  929. }
  930. else
  931. {
  932. if (EdittingDeckData.DeckCards().Count((cardData) => cardData.CardID == cEntity_Base.CardID) <= 0)
  933. {
  934. yield break;
  935. }
  936. }
  937. EdittingDeckData.RemoveCard(cEntity_Base);
  938. EdittingDeckData.DeckCardIDs = DeckData.GetDeckCardCodes(DeckData.SortedDeckCardsList(EdittingDeckData.DeckCards()));
  939. EdittingDeckData.DigitamaDeckCardIDs = DeckData.GetDeckCardCodes(DeckData.SortedDeckCardsList(EdittingDeckData.DigitamaDeckCards()));
  940. ReflectDeckData();
  941. cardDistribution.SetCardDistribution(EdittingDeckData);
  942. }
  943. #endregion
  944. #endregion
  945. public void OnPointerEnterBackground()
  946. {
  947. List<CardPrefab_CreateDeck> cardPrefabs = new List<CardPrefab_CreateDeck>();
  948. for (int i = 0; i < DeckScroll.content.childCount; i++)
  949. {
  950. CardPrefab_CreateDeck cardPrefab = DeckScroll.content.GetChild(i).GetComponent<CardPrefab_CreateDeck>();
  951. if (cardPrefab != null)
  952. {
  953. cardPrefabs.Add(cardPrefab);
  954. }
  955. }
  956. foreach (CardPrefab_CreateDeck cardPrefab in cardPrefabs)
  957. {
  958. if (cardPrefab != null)
  959. {
  960. cardPrefab._OnExit();
  961. }
  962. }
  963. }
  964. public Button TrialDrawButton;
  965. public void OnClickTrial5DrawButton()
  966. {
  967. Opening.instance.deck.trialDraw.Off();
  968. ContinuousController.instance.PlaySE(Opening.instance.DecisionSE);
  969. ContinuousController.instance.StartCoroutine(Opening.instance.deck.trialDraw.SetUpTrialDraw(EdittingDeckData.DeckCards()));
  970. }
  971. public Button ClearDeckButton;
  972. public void OnClickClearDeckButton()
  973. {
  974. List<UnityAction> Commands = new List<UnityAction>()
  975. {
  976. () =>
  977. {
  978. ContinuousController.instance.StartCoroutine(ClearDeckCoroutine());
  979. IEnumerator ClearDeckCoroutine()
  980. {
  981. DraggingCover.SetActive(true);
  982. List<CEntity_Base> cEntity_Bases = new List<CEntity_Base>();
  983. foreach(CEntity_Base cEntity_Base in EdittingDeckData.DeckCards())
  984. {
  985. cEntity_Bases.Add(cEntity_Base);
  986. }
  987. foreach(CEntity_Base cEntity_Base in EdittingDeckData.DigitamaDeckCards())
  988. {
  989. cEntity_Bases.Add(cEntity_Base);
  990. }
  991. foreach(CEntity_Base cEntity_Base in cEntity_Bases)
  992. {
  993. yield return ContinuousController.instance.StartCoroutine(RemoveDeckCards(cEntity_Base));
  994. }
  995. for (int i = 0; i < DeckScroll.content.childCount; i++)
  996. {
  997. Destroy(DeckScroll.content.GetChild(i).gameObject);
  998. }
  999. yield return new WaitWhile(() => DeckScroll.content.childCount >= 1);
  1000. DraggingCover.SetActive(false);
  1001. }
  1002. },
  1003. null,
  1004. };
  1005. List<string> CommandTexts = new List<string>()
  1006. {
  1007. LocalizeUtility.GetLocalizedString(
  1008. EngMessage: "Yes",
  1009. JpnMessage: "はい"
  1010. ),
  1011. LocalizeUtility.GetLocalizedString(
  1012. EngMessage: "No",
  1013. JpnMessage: "いいえ"
  1014. ),
  1015. };
  1016. Opening.instance.SetUpActiveYesNoObject(
  1017. Commands,
  1018. CommandTexts,
  1019. LocalizeUtility.GetLocalizedString(
  1020. EngMessage: "Remove all cards from the deck?",
  1021. JpnMessage: "全てのカードをデッキから除きますか?"
  1022. ),
  1023. true);
  1024. }
  1025. public void OnClickSetDeckIconButton()
  1026. {
  1027. ContinuousController.instance.StartCoroutine(Opening.instance.deck.deckListPanel.SetUpDeckListPanel(
  1028. EdittingDeckData,
  1029. OnClick,
  1030. LocalizeUtility.GetLocalizedString(
  1031. EngMessage: "Choose a deck icon card.",
  1032. JpnMessage: "デッキアイコン選択"
  1033. )));
  1034. void OnClick(CEntity_Base cEntity_Base)
  1035. {
  1036. EdittingDeckData.KeyCardId = cEntity_Base.CardIndex;
  1037. Opening.instance.deck.deckListPanel.Close();
  1038. Opening.instance.PlayDecisionSE();
  1039. }
  1040. }
  1041. }