Interaction logic for SmallEquipView.xaml
Inheritance: System.Windows.Controls.UserControl
Example #1
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.");
            }

            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.");
            }

            if (targetArea.Child == null)
            {
                throw new ArgumentException("No equip is found.");
            }

            SmallEquipView equipLabel = targetArea.Child as SmallEquipView;

            if (!isCopy)
            {
                targetArea.Child = null;
            }

            CardView result = CardView.CreateCard(card);

            ParentGameView.GlobalCanvas.Children.Add(result);
            result.Opacity = 0;
            result.SetCurrentPosition(ComputeCardCenterPos(result, targetArea));
            return(result);
        }
Example #2
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();
        }
Example #3
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();
        }