Ejemplo n.º 1
0
        public GroupControl()
        {
            if (DesignerProperties.GetIsInDesignMode(this)) return;

            this.Loaded += OnLoaded;

            AddHandler(CardControl.CardOverEvent, new CardsEventHandler(OnCardOver));
            AddHandler(CardControl.CardOutEvent, new CardsEventHandler(OnCardOut));
            AddHandler(CardControl.CardDroppedEvent, new CardsEventHandler(OnCardDropped));
            AddHandler(TableControl.TableKeyEvent, new EventHandler<TableKeyEventArgs>(OnKeyShortcut));

            Dispatcher.BeginInvoke(new Action(() =>
                {
                    if (Program.GameEngine != null)
                        Program.GameEngine.ComposeParts(this);
                }));
            DataContextChanged += delegate
                                      {
                                          group = DataContext as Group;
                                          if (group != null)
                                              GroupChanged();
                                      };

            ContextMenuOpening += delegate(object sender, ContextMenuEventArgs e)
                                      {
                                          e.Handled = true;
                                          ShowContextMenu(null);
                                      };
        }
Ejemplo n.º 2
0
Archivo: Card.cs Proyecto: Keterr/OCTGN
        internal static void MoveCardsTo(Group to, Card[] cards, bool[] faceup, bool isScriptMove)
        {
            var idxs = new int[cards.Length];
            if (to is Pile)
            {
                idxs = Enumerable.Repeat(0, cards.Length).ToArray();
            }
            else
            {
                for (var index = 0; index < cards.Length; index++)
                {
                    idxs[index] = to.Cards.Count + index;
                }
            }

            MoveCardsTo(to, cards, faceup, idxs, isScriptMove);
        }
Ejemplo n.º 3
0
 internal group SerializeGroup(Group grp, string rootPath)
 {
     if (grp == null)
         return null;
     var ret = new group();
     ret.name = grp.Name;
     ret.background = (grp.Background ?? "").Replace(rootPath, "");
     ret.backgroundStyle = (groupBackgroundStyle)Enum.Parse(typeof(groupBackgroundStyle), grp.BackgroundStyle);
     ret.collapsed = grp.Collapsed ? boolean.True : boolean.False;
     ret.height = grp.Height.ToString();
     ret.width = grp.Width.ToString();
     ret.icon = (grp.Icon ?? "").Replace(rootPath, "");
     ret.ordered = grp.Ordered ? boolean.True : boolean.False;
     ret.shortcut = grp.Shortcut;
     ret.moveto = grp.MoveTo ? boolean.True : boolean.False;
     var itemList = SerializeActions(grp.CardActions).ToList();
     itemList.AddRange(SerializeActions(grp.GroupActions).ToArray());
     ret.Items = itemList.ToArray();
     switch (grp.Visibility)
     {
         case GroupVisibility.Undefined:
             ret.visibility = groupVisibility.undefined;
             break;
         case GroupVisibility.Nobody:
             ret.visibility = groupVisibility.none;
             break;
         case GroupVisibility.Owner:
             ret.visibility = groupVisibility.me;
             break;
         case GroupVisibility.Everybody:
             ret.visibility = groupVisibility.all;
             break;
     }
     return ret;
 }
Ejemplo n.º 4
0
 internal Group DeserialiseGroup(group grp, int id)
 {
     if (grp == null)
         return null;
     var ret = new Group
     {
         Id = (byte)id,
         Name = grp.name,
         Background = grp.background == null ? null : Path.Combine(directory, grp.background),
         BackgroundStyle = grp.backgroundStyle.ToString(),
         Collapsed = bool.Parse(grp.collapsed.ToString()),
         Height = Int32.Parse(grp.height),
         Width = Int32.Parse(grp.width),
         Icon = grp.icon == null ? null : Path.Combine(directory, grp.icon),
         Ordered = bool.Parse(grp.ordered.ToString()),
         Shortcut = grp.shortcut,
         MoveTo = bool.Parse(grp.moveto.ToString()),
         CardActions = new List<IGroupAction>(),
         GroupActions = new List<IGroupAction>()
     };
     if (ret.Width == 0)
     {
         ret.Width = 1;
     }
     if (ret.Height == 0)
     {
         ret.Height = 1;
     }
     if (grp.Items != null)
     {
         foreach (var item in grp.Items)
         {
             if (item is action)
             {
                 var i = item as action;
                 var to = new GroupAction
                              {
                                  Name = i.menu,
                                  Shortcut = i.shortcut,
                                  ShowIf = i.showIf,
                                  BatchExecute = i.batchExecute,
                                  Execute = i.execute,
                                  DefaultAction = bool.Parse([email protected]())
                              };
                 if (item is cardAction)
                 {
                     to.IsGroup = false;
                     (ret.CardActions as List<IGroupAction>).Add(to);
                 }
                 else if (item is groupAction)
                 {
                     to.IsGroup = true;
                     (ret.GroupActions as List<IGroupAction>).Add(to);
                 }
             }
             else if (item is actionSubmenu)
             {
                 var i = item as actionSubmenu;
                 var to = new GroupActionGroup
                 {
                     Children = new List<IGroupAction>(),
                     Name = i.menu,
                     ShowIf = i.showIf,
                 };
                 if (item is cardActionSubmenu)
                 {
                     to.IsGroup = false;
                     to.Children = this.DeserializeGroupActionGroup(i, false);
                     (ret.CardActions as List<IGroupAction>).Add(to);
                 }
                 else if (item is groupActionSubmenu)
                 {
                     to.IsGroup = true;
                     to.Children = this.DeserializeGroupActionGroup(i, true);
                     (ret.GroupActions as List<IGroupAction>).Add(to);
                 }
             }
             else if (item is actionSeparator)
             {
                 var separator = new GroupActionSeparator {
                     ShowIf = item.showIf,
                 };
                 if (item is groupActionSeparator)
                 {
                     separator.IsGroup = true;
                     (ret.GroupActions as List<IGroupAction>).Add(separator);
                 }
                 else if (item is cardActionSeparator)
                 {
                     separator.IsGroup = false;
                     (ret.CardActions as List<IGroupAction>).Add(separator);
                 }
             }
         }
     }
     switch (grp.visibility)
     {
         case groupVisibility.none:
             ret.Visibility = GroupVisibility.Nobody;
             break;
         case groupVisibility.me:
             ret.Visibility = GroupVisibility.Owner;
             break;
         case groupVisibility.all:
             ret.Visibility = GroupVisibility.Everybody;
             break;
         case groupVisibility.undefined:
             ret.Visibility = GroupVisibility.Undefined;
             break;
         default:
             throw new ArgumentOutOfRangeException();
     }
     return ret;
 }
Ejemplo n.º 5
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;
        }
Ejemplo n.º 6
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;
        }
Ejemplo n.º 7
0
 public void MoveTo(Group to, bool lFaceUp, int idx, bool isScriptMove)
 {
     //converts negative indexes to count from the bottom for consistency with python behavior
     if (idx < 0) idx = to.Count + 1 + idx;
     //over-large indecies reduced to place cards at end of pile
     if (idx >= to.Count) idx = to.Count;
     if (idx < 0) idx = 0;
     //move skipped if card already at location specified
     if (to == Group && idx < Group.Count && Group[idx] == this) return;
     if (to.Visibility != GroupVisibility.Undefined) lFaceUp = FaceUp;
     Program.Client.Rpc.MoveCardReq(this, to, idx, lFaceUp, isScriptMove);
     new MoveCard(Player.LocalPlayer, this, to, idx, lFaceUp,isScriptMove).Do();
 }
Ejemplo n.º 8
0
 public void MoveTo(Group to, bool lFaceUp, bool isScriptMove)
 {
     // Default: move cards to the end of hand, top of table; but top of piles (which is index 0)
     int toIdx = to is Pile ? 0 : to.Cards.Count;
     MoveTo(to, lFaceUp, toIdx, isScriptMove);
 }
Ejemplo n.º 9
0
 internal Group DeserialiseGroup(group grp, int id)
 {
     var ret = new Group
     {
         Id = (byte)id,
         Name = grp.name,
         Background = grp.background == null ? null : Path.Combine(directory, grp.background),
         BackgroundStyle = grp.backgroundStyle.ToString(),
         Board = grp.board == null ? null : Path.Combine(directory, grp.board),
         BoardPosition = grp.boardPosition == null ? new DataRectangle { X = 0, Y = 0, Height = 0, Width = 0 } :
             new DataRectangle
             {
                 X = double.Parse(grp.boardPosition.Split(',')[0]),
                 Y = double.Parse(grp.boardPosition.Split(',')[1]),
                 Width = double.Parse(grp.boardPosition.Split(',')[2]),
                 Height = double.Parse(grp.boardPosition.Split(',')[3])
             },
         Collapsed = bool.Parse(grp.collapsed.ToString()),
         Height = Int32.Parse(grp.height),
         Width = Int32.Parse(grp.width),
         Icon = grp.icon == null ? null : Path.Combine(directory, grp.icon),
         Ordered = bool.Parse(grp.ordered.ToString()),
         Shortcut = grp.shortcut,
         CardActions = new List<IGroupAction>(),
         GroupActions = new List<IGroupAction>()
     };
     if (grp.Items != null)
     {
         foreach (var item in grp.Items)
         {
             if (item is action)
             {
                 var i = item as action;
                 var to = new GroupAction
                              {
                                  Name = i.menu,
                                  Shortcut = i.shortcut,
                                  BatchExecute = i.batchExecute,
                                  Execute = i.execute,
                                  DefaultAction = bool.Parse([email protected]())
                              };
                 if (item is cardAction)
                 {
                     (ret.CardActions as List<IGroupAction>).Add(to);
                 }
                 else if (item is groupAction)
                 {
                     (ret.GroupActions as List<IGroupAction>).Add(to);
                 }
             }
             else if (item is actionSubmenu)
             {
                 var i = item as actionSubmenu;
                 var to = new GroupActionGroup { Children = new List<IGroupAction>(), Name = i.menu };
                 to.Children = this.DeserializeGroupActionGroup(i);
                 if (item is cardActionSubmenu)
                 {
                     (ret.CardActions as List<IGroupAction>).Add(to);
                 }
                 else if (item is groupActionSubmenu)
                 {
                     (ret.GroupActions as List<IGroupAction>).Add(to);
                 }
             }
         }
     }
     switch (grp.visibility)
     {
         case groupVisibility.none:
             ret.Visibility = GroupVisibility.Nobody;
             break;
         case groupVisibility.me:
             ret.Visibility = GroupVisibility.Owner;
             break;
         case groupVisibility.all:
             ret.Visibility = GroupVisibility.Everybody;
             break;
         case groupVisibility.undefined:
             ret.Visibility = GroupVisibility.Undefined;
             break;
         default:
             throw new ArgumentOutOfRangeException();
     }
     return ret;
 }
Ejemplo n.º 10
0
        internal static void MoveCardsTo(Group to, Card[] cards, Action<MoveCardsArgs> it, bool isScriptMove)
        {
            var idxs = new int[cards.Length];
            var fups = new bool[cards.Length];
            MoveCardsArgs prev = null;
            for (var i = 0; i < cards.Length; i++)
            {
                var c = cards[i];
                var cur = new MoveCardsArgs(prev, c);
                it(cur);

                idxs[i] = cur.Index;
                fups[i] = cur.FaceUp;
            }
            //            MoveCardsTo(to, cards, fups, idxs, isScriptMove);
        }
Ejemplo n.º 11
0
 internal static void MoveCardsTo(Group to, Card[] cards, bool[] faceups, int[] idxs, bool isScriptMove)
 {
     var notMoved = new List<Card>();
     for (var i = 0; i < cards.Length; i++)
     {
         var c = cards[i];
         var lFaceUp = faceups[i];
         //converts negative indexes to count from the bottom for consistency with python behavior
         if (idxs[i] < 0) idxs[i] = to.Count + 1 + idxs[i];
         //over-large indecies reduced to place cards at end of pile
         if (idxs[i] >= to.Count) idxs[i] = to.Count;
         if (idxs[i] < 0) idxs[i] = 0;
         //move skipped if card already at location specified
         if (to == c.Group && idxs[i] < c.Group.Count && c.Group[idxs[i]] == c)
         {
             notMoved.Add(c);
             continue;
         }
         if (to.Visibility != GroupVisibility.Undefined) lFaceUp = c.FaceUp;
     }
     Program.Client.Rpc.MoveCardReq(cards.Select(x => x.Id).ToArray(), to, idxs, faceups, isScriptMove);
     new MoveCards(Player.LocalPlayer, cards, to, idxs, faceups, isScriptMove).Do();
     foreach (var c in cards.Where(x => notMoved.Contains(x) == false))
         Program.Client.Rpc.CardSwitchTo(Player.LocalPlayer, c, c.Alternate());
 }
Ejemplo n.º 12
0
 public void MoveTo(Group to, bool lFaceUp, int idx, bool isScriptMove)
 {
     //converts negative indexes to count from the bottom for consistency with python behavior
     if (idx < 0) idx = to.Count + 1 + idx;
     //over-large indecies reduced to place cards at end of pile
     if (idx >= to.Count) idx = to.Count;
     if (idx < 0) idx = 0;
     //move skipped if card already at location specified
     if (to == Group && idx < Group.Count && Group[idx] == this) return;
     if (to.Visibility != GroupVisibility.Undefined) lFaceUp = FaceUp;
     var cards = new Card[1] { this };
     Program.Client.Rpc.MoveCardReq(cards.Select(x => x.Id).ToArray(), to, new[] { idx }, new[] { lFaceUp }, isScriptMove);
     new MoveCards(Player.LocalPlayer, cards, to, new[] { idx }, new[] { lFaceUp }, isScriptMove).Do();
     Program.Client.Rpc.CardSwitchTo(Player.LocalPlayer, this, this.Alternate());
 }
Ejemplo n.º 13
0
 public void MoveTo(Group to, bool lFaceUp, int idx)
 {
     if (to == Group && idx < Group.Count && Group[idx] == this) return;
     if (to.Visibility != GroupVisibility.Undefined) lFaceUp = FaceUp;
     Program.Client.Rpc.MoveCardReq(this, to, idx, lFaceUp);
     new MoveCard(Player.LocalPlayer, this, to, idx, lFaceUp).Do();
 }
Ejemplo n.º 14
0
Archivo: Card.cs Proyecto: octgn/OCTGN
 public void MoveTo(Group to, bool lFaceUp, int idx, bool isScriptMove)
 {
     MoveCardsTo(to, new[] { this }, new[] { lFaceUp }, new[] { idx }, isScriptMove);
 }