SelectDeck.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using System;
  6. using UnityEngine.Events;
  7. public class SelectDeck : OffAnimation
  8. {
  9. [Header("Select Deck Object")]
  10. public GameObject SelectDeckObject;
  11. [Header("Deck Info Tab Prefab")]
  12. public DeckInfoPrefab deckInfoPrefab;
  13. [Header("ScrollRect to place deck information tabs")]
  14. public ScrollRect deckInfoPrefabParentScroll;
  15. [Header("Deck Info Panel")]
  16. public DeckInfoPanel deckInfoPanel;
  17. [Header("Animator")]
  18. public Animator anim;
  19. public bool isOpen { get; set; } = false;
  20. public void OffSelectDeck()
  21. {
  22. anim.enabled = true;
  23. anim.SetInteger("Open", 0);
  24. anim.SetInteger("Close", 1);
  25. isOpen = false;
  26. }
  27. public override void Off()
  28. {
  29. SelectDeckObject.SetActive(false);
  30. }
  31. public async void SetUpSelectDeck()
  32. {
  33. if (isOpen)
  34. {
  35. return;
  36. }
  37. int lastBattleDeckDataIndex = -1;
  38. if (ContinuousController.instance.LastBattleDeckData != null
  39. && ContinuousController.instance.DeckDatas.Contains(ContinuousController.instance.LastBattleDeckData))
  40. {
  41. lastBattleDeckDataIndex = ContinuousController.instance.DeckDatas.IndexOf(ContinuousController.instance.LastBattleDeckData);
  42. }
  43. ContinuousController.instance.ModifyAllDeckDatas();
  44. if (0 <= lastBattleDeckDataIndex && lastBattleDeckDataIndex <= ContinuousController.instance.DeckDatas.Count - 1)
  45. {
  46. ContinuousController.instance.BattleDeckData = ContinuousController.instance.DeckDatas[lastBattleDeckDataIndex];
  47. }
  48. Opening.instance.deck.deckListPanel.Off();
  49. isOpen = true;
  50. ContinuousController.instance.StartCoroutine(SetDeckList(true));
  51. SelectDeckObject.SetActive(true);
  52. anim.SetInteger("Open", 1);
  53. anim.SetInteger("Close", 0);
  54. if (ContinuousController.instance.DeckDatas.Count > 0)
  55. {
  56. if (ContinuousController.instance.LastBattleDeckData != null
  57. && ContinuousController.instance.DeckDatas.Contains(ContinuousController.instance.LastBattleDeckData))
  58. {
  59. await deckInfoPanel.SetUpDeckInfoPanel(ContinuousController.instance.LastBattleDeckData);
  60. }
  61. else
  62. {
  63. await deckInfoPanel.SetUpDeckInfoPanel(ContinuousController.instance.DeckDatas[0]);
  64. }
  65. }
  66. else
  67. {
  68. ResetDeckInfoPanel();
  69. }
  70. }
  71. public async void ResetDeckInfoPanel()
  72. {
  73. await deckInfoPanel.SetUpDeckInfoPanel(null);
  74. }
  75. public IEnumerator SetDeckList(bool open)
  76. {
  77. for (int i = 0; i < deckInfoPrefabParentScroll.content.childCount; i++)
  78. {
  79. if (i > 0)
  80. {
  81. Destroy(deckInfoPrefabParentScroll.content.GetChild(i).gameObject);
  82. }
  83. }
  84. for (int i = 0; i < ContinuousController.instance.DeckDatas.Count; i++)
  85. {
  86. DeckInfoPrefab _deckInfoPrefab = Instantiate(deckInfoPrefab, deckInfoPrefabParentScroll.content);
  87. _deckInfoPrefab.scrollRect.content = deckInfoPrefabParentScroll.content;
  88. _deckInfoPrefab.scrollRect.viewport = deckInfoPrefabParentScroll.viewport;
  89. _deckInfoPrefab.scrollRect.verticalScrollbar = deckInfoPrefabParentScroll.verticalScrollbar;
  90. _deckInfoPrefab.SetUpDeckInfoPrefab(ContinuousController.instance.DeckDatas[i]);
  91. _deckInfoPrefab.transform.localScale = Opening.instance.DeckInfoPrefabStartScale * 1.02f;
  92. _deckInfoPrefab.OnClickAction = (deckdata) =>
  93. {
  94. deckInfoPanel.SetUpDeckInfoPanel(deckdata);
  95. Opening.instance.CreateOnClickEffect();
  96. };
  97. }
  98. yield return null;
  99. for (int i = 0; i < deckInfoPrefabParentScroll.content.childCount; i++)
  100. {
  101. deckInfoPrefabParentScroll.content.GetChild(i).transform.localScale = Opening.instance.DeckInfoPrefabStartScale;
  102. }
  103. if (ContinuousController.instance.DeckDatas.Count == 0)
  104. {
  105. for (int i = 0; i < deckInfoPrefabParentScroll.content.childCount; i++)
  106. {
  107. if (deckInfoPrefabParentScroll.content.GetChild(i).GetComponent<CreateNewDeckButton>() != null)
  108. {
  109. deckInfoPrefabParentScroll.content.GetChild(i).GetComponent<CreateNewDeckButton>().Outline.SetActive(true);
  110. break;
  111. }
  112. }
  113. }
  114. else
  115. {
  116. for (int i = 0; i < deckInfoPrefabParentScroll.content.childCount; i++)
  117. {
  118. if (deckInfoPrefabParentScroll.content.GetChild(i).GetComponent<CreateNewDeckButton>() != null)
  119. {
  120. deckInfoPrefabParentScroll.content.GetChild(i).GetComponent<CreateNewDeckButton>().Outline.SetActive(false);
  121. break;
  122. }
  123. }
  124. for (int i = 0; i < deckInfoPrefabParentScroll.content.childCount; i++)
  125. {
  126. if (deckInfoPrefabParentScroll.content.GetChild(i).GetComponent<DeckInfoPrefab>() != null)
  127. {
  128. if (deckInfoPrefabParentScroll.content.GetChild(i).GetComponent<DeckInfoPrefab>().thisDeckData == deckInfoPanel.ShowingDeckData && deckInfoPanel.DeckInfoPanelObject.activeSelf)
  129. {
  130. deckInfoPrefabParentScroll.content.GetChild(i).GetComponent<DeckInfoPrefab>().Outline.SetActive(true);
  131. }
  132. else
  133. {
  134. deckInfoPrefabParentScroll.content.GetChild(i).GetComponent<DeckInfoPrefab>().Outline.SetActive(false);
  135. }
  136. }
  137. }
  138. }
  139. if (open)
  140. {
  141. yield return new WaitForSeconds(Time.deltaTime);
  142. deckInfoPrefabParentScroll.verticalNormalizedPosition = 1;
  143. }
  144. }
  145. public void OnClickCopyDeckListButton()
  146. {
  147. string deckListCode = "";
  148. for (int i = 0; i < ContinuousController.instance.DeckDatas.Count; i++)
  149. {
  150. deckListCode += DeckData.GetDeckCode(ContinuousController.instance.DeckDatas[i].DeckName, DeckData.SortedDeckCardsList(ContinuousController.instance.DeckDatas[i].DeckCards()), DeckData.SortedDeckCardsList(ContinuousController.instance.DeckDatas[i].DigitamaDeckCards()), ContinuousController.instance.DeckDatas[i].KeyCard) + "分";
  151. }
  152. if (deckListCode.Length >= 1)
  153. {
  154. GUIUtility.systemCopyBuffer = deckListCode;
  155. List<UnityAction> Commands = new List<UnityAction>()
  156. {
  157. null
  158. };
  159. List<string> CommandTexts = new List<string>()
  160. {
  161. "OK"
  162. };
  163. Opening.instance.SetUpActiveYesNoObject(Commands, CommandTexts, $"現在のデッキリストの\nコードをクリップボードにコピーしました!", false);
  164. }
  165. else
  166. {
  167. List<UnityAction> Commands = new List<UnityAction>()
  168. {
  169. null
  170. };
  171. List<string> CommandTexts = new List<string>()
  172. {
  173. "OK"
  174. };
  175. Opening.instance.SetUpActiveYesNoObject(Commands, CommandTexts, $"デッキリストのコード取得に失敗しました", false);
  176. }
  177. }
  178. public void OnClickPasterDeckListButton()
  179. {
  180. List<DeckData> gotDeckDatas = new List<DeckData>();
  181. string deckListCode = GUIUtility.systemCopyBuffer;
  182. if (!string.IsNullOrEmpty(deckListCode))
  183. {
  184. string[] deckCodes = deckListCode.Split('分');
  185. foreach (string deckCode in deckCodes)
  186. {
  187. DeckData deckData = new DeckData(deckCode);
  188. if (deckData.DeckCards().Count >= 1)
  189. {
  190. gotDeckDatas.Add(deckData);
  191. }
  192. }
  193. }
  194. if (gotDeckDatas.Count >= 1)
  195. {
  196. gotDeckDatas.Reverse();
  197. foreach (DeckData deckdata in gotDeckDatas)
  198. {
  199. ContinuousController.instance.DeckDatas.Insert(0, deckdata);
  200. }
  201. List<UnityAction> Commands = new List<UnityAction>()
  202. {
  203. null
  204. };
  205. List<string> CommandTexts = new List<string>()
  206. {
  207. "OK"
  208. };
  209. Opening.instance.SetUpActiveYesNoObject(Commands, CommandTexts, $"デッキリストを\n復元しました!", false);
  210. }
  211. else
  212. {
  213. List<UnityAction> Commands = new List<UnityAction>()
  214. {
  215. null
  216. };
  217. List<string> CommandTexts = new List<string>()
  218. {
  219. "OK"
  220. };
  221. Opening.instance.SetUpActiveYesNoObject(Commands, CommandTexts, $"デッキリストの復元に失敗しました", false);
  222. }
  223. ContinuousController.instance.StartCoroutine(SetDeckList(false));
  224. ContinuousController.instance.SaveDeckDatas();
  225. }
  226. public void OnClickDeleteAllDecksButton()
  227. {
  228. List<UnityAction> Commands = new List<UnityAction>()
  229. {
  230. () =>
  231. {
  232. List<DeckData> deckDatas = new List<DeckData>();
  233. for(int i =0;i<ContinuousController.instance.DeckDatas.Count;i++)
  234. {
  235. deckDatas.Add(ContinuousController.instance.DeckDatas[i]);
  236. }
  237. for(int i =0;i<deckDatas.Count;i++)
  238. {
  239. ContinuousController.instance.DeckDatas.Remove(deckDatas[i]);
  240. }
  241. ContinuousController.instance.StartCoroutine(SetDeckList(false));
  242. ResetDeckInfoPanel();
  243. ContinuousController.instance.SaveDeckDatas();
  244. }
  245. ,null
  246. };
  247. List<string> CommandTexts = new List<string>()
  248. {
  249. "削除する",
  250. "しない"
  251. };
  252. Opening.instance.SetUpActiveYesNoObject(Commands, CommandTexts, $"全デッキを削除しますか?", false);
  253. }
  254. }