Beispiel #1
0
 protected override void RegisterCardEvents(CardView card)
 {
     card.OnDragBegin += cardBeginDragHandler;
     card.OnDragging += cardDraggingHandler;
     card.OnDragEnd += cardEndDragHandler;
     card.MouseEnter += cardMouseEnterHandler;
     card.MouseLeave += cardMouseLeaveHandler;
 }
 void PrivateDeckBox_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
 {
     var model = DataContext as IList<CardViewModel>;
     if (model == null) return;
     this.Width = Math.Min(model.Count * 93, 500);
     foreach (var card in model)
     {
         CardView view = new CardView(card) { Opacity = 1.0 };
         cardStack.Cards.Add(view);
     }
     cardStack.RearrangeCards();
 }
Beispiel #3
0
        void PrivateDeckBox_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            var model = DataContext as IList <CardViewModel>;

            if (model == null)
            {
                return;
            }
            this.Width = Math.Min(model.Count * 93, 500);
            foreach (var card in model)
            {
                CardView view = new CardView(card)
                {
                    Opacity = 1.0
                };
                cardStack.Cards.Add(view);
            }
            cardStack.RearrangeCards();
        }
Beispiel #4
0
        protected override IList <CardView> RemoveHandCards(IList <Card> cards, bool isCopy)
        {
            var cardsToRemove = new List <CardView>();

            foreach (var card in cards)
            {
                bool found = false;
                foreach (var cardView in handCardArea.Cards)
                {
                    CardViewModel viewModel = cardView.DataContext as CardViewModel;
                    Trace.Assert(viewModel != null);
                    if (viewModel.Card == card)
                    {
                        if (isCopy)
                        {
                            var copy = CardView.CreateCard(cardView.Card);
                            ParentGameView.GlobalCanvas.Children.Add(copy);
                            copy.SetCurrentPosition(cardView.Position);
                            copy.Opacity = 100;
                            cardsToRemove.Add(copy);
                        }
                        else
                        {
                            cardsToRemove.Add(cardView);
                            cardView.CardModel.IsSelected = false;
                            cardView.DragDirection        = DragDirection.None;
                        }
                        found = true;
                        break;
                    }
                }
                if (!found)
                {
                    cardsToRemove.Add(CardView.CreateCard(card));
                }
            }
            Trace.Assert(cardsToRemove.Count == cards.Count);
            if (!isCopy)
            {
                handCardArea.RemoveCards(cardsToRemove);
            }
            return(cardsToRemove);
        }
Beispiel #5
0
 protected override void UnRegisterCardEvents(CardView card)
 {
     if (card == InteractingCard)
     {
         if (CardStatus == CardInteraction.Drag)
         {
             card_OnDragEndUnlock();
         }
         if (CardStatus == CardInteraction.MouseMove)
         {
             card_MouseLeaveUnlock();
         }
     }
     card.OnDragBegin -= cardBeginDragHandler;
     card.OnDragging -= cardDraggingHandler;
     card.OnDragEnd -= cardEndDragHandler;
     card.MouseEnter -= cardMouseEnterHandler;
     card.MouseLeave -= cardMouseLeaveHandler;
 }
Beispiel #6
0
        protected override void AddDelayedTool(CardView card, bool isFaked)
        {
            SmallDelayedToolView dtv = new SmallDelayedToolView()
            {
                Width = 23, Height = 24
            };

            dtv.DataContext = card.CardModel;
            dtv.Opacity     = 0;
            dtv.Margin      = new Thickness(0, 0, 50d, 0);
            delayedToolsDock.Children.Add(dtv);

            if (isFaked)
            {
                card.Disappear(0d, true);
            }
            else
            {
                Point dest = delayedToolsDock.TranslatePoint(new Point(-11.5, delayedToolsDock.ActualHeight / 2),
                                                             ParentGameView.GlobalCanvas);
                dest.Offset(-card.Width / 2, -card.Height / 2);
                card.Position = dest;
                card.Disappear(0.5d, true);
                card.Rebase();
            }

            Storyboard         storyBoard = new Storyboard();
            ThicknessAnimation animation1 = new ThicknessAnimation();
            DoubleAnimation    animation2 = new DoubleAnimation();

            animation1.To       = new Thickness(0d, 0d, 0d, 0d);
            animation2.To       = 1.0d;
            animation1.Duration = TimeSpan.FromMilliseconds(500);
            animation2.Duration = TimeSpan.FromMilliseconds(500);
            Storyboard.SetTarget(animation1, dtv);
            Storyboard.SetTarget(animation2, dtv);
            Storyboard.SetTargetProperty(animation1, new PropertyPath(SmallDelayedToolView.MarginProperty));
            Storyboard.SetTargetProperty(animation2, new PropertyPath(SmallDelayedToolView.OpacityProperty));
            storyBoard.Children.Add(animation1);
            storyBoard.Children.Add(animation2);
            storyBoard.Begin();
        }
Beispiel #7
0
 protected override void UnregisterCardEvents(CardView card)
 {
     if (card == InteractingCard)
     {
         if (CardStatus == CardInteraction.Drag)
         {
             card_OnDragEndUnlock();
         }
         if (CardStatus == CardInteraction.MouseMove)
         {
             card_MouseLeaveUnlock();
         }
     }
     card.OnDragBegin -= cardBeginDragHandler;
     card.OnDragging  -= cardDraggingHandler;
     card.OnDragEnd   -= cardEndDragHandler;
     card.MouseEnter  -= cardMouseEnterHandler;
     card.MouseLeave  -= cardMouseLeaveHandler;
     registeredCards.Remove(card);
 }
Beispiel #8
0
        protected override void AddRoleCard(CardView card, bool isFaked)
        {
            if (isFaked)
            {
                card.Disappear(0d, true);
                return;
            }

            card.Position = ComputeCardCenterPos(card, cbRoleBox);
            card.RenderTransformOrigin = new Point(0.5, 0.5);
            card.Opacity = 1.0;

            RotateTransform rotate         = new RotateTransform();
            ScaleTransform  scale          = new ScaleTransform();
            var             transformGroup = new TransformGroup();

            transformGroup.Children.Add(rotate);
            transformGroup.Children.Add(scale);
            card.RenderTransform = transformGroup;

            DoubleAnimation rotateAnim = new DoubleAnimation(180, new Duration(TimeSpan.FromSeconds(0.8d)));
            DoubleAnimation scaleXAnim = new DoubleAnimation(0.25, new Duration(TimeSpan.FromSeconds(0.8d)));
            DoubleAnimation scaleYAnim = new DoubleAnimation(0.25, new Duration(TimeSpan.FromSeconds(0.8d)));

            Storyboard.SetTarget(rotateAnim, card);
            Storyboard.SetTarget(scaleXAnim, card);
            Storyboard.SetTarget(scaleYAnim, card);
            Storyboard.SetTargetProperty(rotateAnim, new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[0].(RotateTransform.Angle)"));
            Storyboard.SetTargetProperty(scaleXAnim, new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[1].(ScaleTransform.ScaleX)"));
            Storyboard.SetTargetProperty(scaleYAnim, new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[1].(ScaleTransform.ScaleY)"));
            Storyboard storyboard = new Storyboard();

            storyboard.Children.Add(rotateAnim);
            storyboard.Children.Add(scaleXAnim);
            storyboard.Children.Add(scaleYAnim);
            card.AddRebaseAnimation(storyboard, 0.8d);
            storyboard.AccelerationRatio = 0.4d;
            storyboard.Begin();
            card.Disappear(1.2d, true);
        }
Beispiel #9
0
        public virtual void AppendCards(IList <CardView> cards)
        {
            if (cards.Count == 0)
            {
                return;
            }
            Canvas canvas = cards[0].Parent as Canvas;
            // Compute the position that the cards should appear
            Point rightMost;

            if (Cards.Count > 0)
            {
                CardView lastCard = Cards.Last();
                rightMost = lastCard.TranslatePoint(new Point(lastCard.ActualWidth * 2, 0), canvas);
            }
            else
            {
                rightMost = TranslatePoint(new Point(this.ActualWidth / 2, 0), canvas);
            }
            rightMost.Y = this.TranslatePoint(new Point(0, this.ActualHeight / 2 - cards[0].Height / 2), canvas).Y;
            foreach (var card in cards)
            {
                if (IsCardConsumer)
                {
                    card.Disappear(_cardOpacityChangeAnimationDurationSeconds, true);
                }
                else
                {
                    card.CardModel.IsFaded = false;
                    card.SetCurrentPosition(rightMost);
                    rightMost.X += card.ActualWidth;
                    card.Appear(0.3d);
                    Cards.Add(card);
                    RegisterCardEvents(card);
                }
            }
            RearrangeCards();
        }
Beispiel #10
0
        internal override void UpdateCards()
        {
            weaponArea.Child = null;
            armorArea.Child  = null;
            horse1Area.Child = null;
            horse2Area.Child = null;
            delayedToolsDock.Children.Clear();

            base.UpdateCards();

            if (PlayerModel == null)
            {
                return;
            }
            var player = PlayerModel.Player;

            if (player == null)
            {
                return;
            }

            EquipCommand[] commands = { PlayerModel.WeaponCommand,         PlayerModel.ArmorCommand,
                                        PlayerModel.DefensiveHorseCommand, PlayerModel.OffensiveHorseCommand };
            foreach (var equip in commands)
            {
                if (equip != null)
                {
                    AddEquipment(CardView.CreateCard(equip, ParentGameView.GlobalCanvas), true);
                }
            }

            foreach (var dt in player.DelayedTools())
            {
                AddDelayedTool(CardView.CreateCard(dt, ParentGameView.GlobalCanvas), true);
            }
        }
Beispiel #11
0
        public IList <CardView> RemoveCards(DeckType deck, IList <Card> cards, bool isCopy)
        {
            IList <CardView> result    = new List <CardView>();
            IList <CardView> remaining = new List <CardView>();

            foreach (var card in cards)
            {
                var oldCardView = Cards.FirstOrDefault(
                    c => ((card.Id > 0 && c.Card.Id == card.Id) || (card.Id <= 0 && c.Card == card)));
                var cardView = CardView.CreateCard(card);
                if (oldCardView != null)
                {
                    ParentCanvas.Children.Add(cardView);
                    cardView.SetCurrentPosition(oldCardView.Position);
                }
                else
                {
                    remaining.Add(cardView);
                }
                result.Add(cardView);
            }
            RemoveCards(remaining);
            return(result);
        }
Beispiel #12
0
 private void MarkClearance(CardView card)
 {
     if (card.DiscardDeckClearTimeStamp > _currentTime)
     {
         card.DiscardDeckClearTimeStamp = _currentTime;
     }
 }
Beispiel #13
0
 void card_OnDragBegin(object sender, EventArgs e)
 {
     if (_cardInteraction == CardInteraction.MouseMove)
     {
         lock (_cards)
         {
             Trace.TraceInformation("DragBegin");
             _interactingCard = sender as CardView;
             _interactingCard.SetValue(Canvas.ZIndexProperty, 1000);
             Trace.Assert(_interactingCard != null);
             _cardInteraction = CardInteraction.Drag;
             RearrangeCards(0.2d);
         }
     }
 }
Beispiel #14
0
 protected virtual void AddRoleCard(CardView card, bool isFaked)
 {
 }
Beispiel #15
0
 protected virtual void AddEquipment(CardView card, bool isFaked)
 {
 }
Beispiel #16
0
 private CardStack _GetParentCardStack(CardView card)
 {
     foreach (var stack in _allCardStacks)
     {
         if (stack.Cards.Contains(card))
         {
             return stack;
         }
     }
     return null;
 }
Beispiel #17
0
 void cardView_OnDragBegin(object sender, EventArgs e)
 {
     lock (cardArrangeLock)
     {
         InteractingCard = sender as CardView;
         InteractingCard.SetValue(Canvas.ZIndexProperty, 1000);
         _sourceDeck = _GetParentCardStack(InteractingCard);
     }
 }
Beispiel #18
0
 private void _MakeDisappear(CardView card)
 {
     card.Disappear(0.5d);
     card.SetValue(Canvas.ZIndexProperty, (int)card.GetValue(Canvas.ZIndexProperty) - 100);
     Cards.Remove(card);
 }
Beispiel #19
0
 public void RemoveCards(IList<CardView> cards)
 {
     foreach (var card in cards)
     {
         if (card == _interactingCard)
         {
             _interactingCard = null;
             _cardInteraction = CardInteraction.None;
         }
         UnregisterCardEvents(card);
     }
     var nonexisted = new List<CardView>(
                         from c in cards
                         where !_cards.Contains(c)
                         select c);
     var space = MaxCardSpacing;
     MaxCardSpacing = 30;
     RearrangeCards(nonexisted);
     MaxCardSpacing = space;
     if (nonexisted.Count != cards.Count)
     {
         _cards = new List<CardView>(_cards.Except(cards));
         RearrangeCards(_cards);
     }
 }
Beispiel #20
0
 public void AddCards(IList<CardViewModel> cards)
 {
     var cardViews = new List<CardView>();
     foreach (var card in cards)
     {
         var cardView = new CardView(card);
         cardViews.Add(cardView);
         ParentCanvas.Children.Add(cardView);
     }
     AddCards(cardViews);
 }
Beispiel #21
0
        protected override void AddEquipment(CardView card, bool isFaked)
        {
            Equipment equip = card.Card.Type as Equipment;

            if (equip == null)
            {
                throw new ArgumentException("Cannot add non-equip to equip area.");
            }

            SmallEquipView equipLabel = new SmallEquipView();

            equipLabel.DataContext = card.CardModel;

            Border targetArea = null;

            switch (equip.Category)
            {
            case CardCategory.Weapon:
                targetArea = weaponArea;
                break;

            case CardCategory.Armor:
                targetArea = armorArea;
                break;

            case CardCategory.DefensiveHorse:
                targetArea = horse1Area;
                break;

            case CardCategory.OffensiveHorse:
                targetArea = horse2Area;
                break;

            default:
                throw new ArgumentException("Cannot install non-equips to equip area.");
            }
            equipLabel.Opacity = 0;

            if (targetArea.Child != null)
            {
                throw new ArgumentException("Duplicate equip not allowed.");
            }
            targetArea.Child = equipLabel;

            if (isFaked)
            {
                card.Disappear(0d, true);
            }
            else
            {
                card.Position = ComputeCardCenterPos(card, targetArea);
                card.Disappear(0.3d, true);
                card.Rebase();
            }

            Storyboard      storyBoard = new Storyboard();
            DoubleAnimation animation1 = new DoubleAnimation();
            DoubleAnimation animation2 = new DoubleAnimation();

            animation1.From     = -50d;
            animation1.To       = 0d;
            animation2.To       = 1d;
            animation1.Duration = TimeSpan.FromMilliseconds(500);
            animation2.Duration = TimeSpan.FromMilliseconds(500);
            Storyboard.SetTarget(animation1, equipLabel);
            Storyboard.SetTarget(animation2, equipLabel);
            Storyboard.SetTargetProperty(animation1, new PropertyPath(Canvas.TopProperty));
            Storyboard.SetTargetProperty(animation2, new PropertyPath(SmallEquipView.OpacityProperty));
            storyBoard.Children.Add(animation1);
            storyBoard.Children.Add(animation2);
            storyBoard.Begin();
        }
Beispiel #22
0
        void cardView_OnDragging(object sender, EventArgs e)
        {
            // First, find the two stacks that the card is hovering above.
            var       relevantStacks  = new List <CardStack>();
            var       yOverlap        = new List <double>();
            CardStack resultDeckStack = null;
            double    maxOverlap      = 0;
            double    resultOverlap   = 0;

            foreach (var stack in _allCardStacks)
            {
                Rect rect = stack.BoundingBox;
                rect.Intersect(new Rect(InteractingCard.Position, new Size(InteractingCard.Width, InteractingCard.Height)));
                if (rect.Size.Height > 0)
                {
                    if (stack.Parent != _resultPanel)
                    {
                        relevantStacks.Add(stack);
                        yOverlap.Add(rect.Size.Height);
                    }
                    else if (rect.Size.Width > maxOverlap)
                    {
                        resultDeckStack = stack;
                        maxOverlap      = rect.Size.Width;
                        resultOverlap   = rect.Size.Height;
                    }
                }
            }

            if (resultDeckStack != null)
            {
                relevantStacks.Add(resultDeckStack);
                yOverlap.Add(resultOverlap);
            }
            Trace.Assert(relevantStacks.Count <= 2 && yOverlap.Count == relevantStacks.Count);

            // Second, set the interacting card of all card stacks accordingly
            foreach (var stack in _allCardStacks)
            {
                CardInteraction status;
                if (relevantStacks.Contains(stack) || stack == _sourceDeck)
                {
                    stack.InteractingCard = InteractingCard;
                    status = CardInteraction.Drag;
                }
                else
                {
                    stack.InteractingCard = null;
                    status = CardInteraction.None;
                }
                if (status != stack.CardStatus || status == CardInteraction.Drag)
                {
                    stack.CardStatus = status;
                    stack.RearrangeCards();
                }
            }

            // Finally, in the stack with greatest overlapping y-distance, highlight the slot.
            _ResetHighlightSlot();

            if (relevantStacks.Count == 0)
            {
                _highlightedStack = null;
            }
            else
            {
                _highlightedStack = relevantStacks[yOverlap.IndexOf(yOverlap.Max())];
                var highlightedSlot = _stackToSlot[_highlightedStack];
                if (highlightedSlot.Cards.Count > 0)
                {
                    int index = Math.Min(_highlightedStack.InteractingCardIndex, highlightedSlot.Cards.Count - 1);
                    _highlightedCardSlot = highlightedSlot.Cards[index];
                    _highlightedCardSlot.CardModel.IsFaded = true;
                }
            }
        }
Beispiel #23
0
 private void _MakeDisappear(CardView card)
 {
     card.Disappear(0.5d);
     Cards.Remove(card);
 }
Beispiel #24
0
        protected override CardView RemoveEquipment(Card card, bool isCopy)
        {
            Trace.Assert(card.Id >= 0, "Cannot remove unknown card from equip area.");
            Equipment equip = GameEngine.CardSet[card.Id].Type as Equipment;

            if (equip == null)
            {
                throw new ArgumentException("Cannot add non-equip to equip area.");
            }

            Grid targetArea = null;

            switch (equip.Category)
            {
            case CardCategory.Weapon:
                targetArea = weaponArea;
                break;

            case CardCategory.Armor:
                targetArea = armorArea;
                break;

            case CardCategory.DefensiveHorse:
                targetArea = horse1Area;
                break;

            case CardCategory.OffensiveHorse:
                targetArea = horse2Area;
                break;

            default:
                throw new ArgumentException("Cannot install non-equips to equip area.");
            }

            if (targetArea.Children.Count == 0)
            {
                throw new ArgumentException("No equip is found.");
            }
            ToggleButton button = targetArea.Children[0] as ToggleButton;

            if (!isCopy)
            {
                targetArea.Children.Clear();
            }

            if (IsEquipmentDockEmpty)
            {
                equipmentArea.Visibility = Visibility.Collapsed;
                handCardArea.RearrangeCards();
            }

            CardView result = CardView.CreateCard(card);

            ParentGameView.GlobalCanvas.Children.Add(result);
            result.Opacity = 0;
            Point dest = targetArea.TranslatePoint(new Point(targetArea.Width / 2, targetArea.Height / 2),
                                                   ParentGameView.GlobalCanvas);

            dest.Offset(-result.Width / 2, -result.Height / 2);
            result.SetCurrentPosition(dest);
            return(result);
        }
Beispiel #25
0
 private void _MakeDisappear(CardView card)
 {
     card.SetValue(Canvas.ZIndexProperty, (int)card.GetValue(Canvas.ZIndexProperty) - 100);
     Cards.Remove(card);
     card.Disappear(0.5d, true);
 }
Beispiel #26
0
 protected virtual void UnregisterCardEvents(CardView card)
 {
 }
Beispiel #27
0
        protected override void AddEquipment(CardView card, bool isFaked)
        {
            Equipment equip = card.Card.Type as Equipment;

            if (equip == null)
            {
                throw new ArgumentException("Cannot add non-equip to equip area.");
            }

            ToggleButton button = new ToggleButton();
            button.Style = Resources["BigEquipToggleButton"] as Style;
            button.HorizontalAlignment = HorizontalAlignment.Left;
            button.VerticalAlignment = VerticalAlignment.Top;

            Grid targetArea = null;
            switch (equip.Category)
            {
                case CardCategory.Weapon:
                    button.DataContext = PlayerModel.WeaponCommand;
                    targetArea = weaponArea;
                    break;
                case CardCategory.Armor:
                    button.DataContext = PlayerModel.ArmorCommand;
                    targetArea = armorArea;
                    break;
                case CardCategory.DefensiveHorse:
                    button.DataContext = PlayerModel.DefensiveHorseCommand;
                    targetArea = horse1Area;
                    break;
                case CardCategory.OffensiveHorse:
                    button.DataContext = PlayerModel.OffensiveHorseCommand;
                    targetArea = horse2Area;
                    break;
                default:
                    throw new ArgumentException("Cannot install non-equips to equip area.");
            }

            button.Width = targetArea.Width;
            button.Height = targetArea.Height;
            button.Opacity = 0;

            if (targetArea.Children.Count != 0)
            {
                throw new ArgumentException("Duplicate equip not allowed.");
            }
            targetArea.Children.Clear();
            targetArea.Children.Add(button);

            if (isFaked)
            {
                card.Disappear(0d);
            }
            else
            {
                Point dest = targetArea.TranslatePoint(new Point(targetArea.Width / 2, targetArea.Height / 2),
                                                       ParentGameView.GlobalCanvas);
                dest.Offset(-card.Width / 2, -card.Height / 2);
                card.Position = dest;
                card.Disappear(0.5d);
                card.Rebase(0.5d);
            }

            Storyboard storyBoard = new Storyboard();
            ThicknessAnimation animation1 = new ThicknessAnimation();
            DoubleAnimation animation2 = new DoubleAnimation();
            animation1.From = new Thickness(-100d, 0d, 0d, 0d);
            animation1.To = new Thickness(0d, 0d, 0d, 0d);
            animation2.To = 1.0d;
            animation1.Duration = TimeSpan.FromMilliseconds(500);
            animation2.Duration = TimeSpan.FromMilliseconds(500);
            Storyboard.SetTarget(animation1, button);
            Storyboard.SetTarget(animation2, button);
            Storyboard.SetTargetProperty(animation1, new PropertyPath(ToggleButton.MarginProperty));
            Storyboard.SetTargetProperty(animation2, new PropertyPath(ToggleButton.OpacityProperty));
            storyBoard.Children.Add(animation1);
            storyBoard.Children.Add(animation2);
            storyBoard.Begin();
        }
Beispiel #28
0
 protected virtual void UnRegisterCardEvents(CardView card)
 {
 }
Beispiel #29
0
        void cardView_OnDragging(object sender, EventArgs e)
        {
            lock (cardArrangeLock)
            {
                // First, find the two stacks that the card is hovering above.
                var relevantStacks = new List<CardStack>();
                var yOverlap = new List<double>();
                CardStack resultDeckStack = null;
                double maxOverlap = 0;
                double resultOverlap = 0;

                foreach (var stack in _allCardStacks)
                {
                    Rect rect = stack.BoundingBox;
                    rect.Intersect(new Rect(InteractingCard.Position, new Size(InteractingCard.Width, InteractingCard.Height)));
                    if (rect.Size.Height > 0)
                    {
                        if (stack.Parent != _resultPanel)
                        {
                            relevantStacks.Add(stack);
                            yOverlap.Add(rect.Size.Height);
                        }
                        else if (rect.Size.Width > maxOverlap)
                        {
                            resultDeckStack = stack;
                            maxOverlap = rect.Size.Width;
                            resultOverlap = rect.Size.Height;
                        }
                    }
                }

                if (resultDeckStack != null)
                {
                    relevantStacks.Add(resultDeckStack);
                    yOverlap.Add(resultOverlap);
                }
                Trace.Assert(relevantStacks.Count <= 2 && yOverlap.Count == relevantStacks.Count);

                // Second, set the interacting card of all card stacks accordingly
                foreach (var stack in _allCardStacks)
                {
                    CardInteraction status;
                    if (relevantStacks.Contains(stack) || stack == _sourceDeck)
                    {
                        stack.InteractingCard = InteractingCard;
                        status = CardInteraction.Drag;
                    }
                    else
                    {
                        stack.InteractingCard = null;
                        status = CardInteraction.None;
                    }
                    if (status != stack.CardStatus || status == CardInteraction.Drag)
                    {
                        stack.CardStatus = status;
                        stack.RearrangeCards();
                    }
                }

                // Finally, in the stack with greatest overlapping y-distance, highlight the slot.
                _ResetHighlightSlot();

                if (relevantStacks.Count == 0)
                {
                    _highlightedStack = null;
                }
                else
                {
                    _highlightedStack = relevantStacks[yOverlap.IndexOf(yOverlap.Max())];
                    var highlightedSlot = _stackToSlot[_highlightedStack];
                    if (highlightedSlot.Cards.Count > 0)
                    {
                        int index = Math.Min(_highlightedStack.InteractingCardIndex, highlightedSlot.Cards.Count - 1);
                        _highlightedCardSlot = highlightedSlot.Cards[index];
                        _highlightedCardSlot.CardModel.IsFaded = true;
                    }
                }
            }
        }
Beispiel #30
0
        protected override void AddEquipment(CardView card, bool isFaked)
        {
            Equipment equip = card.Card.Type as Equipment;

            if (equip == null)
            {
                throw new ArgumentException("Cannot add non-equip to equip area.");
            }

            SmallEquipView equipLabel = new SmallEquipView();
            equipLabel.DataContext = card.CardModel;

            Canvas targetArea = null;
            switch (equip.Category)
            {
                case CardCategory.Weapon:
                    targetArea = weaponArea;
                    break;
                case CardCategory.Armor:
                    targetArea = armorArea;
                    break;
                case CardCategory.DefensiveHorse:
                    targetArea = horse1Area;
                    break;
                case CardCategory.OffensiveHorse:
                    targetArea = horse2Area;
                    break;
                default:
                    throw new ArgumentException("Cannot install non-equips to equip area.");
            }
            equipLabel.Opacity = 0;

            if (targetArea.Children.Count != 0)
            {
                throw new ArgumentException("Duplicate equip not allowed.");
            }
            targetArea.Children.Clear();
            targetArea.Children.Add(equipLabel);

            if (isFaked)
            {
                card.Disappear(0d, true);
            }
            else
            {
                card.Position = ComputeCardCenterPos(card, targetArea);
                card.Disappear(0.3d, true);
                card.Rebase();
            }

            Storyboard storyBoard = new Storyboard();
            DoubleAnimation animation1 = new DoubleAnimation();
            DoubleAnimation animation2 = new DoubleAnimation();
            animation1.From = -50d;
            animation1.To = 0d;
            animation2.To = 1d;
            animation1.Duration = TimeSpan.FromMilliseconds(500);
            animation2.Duration = TimeSpan.FromMilliseconds(500);
            Storyboard.SetTarget(animation1, equipLabel);
            Storyboard.SetTarget(animation2, equipLabel);
            Storyboard.SetTargetProperty(animation1, new PropertyPath(Canvas.TopProperty));
            Storyboard.SetTargetProperty(animation2, new PropertyPath(SmallEquipView.OpacityProperty));
            storyBoard.Children.Add(animation1);
            storyBoard.Children.Add(animation2);
            storyBoard.Begin();
        }
Beispiel #31
0
 private void _ResetHighlightSlot()
 {
     if (_highlightedCardSlot != null)
     {
         _highlightedCardSlot.CardModel.IsFaded = false;
         _highlightedCardSlot = null;
     }
 }
Beispiel #32
0
        protected override void AddEquipment(CardView card, bool isFaked)
        {
            Equipment equip = card.Card.Type as Equipment;

            if (equip == null)
            {
                throw new ArgumentException("Cannot add non-equip to equip area.");
            }

            ToggleButton button = new ToggleButton();

            button.Style = Resources["BigEquipToggleButton"] as Style;
            button.HorizontalAlignment = HorizontalAlignment.Left;
            button.VerticalAlignment   = VerticalAlignment.Top;

            Grid targetArea = null;

            switch (equip.Category)
            {
            case CardCategory.Weapon:
                button.DataContext = PlayerModel.WeaponCommand;
                targetArea         = weaponArea;
                break;

            case CardCategory.Armor:
                button.DataContext = PlayerModel.ArmorCommand;
                targetArea         = armorArea;
                break;

            case CardCategory.DefensiveHorse:
                button.DataContext = PlayerModel.DefensiveHorseCommand;
                targetArea         = horse1Area;
                break;

            case CardCategory.OffensiveHorse:
                button.DataContext = PlayerModel.OffensiveHorseCommand;
                targetArea         = horse2Area;
                break;

            default:
                throw new ArgumentException("Cannot install non-equips to equip area.");
            }

            button.Width   = targetArea.Width;
            button.Height  = targetArea.Height;
            button.Opacity = 0;

            if (IsEquipmentDockEmpty)
            {
                equipmentArea.Visibility = Visibility.Visible;
                this.UpdateLayout();
                handCardArea.RearrangeCards();
            }

            if (targetArea.Children.Count != 0)
            {
                throw new ArgumentException("Duplicate equip not allowed.");
            }
            targetArea.Children.Clear();
            targetArea.Children.Add(button);

            if (isFaked)
            {
                card.Disappear(0d, true);
            }
            else
            {
                Point dest = targetArea.TranslatePoint(new Point(targetArea.Width / 2, targetArea.Height / 2),
                                                       ParentGameView.GlobalCanvas);
                dest.Offset(-card.Width / 2, -card.Height / 2);
                card.Position = dest;
                card.Disappear(0.5d, true);
                card.Rebase();
            }

            Storyboard         storyBoard = new Storyboard();
            ThicknessAnimation animation1 = new ThicknessAnimation();
            DoubleAnimation    animation2 = new DoubleAnimation();

            animation1.From     = new Thickness(-100d, 0d, 0d, 0d);
            animation1.To       = new Thickness(0d, 0d, 0d, 0d);
            animation2.To       = 1.0d;
            animation1.Duration = TimeSpan.FromMilliseconds(500);
            animation2.Duration = TimeSpan.FromMilliseconds(500);
            Storyboard.SetTarget(animation1, button);
            Storyboard.SetTarget(animation2, button);
            Storyboard.SetTargetProperty(animation1, new PropertyPath(ToggleButton.MarginProperty));
            Storyboard.SetTargetProperty(animation2, new PropertyPath(ToggleButton.OpacityProperty));
            storyBoard.Children.Add(animation1);
            storyBoard.Children.Add(animation2);
            storyBoard.Begin();
        }
Beispiel #33
0
 protected virtual void AddDelayedTool(CardView card, bool isFaked)
 {
 }
Beispiel #34
0
 private void card_MouseLeaveUnlock()
 {
     _cardInteraction = CardInteraction.None;
     _interactingCard = null;
     RearrangeCards(0.2d);
 }
Beispiel #35
0
        public IList <CardView> RemoveCards(DeckType deck, IList <Card> cards, bool isCopy)
        {
            List <CardView> cardsToRemove = new List <CardView>();

            if (deck == DeckType.Hand)
            {
                cardsToRemove.AddRange(RemoveHandCards(cards, isCopy));

                if (!isCopy)
                {
                    foreach (var card in cards)
                    {
                        var backup = new List <CardViewModel>(PlayerModel.HandCards);
                        foreach (var cardModel in backup)
                        {
                            if (cardModel.Card == card)
                            {
                                PlayerModel.HandCards.Remove(cardModel);
                            }
                        }
                    }
                    PlayerModel.HandCardCount -= cardsToRemove.Count;
                }
            }
            else if (deck == DeckType.Equipment)
            {
                foreach (var card in cards)
                {
                    Equipment equip = card.Type as Equipment;

                    if (equip != null)
                    {
                        switch (equip.Category)
                        {
                        case CardCategory.Weapon:
                            PlayerModel.WeaponCommand = null;
                            break;

                        case CardCategory.Armor:
                            PlayerModel.ArmorCommand = null;
                            break;

                        case CardCategory.DefensiveHorse:
                            PlayerModel.DefensiveHorseCommand = null;
                            break;

                        case CardCategory.OffensiveHorse:
                            PlayerModel.OffensiveHorseCommand = null;
                            break;
                        }
                    }

                    CardView cardView = RemoveEquipment(card, isCopy);
                    cardsToRemove.Add(cardView);
                }
            }
            else if (deck == DeckType.DelayedTools)
            {
                if (!ViewModelBase.IsDetached)
                {
                    foreach (var card in cards)
                    {
                        CardView cardView = RemoveDelayedTool(card, isCopy);
                        cardsToRemove.Add(cardView);
                    }
                }
            }
            else if (deck == RoleGame.RoleDeckType)
            {
                if (!ViewModelBase.IsDetached)
                {
                    foreach (var card in cards)
                    {
                        CardView cardView = RemoveRoleCard(card);
                        cardsToRemove.Add(cardView);
                    }
                }
            }
            else if (deck is PrivateDeckType)
            {
                var deckModel = PlayerModel.PrivateDecks.FirstOrDefault(d => d.DeckPlace.DeckType == deck);
                Trace.Assert(deckModel != null);

                if (!isCopy)
                {
                    foreach (var card in cards)
                    {
                        var cardModel = deckModel.Cards.First(c => c.Card == card);
                        Trace.Assert(cardModel != null, "Card cannot be found in the private deck");
                        deckModel.Cards.Remove(cardModel);
                    }
                    if (deckModel.Cards.Count == 0)
                    {
                        PlayerModel.PrivateDecks.Remove(deckModel);
                    }
                }

                cardsToRemove.AddRange(RemovePrivateCards(cards));
            }
            else
            {
                cardsToRemove.AddRange(RemoveHandCards(cards, isCopy));
            }

            foreach (var card in cardsToRemove)
            {
                card.CardModel.IsSelectionMode = false;
            }

            return(cardsToRemove);
        }
Beispiel #36
0
 /// <summary>
 /// Compute card position on global canvas such that the card center is aligned to the center of <paramref name="element"/>.
 /// </summary>
 /// <param name="card">Card to be aligned.</param>
 /// <param name="element">FrameworkElement to be aligned to.</param>
 /// <returns>Position of card relative to global canvas.</returns>
 protected Point ComputeCardCenterPos(CardView card, FrameworkElement element)
 {
     double width = element.ActualWidth;
     double height = element.ActualHeight;
     if (width == 0) width = element.Width;
     if (height == 0) height = element.Height;
     Point dest = element.TranslatePoint(new Point(element.Width / 2, element.Height / 2),
                                            ParentGameView.GlobalCanvas);
     dest.Offset(-card.Width / 2, -card.Height / 2);
     return dest;
 }
Beispiel #37
0
 public void AddCards(IList<CardViewModel> cards, double transitionInSeconds = 0d)
 {
     var cardViews = new List<CardView>();
     foreach (var card in cards)
     {
         var cardView = new CardView(card);
         cardViews.Add(cardView);
         ParentCanvas.Children.Add(cardView);
     }
     AddCards(cardViews, transitionInSeconds);
 }
Beispiel #38
0
 void cardView_OnDragBegin(object sender, EventArgs e)
 {
     InteractingCard = sender as CardView;
     InteractingCard.SetValue(Canvas.ZIndexProperty, 1000);
     _sourceDeck = _GetParentCardStack(InteractingCard);
 }
Beispiel #39
0
        protected override void AddDelayedTool(CardView card, bool isFaked)
        {
            SmallDelayedToolView dtv = new SmallDelayedToolView() { Width = 23, Height = 24 };
            dtv.DataContext = card.CardModel;
            dtv.Opacity = 0;
            dtv.Margin = new Thickness(0, 0, 50d, 0);
            delayedToolsDock.Children.Add(dtv);

            if (isFaked)
            {
                card.Disappear(0d, true);
            }
            else
            {
                Point dest = delayedToolsDock.TranslatePoint(new Point(-11.5, delayedToolsDock.ActualHeight / 2),
                                                                       ParentGameView.GlobalCanvas);
                dest.Offset(-card.Width / 2, -card.Height / 2);
                card.Position = dest;
                card.Disappear(0.5d, true);
                card.Rebase();
            }

            Storyboard storyBoard = new Storyboard();
            ThicknessAnimation animation1 = new ThicknessAnimation();
            DoubleAnimation animation2 = new DoubleAnimation();
            animation1.To = new Thickness(0d, 0d, 0d, 0d);
            animation2.To = 1.0d;
            animation1.Duration = TimeSpan.FromMilliseconds(500);
            animation2.Duration = TimeSpan.FromMilliseconds(500);
            Storyboard.SetTarget(animation1, dtv);
            Storyboard.SetTarget(animation2, dtv);
            Storyboard.SetTargetProperty(animation1, new PropertyPath(SmallDelayedToolView.MarginProperty));
            Storyboard.SetTargetProperty(animation2, new PropertyPath(SmallDelayedToolView.OpacityProperty));
            storyBoard.Children.Add(animation1);
            storyBoard.Children.Add(animation2);
            storyBoard.Begin();
        }
Beispiel #40
0
 protected virtual void AddDelayedTool(CardView card, bool isFaked)
 {
 }
Beispiel #41
0
        protected override void AddRoleCard(CardView card, bool isFaked)
        {
            if (isFaked)
            {
                card.Disappear(0d, true);
                return;
            }

            card.Position = ComputeCardCenterPos(card, cbRoleBox);

            ScaleTransform scale = new ScaleTransform();
            var transformGroup = new TransformGroup();
            transformGroup.Children.Add(scale);
            card.RenderTransform = transformGroup;

            card.RenderTransformOrigin = new Point(0.5, 0.5);
            DoubleAnimation scaleXAnim = new DoubleAnimation(0.2, new Duration(TimeSpan.FromSeconds(0.5d)));
            DoubleAnimation scaleYAnim = new DoubleAnimation(0.2, new Duration(TimeSpan.FromSeconds(0.5d)));
            Storyboard.SetTarget(scaleXAnim, card);
            Storyboard.SetTarget(scaleYAnim, card);
            Storyboard.SetTargetProperty(scaleXAnim, new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)"));
            Storyboard.SetTargetProperty(scaleYAnim, new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)"));
            Storyboard storyboard = new Storyboard();
            storyboard.Children.Add(scaleXAnim);
            storyboard.Children.Add(scaleYAnim);
            card.AddRebaseAnimation(storyboard, 0.5d);
            storyboard.AccelerationRatio = 0.4d;
            storyboard.Begin();
            card.Disappear(0.5d, true);
        }
Beispiel #42
0
 protected virtual void AddEquipment(CardView card, bool isFaked)
 {
 }
Beispiel #43
0
 protected virtual void AddRoleCard(CardView card, bool isFaked)
 {
 }
Beispiel #44
0
 void card_MouseEnter(object sender, MouseEventArgs e)
 {
     if (_cardInteraction == CardInteraction.None)
     {
         lock (_cards)
         {
             Trace.TraceInformation("MouseEnter");
             _interactingCard = sender as CardView;
             if (_interactingCard != null)
             {
                 _cardInteraction = CardInteraction.MouseMove;
                 RearrangeCards(0.2d);
             }
         }
     }
 }