| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using UnityEngine.Events;
- public class DeckListPanel : MonoBehaviour
- {
- private static readonly int OpenHash = Animator.StringToHash("Open");
- private static readonly int CloseHash = Animator.StringToHash("Close");
- public Animator anim;
- public CardPrefab_CreateDeck cardPrefab_CreateDeckPrefab;
- public DetailCard_DeckEditor detailCard;
- public ScrollRect DeckScroll;
- public Text DeckNameText;
- public Text DeckCountText;
- public GameObject DeckListPanelObject;
- public IEnumerator SetUpDeckListPanel(DeckData deckData, UnityAction<CEntity_Base> onClickAction, string CustomMessage)
- {
- detailCard.OffDetailCard();
- for (int i = 0; i < DeckScroll.content.childCount; i++)
- {
- Destroy(DeckScroll.content.GetChild(i).gameObject);
- }
- yield return new WaitWhile(() => DeckScroll.content.childCount > 0);
- #region デッキ名を表示
- DeckNameText.text = deckData.DeckName;
- if(!string.IsNullOrEmpty(CustomMessage))
- {
- DeckNameText.text = CustomMessage;
- }
- #endregion
- #region デッキのカードを取得
- List<CEntity_Base> DeckCards = new List<CEntity_Base>();
- foreach (CEntity_Base cEntity_Base in deckData.AllDeckCards())
- {
- DeckCards.Add(cEntity_Base);
- }
- #endregion
- #region デッキのカードを生成
- foreach (CEntity_Base cEntity_Base in DeckCards)
- {
- CardPrefab_CreateDeck _cardPrefab_CreateDeck = null;
- _cardPrefab_CreateDeck = Instantiate(cardPrefab_CreateDeckPrefab, DeckScroll.content);
- _cardPrefab_CreateDeck.OnEnterAction = (cardPrefab) => { OnDetailCard(cEntity_Base, Vector3.zero); };
- //_cardPrefab_CreateDeck.OnExitAction = (cardPrefab) => { OffDetailCard(); };
- SetUpDeckCard(_cardPrefab_CreateDeck, cEntity_Base);
- _cardPrefab_CreateDeck.HideDeckCardTab();
- if(onClickAction != null)
- {
- _cardPrefab_CreateDeck.OnClickAction = () => onClickAction(_cardPrefab_CreateDeck.cEntity_Base);
- }
- }
- #endregion
- SetDeckCountText(deckData);
- yield return new WaitWhile(() => DeckScroll.content.childCount < DeckCards.Count);
- this.gameObject.SetActive(true);
- yield return new WaitForSeconds(Time.deltaTime);
- DeckScroll.verticalNormalizedPosition = 1;
- yield return ContinuousController.instance.StartCoroutine(OpenCoroutine(deckData));
- }
- IEnumerator OpenCoroutine(DeckData deckData)
- {
- yield return new WaitWhile(() => DeckScroll.content.childCount < deckData.AllDeckCards().Count);
- yield return new WaitForSeconds(Time.deltaTime);
- Open();
- yield return new WaitWhile(() => DeckListPanelObject.transform.localScale.y < 0.9f);
- DeckScroll.verticalNormalizedPosition = 1;
- for (int i = 0; i < DeckScroll.content.childCount; i++)
- {
- DeckScroll.content.GetChild(i).GetComponent<CardPrefab_CreateDeck>().SetUpCardPrefab_CreateDeck(DeckScroll.content.GetChild(i).GetComponent<CardPrefab_CreateDeck>().cEntity_Base);
- DeckScroll.content.GetChild(i).GetComponent<CardPrefab_CreateDeck>().ShowCardImage();
- }
- }
- public void Open()
- {
- On();
- anim.SafeSetInt(OpenHash, 1);
- anim.SafeSetInt(CloseHash, 0);
- }
- public void Close()
- {
- //OffDetailCard();
- anim.SafeSetInt(OpenHash, 0);
- anim.SafeSetInt(CloseHash, 1);
- }
- public void On()
- {
- this.gameObject.SetActive(true);
- }
- public void Off()
- {
- this.gameObject.SetActive(false);
- //Close();
- }
- #region Card Detail View
- public void OffDetailCard()
- {
- //detailCard.GetComponent<DetailCard_DeckEditor>().OffDetailCard();
- }
- public void OnDetailCard(CEntity_Base cEntity_Base, Vector3 position)
- {
- detailCard.GetComponent<DetailCard_DeckEditor>().SetUpDetailCard(cEntity_Base);
- }
- #endregion
- public void SetUpDeckCard(CardPrefab_CreateDeck _cardPrefab_CreateDeck, CEntity_Base cEntity_Base)
- {
- foreach (ScrollRect _scroll in _cardPrefab_CreateDeck.scroll)
- {
- _scroll.content = DeckScroll.content;
- _scroll.viewport = DeckScroll.viewport;
- }
- _cardPrefab_CreateDeck.SetUpCardPrefab_CreateDeck(cEntity_Base);
- _cardPrefab_CreateDeck.ShowCardImage();
- _cardPrefab_CreateDeck.Parent.localScale = new Vector3(0.7f, 0.7f, 0.7f);
- }
- #region Display the number of cards in the deck text
- public void SetDeckCountText(DeckData deckData)
- {
- 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);
- }
- }
- #endregion
- }
|