private void AddCardToDeck(DeckCard card, bool withoutCardAmountCounting) { // if there are no cards and no // groups in, create new deck if(this.deckLayout.Items.Count == 0 && this.deckLayout.Groups.Count != 4) { this.deckLayout.Groups.Clear(); this.CreateNewDeck(); } // checked if card exist bool cardIsIn = false; ListViewItem existingItem = null; foreach(ListViewItem item in this.deckLayout.Items) { DeckCard cd = (DeckCard)item.Tag; if(cd != null && cd.Card.Name.Equals(card.Name)) { existingItem = item; cardIsIn = true; break; } } // if card is in, increase amount if(cardIsIn && existingItem != null) { string number = existingItem.Text[0].ToString(); if(number.IsNumeric()) { int amount = number.ToInt32(); DeckCard cd = (DeckCard)existingItem.Tag; amount++; cd.Amount = amount; existingItem.Text = amount.ToString() + " " + cd.Card.Name; if(!withoutCardAmountCounting) { ListViewGroup group = existingItem.Group; if(group.Header.Contains("(") && group.Header.Contains(")")) { // ({0} cards) string name = group.Header.Substring(0, group.Header.IndexOf("(")).Trim(); string intNumber = group.Header.Substring( group.Header.IndexOf("(") + 1, group.Header.IndexOf("cards)") - group.Header.IndexOf("(") - 1 ).Trim(); int newNumber = intNumber.ToInt32() + 1; group.Header = name + " (" + newNumber.ToString() + " cards)"; } } } } else { ListViewItem listItem = new ListViewItem(); listItem.Name = card.Card.Name; listItem.Text = card.Amount + " " + card.Card.Name; listItem.Tag = card; if(card.Card.FirstEditionFromList != null) { string filename = Toenda.Lhurgoyf.Utility.Helper.CreateImageFilename( card.Card.FirstEditionFromList.Shortname, card.Card.Name ); if(!File.Exists(filename)) { if(!Directory.Exists("img\\" + card.Card.FirstEditionFromList.Shortname + "\\")) { Directory.CreateDirectory("img\\" + card.Card.FirstEditionFromList.Shortname + "\\"); } ImageLoader.DownloadImage( card.Card.FirstEditionImageFromList.Url.AbsoluteUri, filename, card.Card.MainType ); } Bitmap bmpToShrink = new Bitmap(filename); Bitmap bmp = this._imageGenerator.GenerateNewResolution(bmpToShrink, 48); this.deckLayout.LargeImageList.Images.Add(card.Card.Name, bmp); //this.deckLayout.SmallImageList.Images.Add(card.Card.Name, bmp); //this.deckLayout.StateImageList.Images.Add(card.Card.Name, bmp); listItem.ImageKey = card.Card.Name; ListViewGroup group = null; if(card.Sideboard) { group = this.deckLayout.Groups["Sideboard"]; } else { switch(card.Card.MainType) { case "Creature": group = this.deckLayout.Groups["Creatures"]; break; case "Land": group = this.deckLayout.Groups["Lands"]; break; default: group = this.deckLayout.Groups["Spells"]; break; } } if(!withoutCardAmountCounting) { if(group.Header.Contains("(") && group.Header.Contains(")")) { // ({0} cards) string name = group.Header.Substring(0, group.Header.IndexOf("(")).Trim(); string number = group.Header.Substring( group.Header.IndexOf("(") + 1, group.Header.IndexOf("cards)") - group.Header.IndexOf("(") - 1 ).Trim(); int newNumber = number.ToInt32() + 1; group.Header = name + " (" + newNumber.ToString() + " cards)"; } } listItem.Group = group; this.deckLayout.Items.Add(listItem); if(this.deckLayout.Tag != null) { Deck deck = (Deck)this.deckLayout.Tag; deck.CardList.Add(card); } } this.deckLayout.Refresh(); this.deckLayout.Update(); } this.SetDeckCardAmountLabel(); }
private void AddCardToDeck(Card card, int amount, bool isSideboard, bool withoutCardAmountCounting) { DeckCard deckCard = new DeckCard(); deckCard.Card = card; deckCard.Amount = amount; deckCard.Sideboard = isSideboard; this.AddCardToDeck(deckCard, withoutCardAmountCounting); }