Пример #1
0
    //sets values of the card
    public void setData(XMLDeckEntry newData)
    {
        data = newData.clone();
        cardNameText.text  = data.name;
        cardCountText.text = data.count.ToString();

        //set color based on card count
        if (data.count <= DeckRules.MAX_CARDS_OF_SAME_TYPE)
        {
            cardCountText.color = normalColor;
        }
        else
        {
            cardCountText.color = overColor;
        }
    }
Пример #2
0
    //called when an existing deck entry changes
    public void deckEntryUpdated(XMLDeckEntry updatedEntry)
    {
        //Debug.Log("deckEntryUpdated"); //DEBUG ONLY

        //first, we have to find the entry that changed
        XMLDeckEntry oldEntry = null;

        foreach (XMLDeckEntry curEntry in openDeck.contents)
        {
            if (curEntry.name == updatedEntry.name)
            {
                oldEntry = curEntry;
                break;
            }
        }

        //if the entry was not in the deck, bail
        if (oldEntry == null)
        {
            Debug.LogError("updated an entry that is not in the deck!");
            return;
        }

        //if the count is now zero, we remove it from the list.  Otherwise, we update it.
        if (updatedEntry.count == 0)
        {
            openDeck.contents.Remove(oldEntry);
            //since an entry was removed, we need to update these lists as well
            CardTypeList.SendMessage("refresh", openDeck);
            CurrentDeckList.SendMessage("refresh", openDeck);
        }
        else
        {
            oldEntry.count = updatedEntry.count;
        }

        unsavedChanges = true; //mark the deck as having changed

        //update the counter to reflect it
        CardCount.SendMessage("refresh", openDeck);
    }
Пример #3
0
    //handles button clicks from the card type list
    public void CardSelected(PlayerCardData c)
    {
        //Debug.Log("CardSelected"); //DEBUG ONLY

        //check the open deck and ignore the message if that card is already in the deck
        foreach (XMLDeckEntry entry in openDeck.contents)
        {
            if (entry.name == c.cardName)
            {
                return;
            }
        }

        //otherwise, we add the card to the deck
        XMLDeckEntry newEntry = new XMLDeckEntry(c.cardName, 1);

        openDeck.contents.Add(newEntry);
        unsavedChanges = true;
        CardCount.SendMessage("refresh", openDeck);
        CurrentDeckList.SendMessage("refresh", openDeck);
        CardTypeList.SendMessage("refresh", openDeck);
    }
Пример #4
0
 //match() overload that takes XMLDeckEntry instead
 public bool match(XMLDeckEntry xEntry)
 {
     return(match(CardTypeManagerScript.instance.getCardByName(xEntry.name)));
 }
Пример #5
0
 //something in the editor wants to preview the given card, but doesnt know how to reach the card preview, so it sent it here instead.
 //this just passes the message along to the intended destination
 public void PreviewXMLDeckEntry(XMLDeckEntry xC)
 {
     cardPreview.SendMessage("PreviewXMLDeckEntry", xC);
 }
Пример #6
0
 public int Compare(XMLDeckEntry a, XMLDeckEntry b)
 {
     return(Compare(CardTypeManagerScript.instance.getCardByName(a.name), CardTypeManagerScript.instance.getCardByName(b.name)));
 }
Пример #7
0
 public int Compare(XMLDeckEntry a, XMLDeckEntry b)
 {
     return(string.Compare(a.name, b.name));
 }
Пример #8
0
    /// <summary>
    /// fetches data on the given deck entry and then previews that card type
    /// </summary>
    private void PreviewXMLDeckEntry(XMLDeckEntry xC)
    {
        PlayerCardData c = CardTypeManagerScript.instance.getCardByName(xC.name);

        StartCoroutine("PreviewCard", c);
    }
    //refreshes the list.  If deck is not null, also sets that as the new deck
    public void refresh(XMLDeck deck)
    {
        if (deck != null)
        {
            data = deck;
        }

        //update existing entries as needed and keep a list of which ones no longer exist
        List <DeckEditorCurrentDeckEntryScript> toRemove = new List <DeckEditorCurrentDeckEntryScript>();

        foreach (DeckEditorCurrentDeckEntryScript entry in deckEntries)
        {
            XMLDeckEntry xde = data.contents.FirstOrDefault(x => x.name == entry.cardName);
            if (xde != null)
            {
                //this entry still corresponds to a card that is in the deck.  Update it

                //update count
                if (entry.cardCount != xde.count)
                {
                    entry.cardCount = xde.count;
                }

                //figure out what color it should be
                Color buttonColor;
                switch (CardTypeManagerScript.instance.getCardByName(xde.name).cardType)
                {
                case PlayerCardType.tower: buttonColor = towerColor; break;

                case PlayerCardType.upgrade: buttonColor = upgradeColor; break;

                case PlayerCardType.spell: buttonColor = spellColor; break;

                default:
                    Debug.LogWarning("current deck list doesnt know what color to use for this card. (" + xde.name + ")");
                    buttonColor = Color.black;
                    break;
                }

                //highlight if it does not match the current filter
                if (filter != null)
                {
                    if (filter.match(xde) == false)
                    {
                        buttonColor = Color.Lerp(buttonColor, highlightColor, 0.5f);
                    }
                }

                //update color
                entry.setColor(buttonColor);
            }
            else
            {
                //the card for this entry is no longer in the deck
                toRemove.Add(entry);
            }
        }

        //get rid of the ones that no longer exist
        foreach (DeckEditorCurrentDeckEntryScript e in toRemove)
        {
            deckEntries.Remove(e);
            Destroy(e.gameObject);
        }

        //create new entries for cards that dont have them yet
        foreach (XMLDeckEntry xEntry in data.contents)
        {
            if (deckEntries.Any(de => de.cardName == xEntry.name) == false)
            {
                //create the entry and add it to the list
                DeckEditorCurrentDeckEntryScript entry = Instantiate(currentDeckEntryPrefab).GetComponent <DeckEditorCurrentDeckEntryScript>();
                entry.setData(xEntry);
                entry.transform.SetParent(this.transform, false);
                deckEntries.Add(entry);

                //set its color based on its type
                Color buttonColor;
                switch (CardTypeManagerScript.instance.getCardByName(xEntry.name).cardType)
                {
                case PlayerCardType.tower: buttonColor = towerColor; break;

                case PlayerCardType.upgrade: buttonColor = upgradeColor; break;

                case PlayerCardType.spell: buttonColor = spellColor; break;

                default:
                    Debug.LogWarning("current deck list doesnt know what color to use for this card. (" + xEntry.name + ")");
                    buttonColor = Color.black;
                    break;
                }

                //highlight if it does not match the current filter
                if (filter != null)
                {
                    if (filter.match(xEntry) == false)
                    {
                        buttonColor = Color.Lerp(buttonColor, highlightColor, 0.5f);
                    }
                }
                entry.setColor(buttonColor);
            }
        }
    }