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();
}