SelectBattleDeck.cs 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using System;
  6. using UnityEngine.Events;
  7. using UnityEngine.SceneManagement;
  8. using System.Linq;
  9. public class SelectBattleDeck : MonoBehaviour
  10. {
  11. private static WaitForSeconds _waitForSeconds1 = new WaitForSeconds(1f);
  12. [Header("Deck selection object")]
  13. public GameObject SelectDeckObject;
  14. [Header("Deck Information Tab Prefab")]
  15. public DeckInfoPrefab deckInfoPrefab;
  16. [Header("ScrollRect to place deck information tabs")]
  17. public ScrollRect deckInfoPrefabParentScroll;
  18. [Header("Deck Information Panel")]
  19. public DeckInfoPanel deckInfoPanel;
  20. [Header("Animator")]
  21. public Animator anim;
  22. [Header("Deck Information Panel")]
  23. public Button SelectDeckButton;
  24. [Header("LoadingObject")]
  25. public LoadingObject loadingObject;
  26. [Header("Invalid deck display")]
  27. public GameObject InvalidDeckObject;
  28. [Header("タイトルテキスト")]
  29. public Text TitleText;
  30. public void OnClickEditDeckButton()
  31. {
  32. Opening.instance.deck.editDeck.EndEditAction = () =>
  33. {
  34. SetSelectDeckButton();
  35. if (deckInfoPanel.ShowingDeckData != null)
  36. {
  37. InvalidDeckObject.SetActive(!deckInfoPanel.ShowingDeckData.IsValidDeckData());
  38. }
  39. };
  40. }
  41. public void SetSelectDeckButton()
  42. {
  43. SelectDeckButton.interactable = false;
  44. if (deckInfoPanel.ShowingDeckData != null)
  45. {
  46. if (deckInfoPanel.ShowingDeckData.DeckCardIDs != null)
  47. {
  48. if (deckInfoPanel.ShowingDeckData.IsValidDeckData())
  49. {
  50. SelectDeckButton.interactable = true;
  51. }
  52. }
  53. }
  54. }
  55. bool once = false;
  56. public void OnClickSelectButton_RandomMatch()
  57. {
  58. if (once || deckInfoPanel.ShowingDeckData == null)
  59. {
  60. return;
  61. }
  62. ContinuousController.instance.StartCoroutine(SetOnce());
  63. ContinuousController.instance.BattleDeckData = deckInfoPanel.ShowingDeckData;
  64. Opening.instance.battle.lobbyManager_RandomMatch.SetUpLobby();
  65. }
  66. public void OnClickSelectButton_BotMatch()
  67. {
  68. if (once || deckInfoPanel.ShowingDeckData == null)
  69. {
  70. return;
  71. }
  72. ContinuousController.instance.StartCoroutine(SetOnce());
  73. ContinuousController.instance.BattleDeckData = deckInfoPanel.ShowingDeckData;
  74. }
  75. public IEnumerator OnClickSelectButton_RoomMatchCoroutine()
  76. {
  77. if (once || deckInfoPanel.ShowingDeckData == null)
  78. {
  79. yield break;
  80. }
  81. ContinuousController.instance.StartCoroutine(SetOnce());
  82. ContinuousController.instance.BattleDeckData = deckInfoPanel.ShowingDeckData;
  83. Off();
  84. yield return ContinuousController.instance.StartCoroutine(PhotonUtility.SignUpBattleDeckData());
  85. }
  86. IEnumerator SetOnce()
  87. {
  88. once = true;
  89. yield return _waitForSeconds1;
  90. once = false;
  91. }
  92. public void Off()
  93. {
  94. if (this.gameObject.activeSelf)
  95. {
  96. this.gameObject.SetActive(false);
  97. OnCloseSelectBattleDeckAction?.Invoke();
  98. }
  99. Opening.instance.OffYesNoObjects();
  100. Opening.instance.deck.trialDraw.Close();
  101. Opening.instance.deck.deckListPanel.Close();
  102. }
  103. public UnityAction OnCloseSelectBattleDeckAction;
  104. public async void SetUpSelectBattleDeck(UnityAction OnClickSelectButtonAction, int defaulSelectDeckIndex)
  105. {
  106. if (SelectDeckObject.activeSelf)
  107. {
  108. return;
  109. }
  110. OnCloseSelectBattleDeckAction = null;
  111. //ContinuousController.instance.ModifyAllDeckDatas();
  112. SelectDeckObject.SetActive(true);
  113. anim.SetInteger("Open", 1);
  114. anim.SetInteger("Close", 0);
  115. ContinuousController.instance.StartCoroutine(SetDeckList(true));
  116. deckInfoPanel.OnClickSelectDeckAction = OnClickSelectButtonAction;
  117. if (ContinuousController.instance.DeckDatas.Count > 0)
  118. {
  119. if (ContinuousController.instance.LastBattleDeckData != null
  120. && ContinuousController.instance.DeckDatas.Contains(ContinuousController.instance.LastBattleDeckData))
  121. {
  122. await deckInfoPanel.SetUpDeckInfoPanel(ContinuousController.instance.LastBattleDeckData);
  123. }
  124. else
  125. {
  126. await deckInfoPanel.SetUpDeckInfoPanel(ContinuousController.instance.DeckDatas[0]);
  127. }
  128. }
  129. else
  130. {
  131. ResetDeckInfoPanel();
  132. }
  133. /*
  134. if (0 <= defaulSelectDeckIndex && defaulSelectDeckIndex <= ContinuousController.instance.DeckDatas.Count - 1)
  135. {
  136. await deckInfoPanel.SetUpDeckInfoPanel(ContinuousController.instance.DeckDatas[defaulSelectDeckIndex]);
  137. }
  138. */
  139. string message;
  140. if (ContinuousController.instance.isAI)
  141. {
  142. message = LocalizeUtility.GetLocalizedString(
  143. EngMessage: "Select Your Deck - Bot Match",
  144. JpnMessage: "使用デッキ選択 - Bot戦"
  145. );
  146. }
  147. else if (ContinuousController.instance.isRandomMatch)
  148. {
  149. message = LocalizeUtility.GetLocalizedString(
  150. EngMessage: "Select Your Deck - Random Match",
  151. JpnMessage: "使用デッキ選択 - ランダムマッチ"
  152. );
  153. }
  154. else
  155. {
  156. message = LocalizeUtility.GetLocalizedString(
  157. EngMessage: "Select Your Deck - Room Match",
  158. JpnMessage: "使用デッキ選択 - ルームマッチ"
  159. );
  160. }
  161. TitleText.text = message;
  162. SetSelectDeckButton();
  163. if (deckInfoPanel.ShowingDeckData != null)
  164. {
  165. InvalidDeckObject.SetActive(!deckInfoPanel.ShowingDeckData.IsValidDeckData());
  166. }
  167. }
  168. public void Close()
  169. {
  170. Close_(true);
  171. }
  172. public void Close_(bool playSE)
  173. {
  174. if (playSE)
  175. {
  176. Opening.instance.PlayCancelSE();
  177. }
  178. anim.SetInteger("Open", 0);
  179. anim.SetInteger("Close", 1);
  180. }
  181. public void ResetDeckInfoPanel()
  182. {
  183. deckInfoPanel.SetUpDeckInfoPanel(null);
  184. }
  185. public IEnumerator SetDeckList(bool open)
  186. {
  187. for (int i = 0; i < deckInfoPrefabParentScroll.content.childCount; i++)
  188. {
  189. Destroy(deckInfoPrefabParentScroll.content.GetChild(i).gameObject);
  190. }
  191. for (int i = 0; i < ContinuousController.instance.DeckDatas.Count; i++)
  192. {
  193. DeckInfoPrefab _deckInfoPrefab = Instantiate(deckInfoPrefab, deckInfoPrefabParentScroll.content);
  194. _deckInfoPrefab.scrollRect.content = deckInfoPrefabParentScroll.content;
  195. _deckInfoPrefab.scrollRect.viewport = deckInfoPrefabParentScroll.viewport;
  196. _deckInfoPrefab.scrollRect.verticalScrollbar = deckInfoPrefabParentScroll.verticalScrollbar;
  197. _deckInfoPrefab.SetUpDeckInfoPrefab(ContinuousController.instance.DeckDatas[i]);
  198. _deckInfoPrefab.transform.localScale = Opening.instance.DeckInfoPrefabStartScale * 1.02f;
  199. _deckInfoPrefab.OnClickAction = (deckdata) =>
  200. {
  201. deckInfoPanel.SetUpDeckInfoPanel(deckdata);
  202. SetSelectDeckButton();
  203. if (deckInfoPanel.ShowingDeckData != null)
  204. {
  205. InvalidDeckObject.SetActive(!deckInfoPanel.ShowingDeckData.IsValidDeckData());
  206. }
  207. Opening.instance.CreateOnClickEffect();
  208. };
  209. }
  210. yield return null;
  211. for (int i = 0; i < deckInfoPrefabParentScroll.content.childCount; i++)
  212. {
  213. deckInfoPrefabParentScroll.content.GetChild(i).transform.localScale = Opening.instance.DeckInfoPrefabStartScale;
  214. }
  215. if (ContinuousController.instance.DeckDatas.Count == 0)
  216. {
  217. }
  218. else
  219. {
  220. for (int i = 0; i < deckInfoPrefabParentScroll.content.childCount; i++)
  221. {
  222. if (deckInfoPrefabParentScroll.content.GetChild(i).GetComponent<DeckInfoPrefab>() != null)
  223. {
  224. if (deckInfoPrefabParentScroll.content.GetChild(i).GetComponent<DeckInfoPrefab>().thisDeckData == deckInfoPanel.ShowingDeckData && deckInfoPanel.DeckInfoPanelObject.activeSelf)
  225. {
  226. deckInfoPrefabParentScroll.content.GetChild(i).GetComponent<DeckInfoPrefab>().Outline.SetActive(true);
  227. }
  228. else
  229. {
  230. deckInfoPrefabParentScroll.content.GetChild(i).GetComponent<DeckInfoPrefab>().Outline.SetActive(false);
  231. }
  232. }
  233. }
  234. }
  235. if (open)
  236. {
  237. yield return new WaitForSeconds(Time.deltaTime);
  238. deckInfoPrefabParentScroll.verticalNormalizedPosition = 1;
  239. }
  240. }
  241. }