Exemplo n.º 1
0
 public override void HandleEscapeKeyPress()
 {
     // close the stack inspector?
     if (model.CurrentSelection != null)
     {
         SelectionChangedMessage.SelectionInfo selectionInfo = new SelectionChangedMessage.SelectionInfo();
         selectionInfo.StackId = -1;
         networkClient.Send(new SelectionChangedMessage(model.StateChangeSequenceNumber, selectionInfo));
         // close the chat text box?
     }
     else if (view.Prompter.InputBoxVisible)
     {
         view.Prompter.HideInputBox();
         // toggle menu visibility?
     }
     else
     {
         view.Menu.IsVisible = !view.Menu.IsVisible;
         if (view.Menu.IsVisible)
         {
             view.Menu.MenuItems = new MenuItem[] {
                 new SubMenuItem(Resources.MenuFile, false, new FileMenuItem()),
                 new SubMenuItem(Resources.MenuMultiplayer, false, new MultiplayerMenuItem()),
                 new SubMenuItem(Resources.MenuSettings, false, new SettingsMenuItem()),
                 new SubMenuItem(Resources.MenuQuestionMark, false, new QuestionMarkMenuItem())
             };
         }
     }
 }
Exemplo n.º 2
0
        public override void HandleLeftMouseDoubleClick()
        {
            if (model.ThisPlayer.CursorLocation is IBoardCursorLocation)
            {
                IBoardCursorLocation location = (IBoardCursorLocation)model.ThisPlayer.CursorLocation;
                IPiece stackBottom            = location.Piece;
                // assumption: the stack will remain unchanged in the meantime
                if (stackBottom != null && model.CurrentGameBox.CurrentGame.Mode != Mode.Terrain && !model.AnimationManager.IsBeingAnimated(stackBottom.Stack))
                {
                    ISelection newSelection = stackBottom.Stack.Select();
                    if (!stackBottom.Stack.Unfolded && stackBottom is ICard)
                    {
                        newSelection = newSelection.RemoveAllPieces();
                    }
                    else
                    {
                        int bottomIndex = stackBottom.IndexInStackFromBottomToTop;
                        if (bottomIndex > 0)
                        {
                            IPiece[] stackPieces = stackBottom.Stack.Pieces;
                            for (int i = 0; i < bottomIndex; ++i)
                            {
                                newSelection = newSelection.RemovePiece(stackPieces[i]);
                            }
                        }
                    }

                    SelectionChangedMessage.SelectionInfo selectionInfo = new SelectionChangedMessage.SelectionInfo();
                    selectionInfo.StackId  = newSelection.Stack.Id;
                    selectionInfo.PieceIds = new int[newSelection.Pieces.Length];
                    for (int i = 0; i < newSelection.Pieces.Length; ++i)
                    {
                        selectionInfo.PieceIds[i] = newSelection.Pieces[i].Id;
                    }

                    networkClient.Send(new SelectionChangedMessage(model.StateChangeSequenceNumber, selectionInfo));
                }
            }
        }
Exemplo n.º 3
0
        public override void HandleLeftMouseButtonUp()
        {
            if (model.ThisPlayer.CursorLocation is IStackInspectorCursorLocation)
            {
                IStackInspectorCursorLocation location = (IStackInspectorCursorLocation)model.ThisPlayer.CursorLocation;
                // assumption: the stack will remain unchanged in the meantime
                if (location.Piece != null && location.Piece == PieceBeingSelected &&
                    !model.AnimationManager.IsBeingAnimated(PieceBeingSelected.Stack))
                {
                    ISelection newSelection;
                    if (model.CurrentSelection != null && model.CurrentSelection.Contains(location.Piece))
                    {
                        newSelection = model.CurrentSelection.RemovePiece(location.Piece);
                    }
                    else
                    {
                        newSelection = model.CurrentSelection.AddPiece(location.Piece);
                    }

                    SelectionChangedMessage.SelectionInfo selectionInfo = new SelectionChangedMessage.SelectionInfo();
                    if (newSelection == null)
                    {
                        selectionInfo.StackId = -1;
                    }
                    else
                    {
                        selectionInfo.StackId  = newSelection.Stack.Id;
                        selectionInfo.PieceIds = new int[newSelection.Pieces.Length];
                        for (int i = 0; i < newSelection.Pieces.Length; ++i)
                        {
                            selectionInfo.PieceIds[i] = newSelection.Pieces[i].Id;
                        }
                    }

                    networkClient.Send(new SelectionChangedMessage(model.StateChangeSequenceNumber, selectionInfo));
                }
            }
            controller.State = controller.IdleState;
        }
Exemplo n.º 4
0
 public override void HandleLeftMouseButtonDown()
 {
     // over the board
     if (model.ThisPlayer.CursorLocation is IBoardCursorLocation)
     {
         IBoardCursorLocation location = (IBoardCursorLocation)model.ThisPlayer.CursorLocation;
         // over a piece
         if (location.Piece != null)
         {
             PointF piecePosition = location.Piece.Position;
             model.ThisPlayer.DragAndDropAnchor = new PointF(
                 location.ModelPosition.X - piecePosition.X,
                 location.ModelPosition.Y - piecePosition.Y);
             controller.SelectingStackState.StackBottomBeingSelected = location.Piece;
             controller.State = controller.SelectingStackState;
             // over an empty space with the stack inspector visible
         }
         else if (model.CurrentSelection != null && !model.CurrentSelection.Empty)
         {
             controller.State = controller.MovingState;
             // over an empty space (no stack inspector)
         }
         else
         {
             controller.State = controller.ScrollingState;
         }
         // over the tabs
     }
     else if (model.ThisPlayer.CursorLocation is ITabsCursorLocation)
     {
         ITabsCursorLocation location = (ITabsCursorLocation)model.ThisPlayer.CursorLocation;
         // over an icon
         if (location.Icon != TabsIcon.None)
         {
             // Undo
             if (location.Icon == TabsIcon.Undo)
             {
                 if (model.CommandManager.CanUndo)
                 {
                     networkClient.Send(new UndoMessage(model.StateChangeSequenceNumber));
                 }
                 // Redo
             }
             else if (location.Icon == TabsIcon.Redo)
             {
                 if (model.CommandManager.CanRedo)
                 {
                     networkClient.Send(new RedoMessage(model.StateChangeSequenceNumber));
                 }
                 // Show/Hide hand
             }
             else if (location.Icon == TabsIcon.Hand)
             {
                 if (model.ThisPlayer.Guid != Guid.Empty)
                 {
                     IPlayerHand playerHand = model.CurrentGameBox.CurrentGame.GetPlayerHand(model.ThisPlayer.Guid);
                     if (controller.View.Hand.IsVisible)
                     {
                         controller.View.Hand.IsVisible = false;
                         if (playerHand != null && playerHand.Count == 0)
                         {
                             networkClient.Send(new RemovePlayerHandMessage(model.StateChangeSequenceNumber));
                         }
                     }
                     else
                     {
                         controller.View.Hand.IsVisible = true;
                         if (playerHand == null)
                         {
                             networkClient.Send(new AddPlayerHandMessage(model.StateChangeSequenceNumber));
                         }
                     }
                 }
                 // Terrain mode
             }
             else if (location.Icon == TabsIcon.TerrainMode)
             {
                 networkClient.Send(new ChangeModeMessage(model.StateChangeSequenceNumber,
                                                          (model.CurrentGameBox.CurrentGame.Mode == Mode.Terrain ? Mode.Default : Mode.Terrain)));
                 // Stacking
             }
             else if (location.Icon == TabsIcon.Stacking)
             {
                 networkClient.Send(new ChangeStackingMessage(model.StateChangeSequenceNumber));
                 // Hide/reveal board
             }
             else if (location.Icon == TabsIcon.HideReveal)
             {
                 Guid visibleBoardOwner = model.CurrentGameBox.CurrentGame.VisibleBoard.Owner;
                 if (model.CurrentGameBox.Reference != model.GameLibrary.DefaultGameBox && model.ThisPlayer.Guid != Guid.Empty)
                 {
                     if (visibleBoardOwner == Guid.Empty || visibleBoardOwner == model.ThisPlayer.Guid)
                     {
                         networkClient.Send(new HideRevealBoardMessage(model.StateChangeSequenceNumber));
                     }
                 }
                 // Tab scrollers
             }
             else if (location.Icon == TabsIcon.FirstTab)
             {
                 view.Tabs.ShowFirstTab();
             }
             else if (location.Icon == TabsIcon.PreviousTab)
             {
                 view.Tabs.ShowPreviousTab();
             }
             else if (location.Icon == TabsIcon.NextTab)
             {
                 view.Tabs.ShowNextTab();
             }
             else if (location.Icon == TabsIcon.LastTab)
             {
                 view.Tabs.ShowLastTab();
             }
             // over a tab
         }
         else if (location.Tab != null)
         {
             networkClient.Send(new VisibleBoardChangedMessage(model.StateChangeSequenceNumber, location.Tab.Id));
         }
         // over the stack inspector
     }
     else if (model.ThisPlayer.CursorLocation is IStackInspectorCursorLocation)
     {
         IStackInspectorCursorLocation location = (IStackInspectorCursorLocation)model.ThisPlayer.CursorLocation;
         // over an icon
         if (location.Icon != StackInspectorIcon.None)
         {
             // Close
             if (location.Icon == StackInspectorIcon.Close)
             {
                 if (model.CurrentSelection != null)
                 {
                     SelectionChangedMessage.SelectionInfo selectionInfo = new SelectionChangedMessage.SelectionInfo();
                     selectionInfo.StackId = -1;
                     networkClient.Send(new SelectionChangedMessage(model.StateChangeSequenceNumber, selectionInfo));
                 }
                 // Recycle
             }
             else if (location.Icon == StackInspectorIcon.Recycle)
             {
                 if (model.CurrentSelection != null && !model.CurrentSelection.Empty && !model.CurrentSelection.Stack.AttachedToCounterSection)
                 {
                     // assumption: the stack will remain unchanged in the meantime
                     if (!model.AnimationManager.IsBeingAnimated(model.CurrentSelection.Stack))
                     {
                         networkClient.Send(new UnpunchSelectionMessage(model.StateChangeSequenceNumber));
                     }
                 }
                 // Shuffle
             }
             else if (location.Icon == StackInspectorIcon.Shuffle)
             {
                 if (model.CurrentSelection != null && model.CurrentSelection.Stack.Pieces.Length > 1)
                 {
                     // assumption: the stack will remain unchanged in the meantime
                     if (!model.AnimationManager.IsBeingAnimated(model.CurrentSelection.Stack))
                     {
                         networkClient.Send(new ShuffleMessage(model.StateChangeSequenceNumber));
                     }
                 }
                 // Invert
             }
             else if (location.Icon == StackInspectorIcon.Invert)
             {
                 if (model.CurrentSelection != null && model.CurrentSelection.Stack.Pieces.Length > 1)
                 {
                     // assumption: the stack will remain unchanged in the meantime
                     if (!model.AnimationManager.IsBeingAnimated(model.CurrentSelection.Stack))
                     {
                         networkClient.Send(new InvertMessage(model.StateChangeSequenceNumber));
                     }
                 }
             }
             // over a piece
         }
         else if (location.Piece != null)
         {
             model.ThisPlayer.DragAndDropAnchor = location.AnchorPosition;
             controller.SelectingPieceState.PieceBeingSelected = location.Piece;
             controller.State = controller.SelectingPieceState;
         }
         // over the hand
     }
     else if (model.ThisPlayer.CursorLocation is IHandCursorLocation)
     {
         IHandCursorLocation location = (IHandCursorLocation)model.ThisPlayer.CursorLocation;
         // over an icon
         if (location.Icon != HandIcon.None)
         {
             // Resize handle
             if (location.Icon == HandIcon.Resize)
             {
                 controller.State = controller.ResizingHandState;
                 // Pin/Unpin
             }
             else if (location.Icon == HandIcon.Pin)
             {
                 view.Hand.IsPinned = !view.Hand.IsPinned;
             }
             // over a piece
         }
         else if (location.Piece != null)
         {
             model.ThisPlayer.DragAndDropAnchor = location.AnchorPosition;
             controller.SelectingPieceState.PieceBeingSelected = location.Piece;
             controller.State = controller.SelectingPieceState;
         }
         // over a menu item
     }
     else if (model.ThisPlayer.CursorLocation is IMenuCursorLocation)
     {
         IMenuCursorLocation location = (IMenuCursorLocation)model.ThisPlayer.CursorLocation;
         if (!location.Item.IsDisabled && location.Item.UserData != null)
         {
             ((ZunTzu.Control.Menu.IMenuItem)location.Item.UserData).Select(controller);
         }
     }
 }