/// <summary> /// Safely update full deck and drawn cards contents, and redraw the set of displayed cards /// </summary> private void UpdateDeckSafe(List <CardWithCount> allCards, List <CardWithCount> currentCards) { if (allCards != null) { AllCards = allCards; } if (currentCards != null) { CurrentCards = currentCards; } // Assume both AllCards and CurrentCards are sorted List <CardWithCount> remainingCards; if (AllCards.Count > 0) { remainingCards = Utilities.Clone(AllCards); int j = 0; for (int i = 0; i < remainingCards.Count; i++) { if (j < CurrentCards.Count && remainingCards[i].Code == CurrentCards[j].Code && remainingCards[i].IsFromDeck == CurrentCards[j].IsFromDeck) { remainingCards[i].Count = CurrentCards[j].Count; j++; } else { remainingCards[i].Count = 0; } } if (HideZeroCountCards) { remainingCards = remainingCards.FindAll(x => x.Count > 0).ToList(); } } else { remainingCards = CurrentCards.Clone(); } if (remainingCards.Count == 0) { MyDeckControl.IsMinimized = false; } MyDeckControl.SetDeck(remainingCards); MyDeckStatsDisplay.TheDeck = remainingCards; MyDeckStatsDisplay.Invalidate(); FixMySize(); if (AllCards.Count == 0 && CurrentCards.Count == 0) { Hide(); } else if (IsNonEmptyDeckVisible) { Show(); } }
/// <summary> /// Fix the size of the window to match the size of the deck control /// <param name="shouldInvalidate">If true, deck control is invalidated</param> /// </summary> private void FixMySize(bool shouldInvalidate = true) { Size bestSize = MyDeckControl.GetBestSize(); int deckStatsHeight = MyDeckStatsDisplay.GetBestHeight(bestSize.Width); MyDeckControl.SetBounds(0, 0, bestSize.Width, bestSize.Height, BoundsSpecified.Size); if (ShouldShowDeckStats && deckStatsHeight > 0) { MyDeckStatsDisplay.SetBounds(0, bestSize.Height, bestSize.Width, deckStatsHeight, BoundsSpecified.All); MyDeckStatsDisplay.Visible = true; } else { MyDeckStatsDisplay.Visible = false; deckStatsHeight = 0; } SetBounds(0, 0, bestSize.Width, bestSize.Height + deckStatsHeight, BoundsSpecified.Size); if (shouldInvalidate) { MyDeckControl.Invalidate(); } }