private void card_MouseEnter(object sender, EventArgs args) { var currentCard = sender as CardView; if (!currentCard.IsEnabled) { return; } if (currentCard.CardModel != null) { CardChoiceViewModel model = DataContext as CardChoiceViewModel; var allCards = from stack in model.CardStacks select stack.Cards; foreach (var cards in allCards) { foreach (var card in cards) { if (card == currentCard.CardModel) { if (currentCard.CardModel.IsEnabled) { currentCard.CardModel.IsFaded = false; } } else { card.IsFaded = true; } } } } }
public static FrameworkElement CreateBox(CardChoiceViewModel choiceModel) { if (choiceModel == null) { return(null); } var results = from line in choiceModel.CardStacks where line.IsResultDeck select line; if (results.Count() > 0) { return(new CardArrangeBox() { DataContext = choiceModel, IsHitTestVisible = !choiceModel.DisplayOnly }); } else { return(new CardChoiceBox() { DataContext = choiceModel, IsHitTestVisible = !choiceModel.DisplayOnly }); } }
private void card_MouseLeave(object sender, EventArgs args) { var currentCard = sender as CardView; CardChoiceViewModel model = DataContext as CardChoiceViewModel; var allCards = from stack in model.CardStacks select stack.Cards; foreach (var cards in allCards) { foreach (var card in cards) { card.IsFaded = !card.IsEnabled; } } }
public static FrameworkElement CreateBox(CardChoiceViewModel choiceModel) { if (choiceModel == null) return null; var results = from line in choiceModel.CardStacks where line.IsResultDeck select line; if (results.Count() > 0) { return new CardArrangeBox() { DataContext = choiceModel }; } else { return new CardChoiceBox() { DataContext = choiceModel }; } }
private void _UpdateAnswer() { CardChoiceViewModel model = DataContext as CardChoiceViewModel; Trace.Assert(model != null); if (model == null) { return; } model.Answer.Clear(); foreach (var s in _allCardStacks) { if (!_stackInfo[s].IsResultDeck) { continue; } List <Card> subAnswer = new List <Card>(); foreach (var c in s.Cards) { subAnswer.Add(c.Card); } model.Answer.Add(subAnswer); } }
public void DisplayPrivateDeck(Player player, PrivateDeckViewModel model) { var choiceModel = new CardChoiceViewModel(); choiceModel.CanClose = true; choiceModel.Prompt = PromptFormatter.Format(new CardChoicePrompt("PrivateDeck", player, model.TraslatedName)); var lineViewModel = new CardChoiceLineViewModel(); lineViewModel.DeckName = model.Name; lineViewModel.Cards = model.Cards; choiceModel.CardStacks.Add(lineViewModel); choiceModel.DisplayOnly = true; deckDisplayWindow.DataContext = choiceModel; deckDisplayWindow.Show(); }
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 / 2 + 1, 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; }
private void UpdateModel() { CardChoiceViewModel model = DataContext as CardChoiceViewModel; if (model == null) { return; } _cardStacks.Children.Clear(); _canvas.Children.Clear(); if (model.CardStacks.Count == 0) { return; } int maxCount = (from line in model.CardStacks select line.Cards.Count).Max(); _cardStacks.Width = Math.Min(maxCount * Settings.CardChoiceBox.CardXSpacing, Settings.CardChoiceBox.MaxWindowWidth); _cardStacks.Height = model.CardStacks.Count * Settings.CardChoiceBox.CardYSpacing; ObservableCollection <string> deckNames = new ObservableCollection <string>(); // First, create layout. foreach (var line in model.CardStacks) { deckNames.Add(line.DeckName); CardStack stack = new SingleRowCardStack() { ParentCanvas = _canvas }; stack.MaxCardSpacing = Settings.CardChoiceBox.CardXSpacing; stack.MaxCardSpacingOnHighlighted = Settings.CardChoiceBox.CardXSpacing + 15; stack.CardAlignment = HorizontalAlignment.Center; stack.Height = 130d; stack.Margin = new Thickness(1, 10, 1, 10); stack.AddCards(line.Cards); foreach (var card in stack.Cards) { card.Cursor = Cursors.Hand; card.MouseEnter += card_MouseEnter; card.MouseLeave += card_MouseLeave; } stack.HorizontalAlignment = HorizontalAlignment.Left; stack.Width = _cardStacks.Width; _cardStacks.Children.Add(stack); } deckIcons.ItemsSource = deckNames; if (model == null || model.DisplayOnly) { return; } Trace.Assert(model != null); foreach (var s in model.CardStacks) { foreach (var card in s.Cards) { if (model.Verifier.Verify(new List <List <Card> >() { new List <Card>() { card.Card } }) != Core.UI.VerifierResult.Success) { card.IsEnabled = false; } card.OnSelectedChanged += (o, e) => { var c = o as CardViewModel; model.Answer.Clear(); model.Answer.Add(new List <Card>()); if (c.IsSelected) { model.Answer[0].Add(c.Card); foreach (var otherCardStack in model.CardStacks) { foreach (var otherCard in otherCardStack.Cards) { if (otherCard != o) { otherCard.IsSelected = false; } } } if (model.MultiChoiceCommands.Count == 1) { model.MultiChoiceCommands.First().Execute(null); } else { foreach (var command in model.MultiChoiceCommands) { MultiChoiceCommand mc = command as MultiChoiceCommand; mc.CanExecuteStatus = true; } } } else { foreach (var command in model.MultiChoiceCommands) { MultiChoiceCommand mc = command as MultiChoiceCommand; mc.CanExecuteStatus = false; } } }; } } if (model.MultiChoiceCommands.Count > 1) { gridChoices.Visibility = Visibility.Visible; } else { Trace.Assert(model.MultiChoiceCommands.Count == 1); gridChoices.Visibility = Visibility.Hidden; } if (model.TimeOutSeconds > 0) { Duration duration = new Duration(TimeSpan.FromSeconds(model.TimeOutSeconds)); DoubleAnimation doubleanimation = new DoubleAnimation(100d, 0d, duration); progressBar.BeginAnimation(ProgressBar.ValueProperty, doubleanimation); } }
public void UpdateModel() { CardChoiceViewModel model = DataContext as CardChoiceViewModel; if (model == null) { return; } _cardStacks.Children.Clear(); _cardSlots.Children.Clear(); _canvas.Children.Clear(); _slotCanvas.Children.Clear(); _allCardStacks.Clear(); _allCardSlots.Clear(); _originalPlace.Clear(); _stackInfo.Clear(); _stackToSlot.Clear(); _resultPanel.Children.Clear(); _resultSlotPanel.Children.Clear(); int maxCount = (from line in model.CardStacks select line.Cards.Count).Max(); var resultDecks = from line in model.CardStacks where line.IsResultDeck select line; bool isResultHorizontal = (resultDecks.Max(l => l.Capacity) == 1); if (isResultHorizontal) { maxCount = Math.Max(maxCount, resultDecks.Count()); } _cardStacks.Width = Math.Min(maxCount * Settings.CardChoiceBox.CardXSpacing, Settings.CardChoiceBox.MaxWindowWidth); if (isResultHorizontal) { _cardStacks.Height = (model.CardStacks.Count - resultDecks.Count() + 1) * Settings.CardChoiceBox.CardYSpacing; } else { _cardStacks.Height = model.CardStacks.Count * Settings.CardChoiceBox.CardYSpacing; } _cardSlots.Width = _cardStacks.Width; _cardSlots.Height = _cardStacks.Height; ObservableCollection <string> deckNames = new ObservableCollection <string>(); // First, create layout. foreach (var line in model.CardStacks) { CardStack slot = new CardStack() { ParentCanvas = _slotCanvas }; slot.MaxCardSpacing = Settings.CardChoiceBox.CardXSpacing; slot.CardAlignment = HorizontalAlignment.Left; slot.Height = 130d; slot.Margin = new Thickness(1, 10, 1, 10); if (isResultHorizontal && line.IsResultDeck) { slot.HorizontalAlignment = HorizontalAlignment.Left; slot.Width = line.Capacity * Settings.CardChoiceBox.CardXSpacing; _resultSlotPanel.Children.Add(slot); } else { slot.HorizontalAlignment = HorizontalAlignment.Stretch; _cardSlots.Children.Add(slot); } if (line.IsResultDeck) { string key = string.Format("CardSlot.Hint.{0}", line.DeckName); string hint = (Application.Current.TryFindResource(key) as string) ?? string.Empty; var slots = new List <CardViewModel>(); for (int i = 0; i < line.Capacity; i++) { slots.Add(new CardSlotViewModel() { Hint = hint, Card = null }); } slot.AddCards(slots); foreach (var cardSlot in slot.Cards) { cardSlot.IsHitTestVisible = false; } } else { deckNames.Add(line.DeckName); } var stack = new SingleRowCardStack() { ParentCanvas = _canvas }; stack.IsDraggingHandled = false; stack.MaxCardSpacing = Settings.CardChoiceBox.CardXSpacing; stack.MaxCardSpacingOnHighlighted = Settings.CardChoiceBox.CardXSpacing; stack.CardAlignment = HorizontalAlignment.Left; stack.Height = 130d; stack.Margin = new Thickness(1, 10, 1, 10); stack.AddCards(line.Cards); _stackInfo.Add(stack, line); foreach (var cardView in stack.Cards) { _originalPlace.Add(cardView, stack); if (!model.DisplayOnly) { cardView.DragDirection = DragDirection.Both; cardView.OnDragBegin += cardView_OnDragBegin; cardView.OnDragging += cardView_OnDragging; cardView.OnDragEnd += cardView_OnDragEnd; } } if (isResultHorizontal && line.IsResultDeck) { stack.HorizontalAlignment = HorizontalAlignment.Left; stack.Width = line.Capacity * Settings.CardChoiceBox.CardXSpacing; _resultPanel.Children.Add(stack); } else { stack.HorizontalAlignment = HorizontalAlignment.Left; stack.Width = _cardStacks.Width; _cardStacks.Children.Add(stack); } _stackToSlot.Add(stack, slot); _allCardStacks.Add(stack); _allCardSlots.Add(slot); } deckIcons.ItemsSource = deckNames; if (isResultHorizontal) { _cardStacks.Children.Add(_resultPanel); _cardSlots.Children.Add(_resultSlotPanel); } _UpdateAnswer(); _UpdateVerifiedStatus(); // Progress bar if (model.TimeOutSeconds > 0) { Duration duration = new Duration(TimeSpan.FromSeconds(model.TimeOutSeconds)); DoubleAnimation doubleanimation = new DoubleAnimation(100d, 0d, duration); progressBar.BeginAnimation(ProgressBar.ValueProperty, doubleanimation); } }
private void cardView_OnDragEnd(object sender, EventArgs e) { CardChoiceViewModel model = DataContext as CardChoiceViewModel; if (model == null) { return; } _ResetHighlightSlot(); if (_highlightedStack != null) { int newPos = _highlightedStack.InteractingCardIndex; List <CardView> backup1 = new List <CardView>(_sourceDeck.Cards); var backup2 = new List <CardView>(_highlightedStack.Cards); int from = _sourceDeck.Cards.IndexOf(InteractingCard); int to = newPos; _sourceDeck.Cards.Remove(InteractingCard); _highlightedStack.Cards.Insert(newPos, InteractingCard); _sourceDeck.InteractingCard = null; _sourceDeck.CardStatus = CardInteraction.None; _sourceDeck.RearrangeCards(); if (_sourceDeck != _highlightedStack) { _highlightedStack.InteractingCard = null; _highlightedStack.CardStatus = CardInteraction.None; _highlightedStack.RearrangeCards(); } _UpdateAnswer(); if (model.Verifier.Verify(model.Answer) == Core.UI.VerifierResult.Fail) { _sourceDeck.Cards.Clear(); foreach (var card in backup1) { _sourceDeck.Cards.Add(card); } _sourceDeck.RearrangeCards(); if (_sourceDeck != _highlightedStack) { Trace.Assert(backup2 != null); _highlightedStack.Cards.Clear(); foreach (var card in backup2) { _highlightedStack.Cards.Add(card); } _highlightedStack.InteractingCard = null; _UpdateAnswer(); _highlightedStack.CardStatus = CardInteraction.None; _highlightedStack.RearrangeCards(); } } else { var handle = OnCardMoved; if (handle != null) { int s = _allCardStacks.IndexOf(_sourceDeck); int d = _allCardStacks.IndexOf(_highlightedStack); Trace.Assert(s >= 0 && d >= 0 && from >= 0 && to >= 0); handle(s, from, d, to); } } _sourceDeck = null; _highlightedStack = null; } else if (_sourceDeck != null) { _sourceDeck.InteractingCard = null; _sourceDeck.CardStatus = CardInteraction.None; _sourceDeck.RearrangeCards(); } _UpdateVerifiedStatus(); }
private void _UpdateVerifiedStatus() { CardChoiceViewModel model = DataContext as CardChoiceViewModel; if (model == null || model.DisplayOnly) { return; } int i = 0; while (!model.CardStacks[i].IsResultDeck) { i++; } bool enabled = (model.Verifier.Verify(model.Answer) == Core.UI.VerifierResult.Success); foreach (var option in model.MultiChoiceCommands) { var mc = option as MultiChoiceCommand; mc.CanExecuteStatus = enabled; } foreach (var stack in _allCardStacks) { if (_stackInfo[stack].IsResultDeck) { break; } foreach (var card in stack.Cards) { bool possible = false; int j = 0; foreach (var list in model.Answer) { // @todo : For now, we do not verify the order of cards. int capacity = model.CardStacks[i + j].Capacity; Trace.Assert(capacity >= list.Count && !list.Contains(card.Card)); if (model.CardStacks[i + j].Capacity == list.Count) { continue; } list.Add(card.Card); if (model.Verifier.Verify(model.Answer) != Core.UI.VerifierResult.Fail) { possible = true; list.Remove(card.Card); break; } list.Remove(card.Card); j++; } if (possible) { card.DragDirection = DragDirection.Both; } else { card.DragDirection = DragDirection.Horizontal; } card.CardModel.IsEnabled = possible; card.CardModel.IsFaded = !possible; } } }
public PlayerViewModel() { IsSelectionMode = false; AutoInvokeSkillCommands = new ObservableCollection<SkillCommand>(); ActiveSkillCommands = new ObservableCollection<SkillCommand>(); DockedSkillCommands = new ObservableCollection<SkillCommand>(); RulerGivenSkillCommands = new ObservableCollection<SkillCommand>(); HeroSkillNames = new ObservableCollection<string>(); heroNameChars = new ObservableCollection<string>(); MultiChoiceCommands = new ObservableCollection<ICommand>(); submitCardUsageCommand = new SimpleRelayCommand(SubmitCardUsageCommand); cancelCardUsageCommand = new SimpleRelayCommand(CancelCardUsageCommand); abortCardUsageCommand = new SimpleRelayCommand(AbortCardUsageCommand); SubmitAnswerCommand = DisabledCommand; CancelAnswerCommand = DisabledCommand; AbortAnswerCommand = DisabledCommand; _possibleRoles = new ObservableCollection<Role>(); _updateCardUsageStatusHandler = (o, e) => { _UpdateCardUsageStatus(); }; IsCardChoiceQuestionShown = false; CardChoiceModel = new CardChoiceViewModel(); Marks = new ObservableCollection<MarkViewModel>(); HandCards = new ObservableCollection<CardViewModel>(); verifierLock = new object(); _lastSelectedPlayers = new List<Player>(); }