| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using System;
- using UnityEngine.UI;
- using System.Linq;
- using UnityEngine.Events;
- using System.IO;
- using System.Text;
- using System.Runtime.Serialization.Formatters.Binary;
- using System.Threading.Tasks;
- public class DeckInfoPanel : MonoBehaviour
- {
- [Header("デッキ情報パネルオブジェクト")]
- public GameObject DeckInfoPanelObject;
- [Header("キーカード画像")]
- public Image KeyCardImage;
- [Header("デッキ名InputField")]
- public InputField DeckName;
- [Header("デッキ名Text")]
- public Text DeckNameText;
- [Header("カード色カウント")]
- public List<CardColorCount> cardColorCountList = new List<CardColorCount>();
- [Header("デッキコード取得ボタン")]
- public Button GetDeckCodeButton;
- [Header("デッキ枚数テキスト")]
- public Text DeckCountText;
- public Button TrialDrawButton;
- public bool isFromSelectDeck;
- public DeckData ShowingDeckData = null;
- public async Task SetUpDeckInfoPanel(DeckData deckData)
- {
- DeckInfoPanelObject.SetActive(deckData != null);
- if (deckData != null)
- {
- if (GetComponent<Animator>() != null)
- {
- GetComponent<Animator>().SetInteger("Open", 1);
- GetComponent<Animator>().SetInteger("Close", 0);
- }
- ShowingDeckData = deckData;
- //MC card image
- KeyCardImage.gameObject.SetActive(deckData.KeyCard != null);
- if (deckData.KeyCard != null)
- {
- KeyCardImage.sprite = await deckData.KeyCard.GetCardSprite();
- }
- else
- {
- KeyCardImage.sprite = null;
- }
- //deck name
- if (DeckName != null)
- {
- DeckName.text = deckData.DeckName;
- DeckName.onEndEdit.RemoveAllListeners();
- DeckName.onEndEdit.AddListener(SetDeckName);
- }
- if (DeckNameText != null)
- {
- DeckNameText.text = deckData.DeckName;
- DeckNameText.transform.parent.gameObject.SetActive(deckData.GetThisDeckCode() != DeckData.EmptyDeckData().GetThisDeckCode());
- }
- //Number of cards of each color
- if (cardColorCountList != null)
- {
- if (cardColorCountList.Count > 0)
- {
- foreach (CardColorCount cardColorCount in cardColorCountList)
- {
- if (cardColorCount != null)
- {
- cardColorCount.SetUpCardColorCount(deckData);
- ContinuousController.instance.StartCoroutine(cardColorCount.SetIconScale());
- }
- }
- }
- }
- //Number of cards in the deck
- if (DeckCountText != null)
- {
- DeckCountText.text = $"{deckData.DeckCards().Count}+{deckData.DigitamaDeckCards().Count}/50+5";
- if (deckData.IsValidDeckData())
- {
- DeckCountText.color = new Color32(69, 255, 69, 255);
- }
- else
- {
- DeckCountText.color = new Color32(255, 64, 64, 255);
- }
- }
- //Get Deck Code button
- if (GetDeckCodeButton != null)
- {
- GetDeckCodeButton.gameObject.SetActive(deckData.IsValidDeckData());
- }
- if (TrialDrawButton != null)
- {
- TrialDrawButton.gameObject.SetActive(ShowingDeckData.DeckCards().Count >= 1);
- }
- }
- }
- public void OnClickTrial5DrawButton()
- {
- Opening.instance.deck.trialDraw.Off();
- ContinuousController.instance.StartCoroutine(Opening.instance.deck.trialDraw.SetUpTrialDraw(ShowingDeckData.DeckCards()));
- }
- public void OnClickEditButton()
- {
- if (ShowingDeckData != null)
- {
- Opening.instance.deck.editDeck.SetUpCreateDeck(ShowingDeckData, isFromSelectDeck);
- }
- }
- public void OnClickShowDeckButton()
- {
- if (ShowingDeckData != null)
- {
- Opening.instance.deck.deckListPanel.Off();
- ContinuousController.instance.StartCoroutine(Opening.instance.deck.deckListPanel.SetUpDeckListPanel(ShowingDeckData, null, ""));
- }
- }
- public void OnClickDeleteDeckButton()
- {
- if (ShowingDeckData != null)
- {
- DeckData deckData = ShowingDeckData;
- List<UnityAction> Commands = new List<UnityAction>()
- {
- () =>
- {
- if(isFromSelectDeck)
- {
- ContinuousController.instance.DeckDatas.Remove(deckData);
- ContinuousController.instance.StartCoroutine(Opening.instance.deck.selectDeck.SetDeckList(false));
- Opening.instance.deck.selectDeck.ResetDeckInfoPanel();
- ContinuousController.instance.SaveDeckDatas();
- }
- },
- null
- };
- List<string> CommandTexts = new List<string>()
- {
- LocalizeUtility.GetLocalizedString(
- EngMessage: "Yes",
- JpnMessage: "はい"
- ),
- LocalizeUtility.GetLocalizedString(
- EngMessage: "No",
- JpnMessage: "いいえ"
- ),
- };
- Opening.instance.SetUpActiveYesNoObject(
- Commands,
- CommandTexts,
- LocalizeUtility.GetLocalizedString(
- EngMessage: "Delete the deck?",
- JpnMessage: "デッキを削除しますか?"
- ),
- true);
- }
- }
- public void OnClickGetDeckCodeButton()
- {
- if (ShowingDeckData != null)
- {
- if (ShowingDeckData != null)
- {
- GUIUtility.systemCopyBuffer = DeckCodeUtility.GetDeckBuilderDeckCode(ShowingDeckData.AllDeckCards());
- List<UnityAction> Commands = new List<UnityAction>()
- {
- null
- };
- List<string> CommandTexts = new List<string>()
- {
- "OK"
- };
- Opening.instance.SetUpActiveYesNoObject(
- Commands,
- CommandTexts,
- LocalizeUtility.GetLocalizedString(
- EngMessage: "Copied the deck code to the clipboard!\n(Also, you can use it for Digimon Card dev.)",
- JpnMessage: "デッキコードをクリップボードにコピーしました!\n(Digimon Card dev.でも使えます)"
- ),
- true);
- }
- }
- }
- public void SetDeckName(string text)
- {
- if (string.IsNullOrEmpty(text))
- {
- text = ShowingDeckData.DeckName;
- DeckName.text = ShowingDeckData.DeckName;
- }
- if (ShowingDeckData.DeckName == text)
- {
- return;
- }
- text = DeckData.ValidateDeckName(text);
- while (text.Length > 15)
- {
- text = text.Substring(0, text.Length - 1);
- }
- ShowingDeckData.DeckName = text;
- ContinuousController.instance.SaveDeckDatas();
- if (isFromSelectDeck)
- {
- if (Opening.instance.deck.selectDeck != null)
- {
- if (Opening.instance.deck.editDeck != null)
- {
- if (Opening.instance.deck.editDeck.CreateDeckObject.activeSelf)
- {
- return;
- }
- }
- ContinuousController.instance.StartCoroutine(Opening.instance.deck.selectDeck.SetDeckList(false));
- for (int i = 0; i < Opening.instance.deck.selectDeck.deckInfoPrefabParentScroll.content.childCount; i++)
- {
- if (Opening.instance.deck.selectDeck.deckInfoPrefabParentScroll.content.GetChild(i).GetComponent<DeckInfoPrefab>() != null)
- {
- if (Opening.instance.deck.selectDeck.deckInfoPrefabParentScroll.content.GetChild(i).GetComponent<DeckInfoPrefab>().thisDeckData == ShowingDeckData)
- {
- Opening.instance.deck.selectDeck.deckInfoPrefabParentScroll.content.GetChild(i).GetComponent<DeckInfoPrefab>().OnClick_DeckInfoPrefab(true);
- }
- }
- }
- }
- }
- else
- {
- if (Opening.instance.battle.selectBattleDeck != null)
- {
- if (Opening.instance.deck.editDeck != null)
- {
- if (Opening.instance.deck.editDeck.CreateDeckObject.activeSelf)
- {
- return;
- }
- }
- ContinuousController.instance.StartCoroutine(Opening.instance.battle.selectBattleDeck.SetDeckList(false));
- for (int i = 0; i < Opening.instance.battle.selectBattleDeck.deckInfoPrefabParentScroll.content.childCount; i++)
- {
- if (Opening.instance.battle.selectBattleDeck.deckInfoPrefabParentScroll.content.GetChild(i).GetComponent<DeckInfoPrefab>() != null)
- {
- if (Opening.instance.battle.selectBattleDeck.deckInfoPrefabParentScroll.content.GetChild(i).GetComponent<DeckInfoPrefab>().thisDeckData == ShowingDeckData)
- {
- Opening.instance.battle.selectBattleDeck.deckInfoPrefabParentScroll.content.GetChild(i).GetComponent<DeckInfoPrefab>().OnClick_DeckInfoPrefab(true);
- }
- }
- }
- }
- }
- }
- public UnityAction OnClickSelectDeckAction;
- public void OnClickSelectDeck()
- {
- Opening.instance.PlayDecisionSE();
- OnClickSelectDeckAction?.Invoke();
- }
- }
- [Serializable]
- public class CardColorCount
- {
- [Header("Corresponding color")]
- public CardColor cardColor;
- [Header("Count Text")]
- public Text CountText;
- public Image icon;
- public void SetUpCardColorCount(DeckData deckData)
- {
- if (CountText != null)
- {
- CountText.text = $"{deckData.DeckCards().Count((card) => card.cardColors[0] == cardColor)}";
- }
- }
- public IEnumerator SetIconScale()
- {
- if (icon != null)
- {
- icon.transform.localScale = new Vector3(1.02f, 1.02f, 1);
- yield return null;
- icon.transform.localScale = new Vector3(1, 1, 1);
- }
- }
- }
|