SelectDeck.cs 11 KB

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