public void Sort(ResultSortOrder newSortOrder) { if (Cards == null) { return; } this.sortOrder = newSortOrder != ResultSortOrder.None ? newSortOrder : ResultSortOrder.Name; switch (this.sortOrder) { case ResultSortOrder.Cost: Cards = Cards.OrderBy(c => c.Cost).ToCardList(); break; case ResultSortOrder.Set: // Order them by set then alphabetically // This makes the most sense because it's probably // being used by someone who has the cards in the // original set boxes Cards = Cards.OrderBy(c => c.Set + "," + c.DisplayName).ToCardList(); break; case ResultSortOrder.Name: default: Cards = Cards.OrderBy(c => c.DisplayName).ToCardList(); // Orders them randomly, not used ////Cards = Cards.OrderBy(c => Guid.NewGuid()).ToCardList(); break; } }
private void UpdateSorting(ResultSortOrder sortOrder) { this.MainView.Result.GroupedCards.First(g => g.Key.Type == CardGroupType.KingdomCard).Sort(sortOrder); // The sort button will display the next sort order option String nextSort = sortOrder.Next().ToString(); this.SortButton.Text = Strings.ResourceManager.GetString("Results_Sort" + nextSort, Strings.Culture); this.SortButton.IconUri = new Uri("/images/appbar.sort." + nextSort + ".png", UriKind.Relative); }
private void UpdateSorting(ResultSortOrder sortOrder) { this.MainView.Result.GroupedCards.First(g => g.Key.Type == CardGroupType.KingdomCard).Sort(sortOrder); // The sort button will display the next sort order option String nextSort = sortOrder.Next().ToString(); this.SortButton.Label = Strings.GetString("Results_Sort" + nextSort); //this.SortButton.Icon = new BitmapIcon() //{ // UriSource = new Uri("ms-appx:///Images/appbar.sort." + nextSort + ".png") //}; }
public static ResultSortOrder Next(this ResultSortOrder sortOrder) { switch (sortOrder) { case ResultSortOrder.Name: return(ResultSortOrder.Cost); case ResultSortOrder.Cost: return(ResultSortOrder.Set); case ResultSortOrder.Set: return(ResultSortOrder.Name); default: return(ResultSortOrder.Name); } }
/// <summary> /// Generates a new card list using the current settings /// </summary> /// <returns>True if the list was successfully generated, false otherwise</returns> public bool GenerateCardList() { if (this.Settings.SelectedSets.Count == 0) { return(false); } try { this.IsGenerating = true; // Save the sort order from the current result if there is one. ResultSortOrder sortOrder = this.Result != null ? this.Result.SortOrder : ResultSortOrder.Name; this.Result = Picker.GenerateCardList(this.Settings, sortOrder); } finally { this.IsGenerating = false; } return(this.Result != null); }
public void Sort(ResultSortOrder sortOrder) { IEnumerable <Card> orderedCards; if (sortOrder == ResultSortOrder.Name) { orderedCards = this.OrderBy(c => c.Name); } else { Type cardType = typeof(Card); var sortProperty = cardType.GetProperty(sortOrder.ToString(), BindingFlags.Public | BindingFlags.Instance); orderedCards = this.OrderBy(c => sortProperty.GetValue(c)).ThenBy(c => c.Name); } List <Card> newCardsList = orderedCards.ToList(); this.Clear(); foreach (Card card in newCardsList) { this.Add(card); } }
public static PickerResult GenerateCardList(SettingsViewModel settings, ResultSortOrder sortOrder) { // This is the number of cards to generate in the set const Int32 count = 10; // Reperesents the number of times we've tried to find a set Int32 creationAttempts = 0; List <CardSet> availableSets; Int32 minimumCardsPerSet = settings.MinimumCardsPerSet.Enabled ? settings.MinimumCardsPerSet.OptionValue : 1; Int32 maxSets = (Int32)Math.Floor((double)count / minimumCardsPerSet); PickerResult result = new PickerResult(); generationCanceled = false; try { isGenerating = true; do { // Allows fast fail if (generationCanceled) { return(null); } creationAttempts++; // 1. Select the sets that are going to be in the result { // Starting with the pinned sets take as many as we can availableSets = settings.Sets .Where(s => s.Required) .Select(s => s.Set) .OrderBy(s => Guid.NewGuid()) .Take(maxSets) .ToList(); // Fill in the remainder with random sets. We don't care if it's // one that's already in the result which means that we could end // up with fewer than N sets (e.g. even if MinCardsPerSet is 5 we // can still end up with all cards from a single set). for (int i = availableSets.Count; i < maxSets; i++) { availableSets.Add(settings.SelectedSets[random.Next(settings.SelectedSets.Count)]); } availableSets = availableSets.Distinct().ToList(); } // 2. Initialize the card pool { result.Pool = Cards.PickableCards.Where(c => c.InSet(availableSets)).Where(c => !settings.FilteredCards.Ids.Contains(c.ID)).OrderBy(c => Guid.NewGuid()).ToCardList(); } // 3. Generate a set of cards { List <Card> cardSet = new List <Card>(); // For each of the sets in the result, take the minimum number of cards foreach (var set in availableSets) { result.Pool.Where(c => c.InSet(set)).Take(minimumCardsPerSet).Move(result.Pool, cardSet); } // Then fill up the card set with random cards result.Pool.Take(10 - cardSet.Count).Move(result.Pool, cardSet); // Put the cards in the result to get access to all the properties we want CardGroup kingdomCard = new CardGroup(CardGroupType.KingdomCard); result.Cards = cardSet.Select(c => c.WithGroup(kingdomCard)).ToCardList(); } // 3. Verify the validity of the set, if it's not valid, generate another // If we have <= 10 cards, there are no other possible sets to generate // so don't look at any of the options just use this set if (result.Cards.Count >= 10) { if (!CheckResultValidity(settings, result)) { continue; } } // 4. Add any additional cards/tokens/etc. that we might need AddAdditionalCards(settings, result); break; } while (true); } finally { isGenerating = false; } AppLog.Instance.Log(String.Format("Completed in {0} tries.", creationAttempts)); //EasyTracker.GetTracker().SendEvent("Picker", "Generate Set", "Complete", creationAttempts); result.SortOrder = sortOrder != ResultSortOrder.None ? sortOrder : ResultSortOrder.Name; return(result); }