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. #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. Debug.Log($"CARD TO ADD: {_cardPrefab_CreateDeck.cEntity_Base}");
  803. yield return StartCoroutine(AddDeckCards(_cardPrefab_CreateDeck.cEntity_Base));
  804. List<CEntity_Base> DeckCards = new List<CEntity_Base>();
  805. foreach (CEntity_Base cEntity_Base in EdittingDeckData.AllDeckCards())
  806. {
  807. //Debug.Log($"ADD: {cEntity_Base.CardIndex} || {cEntity_Base.CardID}");
  808. DeckCards.Add(cEntity_Base);
  809. }
  810. 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)}");
  811. int index = DeckCards.IndexOf(_cardPrefab_CreateDeck.cEntity_Base) + DeckCards.Count((cEntity_Base) => cEntity_Base == _cardPrefab_CreateDeck.cEntity_Base) - 1;
  812. Debug.Log("GETTING INDEX OF LAST ADDED CARD: " + index);
  813. CardPrefab_CreateDeck newCardPrefab = CreateDeckCard(_cardPrefab_CreateDeck.cEntity_Base);
  814. newCardPrefab.HideDeckCardTab();
  815. newCardPrefab.transform.SetSiblingIndex(index);
  816. List<CardPrefab_CreateDeck> cardPrefabs = new List<CardPrefab_CreateDeck>();
  817. for (int i = 0; i < DeckScroll.content.childCount; i++)
  818. {
  819. CardPrefab_CreateDeck cardPrefab = DeckScroll.content.GetChild(i).GetComponent<CardPrefab_CreateDeck>();
  820. if (cardPrefab != null)
  821. {
  822. cardPrefabs.Add(cardPrefab);
  823. if (cardPrefab.AddRemoveButtonParent.activeSelf)
  824. {
  825. cardPrefab.OffAddRemoveButton();
  826. cardPrefab.SetupAddRemoveButton(EdittingDeckData);
  827. }
  828. }
  829. }
  830. foreach (CardPrefab_CreateDeck cardPrefab in cardPrefabs)
  831. {
  832. cardPrefab.transform.SetParent(null);
  833. }
  834. foreach (CEntity_Base cEntity_Base in EdittingDeckData.AllDeckCards())
  835. {
  836. for (int i = 0; i < cardPrefabs.Count; i++)
  837. {
  838. if (cardPrefabs[i].cEntity_Base == cEntity_Base)
  839. {
  840. cardPrefabs[i].transform.SetParent(DeckScroll.content);
  841. cardPrefabs.Remove(cardPrefabs[i]);
  842. break;
  843. }
  844. }
  845. }
  846. yield return new WaitForSeconds(Time.deltaTime);
  847. bool end = false;
  848. var sequence = DOTween.Sequence();
  849. sequence
  850. .Append(draggable_Card.transform.DOMove(newCardPrefab.transform.position, _addCardAnimationTime))
  851. .Join(draggable_Card.transform.DOScale(new Vector3(0.5f, 0.5f, 0.5f), _addCardAnimationTime))
  852. .AppendCallback(() => end = true);
  853. sequence.Play();
  854. yield return new WaitWhile(() => !end);
  855. end = false;
  856. yield return new WaitForSeconds(_addCardAnimationTime);
  857. newCardPrefab.ShowCardImage();
  858. draggable_Card.gameObject.SetActive(false);
  859. }
  860. #endregion
  861. #region Animation to remove cards on drop
  862. IEnumerator RemoveDeckCardCoroutine(CardPrefab_CreateDeck _cardPrefab_CreateDeck, Draggable_Card draggable_Card)
  863. {
  864. ContinuousController.instance.PlaySE(Opening.instance.DrawSE);
  865. bool end = false;
  866. yield return StartCoroutine(RemoveDeckCards(_cardPrefab_CreateDeck.cEntity_Base));
  867. var sequence = DOTween.Sequence();
  868. sequence
  869. .Append(draggable_Card.transform.DOMove(DisappearDeckCardTransform.position, _addCardAnimationTime))
  870. .Join(draggable_Card.transform.DOScale(new Vector3(0.5f, 0.5f, 0.5f), _addCardAnimationTime))
  871. .AppendCallback(() => end = true);
  872. sequence.Play();
  873. yield return new WaitWhile(() => !end);
  874. end = false;
  875. yield return new WaitForSeconds(_addCardAnimationTime);
  876. draggable_Card.gameObject.SetActive(false);
  877. if (_cardPrefab_CreateDeck.transform.parent != CardPoolScroll.content)
  878. {
  879. DestroyImmediate(_cardPrefab_CreateDeck.gameObject);
  880. }
  881. }
  882. #endregion
  883. #region Add card to deck animation when right-clicking
  884. public IEnumerator AddDeckCardCoroutine_OnClick(CardPrefab_CreateDeck _cardPrefab_CreateDeck)
  885. {
  886. if (!DeckBuildingRule.CanAddCard(_cardPrefab_CreateDeck.cEntity_Base, EdittingDeckData))
  887. {
  888. yield break;
  889. }
  890. Draggable_Card draggable_Card = CreateDraggable_Card();
  891. SetStartDrag(_cardPrefab_CreateDeck, draggable_Card);
  892. draggable_Card.IsDragging = false;
  893. yield return StartCoroutine(AddDeckCardCoroutine(_cardPrefab_CreateDeck, draggable_Card));
  894. Reset_EndDrag(draggable_Card);
  895. }
  896. #endregion
  897. #region Animation to remove cards from deck when right-clicking
  898. public IEnumerator RemoveDeckCardCoroutine_OnClick(CardPrefab_CreateDeck _cardPrefab_CreateDeck)
  899. {
  900. Draggable_Card draggable_Card = CreateDraggable_Card();
  901. _cardPrefab_CreateDeck.HideDeckCardTab();
  902. SetStartDrag(_cardPrefab_CreateDeck, draggable_Card);
  903. draggable_Card.IsDragging = false;
  904. yield return StartCoroutine(RemoveDeckCardCoroutine(_cardPrefab_CreateDeck, draggable_Card));
  905. Reset_EndDrag(draggable_Card);
  906. }
  907. #endregion
  908. #region add cards to deck
  909. public IEnumerator AddDeckCards(CEntity_Base cEntity_Base)
  910. {
  911. Debug.Log($"ADD DECK CARD: {cEntity_Base.CardID}: {DeckBuildingRule.CanAddCard(cEntity_Base, EdittingDeckData)}");
  912. if (!DeckBuildingRule.CanAddCard(cEntity_Base, EdittingDeckData))
  913. {
  914. yield break;
  915. }
  916. Debug.Log($"ADD DECK CARD: {EdittingDeckData.DeckCardIDs.Count}");
  917. EdittingDeckData.AddCard(cEntity_Base);
  918. Debug.Log($"ADD DECK CARD: {EdittingDeckData.DeckCardIDs.Count}");
  919. Debug.Log($"ADD DECK CARD: {EdittingDeckData.DeckCards().Count}");
  920. EdittingDeckData.DeckCardIDs = DeckData.GetDeckCardCodes(DeckData.SortedDeckCardsList(EdittingDeckData.DeckCards()));
  921. EdittingDeckData.DigitamaDeckCardIDs = DeckData.GetDeckCardCodes(DeckData.SortedDeckCardsList(EdittingDeckData.DigitamaDeckCards()));
  922. ReflectDeckData();
  923. cardDistribution.SetCardDistribution(EdittingDeckData);
  924. }
  925. #endregion
  926. #region remove cards from deck
  927. public IEnumerator RemoveDeckCards(CEntity_Base cEntity_Base)
  928. {
  929. if (cEntity_Base.cardKind == CardKind.DigiEgg)
  930. {
  931. if (EdittingDeckData.DigitamaDeckCards().Count((cardData) => cardData.CardID == cEntity_Base.CardID) <= 0)
  932. {
  933. yield break;
  934. }
  935. }
  936. else
  937. {
  938. if (EdittingDeckData.DeckCards().Count((cardData) => cardData.CardID == cEntity_Base.CardID) <= 0)
  939. {
  940. yield break;
  941. }
  942. }
  943. EdittingDeckData.RemoveCard(cEntity_Base);
  944. EdittingDeckData.DeckCardIDs = DeckData.GetDeckCardCodes(DeckData.SortedDeckCardsList(EdittingDeckData.DeckCards()));
  945. EdittingDeckData.DigitamaDeckCardIDs = DeckData.GetDeckCardCodes(DeckData.SortedDeckCardsList(EdittingDeckData.DigitamaDeckCards()));
  946. ReflectDeckData();
  947. cardDistribution.SetCardDistribution(EdittingDeckData);
  948. }
  949. #endregion
  950. #endregion
  951. public void OnPointerEnterBackground()
  952. {
  953. List<CardPrefab_CreateDeck> cardPrefabs = new List<CardPrefab_CreateDeck>();
  954. for (int i = 0; i < DeckScroll.content.childCount; i++)
  955. {
  956. CardPrefab_CreateDeck cardPrefab = DeckScroll.content.GetChild(i).GetComponent<CardPrefab_CreateDeck>();
  957. if (cardPrefab != null)
  958. {
  959. cardPrefabs.Add(cardPrefab);
  960. }
  961. }
  962. foreach (CardPrefab_CreateDeck cardPrefab in cardPrefabs)
  963. {
  964. if (cardPrefab != null)
  965. {
  966. cardPrefab._OnExit();
  967. }
  968. }
  969. }
  970. public Button TrialDrawButton;
  971. public void OnClickTrial5DrawButton()
  972. {
  973. Opening.instance.deck.trialDraw.Off();
  974. ContinuousController.instance.PlaySE(Opening.instance.DecisionSE);
  975. ContinuousController.instance.StartCoroutine(Opening.instance.deck.trialDraw.SetUpTrialDraw(EdittingDeckData.DeckCards()));
  976. }
  977. public Button ClearDeckButton;
  978. public void OnClickClearDeckButton()
  979. {
  980. List<UnityAction> Commands = new List<UnityAction>()
  981. {
  982. () =>
  983. {
  984. ContinuousController.instance.StartCoroutine(ClearDeckCoroutine());
  985. IEnumerator ClearDeckCoroutine()
  986. {
  987. DraggingCover.SetActive(true);
  988. List<CEntity_Base> cEntity_Bases = new List<CEntity_Base>();
  989. foreach(CEntity_Base cEntity_Base in EdittingDeckData.DeckCards())
  990. {
  991. cEntity_Bases.Add(cEntity_Base);
  992. }
  993. foreach(CEntity_Base cEntity_Base in EdittingDeckData.DigitamaDeckCards())
  994. {
  995. cEntity_Bases.Add(cEntity_Base);
  996. }
  997. foreach(CEntity_Base cEntity_Base in cEntity_Bases)
  998. {
  999. yield return ContinuousController.instance.StartCoroutine(RemoveDeckCards(cEntity_Base));
  1000. }
  1001. for (int i = 0; i < DeckScroll.content.childCount; i++)
  1002. {
  1003. Destroy(DeckScroll.content.GetChild(i).gameObject);
  1004. }
  1005. yield return new WaitWhile(() => DeckScroll.content.childCount >= 1);
  1006. DraggingCover.SetActive(false);
  1007. }
  1008. },
  1009. null,
  1010. };
  1011. List<string> CommandTexts = new List<string>()
  1012. {
  1013. LocalizeUtility.GetLocalizedString(
  1014. EngMessage: "Yes",
  1015. JpnMessage: "はい"
  1016. ),
  1017. LocalizeUtility.GetLocalizedString(
  1018. EngMessage: "No",
  1019. JpnMessage: "いいえ"
  1020. ),
  1021. };
  1022. Opening.instance.SetUpActiveYesNoObject(
  1023. Commands,
  1024. CommandTexts,
  1025. LocalizeUtility.GetLocalizedString(
  1026. EngMessage: "Remove all cards from the deck?",
  1027. JpnMessage: "全てのカードをデッキから除きますか?"
  1028. ),
  1029. true);
  1030. }
  1031. public void OnClickSetDeckIconButton()
  1032. {
  1033. ContinuousController.instance.StartCoroutine(Opening.instance.deck.deckListPanel.SetUpDeckListPanel(
  1034. EdittingDeckData,
  1035. OnClick,
  1036. LocalizeUtility.GetLocalizedString(
  1037. EngMessage: "Choose a deck icon card.",
  1038. JpnMessage: "デッキアイコン選択"
  1039. )));
  1040. void OnClick(CEntity_Base cEntity_Base)
  1041. {
  1042. EdittingDeckData.KeyCardId = cEntity_Base.CardIndex;
  1043. Opening.instance.deck.deckListPanel.Close();
  1044. Opening.instance.PlayDecisionSE();
  1045. }
  1046. }
  1047. }