Ejemplo n.º 1
0
        protected void TableKeyDown(object sender, TableKeyEventArgs te)
        {
            KeyEventArgs e = te.KeyEventArgs;

            switch (e.Key)
            {
            case Key.Add:
            {
                te.Handled = e.Handled = true;
                var marker = DataContext as Marker;
                if (marker != null)
                {
                    marker.Count++;
                }
            }
            break;

            case Key.Subtract:
            {
                te.Handled = e.Handled = true;
                var marker = DataContext as Marker;
                if (marker != null)
                {
                    marker.Count--;
                }
            }
            break;
            }
        }
Ejemplo n.º 2
0
        protected virtual void OnKeyShortcut(object sender, TableKeyEventArgs e)
        {
            ActionShortcut[] shortcuts = group.GroupShortcuts;
            ActionShortcut   match     = shortcuts.FirstOrDefault(shortcut => shortcut.Key.Matches(this, e.KeyEventArgs));

            if (match == null || [email protected]())
            {
                return;
            }
            if (match.ActionDef.AsAction().Execute != null)
            {
                ScriptEngine.ExecuteOnGroup(match.ActionDef.AsAction().Execute, @group);
            }
            e.Handled = e.KeyEventArgs.Handled = true;
        }
Ejemplo n.º 3
0
        protected virtual void OnKeyShortcut(object sender, TableKeyEventArgs e)
        {
            if ([email protected]())
            {
                return;
            }
            ActionShortcut match = group.GroupShortcuts.FirstOrDefault(shortcut => shortcut.Key.Matches(this, e.KeyEventArgs));

            if (match != null)
            {
                if (match.ActionDef.AsAction().Execute != null)
                {
                    ScriptEngine.ExecuteOnGroup(match.ActionDef.AsAction().Execute, @group);
                }
                e.Handled = e.KeyEventArgs.Handled = true;
            }
            else if (group is Pile pile && pile.ShufflePileShortcut != null && pile.ShufflePileShortcut.Matches(this, e.KeyEventArgs))
            {
                pile.Shuffle();
                e.Handled = e.KeyEventArgs.Handled = true;
            }
        }
Ejemplo n.º 4
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);
            }
        }