private void Untargetting(object sender, EventArgs e) { var targetAction = (Target)sender; CardControl card = (from ContentPresenter child in Children where child.DataContext == targetAction.FromCard select VisualTreeHelper.GetChild(child, 0) as CardControl).FirstOrDefault(); if (card == null) { return; // Opponent moved the card out of the table concurently } AdornerLayer layer = AdornerLayer.GetAdornerLayer(card); Adorner[] adorners = layer.GetAdorners(card); if (adorners == null) { return; // Opponent removed the target card out of the table concurently } foreach (ArrowAdorner arrow in adorners.OfType <ArrowAdorner>()) { layer.Remove(arrow); } targetAction.FromCard.TargetsOtherCards = false; }
private void Targetting(object sender, EventArgs e) { var targetAction = (Target)sender; CardControl fromCard = null, toCard = null; foreach (ContentPresenter child in Children) { if (targetAction.FromCard == child.DataContext) { fromCard = VisualTreeHelper.GetChild(child, 0) as CardControl; if (toCard != null) { break; } } else if (targetAction.ToCard == child.DataContext) { toCard = VisualTreeHelper.GetChild(child, 0) as CardControl; if (fromCard != null) { break; } } } if (fromCard == null || toCard == null) { return; } fromCard.CreateArrowTo(targetAction.Who, toCard); targetAction.FromCard.TargetsOtherCards = true; }
private void AlphaOrderChecked(object sender, RoutedEventArgs e) { CardControl.SetAnimateLoad(this, false); positionOrderBtn.IsChecked = false; cardsList.SortByName = true; }
public void CreateArrowTo(Player player, CardControl toCard) { AdornerLayer layer = AdornerLayer.GetAdornerLayer(this); var arrow = new ArrowAdorner(player, this); layer.Add(arrow); arrow.LinkToCard(toCard); }
public static IEnumerable<CardControl> GetCardControls(GroupControl ctrl, CardControl empty) { if (IsEmpty()) yield return empty; else foreach (CardControl cardCtrl in GetCardControls(ctrl)) yield return cardCtrl; }
private void IdOrderChecked(object sender, RoutedEventArgs e) { if (cardsList.SortMethod == SortTypes.Id) { return; } CardControl.SetAnimateLoad(this, false); IdOrderBtn.IsChecked = true; positionOrderBtn.IsChecked = false; alphaOrderBtn.IsChecked = false; cardsList.SortCards(SortTypes.Id); }
public static IEnumerable <CardControl> GetCardControls(GroupControl ctrl, CardControl empty) { if (IsEmpty()) { yield return(empty); } else { foreach (CardControl cardCtrl in GetCardControls(ctrl)) { yield return(cardCtrl); } } }
public void LinkToCard(CardControl cardCtrl) { toCard = cardCtrl; UpdateToPoint(this, EventArgs.Empty); cardCtrl.rotate90.Changed += UpdateToPoint; var adornedCard = (CardControl)AdornedElement; var leftDescriptor = DependencyPropertyDescriptor.FromProperty(Canvas.LeftProperty, typeof(Canvas)); var topDescriptor = DependencyPropertyDescriptor.FromProperty(Canvas.TopProperty, typeof(Canvas)); leftDescriptor.AddValueChanged(VisualTreeHelper.GetParent(cardCtrl), UpdateToPoint); topDescriptor.AddValueChanged(VisualTreeHelper.GetParent(cardCtrl), UpdateToPoint); leftDescriptor.AddValueChanged(VisualTreeHelper.GetParent(adornedCard), UpdateToPoint); topDescriptor.AddValueChanged(VisualTreeHelper.GetParent(adornedCard), UpdateToPoint); cardCtrl.Unloaded += RemoveFromLayer; }
private void DragCollapseSelection(IInputElement previous, IInputElement current) { if (current == previous) { return; } if (DraggedCards.Count <= 1) { return; } bool isFirst = true; // Collapse if we leave the table if (previous is TableControl) { foreach (CardDragAdorner overlay in OverlayElements) { if (overlay.SourceCard == this && isFirst) { isFirst = false; continue; } CardControl cardCtrl = overlay.SourceCard; double dx = Card.X - cardCtrl.Card.X, dy = Card.Y - cardCtrl.Card.Y; overlay.CollapseTo(dx * ScaleFactor.Width, dy * ScaleFactor.Height); } } // Expand if we enter the table else if (current is TableControl) { foreach (CardDragAdorner overlay in OverlayElements) { if (overlay.SourceCard == this && isFirst) { isFirst = false; continue; } overlay.Expand(); } } }
private void FilterChanged(object sender, TextChangedEventArgs e) { CardControl.SetAnimateLoad(this, false); string filter = filterBox.Text; if (filter == "") { watermark.Visibility = Visibility.Visible; cardsList.FilterCards = null; } else { IEnumerable <string> textProperties = Program.GameEngine.Definition.CustomProperties .Where(p => !p.IgnoreText) .Select(p => p.Name); watermark.Visibility = Visibility.Hidden; cardsList.FilterCards = c => { if (!cardsList.IsAlwaysUp && !c.FaceUp) { return(false); } return (c.RealName.IndexOf(filter, StringComparison.CurrentCultureIgnoreCase) >= 0 || textProperties.Select(property => c.GetProperty(property)). Where(propertyValue => propertyValue != null).Any( propertyValue => propertyValue.ToString().IndexOf(filter, StringComparison. CurrentCultureIgnoreCase) >= 0)); }; if (cardsList.SortMethod == SortTypes.None) { IdOrderBtn.IsChecked = true; } } }
public CardDragAdorner(CardControl anchor, CardControl sourceCard, Vector mousePoint) : base(Application.Current.MainWindow.Content as UIElement) { SourceCard = sourceCard; bool isCardInverted = anchor.IsOnTableCanvas && (Player.LocalPlayer.InvertedTable ^ anchor.IsInverted); Point cardOrigin; if (isCardInverted) { var cardDef = Program.Game.Definition.CardDefinition; cardOrigin = new Point(cardDef.Width, cardDef.Height); mouseOffset = new Vector(cardDef.Width - mousePoint.X, cardDef.Height - mousePoint.Y); } else { cardOrigin = new Point(); mouseOffset = mousePoint; } basePt = anchor.TranslatePoint(cardOrigin, Application.Current.MainWindow.Content as UIElement); _faceUp = sourceCard.IsAlwaysUp ? true : sourceCard.Card.FaceUp; lightRedBrush = Brushes.Red.Clone(); faceDownBrush = new ImageBrush(sourceCard.Card.GetBitmapImage(false)); faceUpBrush = _faceUp ? (Brush)new VisualBrush(sourceCard.GetCardVisual()) { Viewbox = new Rect(0, 0, sourceCard.ActualWidth, sourceCard.ActualHeight), ViewboxUnits = BrushMappingMode.Absolute } : (Brush)new ImageBrush(new BitmapImage(new Uri(Program.Game.Definition.CardDefinition.Front))); invertTransform = new ScaleTransform() { CenterX = 0.5, CenterY = 0.5 }; faceUpBrush.RelativeTransform = invertTransform; if (faceUpBrush is VisualBrush) RenderOptions.SetCachingHint(faceUpBrush, CachingHint.Cache); child.BeginInit(); child.Width = anchor.ActualWidth * CardControl.scaleFactor.Width; child.Height = anchor.ActualHeight * CardControl.scaleFactor.Height; child.Fill = _faceUp ? faceUpBrush : faceDownBrush; child.StrokeThickness = 3; var transforms = new TransformGroup(); child.RenderTransform = transforms; rot = sourceCard.Card.Orientation; if ((rot & CardOrientation.Rot180) != 0) { rot180Transform = new RotateTransform(180, child.Width / 2, child.Height / 2); transforms.Children.Add(rot180Transform); } if ((rot & CardOrientation.Rot90) != 0) { rot90Transform = isCardInverted ? new RotateTransform(90, child.Width / 2, child.Width / 2) : new RotateTransform(90, child.Width / 2, child.Height - child.Width / 2); transforms.Children.Add(rot90Transform); } translate = new TranslateTransform(); transforms.Children.Add(translate); child.IsHitTestVisible = false; child.EndInit(); AddVisualChild(child); DoubleAnimation animation = new DoubleAnimation(0.55, 0.75, new Duration(TimeSpan.FromMilliseconds(500))); animation.AutoReverse = true; animation.RepeatBehavior = RepeatBehavior.Forever; animation.Freeze(); faceUpBrush.BeginAnimation(Brush.OpacityProperty, animation); faceDownBrush.BeginAnimation(Brush.OpacityProperty, animation); lightRedBrush.BeginAnimation(Brush.OpacityProperty, animation); }
public CardDragAdorner(CardControl sourceCard, Vector mousePoint) : this(sourceCard, sourceCard, mousePoint) { }