示例#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;
     }
 }
示例#2
0
        private void TableKeyDown(object source, TableKeyEventArgs te)
        {
            // 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.Game.Table.BringToFront(Card);
                    e.Handled = te.Handled = true;
                    break;
                case Key.PageDown:
                    Program.Game.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.Execute != null)
                            ScriptEngine.ExecuteOnCards(match.ActionDef.Execute, targets, pos);
                        else if (match.ActionDef.BatchExecute != null)
                            ScriptEngine.ExecuteOnBatch(match.ActionDef.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;
            }
        }
示例#3
0
        protected override void OnKeyDown(KeyEventArgs e)
        {
            base.OnKeyDown(e);

            if (_currentCard != null && _currentCardUpStatus && (Keyboard.GetKeyStates(Key.LeftCtrl) & KeyStates.Down) > 0 && Prefs.ZoomOption == Prefs.ZoomType.ProxyOnKeypress && _newCard)
            {
                var img = _currentCard.GetBitmapImage(_currentCardUpStatus, true);
                ShowCardPicture(_currentCard, img);
                _newCard = false;
            }

            if (e.OriginalSource is TextBox)
                return; // Do not tinker with the keyboard events when the focus is inside a textbox

            if (e.IsRepeat)
                return;
            IInputElement mouseOver = Mouse.DirectlyOver;
            var te = new TableKeyEventArgs(this, e);
            if (mouseOver != null) mouseOver.RaiseEvent(te);
            if (te.Handled) return;

            // If the event was unhandled, check if there's a selection and try to apply a shortcut action to it
            if (!Selection.IsEmpty() && Selection.Source.CanManipulate())
            {
                ActionShortcut match =
                    Selection.Source.CardShortcuts.FirstOrDefault(
                        shortcut => shortcut.Key.Matches(this, te.KeyEventArgs));
                if (match != null)
                {
                    if (match.ActionDef.AsAction().Execute != null)
                        ScriptEngine.ExecuteOnCards(match.ActionDef.AsAction().Execute, Selection.Cards);
                    else if (match.ActionDef.AsAction().BatchExecute != null)
                        ScriptEngine.ExecuteOnBatch(match.ActionDef.AsAction().BatchExecute, Selection.Cards);
                    e.Handled = true;
                    return;
                }
            }

            // The event was still unhandled, try all groups, starting with the table
            if (table == null) return;
            table.RaiseEvent(te);
            if (te.Handled) return;
            foreach (Group g in Player.LocalPlayer.Groups.Where(g => g.CanManipulate()))
            {
                ActionShortcut a = g.GroupShortcuts.FirstOrDefault(shortcut => shortcut.Key.Matches(this, e));
                if (a == null) continue;
                if (a.ActionDef.AsAction().Execute != null)
                    ScriptEngine.ExecuteOnGroup(a.ActionDef.AsAction().Execute, g);
                e.Handled = true;
                return;
            }
        }
示例#4
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;
 }
示例#5
0
    protected override void OnKeyDown(KeyEventArgs e)
    {
      base.OnKeyDown(e);
      if (e.OriginalSource is TextBox) return;  // Do not tinker with the keyboard events when the focus is inside a textbox

      IInputElement mouseOver = Mouse.DirectlyOver;
      var te = new TableKeyEventArgs(this, e);
      if (mouseOver != null) mouseOver.RaiseEvent(te);
      if (te.Handled) return;

      // If the event was unhandled, check if there's a selection and try to apply a shortcut action to it
      if (!Selection.IsEmpty() && Selection.Source.CanManipulate())
      {
        var match = Selection.Source.CardShortcuts.FirstOrDefault(shortcut => shortcut.Key.Matches(this, te.KeyEventArgs));
        if (match != null)
        {
          if (match.ActionDef.Execute != null)
            scriptEngine.ExecuteOnCards(match.ActionDef.Execute, Selection.Cards);
          else if (match.ActionDef.BatchExecute != null)
            scriptEngine.ExecuteOnBatch(match.ActionDef.BatchExecute, Selection.Cards);
          else
            Script.ScriptEngine.Run(match.ActionDef.Actions, Selection.Cards);
          e.Handled = true;
          return;
        }
      }

      // The event was still unhandled, try all groups, starting with the table
      table.RaiseEvent(te);
      if (te.Handled) return;
      foreach (Octgn.Play.Group g in Player.LocalPlayer.Groups.Where(g => g.CanManipulate()))
      {
        ActionShortcut a = g.GroupShortcuts.FirstOrDefault(shortcut => shortcut.Key.Matches(this, e));
        if (a == null) continue;
        if (a.ActionDef.Execute != null)
           scriptEngine.ExecuteOnGroup(a.ActionDef.Execute, g);
        else
          Script.ScriptEngine.Run(a.ActionDef.Actions, g);  
        e.Handled = true;
        return;
      }
    }