コード例 #1
0
        /// <summary>
        /// Updated the whole UI using a deck code
        /// </summary>
        /// <param name="deckCode"></param>
        /// <returns></returns>
        private async Task Update(string deckCode)
        {
            //Decode the string into a deck. See if it's valid
            DecodedDeck decodedDeck = await m_client.DecodeDeckAsync(deckCode);

            if (decodedDeck == null)
            {
                Console.WriteLine("Unable to get deck. DeckCode is invald");
                return;
            }

            g_Loading.Visibility = Visibility.Visible;

            /*Reset all UI holder*/
            if (img_HeroOne.Source != null)
            {
                img_HeroOne.Source = null;
            }
            if (img_HeroTwo.Source != null)
            {
                img_HeroTwo.Source = null;
            }
            if (img_HeroThree.Source != null)
            {
                img_HeroThree.Source = null;
            }
            if (img_HeroFour.Source != null)
            {
                img_HeroFour.Source = null;
            }
            if (img_HeroFive.Source != null)
            {
                img_HeroFive.Source = null;
            }

            await SetFocusedCard(-1, ArtType.Ingame, Enums.Language.English);

            t_totalCards.Text    = null;
            t_totalItems.Text    = null;
            t_TCSpell.Text       = null;
            t_TCCreep.Text       = null;
            t_TCImprovement.Text = null;
            t_TIarmor.Text       = null;
            t_TIweapon.Text      = null;
            t_TIhealth.Text      = null;
            t_TIconsumable.Text  = null;
            /*End of resetting UI holders*/

            //Set the deck name title
            tb_DeckName.Text = decodedDeck.Name;

            //Decode the deck to the complete deck
            Deck deck = await m_client.GetCardsFromDecodedDeckAsync(decodedDeck);

            //Populate the hero UI
            List <System.Windows.Controls.Image> heroImageHolders = new List <System.Windows.Controls.Image>()
            {
                img_HeroOne, img_HeroTwo, img_HeroThree, img_HeroFour, img_HeroFive
            };

            for (int i = 0; i < deck.Heroes.Count; i++)
            {
                int additional = 0;
                int turn       = deck.Heroes[i].Turn;
                if (turn > 1)
                {
                    turn += 2; //Add 2 because of heroImageHolders elements 0-2
                }
                //If the hero turn is 1, but already added a hero, then increase additional counter
                while (heroImageHolders[turn - 1 + additional].Source != null)
                {
                    additional++;
                }

                System.Windows.Controls.Image img = heroImageHolders[turn - 1 + additional];
                img.Source      = GetImageFromUrl(deck.Heroes[i].IngameImage.Default);
                img.DataContext = deck.Heroes[i]; //Set context for click event finding card art
            }

            //Sort cards by mana cost & set UI
            List <GenericCard> sortedList = deck.Cards.OrderBy(x => x.ManaCost).ToList();

            ic_genericCardsList.ItemsSource = sortedList;

            //Total cards excludes items, hence the separate total items UI
            int totalGeneric = deck.Cards.Sum(x => x is GenericCard && x.Type == CardType.Item ? ((GenericCard)x).Count : 0);

            t_totalCards.Text = $"{totalGeneric} CARDS";
            t_totalItems.Text = $"{deck.Cards.Sum(x => x.Type == CardType.Item ? x.Count : 0)} ITEMS";

            //Find out both colors of deck and get stats for each color
            CardColor       colorOne     = GetOtherColor(deck.Cards, CardColor.None);
            CardColor       colorTwo     = GetOtherColor(deck.Cards, colorOne | CardColor.None);
            ManaDeckInfoDto deckManaInfo = new ManaDeckInfoDto()
            {
                OneManaCards       = GetManaAmount(deck.Cards, 1),
                TwoManaCards       = GetManaAmount(deck.Cards, 2),
                ThreeManaCards     = GetManaAmount(deck.Cards, 3),
                FourManaCards      = GetManaAmount(deck.Cards, 4),
                FiveManaCards      = GetManaAmount(deck.Cards, 5),
                SixManaCards       = GetManaAmount(deck.Cards, 6),
                SevenManaCards     = GetManaAmount(deck.Cards, 7),
                EightPlusManaCards = deck.Cards.Sum(x => x.ManaCost >= 8 ? x.Count : 0),

                ColorOneBrush          = FactionColorToBrush(colorOne),
                ColorTwoBrush          = FactionColorToBrush(colorTwo),
                ColorOneTotalCardCount = deck.Cards.Sum(x => x.FactionColor == colorOne ? x.Count : 0),
                ColorTwoTotalCardCount = deck.Cards.Sum(x => x.FactionColor == colorTwo ? x.Count : 0),
            };

            deckManaInfo.MaxManaCardCount = GetMaxMana(deckManaInfo.OneManaCards,
                                                       deckManaInfo.TwoManaCards,
                                                       deckManaInfo.ThreeManaCards,
                                                       deckManaInfo.FourManaCards,
                                                       deckManaInfo.FiveManaCards,
                                                       deckManaInfo.SixManaCards,
                                                       deckManaInfo.SevenManaCards,
                                                       deckManaInfo.EightPlusManaCards);

            ic_deckStats.ItemsSource = new List <ManaDeckInfoDto>()
            {
                deckManaInfo
            };

            //Set relevant stat information for deck
            t_TCSpell.Text       = deck.Cards.Sum(x => x.Type == CardType.Spell ? x.Count : 0).ToString();
            t_TCCreep.Text       = deck.Cards.Sum(x => x.Type == CardType.Creep ? x.Count : 0).ToString();
            t_TCImprovement.Text = deck.Cards.Sum(x => (x.Type == CardType.Improvement) ? x.Count : 0).ToString();

            t_TIarmor.Text      = deck.Cards.Sum(x => x.Type == CardType.Item && x.SubType == CardType.Armor ? x.Count : 0).ToString();
            t_TIweapon.Text     = deck.Cards.Sum(x => x.Type == CardType.Item && x.SubType == CardType.Weapon ? x.Count : 0).ToString();
            t_TIhealth.Text     = deck.Cards.Sum(x => x.Type == CardType.Item && x.SubType == CardType.Accessory ? x.Count : 0).ToString();
            t_TIconsumable.Text = deck.Cards.Sum(x => x.Type == CardType.Item && x.SubType == CardType.Consumable ? x.Count : 0).ToString();

            g_Loading.Visibility = Visibility.Collapsed;
        }