private void GenerateAllCards()
    {
        /*foreach (string cardInfo in PlayerInfo.DeckInventroy)
         * {
         *  Transform parent = GetCardPage();
         *  GameObject card = Instantiate(SelectCardPrefab, parent.position, Quaternion.identity,
         *      parent);
         *  PlayCardSelection_script pcs = card.GetComponentInChildren<PlayCardSelection_script>();
         *  PlayCard_script pc = card.GetComponentInChildren<PlayCard_script>();
         *  string[] cardString = cardInfo.Split(',');
         *  int cardAmount = int.Parse(cardString[0]);
         *  pc.Config(0, cardString[1], CardColors, GameController);
         *  pcs.ConfigDefaultCard(cardString[1], cardAmount, GameController);
         * }*/

        _allcards     = new List <PlayCard_script>();
        _allCardSlots = new List <PlayCardSelection_script>();
        _activePages  = 0;
        //Need to add check so only generation newly bought cards. currently clearing all and regenerating when new bought

        foreach (PlayerInfoManager_script.DeckInventroyClass cardInfo in PlayerInfo.PlayerDeck)
        {
            Transform  parent = GetCardPage();
            GameObject card   = Instantiate(SelectCardPrefab, parent.position, Quaternion.identity,
                                            parent);
            PlayCardSelection_script pcs = card.GetComponentInChildren <PlayCardSelection_script>();
            PlayCard_script          pc  = card.GetComponentInChildren <PlayCard_script>();

            pc.Config(0, cardInfo.CardInfo, CardColors, GameController);
            pcs.ConfigDefaultCard(cardInfo.CardInfo, cardInfo.CardAmount, GameController);

            _allcards.Add(pc);
            _allCardSlots.Add(pcs);
        }


        foreach (Transform c in _cardPages)
        {
            c.gameObject.SetActive(false);
            if (c.childCount > 0)
            {
                _activePages++;
            }
        }

        _activePages--; //reduce one to get array index
        _cardPages[0].gameObject.SetActive(true);

        if (_activePages <= 0) //one page? skip page setup
        {
            CardPageButtonHolder.SetActive(false);
            return;
        }

        _pageText.text = "1 / " + (_activePages + 1);

        _cardPageIndex = _cardPages.IndexOf(_cardPages[0]);
    }
Ejemplo n.º 2
0
    public void GenereteShop()
    {
        if (!NewShop)
        {
            return;
        }
        _activeList = new List <string>(ShopMasterList);
        int r = Random.Range(MinAmount, MaxAmount);

        foreach (Transform card in _cardHolder)
        {
            Destroy(card.gameObject);
        }

        CurrentShop = new List <ShopCardInfo>();
        for (int i = 0; i < r; i++)
        {
            _activeList.Shuffle();
            string[]     cardInfo = _activeList[r].Split(',');
            ShopCardInfo shopCard = new ShopCardInfo();

            shopCard.CardPrice = int.Parse(cardInfo[0]);
            shopCard.CardInfo  = cardInfo[1];

            GameObject card = Instantiate(DefaultCard, _cardHolder);
            card.SetActive(true);

            PlayCardSelection_script pcs = card.GetComponentInChildren <PlayCardSelection_script>();
            PlayCard_script          pc  = card.GetComponentInChildren <PlayCard_script>();
            pc.Config(0, shopCard.CardInfo, CardColors, GameController);
            pcs.ConfigDefaultCard(shopCard.CardInfo, 1, GameController);

            shopCard.PlayCard = pc;

            Button buyButton = pcs.transform.GetChild(2).GetChild(1).GetComponent <Button>();
            int    index     = i;
            buyButton.onClick.AddListener(() => BuyCard(index));
            TextMeshProUGUI priceText = card.transform.GetChild(3).GetComponent <TextMeshProUGUI>();
            priceText.text = shopCard.CardPrice.ToString("F0") + "\nCredits";

            if (PlayerInfoManager.Credits < shopCard.CardPrice)
            {
                buyButton.interactable = false;
            }

            shopCard.BuyButton = buyButton;

            CurrentShop.Add(shopCard);
        }

        NewShop = false;

        _refreshButton.interactable = _activePrice < PlayerInfoManager.Credits;
    }