Exemple #1
0
        internal virtual void ShowContextMenu(Card card, bool showGroupActions = true)
        {
            // Modify selection
            if (card == null || !card.Selected)
            {
                Selection.Clear();
            }

            var menuItems = new CompositeCollection();

            ContextGroup = group;
            ContextMenu  = new ContextMenu {
                ItemsSource = menuItems, Tag = card
            };
            // card has to captured somehow, otherwise it may be overwritten before released in the OnClosed handler, e.g. when rightclicking on a card, then directly right-clicking on another card.
            ContextMenu.Opened += (sender, args) =>
            {
                ContextGroup.KeepControl();
                var c = ((ContextMenu)sender).Tag as Card;
                if (c != null)
                {
                    c.KeepControl();
                }
            };
            ContextMenu.Closed += (sender, args) =>
            {
                ContextGroup.ReleaseControl();
                var c = ((ContextMenu)sender).Tag as Card;
                if (c != null)
                {
                    c.ReleaseControl();
                }
            };

            ContextCard = card;
            menuItems.Clear();

            if (group.CanManipulate())
            {
                if (card != null)
                {
                    if (card.CanManipulate())
                    {
                        if (_cardHeader != null)
                        {
                            _cardHeader.Header     = card.Name;
                            _cardHeader.Background = card.Controller.TransparentBrush;
                            menuItems.Add(_cardMenu);
                        }
                    }
                    else
                    {
                        var item = new MenuItem {
                            Header = card.Name, Background = card.Controller.TransparentBrush
                        };
                        item.SetResourceReference(StyleProperty, "MenuHeader");
                        menuItems.Add(item);

                        item = new MenuItem {
                            Header = "Take control"
                        };
                        item.Click += delegate { card.TakeControl(); };
                        menuItems.Add(item);
                    }

                    if (!card.FaceUp)
                    {
                        var peekItem = new MenuItem {
                            Header = "Peek", InputGestureText = "Ctrl+P"
                        };
                        peekItem.Click += delegate { ContextCard.Peek(); };
                        if (menuItems.Count == 0)
                        {
                            var item = new MenuItem {
                                Header = card.Name, Background = card.Owner.TransparentBrush
                            };
                            item.SetResourceReference(StyleProperty, "MenuHeader");
                            menuItems.Add(item);
                        }
                        menuItems.Add(peekItem);
                    }
                }

                if (showGroupActions)
                {
                    menuItems.Add(_groupMenu);
                }
            }
            else if (!group.WantToShuffle)
            {
                menuItems.Add(CreateGroupHeader());

                var item = new MenuItem {
                    Header = "Take control"
                };
                item.Click += delegate { group.TakeControl(); };
                menuItems.Add(item);

                menuItems.Add(new Separator());
                item = CreateLookAtCardsMenuItem();
                if (item != null)
                {
                    menuItems.Add(item);
                }
            }
            else // Group is being shuffled
            {
                return;
            }

            ContextMenu.IsOpen = false;
            // Required to trigger the ReleaseControl calls if the ContextMenu was already open
            ContextMenu.UpdateLayout(); // Required if the ContextMenu was already open
            ContextMenu.IsOpen     = true;
            ContextMenu.FontFamily = groupFont;
            ContextMenu.FontSize   = fontsize;
        }
Exemple #2
0
        internal virtual void ShowContextMenu(Card card)
        {
            if (Player.LocalPlayer.Spectator)
            {
                return;
            }
            // Modify selection
            if (card == null || !card.Selected)
            {
                Selection.Clear();
            }

            var menuItems = new CompositeCollection();

            ContextGroup = group;
            ContextMenu  = new ContextMenu {
                ItemsSource = menuItems, Tag = card
            };
            // card has to captured somehow, otherwise it may be overwritten before released in the OnClosed handler, e.g. when rightclicking on a card, then directly right-clicking on another card.
            ContextMenu.Opened += (sender, args) =>
            {
                ContextGroup.KeepControl();
                var c = ((ContextMenu)sender).Tag as Card;
                if (c != null)
                {
                    c.KeepControl();
                }
            };
            ContextMenu.Closed += (sender, args) =>
            {
                ContextGroup.ReleaseControl();
                var c = ((ContextMenu)sender).Tag as Card;
                if (c != null)
                {
                    c.ReleaseControl();
                }
            };

            ContextCard = card;
            menuItems.Clear();

            if (card != null)
            {
                //var cardMenuItems = await CreateCardMenuItems(card, group.Definition);
                var cardMenuItems = CreateCardMenuItems(card, group.Definition);
                var container     = new CollectionContainer {
                    Collection = cardMenuItems
                };
                menuItems.Add(container);
            }

            if (ShouldShowGroupActions(card))
            {
                var container = new CollectionContainer {
                    Collection = CreateGroupMenuItems(group.Definition)
                };
                menuItems.Add(container);
            }
            //else // Group is being shuffled
            //    return;

            ContextMenu.IsOpen = false;
            // Required to trigger the ReleaseControl calls if the ContextMenu was already open
            ContextMenu.UpdateLayout(); // Required if the ContextMenu was already open
            ContextMenu.IsOpen     = true;
            ContextMenu.FontFamily = groupFont;
            ContextMenu.FontSize   = fontsize;
        }