SelectBattleDeck.cs 8.9 KB

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