EditDeck.cs 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355
  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. else
  250. {
  251. ContinuousController.instance.SaveDeckDatas();
  252. ContinuousController.instance.SaveDeckData(EdittingDeckData);
  253. }
  254. #endregion
  255. for (int i = 0; i < DeckScroll.content.childCount; i++)
  256. {
  257. Destroy(DeckScroll.content.GetChild(i).gameObject);
  258. }
  259. if (!Canceled)
  260. {
  261. EdittingDeckData.DeckCardIDs = DeckData.GetDeckCardCodes(DeckData.SortedDeckCardsList(EdittingDeckData.DeckCards()));
  262. EdittingDeckData.DigitamaDeckCardIDs = DeckData.GetDeckCardCodes(DeckData.SortedDeckCardsList(EdittingDeckData.DigitamaDeckCards()));
  263. }
  264. foreach (CardPrefab_CreateDeck cardPrefab_CreateDeck in _cardPoolPrefabs)
  265. {
  266. if (cardPrefab_CreateDeck._OnEnterCoroutine != null)
  267. {
  268. cardPrefab_CreateDeck.StopCoroutine(cardPrefab_CreateDeck._OnEnterCoroutine);
  269. cardPrefab_CreateDeck._OnEnterCoroutine = null;
  270. }
  271. cardPrefab_CreateDeck.StopAllCoroutines();
  272. cardPrefab_CreateDeck.gameObject.SetActive(false);
  273. }
  274. yield return new WaitUntil(() => DeckScroll.content.childCount == 0);
  275. yield return new WaitForSeconds(0.1f);
  276. CreateDeckObject.SetActive(false);
  277. #region Set up previous screen
  278. if (_isFromSelectDeck)
  279. {
  280. Opening.instance.deck.selectDeck.ResetDeckInfoPanel();
  281. yield return ContinuousController.instance.StartCoroutine(Opening.instance.deck.selectDeck.SetDeckList(false));
  282. for (int i = 0; i < Opening.instance.deck.selectDeck.deckInfoPrefabParentScroll.content.childCount; i++)
  283. {
  284. if (Opening.instance.deck.selectDeck.deckInfoPrefabParentScroll.content.GetChild(i).GetComponent<DeckInfoPrefab>() != null)
  285. {
  286. if (Opening.instance.deck.selectDeck.deckInfoPrefabParentScroll.content.GetChild(i).GetComponent<DeckInfoPrefab>().thisDeckData == EdittingDeckData)
  287. {
  288. if (Opening.instance.deck.selectDeck.deckInfoPrefabParentScroll.content.GetChild(i).GetComponent<DeckInfoPrefab>().thisDeckData != null)
  289. {
  290. if (Opening.instance.deck.selectDeck.deckInfoPrefabParentScroll.content.GetChild(i).GetComponent<DeckInfoPrefab>().thisDeckData.DeckCards().Count > 0)
  291. {
  292. Opening.instance.deck.selectDeck.deckInfoPrefabParentScroll.content.GetChild(i).GetComponent<DeckInfoPrefab>().OnClick_DeckInfoPrefab(false);
  293. }
  294. }
  295. }
  296. }
  297. }
  298. if (EdittingDeckData != null)
  299. {
  300. ContinuousController.instance.BattleDeckData = EdittingDeckData;
  301. }
  302. }
  303. else
  304. {
  305. Opening.instance.battle.selectBattleDeck.ResetDeckInfoPanel();
  306. yield return ContinuousController.instance.StartCoroutine(Opening.instance.battle.selectBattleDeck.SetDeckList(false));
  307. for (int i = 0; i < Opening.instance.battle.selectBattleDeck.deckInfoPrefabParentScroll.content.childCount; i++)
  308. {
  309. if (Opening.instance.battle.selectBattleDeck.deckInfoPrefabParentScroll.content.GetChild(i).GetComponent<DeckInfoPrefab>() != null)
  310. {
  311. if (Opening.instance.battle.selectBattleDeck.deckInfoPrefabParentScroll.content.GetChild(i).GetComponent<DeckInfoPrefab>().thisDeckData == EdittingDeckData)
  312. {
  313. Opening.instance.battle.selectBattleDeck.deckInfoPrefabParentScroll.content.GetChild(i).GetComponent<DeckInfoPrefab>().OnClick_DeckInfoPrefab(false);
  314. }
  315. }
  316. }
  317. }
  318. #endregion
  319. EndEditAction?.Invoke();
  320. EndEditAction = null;
  321. yield return ContinuousController.instance.StartCoroutine(LoadingObjec.EndLoading());
  322. }
  323. #endregion
  324. #region Open deck editing screen
  325. public void SetUpCreateDeck(DeckData deckData, bool isFromSelectDeck, bool isFromClipboard = false)
  326. {
  327. if (deckData == null)
  328. {
  329. return;
  330. }
  331. _isFromClipboard = isFromClipboard;
  332. Opening.instance.OffYesNoObjects();
  333. Opening.instance.deck.trialDraw.Close();
  334. Opening.instance.deck.deckListPanel.Close();
  335. _oldDeckName = deckData.DeckName;
  336. _oldDeckCards = new List<CEntity_Base>();
  337. foreach (CEntity_Base cEntity_Base in deckData.DeckCards())
  338. {
  339. _oldDeckCards.Add(cEntity_Base);
  340. }
  341. _oldDigitamaDeckCards = new List<CEntity_Base>();
  342. foreach (CEntity_Base cEntity_Base in deckData.DigitamaDeckCards())
  343. {
  344. _oldDigitamaDeckCards.Add(cEntity_Base);
  345. }
  346. _oldKeyCardId = deckData.KeyCardId;
  347. _checkCoverCoroutine = null;
  348. this._isFromSelectDeck = isFromSelectDeck;
  349. DisplayPageIndex = 0;
  350. SetCardData();
  351. CheckButtonEnabled();
  352. isSearchingObject.Off();
  353. ContinuousController.instance.StartCoroutine(SetUpCreateDeckCoroutine(deckData));
  354. }
  355. public IEnumerator SetUpCreateDeckCoroutine(DeckData deckData)
  356. {
  357. yield return ContinuousController.instance.StartCoroutine(LoadingObjec.StartLoading("Now Loading"));
  358. yield return new WaitForSeconds(0.1f);
  359. for (int i = 0; i < draggable_CardParent.childCount; i++)
  360. {
  361. Destroy(draggable_CardParent.GetChild(i).gameObject);
  362. }
  363. DraggingCover.SetActive(false);
  364. CardPoolScroll.verticalNormalizedPosition = 1;
  365. DeckScroll.verticalNormalizedPosition = 1;
  366. deckData.DeckCardIDs = DeckData.GetDeckCardCodes(DeckData.SortedDeckCardsList(deckData.DeckCards()));
  367. deckData.DigitamaDeckCardIDs = DeckData.GetDeckCardCodes(DeckData.SortedDeckCardsList(deckData.DigitamaDeckCards()));
  368. EdittingDeckData = deckData;
  369. ContinuousController.instance.SaveDeckDatas();
  370. //ContinuousController.instance.SaveDeckData(EdittingDeckData);
  371. OffDetailCard();
  372. for (int i = 0; i < DeckScroll.content.childCount; i++)
  373. {
  374. Destroy(DeckScroll.content.GetChild(i).gameObject);
  375. }
  376. yield return new WaitUntil(() => DeckScroll.content.childCount == 0);
  377. for (int i = 0; i < DeckScroll.viewport.childCount; i++)
  378. {
  379. if (i != 0)
  380. {
  381. Destroy(DeckScroll.viewport.GetChild(i).gameObject);
  382. }
  383. }
  384. yield return new WaitUntil(() => DeckScroll.viewport.childCount == 1);
  385. _maxDisplayPageIndex = (ContinuousController.instance.CardList.Length - 1) / _cardPoolPrefabs.Count;
  386. if (deckData != null)
  387. {
  388. List<CEntity_Base> DeckCards = new List<CEntity_Base>();
  389. foreach (CEntity_Base cEntity_Base in deckData.AllDeckCards())
  390. {
  391. DeckCards.Add(cEntity_Base);
  392. }
  393. foreach (CEntity_Base cEntity_Base in DeckCards)
  394. {
  395. CreateDeckCard(cEntity_Base);
  396. }
  397. }
  398. CreateDeckObject.SetActive(true);
  399. foreach (CardPrefab_CreateDeck _CardPrefab_CreateDeck in _cardPoolPrefabs)
  400. {
  401. _CardPrefab_CreateDeck.isActive = true;
  402. if (_CardPrefab_CreateDeck._OnEnterCoroutine != null)
  403. {
  404. _CardPrefab_CreateDeck.StopCoroutine(_CardPrefab_CreateDeck._OnEnterCoroutine);
  405. _CardPrefab_CreateDeck._OnEnterCoroutine = null;
  406. }
  407. }
  408. filterCardList.Init(() => ContinuousController.instance.StartCoroutine(ShowPoolCard_MatchCondition()));
  409. DeckNameInputField.onEndEdit.RemoveAllListeners();
  410. DeckNameInputField.text = EdittingDeckData.DeckName;
  411. DeckNameInputField.onEndEdit.AddListener(OnEndEdit);
  412. yield return ContinuousController.instance.StartCoroutine(SetSprittedCardLists());
  413. SetCardData();
  414. CheckButtonEnabled();
  415. ReflectDeckData();
  416. cardDistribution.SetCardDistribution(EdittingDeckData);
  417. yield return new WaitForSeconds(0.1f);
  418. for (int i = 0; i < DeckScroll.content.childCount; i++)
  419. {
  420. DeckScroll.content.GetChild(i).GetComponent<CardPrefab_CreateDeck>().ShowCardImage();
  421. }
  422. yield return StartCoroutine(LoadingObjec.EndLoading());
  423. isEditting = true;
  424. }
  425. public void OnEndEdit(string text)
  426. {
  427. ContinuousController.instance.RenameDeck(EdittingDeckData, text);
  428. DeckNameInputField.onEndEdit.RemoveAllListeners();
  429. DeckNameInputField.text = text;
  430. DeckNameInputField.onEndEdit.AddListener(OnEndEdit);
  431. }
  432. #endregion
  433. public List<CardPrefab_CreateDeck> CardPoolCardPrefabs_CreateDeck = new List<CardPrefab_CreateDeck>();
  434. #region Initialize the deck editing screen at the start of the game
  435. public List<CardPrefab_CreateDeck> cardPoolPrefabs_all = new List<CardPrefab_CreateDeck>();
  436. List<CardPrefab_CreateDeck> _cardPoolPrefabs = new List<CardPrefab_CreateDeck>();
  437. bool DoneSetUp { get; set; } = false;
  438. public IEnumerator InitEditDeck()
  439. {
  440. cardDistribution.Init();
  441. for (int i = 0; i < CardPoolScroll.content.childCount; i++)
  442. {
  443. CardPrefab_CreateDeck cardPrefab_CreateDeck = CardPoolScroll.content.GetChild(i).GetComponent<CardPrefab_CreateDeck>();
  444. if (cardPrefab_CreateDeck != null)
  445. {
  446. CardPoolCardPrefabs_CreateDeck.Add(cardPrefab_CreateDeck);
  447. }
  448. }
  449. for (int i = 0; i < DeckScroll.content.childCount; i++)
  450. {
  451. Destroy(DeckScroll.content.GetChild(i).gameObject);
  452. }
  453. foreach (CardPrefab_CreateDeck cardPrefab_CreateDeck in cardPoolPrefabs_all)
  454. {
  455. if (cardPrefab_CreateDeck.gameObject.activeSelf)
  456. {
  457. cardPrefab_CreateDeck.gameObject.SetActive(false);
  458. }
  459. }
  460. for (int i = 0; i < cardPoolPrefabs_all.Count; i++)
  461. {
  462. if (i < ContinuousController.instance.CardList.Length)
  463. {
  464. CardPrefab_CreateDeck _cardPrefab_CreateDeck = cardPoolPrefabs_all[i];
  465. _cardPoolPrefabs.Add(_cardPrefab_CreateDeck);
  466. CEntity_Base cEntity_Base = ContinuousController.instance.CardList[i];
  467. foreach (ScrollRect _scroll in _cardPrefab_CreateDeck.scroll)
  468. {
  469. _scroll.content = CardPoolScroll.content;
  470. _scroll.viewport = CardPoolScroll.viewport;
  471. _scroll.enabled = false;
  472. }
  473. _cardPrefab_CreateDeck.OnClickAction = () =>
  474. {
  475. StartCoroutine(AddDeckCardCoroutine_OnClick(_cardPrefab_CreateDeck));
  476. };
  477. _cardPrefab_CreateDeck.OnBeginDragAction = (cardPrefab_CreateDeck) => { StartCoroutine(OnBeginDrag(cardPrefab_CreateDeck)); };
  478. _cardPrefab_CreateDeck.OnEnterAction = (cardPrefab) =>
  479. {
  480. OnDetailCard(_cardPrefab_CreateDeck.cEntity_Base);
  481. };
  482. }
  483. }
  484. yield return ContinuousController.instance.StartCoroutine(SetSprittedCardLists());
  485. yield return new WaitForSeconds(0.1f);
  486. DoneSetUp = true;
  487. }
  488. #endregion
  489. #region Changed deck content changes to UI
  490. public void ReflectDeckData()
  491. {
  492. if (EdittingDeckData != null)
  493. {
  494. //Turn on covers for cards that cannot be included in the deck
  495. if (_checkCoverCoroutine != null)
  496. {
  497. StopCoroutine(_checkCoverCoroutine);
  498. }
  499. _checkCoverCoroutine = StartCoroutine(CheckCoverIEnumerator());
  500. SetDeckCountText();
  501. }
  502. }
  503. Coroutine _checkCoverCoroutine = null;
  504. IEnumerator CheckCoverIEnumerator()
  505. {
  506. foreach (CardPrefab_CreateDeck cardPrefab_CreateDeck in _cardPoolPrefabs)
  507. {
  508. yield return null;
  509. cardPrefab_CreateDeck.CheckCover(EdittingDeckData);
  510. }
  511. }
  512. #endregion
  513. #region Show deck number text
  514. public void SetDeckCountText()
  515. {
  516. DeckCountText.text = $"{EdittingDeckData.DeckCards().Count}+{EdittingDeckData.DigitamaDeckCards().Count}/50+5";
  517. if (EdittingDeckData.IsValidDeckData())
  518. {
  519. DeckCountText.color = new Color32(69, 255, 69, 255);
  520. }
  521. else
  522. {
  523. DeckCountText.color = new Color32(255, 64, 64, 255);
  524. }
  525. }
  526. #endregion
  527. #region Generate cards for deck
  528. public CardPrefab_CreateDeck CreateDeckCard(CEntity_Base cEntity_Base)
  529. {
  530. CardPrefab_CreateDeck _cardPrefab_CreateDeck = Instantiate(cardPrefab_CreateDeck, DeckScroll.content);
  531. SetUpDeckCard(_cardPrefab_CreateDeck, cEntity_Base);
  532. return _cardPrefab_CreateDeck;
  533. }
  534. public void SetUpDeckCard(CardPrefab_CreateDeck _cardPrefab_CreateDeck, CEntity_Base cEntity_Base)
  535. {
  536. foreach (ScrollRect _scroll in _cardPrefab_CreateDeck.scroll)
  537. {
  538. _scroll.content = DeckScroll.content;
  539. _scroll.viewport = DeckScroll.viewport;
  540. }
  541. _cardPrefab_CreateDeck.SetUpCardPrefab_CreateDeck(cEntity_Base);
  542. _cardPrefab_CreateDeck.ShowCardImage();
  543. _cardPrefab_CreateDeck.OnClickAction = () =>
  544. {
  545. StartCoroutine(RemoveDeckCardCoroutine_OnClick(_cardPrefab_CreateDeck));
  546. };
  547. _cardPrefab_CreateDeck.OnBeginDragAction = (cardPrefab_CreateDeck) => { StartCoroutine(OnBeginDrag(cardPrefab_CreateDeck)); };
  548. _cardPrefab_CreateDeck.OnEnterAction = (cardPrefab) =>
  549. {
  550. OnDetailCard(cEntity_Base);
  551. cardPrefab.SetupAddRemoveButton(EdittingDeckData);
  552. };
  553. _cardPrefab_CreateDeck.OnExitAction = (cardPrefab) =>
  554. {
  555. cardPrefab.OffAddRemoveButton();
  556. };
  557. _cardPrefab_CreateDeck.Parent.localScale = new Vector3(0.76f, 0.76f, 0.76f);
  558. _cardPrefab_CreateDeck.OnClickAddButtonAction = (cardPrefab) => StartCoroutine(AddDeckCardCoroutine_OnClick(cardPrefab));
  559. _cardPrefab_CreateDeck.OnClickRemoveButtonAction = (cardPrefab) => StartCoroutine(RemoveDeckCardCoroutine_OnClick(cardPrefab));
  560. }
  561. #endregion
  562. #region Display only cards that meet search/filter conditions
  563. bool MatchCondition(CEntity_Base cEntity_Base)
  564. {
  565. if (!filterCardList.OnlyContainsName()(cEntity_Base))
  566. {
  567. return false;
  568. }
  569. if (!filterCardList.OnlyContainsColor()(cEntity_Base))
  570. {
  571. return false;
  572. }
  573. if (!filterCardList.OnlyMatchRarity()(cEntity_Base))
  574. {
  575. return false;
  576. }
  577. if (!filterCardList.OnlyMatchCardKind()(cEntity_Base))
  578. {
  579. return false;
  580. }
  581. if (!filterCardList.OnlyMatchCardSet()(cEntity_Base))
  582. {
  583. return false;
  584. }
  585. if (!filterCardList.OnlyMatchPlayCost()(cEntity_Base))
  586. {
  587. return false;
  588. }
  589. if (!filterCardList.OnlyMatchLevel()(cEntity_Base))
  590. {
  591. return false;
  592. }
  593. if (!filterCardList.OnlyMatchSpecialCardKind()(cEntity_Base))
  594. {
  595. return false;
  596. }
  597. if (!filterCardList.OnlyMatchParallelCondition()(cEntity_Base))
  598. {
  599. return false;
  600. }
  601. return true;
  602. }
  603. public IEnumerator ShowPoolCard_MatchCondition()
  604. {
  605. DraggingCover.SetActive(true);
  606. DisplayPageIndex = 0;
  607. _maxDisplayPageIndex = (ContinuousController.instance.CardList.Count((cEntity_Base) => MatchCondition(cEntity_Base)) - 1) / _cardPoolPrefabs.Count;
  608. yield return ContinuousController.instance.StartCoroutine(SetSprittedCardLists());
  609. SetCardData();
  610. CheckButtonEnabled();
  611. ReflectDeckData();
  612. DraggingCover.SetActive(false);
  613. for (int i = 0; i < CardPoolCardPrefabs_CreateDeck.Count; i++)
  614. {
  615. CardPrefab_CreateDeck cardPrefab_CreateDeck = CardPoolCardPrefabs_CreateDeck[i];
  616. if (cardPrefab_CreateDeck != null)
  617. {
  618. cardPrefab_CreateDeck.uIShiny.enabled = false;
  619. if (cardPrefab_CreateDeck._OnEnterCoroutine != null)
  620. {
  621. cardPrefab_CreateDeck.StopCoroutine(cardPrefab_CreateDeck._OnEnterCoroutine);
  622. cardPrefab_CreateDeck._OnEnterCoroutine = null;
  623. }
  624. cardPrefab_CreateDeck.StopAllCoroutines();
  625. }
  626. }
  627. }
  628. #endregion
  629. #region Manipulating card objects
  630. [Header("draggable card object")]
  631. public Draggable_Card draggable_CardPrefab;
  632. [Header("draggable card object parent")]
  633. public Transform draggable_CardParent;
  634. [Header("Deck card dropArea")]
  635. public DropArea DeckCardsDropArea;
  636. [Header("card pool dropArea")]
  637. public DropArea CardPoolDropArea;
  638. [Header("Cover while dragging")]
  639. public GameObject DraggingCover;
  640. [Header("Coordinates of the disappearing deck card")]
  641. public Transform DisappearDeckCardTransform;
  642. //Is it draggable?
  643. public bool CanDrag { get; set; } = true;
  644. //Whether you are dragging
  645. public bool isDragging { get; set; } = false;
  646. #region Generate draggable objects
  647. public Draggable_Card CreateDraggable_Card()
  648. {
  649. Draggable_Card draggable_Card = Instantiate(draggable_CardPrefab, draggable_CardParent);
  650. draggable_Card.DefaultParent = draggable_CardParent;
  651. draggable_Card.transform.localScale = new Vector3(1, 1, 1);
  652. draggable_Card.CardImage.color = new Color(1, 1, 1, 1);
  653. return draggable_Card;
  654. }
  655. #endregion
  656. #region At the start of drag
  657. public IEnumerator OnBeginDrag(CardPrefab_CreateDeck _cardPrefab_CreateDeck)
  658. {
  659. if (_cardPrefab_CreateDeck.transform.parent == CardPoolScroll.content)
  660. {
  661. if (!DeckBuildingRule.CanAddCard(_cardPrefab_CreateDeck.cEntity_Base, EdittingDeckData))
  662. {
  663. yield break;
  664. }
  665. }
  666. if (Input.GetMouseButton(1))
  667. {
  668. yield break;
  669. }
  670. if (!isDragging && CanDrag)
  671. {
  672. Draggable_Card draggable_Card = CreateDraggable_Card();
  673. SetStartDrag(_cardPrefab_CreateDeck, draggable_Card);
  674. draggable_Card.OnDropAction = (dropAreas) => { OnEndDrag(dropAreas, _cardPrefab_CreateDeck, draggable_Card); };
  675. draggable_Card.OnDragAction = (dropAreas) =>
  676. {
  677. DeckCardsDropArea.OnPointerExit();
  678. CardPoolDropArea.OnPointerExit();
  679. if (_cardPrefab_CreateDeck.transform.parent == DeckScroll.content)
  680. {
  681. if (dropAreas.Count((dropArea) => dropArea == CardPoolDropArea) > 0)
  682. {
  683. CardPoolDropArea.OnPointerEnter();
  684. }
  685. }
  686. else if (_cardPrefab_CreateDeck.transform.parent == CardPoolScroll.content)
  687. {
  688. if (dropAreas.Count((dropArea) => dropArea == DeckCardsDropArea) > 0)
  689. {
  690. DeckCardsDropArea.OnPointerEnter();
  691. }
  692. }
  693. };
  694. if (_cardPrefab_CreateDeck.transform.parent == DeckScroll.content)
  695. {
  696. DeckCardsDropArea.OffDropPanel();
  697. CardPoolDropArea.OnDropPanel();
  698. _cardPrefab_CreateDeck.HideDeckCardTab();
  699. _cardPrefab_CreateDeck.OffAddRemoveButton();
  700. }
  701. else if (_cardPrefab_CreateDeck.transform.parent == CardPoolScroll.content)
  702. {
  703. DeckCardsDropArea.OnDropPanel();
  704. CardPoolDropArea.OffDropPanel();
  705. }
  706. DeckScroll.enabled = false;
  707. for (int i = 0; i < DeckScroll.content.childCount; i++)
  708. {
  709. foreach (ScrollRect scroll in DeckScroll.content.GetChild(i).GetComponent<CardPrefab_CreateDeck>().scroll)
  710. {
  711. scroll.enabled = false;
  712. }
  713. }
  714. CardPoolScroll.enabled = false;
  715. for (int i = 0; i < _cardPoolPrefabs.Count; i++)
  716. {
  717. foreach (ScrollRect scroll in _cardPoolPrefabs[i].scroll)
  718. {
  719. scroll.enabled = false;
  720. }
  721. }
  722. }
  723. }
  724. public void SetStartDrag(CardPrefab_CreateDeck _cardPrefab_CreateDeck, Draggable_Card draggable_Card)
  725. {
  726. isDragging = true;
  727. CanDrag = false;
  728. DraggingCover.SetActive(true);
  729. draggable_Card.SetUpDraggable_Card(_cardPrefab_CreateDeck.cEntity_Base, _cardPrefab_CreateDeck.transform.position);
  730. }
  731. #endregion
  732. #region At the end of dragging
  733. public void OnEndDrag(List<DropArea> dropAreas, CardPrefab_CreateDeck _cardPrefab_CreateDeck, Draggable_Card draggable_Card)
  734. {
  735. DeckCardsDropArea.OffDropPanel();
  736. CardPoolDropArea.OffDropPanel();
  737. StartCoroutine(OnEndDragCoroutine(dropAreas, _cardPrefab_CreateDeck, draggable_Card));
  738. DeckScroll.enabled = true;
  739. for (int i = 0; i < DeckScroll.content.childCount; i++)
  740. {
  741. foreach (ScrollRect scroll in DeckScroll.content.GetChild(i).GetComponent<CardPrefab_CreateDeck>().scroll)
  742. {
  743. scroll.enabled = true;
  744. }
  745. }
  746. CardPoolScroll.enabled = true;
  747. for (int i = 0; i < _cardPoolPrefabs.Count; i++)
  748. {
  749. foreach (ScrollRect scroll in _cardPoolPrefabs[i].scroll)
  750. {
  751. scroll.enabled = true;
  752. }
  753. }
  754. }
  755. IEnumerator OnEndDragCoroutine(List<DropArea> dropAreas, CardPrefab_CreateDeck _cardPrefab_CreateDeck, Draggable_Card draggable_Card)
  756. {
  757. if (_cardPrefab_CreateDeck.transform.parent == DeckScroll.content)
  758. {
  759. if (dropAreas.Count((dropArea) => dropArea == CardPoolDropArea) > 0)
  760. {
  761. yield return StartCoroutine(RemoveDeckCardCoroutine(_cardPrefab_CreateDeck, draggable_Card));
  762. }
  763. else
  764. {
  765. _cardPrefab_CreateDeck.ShowCardImage();
  766. }
  767. }
  768. else if (_cardPrefab_CreateDeck.transform.parent == CardPoolScroll.content)
  769. {
  770. if (dropAreas.Count((dropArea) => dropArea == DeckCardsDropArea) > 0)
  771. {
  772. yield return StartCoroutine(AddDeckCardCoroutine(_cardPrefab_CreateDeck, draggable_Card));
  773. }
  774. }
  775. Reset_EndDrag(draggable_Card);
  776. }
  777. public void Reset_EndDrag(Draggable_Card draggable_Card)
  778. {
  779. isDragging = false;
  780. DestroyImmediate(draggable_Card.gameObject);
  781. CanDrag = true;
  782. DraggingCover.SetActive(false);
  783. }
  784. #endregion
  785. float _addCardAnimationTime = 0.01f;
  786. #region Animation to add cards to deck when dropped
  787. IEnumerator AddDeckCardCoroutine(CardPrefab_CreateDeck _cardPrefab_CreateDeck, Draggable_Card draggable_Card)
  788. {
  789. if (!DeckBuildingRule.CanAddCard(_cardPrefab_CreateDeck.cEntity_Base, EdittingDeckData))
  790. {
  791. yield break;
  792. }
  793. ContinuousController.instance.PlaySE(Opening.instance.DrawSE);
  794. for (int i = 0; i < CardPoolCardPrefabs_CreateDeck.Count; i++)
  795. {
  796. CardPrefab_CreateDeck cardPrefab_CreateDeck = CardPoolCardPrefabs_CreateDeck[i];
  797. if (cardPrefab_CreateDeck != null)
  798. {
  799. cardPrefab_CreateDeck.uIShiny.enabled = false;
  800. cardPrefab_CreateDeck.OffAddRemoveButton();
  801. }
  802. }
  803. Debug.Log($"CARD TO ADD: {_cardPrefab_CreateDeck.cEntity_Base}");
  804. yield return StartCoroutine(AddDeckCards(_cardPrefab_CreateDeck.cEntity_Base));
  805. List<CEntity_Base> DeckCards = new List<CEntity_Base>();
  806. foreach (CEntity_Base cEntity_Base in EdittingDeckData.AllDeckCards())
  807. {
  808. //Debug.Log($"ADD: {cEntity_Base.CardIndex} || {cEntity_Base.CardID}");
  809. DeckCards.Add(cEntity_Base);
  810. }
  811. 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)}");
  812. int index = DeckCards.IndexOf(_cardPrefab_CreateDeck.cEntity_Base) + DeckCards.Count((cEntity_Base) => cEntity_Base == _cardPrefab_CreateDeck.cEntity_Base) - 1;
  813. Debug.Log("GETTING INDEX OF LAST ADDED CARD: " + index);
  814. CardPrefab_CreateDeck newCardPrefab = CreateDeckCard(_cardPrefab_CreateDeck.cEntity_Base);
  815. newCardPrefab.HideDeckCardTab();
  816. newCardPrefab.transform.SetSiblingIndex(index);
  817. List<CardPrefab_CreateDeck> cardPrefabs = new List<CardPrefab_CreateDeck>();
  818. for (int i = 0; i < DeckScroll.content.childCount; i++)
  819. {
  820. CardPrefab_CreateDeck cardPrefab = DeckScroll.content.GetChild(i).GetComponent<CardPrefab_CreateDeck>();
  821. if (cardPrefab != null)
  822. {
  823. cardPrefabs.Add(cardPrefab);
  824. if (cardPrefab.AddRemoveButtonParent.activeSelf)
  825. {
  826. cardPrefab.OffAddRemoveButton();
  827. cardPrefab.SetupAddRemoveButton(EdittingDeckData);
  828. }
  829. }
  830. }
  831. foreach (CardPrefab_CreateDeck cardPrefab in cardPrefabs)
  832. {
  833. cardPrefab.transform.SetParent(null);
  834. }
  835. foreach (CEntity_Base cEntity_Base in EdittingDeckData.AllDeckCards())
  836. {
  837. for (int i = 0; i < cardPrefabs.Count; i++)
  838. {
  839. if (cardPrefabs[i].cEntity_Base == cEntity_Base)
  840. {
  841. cardPrefabs[i].transform.SetParent(DeckScroll.content);
  842. cardPrefabs.Remove(cardPrefabs[i]);
  843. break;
  844. }
  845. }
  846. }
  847. yield return new WaitForSeconds(Time.deltaTime);
  848. bool end = false;
  849. var sequence = DOTween.Sequence();
  850. sequence
  851. .Append(draggable_Card.transform.DOMove(newCardPrefab.transform.position, _addCardAnimationTime))
  852. .Join(draggable_Card.transform.DOScale(new Vector3(0.5f, 0.5f, 0.5f), _addCardAnimationTime))
  853. .AppendCallback(() => end = true);
  854. sequence.Play();
  855. yield return new WaitWhile(() => !end);
  856. end = false;
  857. yield return new WaitForSeconds(_addCardAnimationTime);
  858. newCardPrefab.ShowCardImage();
  859. draggable_Card.gameObject.SetActive(false);
  860. }
  861. #endregion
  862. #region Animation to remove cards on drop
  863. IEnumerator RemoveDeckCardCoroutine(CardPrefab_CreateDeck _cardPrefab_CreateDeck, Draggable_Card draggable_Card)
  864. {
  865. ContinuousController.instance.PlaySE(Opening.instance.DrawSE);
  866. bool end = false;
  867. yield return StartCoroutine(RemoveDeckCards(_cardPrefab_CreateDeck.cEntity_Base));
  868. var sequence = DOTween.Sequence();
  869. sequence
  870. .Append(draggable_Card.transform.DOMove(DisappearDeckCardTransform.position, _addCardAnimationTime))
  871. .Join(draggable_Card.transform.DOScale(new Vector3(0.5f, 0.5f, 0.5f), _addCardAnimationTime))
  872. .AppendCallback(() => end = true);
  873. sequence.Play();
  874. yield return new WaitWhile(() => !end);
  875. end = false;
  876. yield return new WaitForSeconds(_addCardAnimationTime);
  877. draggable_Card.gameObject.SetActive(false);
  878. if (_cardPrefab_CreateDeck.transform.parent != CardPoolScroll.content)
  879. {
  880. DestroyImmediate(_cardPrefab_CreateDeck.gameObject);
  881. }
  882. }
  883. #endregion
  884. #region Add card to deck animation when right-clicking
  885. public IEnumerator AddDeckCardCoroutine_OnClick(CardPrefab_CreateDeck _cardPrefab_CreateDeck)
  886. {
  887. if (!DeckBuildingRule.CanAddCard(_cardPrefab_CreateDeck.cEntity_Base, EdittingDeckData))
  888. {
  889. yield break;
  890. }
  891. Draggable_Card draggable_Card = CreateDraggable_Card();
  892. SetStartDrag(_cardPrefab_CreateDeck, draggable_Card);
  893. draggable_Card.IsDragging = false;
  894. yield return StartCoroutine(AddDeckCardCoroutine(_cardPrefab_CreateDeck, draggable_Card));
  895. Reset_EndDrag(draggable_Card);
  896. }
  897. #endregion
  898. #region Animation to remove cards from deck when right-clicking
  899. public IEnumerator RemoveDeckCardCoroutine_OnClick(CardPrefab_CreateDeck _cardPrefab_CreateDeck)
  900. {
  901. Draggable_Card draggable_Card = CreateDraggable_Card();
  902. _cardPrefab_CreateDeck.HideDeckCardTab();
  903. SetStartDrag(_cardPrefab_CreateDeck, draggable_Card);
  904. draggable_Card.IsDragging = false;
  905. yield return StartCoroutine(RemoveDeckCardCoroutine(_cardPrefab_CreateDeck, draggable_Card));
  906. Reset_EndDrag(draggable_Card);
  907. }
  908. #endregion
  909. #region add cards to deck
  910. public IEnumerator AddDeckCards(CEntity_Base cEntity_Base)
  911. {
  912. Debug.Log($"ADD DECK CARD: {cEntity_Base.CardID}: {DeckBuildingRule.CanAddCard(cEntity_Base, EdittingDeckData)}");
  913. if (!DeckBuildingRule.CanAddCard(cEntity_Base, EdittingDeckData))
  914. {
  915. yield break;
  916. }
  917. Debug.Log($"ADD DECK CARD: {EdittingDeckData.DeckCardIDs.Count}");
  918. EdittingDeckData.AddCard(cEntity_Base);
  919. Debug.Log($"ADD DECK CARD: {EdittingDeckData.DeckCardIDs.Count}");
  920. Debug.Log($"ADD DECK CARD: {EdittingDeckData.DeckCards().Count}");
  921. EdittingDeckData.DeckCardIDs = DeckData.GetDeckCardCodes(DeckData.SortedDeckCardsList(EdittingDeckData.DeckCards()));
  922. EdittingDeckData.DigitamaDeckCardIDs = DeckData.GetDeckCardCodes(DeckData.SortedDeckCardsList(EdittingDeckData.DigitamaDeckCards()));
  923. ReflectDeckData();
  924. cardDistribution.SetCardDistribution(EdittingDeckData);
  925. }
  926. #endregion
  927. #region remove cards from deck
  928. public IEnumerator RemoveDeckCards(CEntity_Base cEntity_Base)
  929. {
  930. if (cEntity_Base.cardKind.Contains(CardKind.DigiEgg))
  931. {
  932. if (EdittingDeckData.DigitamaDeckCards().Count((cardData) => cardData.CardID == cEntity_Base.CardID) <= 0)
  933. {
  934. yield break;
  935. }
  936. }
  937. else
  938. {
  939. if (EdittingDeckData.DeckCards().Count((cardData) => cardData.CardID == cEntity_Base.CardID) <= 0)
  940. {
  941. yield break;
  942. }
  943. }
  944. EdittingDeckData.RemoveCard(cEntity_Base);
  945. EdittingDeckData.DeckCardIDs = DeckData.GetDeckCardCodes(DeckData.SortedDeckCardsList(EdittingDeckData.DeckCards()));
  946. EdittingDeckData.DigitamaDeckCardIDs = DeckData.GetDeckCardCodes(DeckData.SortedDeckCardsList(EdittingDeckData.DigitamaDeckCards()));
  947. ReflectDeckData();
  948. cardDistribution.SetCardDistribution(EdittingDeckData);
  949. }
  950. #endregion
  951. #endregion
  952. public void OnPointerEnterBackground()
  953. {
  954. List<CardPrefab_CreateDeck> cardPrefabs = new List<CardPrefab_CreateDeck>();
  955. for (int i = 0; i < DeckScroll.content.childCount; i++)
  956. {
  957. CardPrefab_CreateDeck cardPrefab = DeckScroll.content.GetChild(i).GetComponent<CardPrefab_CreateDeck>();
  958. if (cardPrefab != null)
  959. {
  960. cardPrefabs.Add(cardPrefab);
  961. }
  962. }
  963. foreach (CardPrefab_CreateDeck cardPrefab in cardPrefabs)
  964. {
  965. if (cardPrefab != null)
  966. {
  967. cardPrefab._OnExit();
  968. }
  969. }
  970. }
  971. public Button TrialDrawButton;
  972. public void OnClickTrial5DrawButton()
  973. {
  974. Opening.instance.deck.trialDraw.Off();
  975. ContinuousController.instance.PlaySE(Opening.instance.DecisionSE);
  976. ContinuousController.instance.StartCoroutine(Opening.instance.deck.trialDraw.SetUpTrialDraw(EdittingDeckData.DeckCards()));
  977. }
  978. public Button ClearDeckButton;
  979. public void OnClickClearDeckButton()
  980. {
  981. List<UnityAction> Commands = new List<UnityAction>()
  982. {
  983. () =>
  984. {
  985. ContinuousController.instance.StartCoroutine(ClearDeckCoroutine());
  986. IEnumerator ClearDeckCoroutine()
  987. {
  988. DraggingCover.SetActive(true);
  989. List<CEntity_Base> cEntity_Bases = new List<CEntity_Base>();
  990. foreach(CEntity_Base cEntity_Base in EdittingDeckData.DeckCards())
  991. {
  992. cEntity_Bases.Add(cEntity_Base);
  993. }
  994. foreach(CEntity_Base cEntity_Base in EdittingDeckData.DigitamaDeckCards())
  995. {
  996. cEntity_Bases.Add(cEntity_Base);
  997. }
  998. foreach(CEntity_Base cEntity_Base in cEntity_Bases)
  999. {
  1000. yield return ContinuousController.instance.StartCoroutine(RemoveDeckCards(cEntity_Base));
  1001. }
  1002. for (int i = 0; i < DeckScroll.content.childCount; i++)
  1003. {
  1004. Destroy(DeckScroll.content.GetChild(i).gameObject);
  1005. }
  1006. yield return new WaitWhile(() => DeckScroll.content.childCount >= 1);
  1007. DraggingCover.SetActive(false);
  1008. }
  1009. },
  1010. null,
  1011. };
  1012. List<string> CommandTexts = new List<string>()
  1013. {
  1014. LocalizeUtility.GetLocalizedString(
  1015. EngMessage: "Yes",
  1016. JpnMessage: "はい"
  1017. ),
  1018. LocalizeUtility.GetLocalizedString(
  1019. EngMessage: "No",
  1020. JpnMessage: "いいえ"
  1021. ),
  1022. };
  1023. Opening.instance.SetUpActiveYesNoObject(
  1024. Commands,
  1025. CommandTexts,
  1026. LocalizeUtility.GetLocalizedString(
  1027. EngMessage: "Remove all cards from the deck?",
  1028. JpnMessage: "全てのカードをデッキから除きますか?"
  1029. ),
  1030. true);
  1031. }
  1032. public void OnClickSetDeckIconButton()
  1033. {
  1034. ContinuousController.instance.StartCoroutine(Opening.instance.deck.deckListPanel.SetUpDeckListPanel(
  1035. EdittingDeckData,
  1036. OnClick,
  1037. LocalizeUtility.GetLocalizedString(
  1038. EngMessage: "Choose a deck icon card.",
  1039. JpnMessage: "デッキアイコン選択"
  1040. )));
  1041. void OnClick(CEntity_Base cEntity_Base)
  1042. {
  1043. EdittingDeckData.KeyCardId = cEntity_Base.CardIndex;
  1044. Opening.instance.deck.deckListPanel.Close();
  1045. Opening.instance.PlayDecisionSE();
  1046. }
  1047. }
  1048. }