Sanguosha.UI.Controls.PlayerViewModel._ConstructCardChoiceModel C# (CSharp) Method

_ConstructCardChoiceModel() private method

private _ConstructCardChoiceModel ( List sourceDecks, List resultDeckNames, List resultDeckMaximums, AdditionalCardChoiceOptions options, ICardChoiceVerifier verifier, int timeOutSeconds, CardChoiceRearrangeCallback callback ) : void
sourceDecks List
resultDeckNames List
resultDeckMaximums List
options Sanguosha.Core.UI.AdditionalCardChoiceOptions
verifier ICardChoiceVerifier
timeOutSeconds int
callback CardChoiceRearrangeCallback
return void
        private void _ConstructCardChoiceModel(List<DeckPlace> sourceDecks, List<string> resultDeckNames,
                                               List<int> resultDeckMaximums,
                                               AdditionalCardChoiceOptions options,
                                               ICardChoiceVerifier verifier,
                                               int timeOutSeconds,
                                               CardChoiceRearrangeCallback callback)
        {
            bool isSingleResult = (resultDeckMaximums.Sum() == 1);

            var choiceModel = new CardChoiceViewModel();

            int numLines = sourceDecks.Count;

            foreach (var deck in sourceDecks)
            {
                if (Game.CurrentGame.Decks[deck].Count == 0)
                {
                    continue;
                }
                CardChoiceLineViewModel line = new CardChoiceLineViewModel();
                line.DeckName = deck.DeckType.Name;
                line.IsResultDeck = false;
                int i = 0;
                int numCards = Game.CurrentGame.Decks[deck].Count;
                int maxColumns = Math.Max((numCards + 1) / 2, 5);
                bool firstRow = true;
                foreach (var card in Game.CurrentGame.Decks[deck])
                {
                    if (numLines == 1 && isSingleResult && i >= maxColumns && firstRow)
                    {
                        Trace.Assert(choiceModel.CardStacks.Count == 0);
                        choiceModel.CardStacks.Add(line);
                        line = new CardChoiceLineViewModel();
                        line.DeckName = deck.DeckType.Name;
                        line.IsResultDeck = false;
                        firstRow = false;
                    }
                    CardViewModel model = new CardViewModel()
                    {
                        Card = card,
                        IsSelectionMode = isSingleResult,
                        IsEnabled = true
                    };

                    line.Cards.Add(model);
                    i++;
                }
                choiceModel.CardStacks.Add(line);
            }

            if (!isSingleResult)
            {
                int k = 0;
                foreach (var deckName in resultDeckNames)
                {
                    CardChoiceLineViewModel line = new CardChoiceLineViewModel();
                    line.DeckName = deckName;
                    if (options != null)
                    {
                        if (options.Rearrangeable != null)
                        {
                            line.Rearrangable = options.Rearrangeable[k];
                        }
                        if (options.DefaultResult != null)
                        {
                            foreach (var card in options.DefaultResult[k])
                            {
                                line.Cards.Add(new CardViewModel() { Card = card });
                            }
                        }
                    }
                    line.Capacity = resultDeckMaximums[k++];
                    line.IsResultDeck = true;
                    choiceModel.CardStacks.Add(line);
                }
            }

            if (options != null && options.Options != null)
            {
                for (int i = 0; i < options.Options.Count; i++)
                {
                    MultiChoiceCommand command = new MultiChoiceCommand(ExecuteCardChoiceCommand)
                    {
                        CanExecuteStatus = false,
                        ChoiceKey = options.Options[i],
                        ChoiceIndex = i
                    };
                    choiceModel.MultiChoiceCommands.Add(command);
                }
            }
            else
            {
                MultiChoiceCommand command = new MultiChoiceCommand(ExecuteCardChoiceCommand)
                {
                    CanExecuteStatus = false,
                    ChoiceKey = new OptionPrompt("Confirm")
                };
                choiceModel.MultiChoiceCommands.Add(command);
            }
            if (options != null && options.IsCancellable)
            {
                MultiChoiceCommand command = new MultiChoiceCommand(CancelCardChoiceCommand)
                {
                    IsCancel = true,
                    ChoiceKey = new OptionPrompt("Cancel")
                };
                choiceModel.MultiChoiceCommands.Add(command);
            }

            choiceModel.Verifier = verifier;
            choiceModel.TimeOutSeconds = timeOutSeconds;
            CardChoiceModel = choiceModel;
        }