Exemple #1
0
        protected virtual List<Control> CreateCardMenuItems(Card card, DataNew.Entities.Group def)
        {
            var items = new List<Control>();
            if (!card.CanManipulate())
            {
                var item = new MenuItem { Header = card.Name, Background = card.Controller.TransparentBrush };
                item.SetResourceReference(StyleProperty, "MenuHeader");
                items.Add(item);

                item = new MenuItem { Header = "Take control" };
                item.Click += delegate { card.TakeControl(); };
                items.Add(item);
                return items;
            }
            else {
                var selection = Selection.ExtendToSelection(card);
                //actionFilter showCard = async (IGroupAction a) =>
                actionFilter showCard = (IGroupAction a) =>
                {
                    if (a.ShowIf != null)
                    {
                      //return await CallActionShowIf(a.ShowIf, selection);
                      return CallActionShowIf(a.ShowIf, selection);
                    }
                    return true;
                };
                var visibleActionsTasks = def.CardActions.Select(item => new { Item = item, PredTask = showCard.Invoke(item) }).ToList();
                //await TaskEx.WhenAll(visibleActionsTasks.Select(x => x.PredTask));
                //var visibleActions = visibleActionsTasks.Where(x => x.PredTask.Result).Select(x => x.Item).ToArray();
                var visibleActions = visibleActionsTasks.Where(x => x.PredTask).Select(x => x.Item).ToArray();
                var nCardActions = visibleActions.Length;

                if (nCardActions > 0 || group.Controller == null)
                {
                    var cardHeader = new MenuItem();
                    cardHeader.SetResourceReference(StyleProperty, "MenuHeader");
                    cardHeader.Header = card.Name;
                    cardHeader.Background = card.Controller.TransparentBrush;
                    items.Add(cardHeader);
                }
                if (nCardActions > 0)
                {
                    items.AddRange(visibleActions.Select(action => CreateActionMenuItem(action, CardActionClicked)));
                    if (group.Controller == null)
                        items.Add(new Separator());
                }
                if (group.Controller == null)
                    items.Add(CreateCardPassToItem());
            }
            if (!card.FaceUp)
            {
              var peekItem = new MenuItem { Header = "Peek", InputGestureText = "Ctrl+P" };
              peekItem.Click += delegate { ContextCard.Peek(); };
              items.Add(peekItem);
            }

            return items;
        }
Exemple #2
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 #3
0
 protected virtual List<Control> CreateCardMenuItems(Card card, DataNew.Entities.Group def)
 {
     var items = new List<Control>();
     var menuItem = new MenuItem { Header = card.Name, Background = card.Controller != null ? card.Controller.TransparentBrush : new SolidColorBrush(Color.FromArgb(100, 100, 100, 100)) };
     menuItem.SetResourceReference(StyleProperty, "MenuHeader");
     items.Add(menuItem);
     if (card.CanManipulate())
     {
         var selection = Selection.ExtendToSelection(card);
         //actionFilter showCard = async (IGroupAction a) =>
         actionFilter showCard = (IGroupAction a) =>
         {
             if (a.ShowIf != null)
             {
                 //return await CallActionShowIf(a.ShowIf, selection);
                 return CallActionShowIf(a.ShowIf, selection);
             }
             return true;
         };
         var visibleActionsTasks = def.CardActions.Select(item => new { Item = item, PredTask = showCard.Invoke(item) }).ToList();
         //await TaskEx.WhenAll(visibleActionsTasks.Select(x => x.PredTask));
         //var visibleActions = visibleActionsTasks.Where(x => x.PredTask.Result).Select(x => x.Item).ToArray();
         var visibleActions = visibleActionsTasks.Where(x => x.PredTask).Select(x => x.Item).ToArray();
         var nCardActions = visibleActions.Length;
         if (nCardActions > 0)
         {
             items.AddRange(visibleActions.Select(action => CreateActionMenuItem(action, CardActionClicked)));
             if (group.Controller == null)
                 items.Add(new Separator());
         }
     }
     if (card.Controller != Player.LocalPlayer)
     {
         var item = new MenuItem { Header = "Take control" };
         item.Click += delegate { card.TakeControl(); };
         items.Add(item);
         return items;
     }
     else
     {
         if (group.Controller == null)
             items.Add(CreateCardPassToItem());
     }
     if (def.Id == Program.GameEngine.Definition.Table.Id)
     {
         var ami = new MenuItem() { Header = card.Anchored ? "Unanchor" : "Anchor" };
         ami.Click += (sender, args) => ContextCard.SetAnchored(false, card.Anchored == false);
         items.Add(ami);
     }
     if (!card.FaceUp)
     {
         var peekItem = new MenuItem { Header = "Peek", InputGestureText = "Ctrl+P" };
         peekItem.Click += delegate { ContextCard.Peek(); };
         items.Add(peekItem);
     }
     return items;
 }
Exemple #4
0
        protected virtual List<Control> CreateCardMenuItems(Card card, DataNew.Entities.Group def)
        {
            var items = new List<Control>();
            if (!card.CanManipulate())
            {
                var item = new MenuItem { Header = card.Name, Background = card.Controller.TransparentBrush };
                item.SetResourceReference(StyleProperty, "MenuHeader");
                items.Add(item);

                item = new MenuItem { Header = "Take control" };
                item.Click += delegate { card.TakeControl(); };
                items.Add(item);
                return items;
            }
            else
            {
                var actions = def.CardActions.ToList();
                var nCardActions = actions.ToArray().Length;

                if (nCardActions > 0 || group.Controller == null)
                {
                    var cardHeader = new MenuItem();
                    cardHeader.SetResourceReference(StyleProperty, "MenuHeader");
                    cardHeader.Header = card.Name;
                    cardHeader.Background = card.Controller.TransparentBrush;
                    items.Add(cardHeader);
                }
                if (nCardActions > 0)
                {
                    items.AddRange(actions.Select(action => CreateActionMenuItem(action, CardActionClicked, card)).Where(x => x.Visibility == Visibility.Visible));
                    if (group.Controller == null)
                        items.Add(new Separator());
                }
                if (group.Controller == null)
                    items.Add(CreateCardPassToItem());
            }
            if (def.Id == Program.GameEngine.Definition.Table.Id)
            {
                var ami = new MenuItem() { Header = card.Anchored ? "Unanchor" : "Anchor" };
                ami.Click += (sender, args) => ContextCard.SetAnchored(false, card.Anchored == false);
                items.Add(ami);
            }
            if (!card.FaceUp)
            {
                var peekItem = new MenuItem { Header = "Peek", InputGestureText = "Ctrl+P" };
                peekItem.Click += delegate { ContextCard.Peek(); };
                items.Add(peekItem);
            }
            return items;
        }
Exemple #5
0
 public virtual bool ExecuteDefaultCardAction(Card card)
 {
     var defaultCardAction = GetDefaultCardAction();
     if (defaultCardAction == null || !card.CanManipulate())
         return false;
     group.KeepControl();
     card.KeepControl();
     if (defaultCardAction.Execute != null)
         ScriptEngine.ExecuteOnCards(defaultCardAction.Execute, Selection.ExtendToSelection(card));
     else if (defaultCardAction.BatchExecute != null)
         ScriptEngine.ExecuteOnBatch(defaultCardAction.BatchExecute, Selection.ExtendToSelection(card));
     group.ReleaseControl();
     card.ReleaseControl();
     return true;
 }