SelectDeck.cs 11 KB

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