DeckInfoPanel.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using System;
  5. using UnityEngine.UI;
  6. using System.Linq;
  7. using UnityEngine.Events;
  8. using System.IO;
  9. using System.Text;
  10. using System.Runtime.Serialization.Formatters.Binary;
  11. using System.Threading.Tasks;
  12. public class DeckInfoPanel : MonoBehaviour
  13. {
  14. [Header("デッキ情報パネルオブジェクト")]
  15. public GameObject DeckInfoPanelObject;
  16. [Header("キーカード画像")]
  17. public Image KeyCardImage;
  18. [Header("デッキ名InputField")]
  19. public InputField DeckName;
  20. [Header("デッキ名Text")]
  21. public Text DeckNameText;
  22. [Header("カード色カウント")]
  23. public List<CardColorCount> cardColorCountList = new List<CardColorCount>();
  24. [Header("デッキコード取得ボタン")]
  25. public Button GetDeckCodeButton;
  26. [Header("デッキ枚数テキスト")]
  27. public Text DeckCountText;
  28. public Button TrialDrawButton;
  29. public bool isFromSelectDeck;
  30. public DeckData ShowingDeckData = null;
  31. public async Task SetUpDeckInfoPanel(DeckData deckData)
  32. {
  33. DeckInfoPanelObject.SetActive(deckData != null);
  34. if (deckData != null)
  35. {
  36. if (GetComponent<Animator>() != null)
  37. {
  38. GetComponent<Animator>().SetInteger("Open", 1);
  39. GetComponent<Animator>().SetInteger("Close", 0);
  40. }
  41. ShowingDeckData = deckData;
  42. //MC card image
  43. KeyCardImage.gameObject.SetActive(deckData.KeyCard != null);
  44. if (deckData.KeyCard != null)
  45. {
  46. KeyCardImage.sprite = await deckData.KeyCard.GetCardSprite();
  47. }
  48. else
  49. {
  50. KeyCardImage.sprite = null;
  51. }
  52. //deck name
  53. if (DeckName != null)
  54. {
  55. DeckName.text = deckData.DeckName;
  56. DeckName.onEndEdit.RemoveAllListeners();
  57. DeckName.onEndEdit.AddListener(SetDeckName);
  58. }
  59. if (DeckNameText != null)
  60. {
  61. DeckNameText.text = deckData.DeckName;
  62. DeckNameText.transform.parent.gameObject.SetActive(deckData.GetThisDeckCode() != DeckData.EmptyDeckData().GetThisDeckCode());
  63. }
  64. //Number of cards of each color
  65. if (cardColorCountList != null)
  66. {
  67. if (cardColorCountList.Count > 0)
  68. {
  69. foreach (CardColorCount cardColorCount in cardColorCountList)
  70. {
  71. if (cardColorCount != null)
  72. {
  73. cardColorCount.SetUpCardColorCount(deckData);
  74. ContinuousController.instance.StartCoroutine(cardColorCount.SetIconScale());
  75. }
  76. }
  77. }
  78. }
  79. //Number of cards in the deck
  80. if (DeckCountText != null)
  81. {
  82. DeckCountText.text = $"{deckData.DeckCards().Count}+{deckData.DigitamaDeckCards().Count}/50+5";
  83. if (deckData.IsValidDeckData())
  84. {
  85. DeckCountText.color = new Color32(69, 255, 69, 255);
  86. }
  87. else
  88. {
  89. DeckCountText.color = new Color32(255, 64, 64, 255);
  90. }
  91. }
  92. //Get Deck Code button
  93. if (GetDeckCodeButton != null)
  94. {
  95. GetDeckCodeButton.gameObject.SetActive(deckData.IsValidDeckData());
  96. }
  97. if (TrialDrawButton != null)
  98. {
  99. TrialDrawButton.gameObject.SetActive(ShowingDeckData.DeckCards().Count >= 1);
  100. }
  101. }
  102. }
  103. public void OnClickTrial5DrawButton()
  104. {
  105. Opening.instance.deck.trialDraw.Off();
  106. ContinuousController.instance.StartCoroutine(Opening.instance.deck.trialDraw.SetUpTrialDraw(ShowingDeckData.DeckCards()));
  107. }
  108. public void OnClickEditButton()
  109. {
  110. if (ShowingDeckData != null)
  111. {
  112. Opening.instance.deck.editDeck.SetUpCreateDeck(ShowingDeckData, isFromSelectDeck);
  113. }
  114. }
  115. public void OnClickShowDeckButton()
  116. {
  117. if (ShowingDeckData != null)
  118. {
  119. Opening.instance.deck.deckListPanel.Off();
  120. ContinuousController.instance.StartCoroutine(Opening.instance.deck.deckListPanel.SetUpDeckListPanel(ShowingDeckData, null, ""));
  121. }
  122. }
  123. public void OnClickDeleteDeckButton()
  124. {
  125. if (ShowingDeckData != null)
  126. {
  127. DeckData deckData = ShowingDeckData;
  128. List<UnityAction> Commands = new List<UnityAction>()
  129. {
  130. () =>
  131. {
  132. if(isFromSelectDeck)
  133. {
  134. ContinuousController.instance.DeckDatas.Remove(deckData);
  135. ContinuousController.instance.StartCoroutine(Opening.instance.deck.selectDeck.SetDeckList(false));
  136. Opening.instance.deck.selectDeck.ResetDeckInfoPanel();
  137. ContinuousController.instance.DeleteDeck(deckData);
  138. }
  139. },
  140. null
  141. };
  142. List<string> CommandTexts = new List<string>()
  143. {
  144. LocalizeUtility.GetLocalizedString(
  145. EngMessage: "Yes",
  146. JpnMessage: "はい"
  147. ),
  148. LocalizeUtility.GetLocalizedString(
  149. EngMessage: "No",
  150. JpnMessage: "いいえ"
  151. ),
  152. };
  153. Opening.instance.SetUpActiveYesNoObject(
  154. Commands,
  155. CommandTexts,
  156. LocalizeUtility.GetLocalizedString(
  157. EngMessage: "Delete the deck?",
  158. JpnMessage: "デッキを削除しますか?"
  159. ),
  160. true);
  161. }
  162. }
  163. public void OnClickGetDeckCodeButton()
  164. {
  165. if (ShowingDeckData != null)
  166. {
  167. if (ShowingDeckData != null)
  168. {
  169. GUIUtility.systemCopyBuffer = DeckCodeUtility.GetDeckBuilderDeckCode(ShowingDeckData.AllDeckCards());
  170. List<UnityAction> Commands = new List<UnityAction>()
  171. {
  172. null
  173. };
  174. List<string> CommandTexts = new List<string>()
  175. {
  176. "OK"
  177. };
  178. Opening.instance.SetUpActiveYesNoObject(
  179. Commands,
  180. CommandTexts,
  181. LocalizeUtility.GetLocalizedString(
  182. EngMessage: "Copied the deck code to the clipboard!\n(Also, you can use it for Digimon Card dev.)",
  183. JpnMessage: "デッキコードをクリップボードにコピーしました!\n(Digimon Card dev.でも使えます)"
  184. ),
  185. true);
  186. }
  187. }
  188. }
  189. public void SetDeckName(string text)
  190. {
  191. if (string.IsNullOrEmpty(text))
  192. {
  193. text = ShowingDeckData.DeckName;
  194. DeckName.text = ShowingDeckData.DeckName;
  195. }
  196. if (ShowingDeckData.DeckName == text)
  197. {
  198. return;
  199. }
  200. while (text.Length > DeckName.characterLimit)
  201. {
  202. text = text.Substring(0, text.Length - 1);
  203. }
  204. ContinuousController.instance.RenameDeck(ShowingDeckData, text);
  205. if (isFromSelectDeck)
  206. {
  207. if (Opening.instance.deck.selectDeck != null)
  208. {
  209. if (Opening.instance.deck.editDeck != null)
  210. {
  211. if (Opening.instance.deck.editDeck.CreateDeckObject.activeSelf)
  212. {
  213. return;
  214. }
  215. }
  216. ContinuousController.instance.StartCoroutine(Opening.instance.deck.selectDeck.SetDeckList(false));
  217. for (int i = 0; i < Opening.instance.deck.selectDeck.deckInfoPrefabParentScroll.content.childCount; i++)
  218. {
  219. if (Opening.instance.deck.selectDeck.deckInfoPrefabParentScroll.content.GetChild(i).GetComponent<DeckInfoPrefab>() != null)
  220. {
  221. if (Opening.instance.deck.selectDeck.deckInfoPrefabParentScroll.content.GetChild(i).GetComponent<DeckInfoPrefab>().thisDeckData == ShowingDeckData)
  222. {
  223. Opening.instance.deck.selectDeck.deckInfoPrefabParentScroll.content.GetChild(i).GetComponent<DeckInfoPrefab>().OnClick_DeckInfoPrefab(true);
  224. }
  225. }
  226. }
  227. }
  228. }
  229. else
  230. {
  231. if (Opening.instance.battle.selectBattleDeck != null)
  232. {
  233. if (Opening.instance.deck.editDeck != null)
  234. {
  235. if (Opening.instance.deck.editDeck.CreateDeckObject.activeSelf)
  236. {
  237. return;
  238. }
  239. }
  240. ContinuousController.instance.StartCoroutine(Opening.instance.battle.selectBattleDeck.SetDeckList(false));
  241. for (int i = 0; i < Opening.instance.battle.selectBattleDeck.deckInfoPrefabParentScroll.content.childCount; i++)
  242. {
  243. if (Opening.instance.battle.selectBattleDeck.deckInfoPrefabParentScroll.content.GetChild(i).GetComponent<DeckInfoPrefab>() != null)
  244. {
  245. if (Opening.instance.battle.selectBattleDeck.deckInfoPrefabParentScroll.content.GetChild(i).GetComponent<DeckInfoPrefab>().thisDeckData == ShowingDeckData)
  246. {
  247. Opening.instance.battle.selectBattleDeck.deckInfoPrefabParentScroll.content.GetChild(i).GetComponent<DeckInfoPrefab>().OnClick_DeckInfoPrefab(true);
  248. }
  249. }
  250. }
  251. }
  252. }
  253. }
  254. public UnityAction OnClickSelectDeckAction;
  255. public void OnClickSelectDeck()
  256. {
  257. Opening.instance.PlayDecisionSE();
  258. OnClickSelectDeckAction?.Invoke();
  259. }
  260. }
  261. [Serializable]
  262. public class CardColorCount
  263. {
  264. [Header("Corresponding color")]
  265. public CardColor cardColor;
  266. [Header("Count Text")]
  267. public Text CountText;
  268. public Image icon;
  269. public void SetUpCardColorCount(DeckData deckData)
  270. {
  271. if (CountText != null)
  272. {
  273. CountText.text = $"{deckData.DeckCards().Count((card) => card.cardColors[0] == cardColor)}";
  274. }
  275. }
  276. public IEnumerator SetIconScale()
  277. {
  278. if (icon != null)
  279. {
  280. icon.transform.localScale = new Vector3(1.02f, 1.02f, 1);
  281. yield return null;
  282. icon.transform.localScale = new Vector3(1, 1, 1);
  283. }
  284. }
  285. }