コード例 #1
0
 public void ExecuteDefaultAction(Card card)
 {
     if (_defaultCardAction != null)
     {
         if (!card.TryToManipulate())
         {
             return;
         }
         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();
     }
     else
     {
         ExecuteDefaultAction();
     }
 }
コード例 #2
0
ファイル: GroupControl.cs プロジェクト: nickgroenke/OCTGN
        protected virtual void CardActionClicked(object sender, RoutedEventArgs e)
        {
            var action = (GroupAction)((MenuItem)sender).Tag;

            if (action.Execute != null)
            {
                ScriptEngine.ExecuteOnCards(action.Execute, Selection.ExtendToSelection(ContextCard));
            }
            else if (action.BatchExecute != null)
            {
                ScriptEngine.ExecuteOnBatch(action.BatchExecute, Selection.ExtendToSelection(ContextCard));
            }
        }
コード例 #3
0
ファイル: TableControl.xaml.cs プロジェクト: karlnp/OCTGN
        protected override void CardActionClicked(object sender, RoutedEventArgs e)
        {
            var action = (DataNew.Entities.GroupAction)((MenuItem)sender).Tag;

            if (action.Execute != null)
            {
                ScriptEngine.ExecuteOnCards(action.Execute, Selection.ExtendToSelection(ContextCard),
                                            ContextMenuPosition);
            }
            else if (action.BatchExecute != null)
            {
                ScriptEngine.ExecuteOnBatch(action.BatchExecute, Selection.ExtendToSelection(ContextCard),
                                            ContextMenuPosition);
            }
        }
コード例 #4
0
ファイル: GroupControl.cs プロジェクト: rerbes/OCTGN
 public virtual bool ExecuteDefaultCardAction(Card card)
 {
     if (_defaultCardAction == null || !card.TryToManipulate())
     {
         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);
 }
コード例 #5
0
        private void TableKeyDown(object source, TableKeyEventArgs te)
        {
            try
            {
                // Fix: keyboard shortcuts are forbidden during a DnD
                if (_isDragging)
                {
                    te.Handled = te.KeyEventArgs.Handled = true;
                    return;
                }

                KeyEventArgs e = te.KeyEventArgs;
                switch (e.Key)
                {
                case Key.PageUp:
                    Program.GameEngine.Table.BringToFront(Card);
                    e.Handled = te.Handled = true;
                    break;

                case Key.PageDown:
                    Program.GameEngine.Table.SendToBack(Card);
                    e.Handled = te.Handled = true;
                    break;

                case Key.P:
                    if (e.KeyboardDevice.Modifiers.HasFlag(ModifierKeys.Control) && !Card.FaceUp)
                    {
                        if (Card != null)
                        {
                            Card.Peek();
                        }
                        break;
                    }
                    goto default;

                default:
                    // Look for a custom shortcut in the game definition
                    ActionShortcut[] shortcuts = Card.Group.CardShortcuts;
                    ActionShortcut   match     =
                        shortcuts.FirstOrDefault(shortcut => shortcut.Key.Matches(this, te.KeyEventArgs));
                    if (match != null && Card.Group.CanManipulate())
                    {
                        // Look for cards to execute it upon, shortcuts are applied to selection first
                        IEnumerable <Card> targets;
                        if (!Selection.IsEmpty())
                        {
                            targets = Selection.Cards;
                        }
                        else if (Card.CanManipulate())
                        {
                            targets = Selection.ExtendToSelection(Card);
                        }
                        else
                        {
                            break;
                        }
                        // If the card is on the table, extract the cursor position
                        Point?pos = GroupControl is TableControl
                                             ? ((TableControl)GroupControl).MousePosition()
                                             : (Point?)null;
                        if (match.ActionDef.AsAction().Execute != null)
                        {
                            ScriptEngine.ExecuteOnCards(match.ActionDef.AsAction().Execute, targets, pos);
                        }
                        else if (match.ActionDef.AsAction().BatchExecute != null)
                        {
                            ScriptEngine.ExecuteOnBatch(match.ActionDef.AsAction().BatchExecute, targets, pos);
                        }
                        e.Handled = te.Handled = true;
                        break;
                    }

                    // Look for a "Move to" shortcut
                    Group group =
                        Player.LocalPlayer.Groups.FirstOrDefault(
                            g => g.MoveToShortcut != null && g.MoveToShortcut.Matches(this, te.KeyEventArgs));
                    bool toBottom = false;
                    // If no group is found, try to match a shortcut with "Alt" and use it as "Move to bottom"
                    if (group == null)
                    {
                        group =
                            Player.LocalPlayer.Groups.FirstOrDefault(
                                g =>
                                g.MoveToShortcut != null &&
                                new KeyGesture(g.MoveToShortcut.Key, g.MoveToShortcut.Modifiers | ModifierKeys.Alt).
                                Matches(this, te.KeyEventArgs));
                        if (group is Pile)
                        {
                            toBottom = true;
                        }
                    }
                    if (group != null && group.CanManipulate())
                    {
                        Action <Card> moveAction = toBottom
                                                          ? (c => c.MoveTo(@group, true, @group.Count))
                                                          : new Action <Card>(c => c.MoveTo(group, true));
                        if (!Selection.IsEmpty())
                        {
                            Selection.ForEachModifiable(moveAction);
                        }
                        else if (count.IsMouseOver)
                        {
                            for (int i = MultipleCards.Count - 1; i >= 0; --i)
                            {
                                var c = (Card)MultipleCards[i];
                                if (c.CanManipulate())
                                {
                                    moveAction(c);
                                }
                            }
                        }
                        else if (Card.CanManipulate())
                        {
                            moveAction(Card);
                        }
                        else
                        {
                            break;
                        }
                        e.Handled = te.Handled = true;
                        break;
                    }
                    break;
                }
            }
            catch (Exception e)
            {
                Log.Warn("TableKeyDown Error", e);
            }
        }
コード例 #6
0
ファイル: GroupControl.cs プロジェクト: nickgroenke/OCTGN
        private Control CreateActionMenuItem(IGroupAction baseAction, RoutedEventHandler onClick, Card card)
        {
            var selection = card == null?Enumerable.Empty <Card>() : Selection.ExtendToSelection(card);

            bool showAction = true;

            if (baseAction.ShowExecute != null)
            {
                showAction = CallActionConditionalExecute(baseAction, selection);
            }
            if (!showAction)
            {
                return new MenuItem()
                       {
                           Visibility = Visibility.Collapsed
                       }
            }
            ;

            //action is a separator
            var separatorAction = baseAction as GroupActionSeparator;

            if (separatorAction != null)
            {
                return(new Separator());
            }

            string newName = baseAction.Name;

            if (baseAction.HeaderExecute != null)
            {
                var name = CallActionNameExecute(baseAction, selection);
                if (name != null)
                {
                    newName = name;
                }
            }
            var item = new MenuItem {
                Header = newName
            };

            //action is a submenu
            var actionGroupDef = baseAction as GroupActionGroup;

            if (actionGroupDef != null)
            {
                foreach (var i in actionGroupDef.Children.Select(subAction => CreateActionMenuItem(subAction, onClick, card)).Where(x => x.Visibility == Visibility.Visible))
                {
                    item.Items.Add(i);
                }
                if (item.Items.Count == 0)
                {
                    return new MenuItem()
                           {
                               Visibility = Visibility.Collapsed
                           }
                }
                ;
                return(item);
            }

            //action is a proper action
            var action = baseAction as GroupAction;

            item.Tag = action;

            if (action != null)
            {
                item.InputGestureText = action.Shortcut;
                if (action.DefaultAction)
                {
                    item.FontWeight = FontWeights.Bold;
                }
            }
            item.Click += onClick;
            return(item);
        }
コード例 #7
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);
        }