public override void UpdateCursor(System.Windows.Forms.Form mainForm, IView view) { ICursorLocation cursorLocation = model.ThisPlayer.CursorLocation; if (cursorLocation is IBoardCursorLocation) { IBoardCursorLocation location = (IBoardCursorLocation)cursorLocation; mainForm.Cursor = (location.Piece == null ? (model.CurrentSelection == null || model.CurrentSelection.Empty ? view.HandCursor : System.Windows.Forms.Cursors.Cross) : view.FingerCursor); /* * mainForm.Cursor = (location.Piece == null ? * (model.CurrentSelection == null || model.CurrentSelection.Empty ? * (model.CurrentGameBox.Reference == model.GameLibrary.DefaultGameBox ? System.Windows.Forms.Cursors.WaitCursor : view.HandCursor) : * System.Windows.Forms.Cursors.Cross) : * view.FingerCursor); */ } else if (cursorLocation is IStackInspectorCursorLocation) { IStackInspectorCursorLocation location = (IStackInspectorCursorLocation)cursorLocation; mainForm.Cursor = (location.Piece == null && location.Icon == StackInspectorIcon.None ? System.Windows.Forms.Cursors.Default : view.FingerCursor); } else if (cursorLocation is IDiceBagCursorLocation) { IDiceBagCursorLocation location = (IDiceBagCursorLocation)cursorLocation; mainForm.Cursor = (location.DiceCount == 0 ? System.Windows.Forms.Cursors.Default : view.FingerDoubleCursor); } else if (cursorLocation is ITabsCursorLocation) { ITabsCursorLocation location = (ITabsCursorLocation)cursorLocation; mainForm.Cursor = (location.Tab == null && location.Icon == TabsIcon.None ? System.Windows.Forms.Cursors.Default : view.FingerCursor); } else if (cursorLocation is IMenuCursorLocation) { IMenuCursorLocation location = (IMenuCursorLocation)cursorLocation; mainForm.Cursor = (location.Item == null ? System.Windows.Forms.Cursors.Default : view.FingerCursor); } else if (cursorLocation is IHandCursorLocation) { IHandCursorLocation location = (IHandCursorLocation)cursorLocation; mainForm.Cursor = (location.Piece == null && location.Icon == HandIcon.None ? System.Windows.Forms.Cursors.Default : (location.Icon == HandIcon.Resize ? System.Windows.Forms.Cursors.HSplit : view.FingerCursor)); } else { mainForm.Cursor = System.Windows.Forms.Cursors.Default; } }
public override void HandleDeleteKeyPress() { ICursorLocation cursorLocation = model.ThisPlayer.CursorLocation; // over the board if (cursorLocation is IBoardCursorLocation) { IBoardCursorLocation location = (IBoardCursorLocation)cursorLocation; IPiece stackBottom = location.Piece; // over a unattached stack if (stackBottom != null && !stackBottom.Stack.AttachedToCounterSection) { // assumption: the stack will remain unchanged in the meantime if (!model.AnimationManager.IsBeingAnimated(stackBottom.Stack)) { if (stackBottom is ITerrainClone) { networkClient.Send(new RemoveTerrainMessage(model.StateChangeSequenceNumber, stackBottom.Stack.Board.Id, stackBottom.Stack.Board.GetZOrder(stackBottom.Stack))); } else { networkClient.Send(new UnpunchStackMessage(model.StateChangeSequenceNumber, stackBottom.Id)); } } } // over the stack inspector } else if (cursorLocation is IStackInspectorCursorLocation) { IStackInspectorCursorLocation location = (IStackInspectorCursorLocation)cursorLocation; IPiece piece = location.Piece; // over an unattached piece if (piece != null && !piece.Stack.AttachedToCounterSection) { // assumption: the stack will remain unchanged in the meantime if (!model.AnimationManager.IsBeingAnimated(piece.Stack)) { networkClient.Send(new UnpunchPieceMessage(model.StateChangeSequenceNumber, piece.Id)); } } // over the hand } else if (cursorLocation is IHandCursorLocation) { IHandCursorLocation location = (IHandCursorLocation)cursorLocation; IPiece piece = location.Piece; // over a piece if (piece != null) { // assumption: the stack will remain unchanged in the meantime if (!model.AnimationManager.IsBeingAnimated(piece.Stack)) { if (piece is ITerrainClone) { networkClient.Send(new RemoveTerrainMessage(model.StateChangeSequenceNumber, -1, piece.IndexInStackFromBottomToTop)); } else { networkClient.Send(new UnpunchPieceMessage(model.StateChangeSequenceNumber, piece.Id)); } } } } }
public override void HandleMouseWheel(int detents) { IPiece[] piecesBeingRotated = null; // over the board if (model.ThisPlayer.CursorLocation is IBoardCursorLocation) { IBoardCursorLocation location = (IBoardCursorLocation)model.ThisPlayer.CursorLocation; // over an unattached stack if (location.Piece != null && !location.Piece.Stack.AttachedToCounterSection) { // assumption: the stack will remain unchanged in the meantime if (!model.AnimationManager.IsBeingAnimated(location.Piece.Stack)) { int indexOfStackBottom = location.Piece.IndexInStackFromBottomToTop; IPiece[] stackPieces = location.Piece.Stack.Pieces; piecesBeingRotated = new IPiece[stackPieces.Length - indexOfStackBottom]; for (int i = 0; i < piecesBeingRotated.Length; ++i) { piecesBeingRotated[i] = stackPieces[i + indexOfStackBottom]; } } } // over the stack inspector } else if (model.ThisPlayer.CursorLocation is IStackInspectorCursorLocation) { IStackInspectorCursorLocation location = (IStackInspectorCursorLocation)model.ThisPlayer.CursorLocation; // over an unattached piece if (location.Piece != null && !location.Piece.Stack.AttachedToCounterSection) { // assumption: the stack will remain unchanged in the meantime if (!model.AnimationManager.IsBeingAnimated(location.Piece.Stack)) { piecesBeingRotated = new IPiece[1] { location.Piece } } } ; // over the hand } else if (model.ThisPlayer.CursorLocation is IHandCursorLocation) { IHandCursorLocation location = (IHandCursorLocation)model.ThisPlayer.CursorLocation; if (location.Piece != null) { // assumption: the stack will remain unchanged in the meantime if (!model.AnimationManager.IsBeingAnimated(location.Piece.Stack)) { piecesBeingRotated = new IPiece[1] { location.Piece } } } ; } if (piecesBeingRotated != null) { // if another rotation is in progress, ignore this new rotation if (PiecesBeingRotated != null) { if (PiecesBeingRotated.Length != piecesBeingRotated.Length) { return; } else { for (int i = 0; i < PiecesBeingRotated.Length; ++i) { if (piecesBeingRotated[i] != PiecesBeingRotated[i]) { return; } } } } PiecesBeingRotated = piecesBeingRotated; RotationInProgress = true; RotationIncrements += (detents / 120) * 120; model.AnimationManager.LaunchAnimationSequence(new InstantRotatePiecesAnimation(PiecesBeingRotated, (detents / 120) * 120)); // NOT(C) => BeginRotation if (!WaitingForContinueRotationMessage) { WaitingForContinueRotationMessage = true; RotationInProgress = false; networkClient.Send(new BeginRotationMessage()); } } }
public override void HandleRightMouseDoubleClick() { // over the board if (model.ThisPlayer.CursorLocation is IBoardCursorLocation) { IBoardCursorLocation location = (IBoardCursorLocation)model.ThisPlayer.CursorLocation; IPiece stackBottom = location.Piece; // over a stack if (stackBottom != null && !stackBottom.Stack.AttachedToCounterSection) { bool pieceIsEligible = false; foreach (IPiece piece in stackBottom.Stack.Pieces) { if (piece == stackBottom) { pieceIsEligible = true; } if (pieceIsEligible && !piece.CounterSection.IsSingleSided) { // assumption: the stack will remain unchanged in the meantime if (!model.AnimationManager.IsBeingAnimated(stackBottom.Stack)) { if (stackBottom is ITerrainClone) { networkClient.Send(new FlipTerrainMessage(model.StateChangeSequenceNumber, stackBottom.Stack.Board.Id, stackBottom.Stack.Board.GetZOrder(stackBottom.Stack))); } else { networkClient.Send(new FlipStackMessage(model.StateChangeSequenceNumber, stackBottom.Id)); } } break; } } // over an empty space } else { ICounterSheet visibleBoard = model.CurrentGameBox.CurrentGame.VisibleBoard as ICounterSheet; if (visibleBoard != null && visibleBoard.Properties.BackImageFileName != null) { networkClient.Send(new FlipCounterSheetMessage(model.StateChangeSequenceNumber)); } } // over the stack inspector } else if (model.ThisPlayer.CursorLocation is IStackInspectorCursorLocation) { IStackInspectorCursorLocation location = (IStackInspectorCursorLocation)model.ThisPlayer.CursorLocation; IPiece piece = location.Piece; if (piece != null && !piece.CounterSection.IsSingleSided) { // assumption: the stack will remain unchanged in the meantime if (!model.AnimationManager.IsBeingAnimated(piece.Stack)) { networkClient.Send(new FlipPieceMessage(model.StateChangeSequenceNumber, piece.Id)); } } // over the hand } else if (model.ThisPlayer.CursorLocation is IHandCursorLocation) { IHandCursorLocation location = (IHandCursorLocation)model.ThisPlayer.CursorLocation; IPiece piece = location.Piece; if (piece != null && !piece.CounterSection.IsSingleSided) { // assumption: the stack will remain unchanged in the meantime if (!model.AnimationManager.IsBeingAnimated(piece.Stack)) { if (piece is ITerrainClone) { networkClient.Send(new FlipTerrainMessage(model.StateChangeSequenceNumber, -1, piece.IndexInStackFromBottomToTop)); } else { networkClient.Send(new FlipPieceMessage(model.StateChangeSequenceNumber, piece.Id)); } } } } }
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); } } }
public override void HandleLeftMouseButtonUp() { IPlayer thisPlayer = model.ThisPlayer; IPiece pieceBeingDragged = thisPlayer.PieceBeingDragged; IPlayerHand playerHand = model.CurrentGameBox.CurrentGame.GetPlayerHand(thisPlayer.Guid); if (pieceBeingDragged != null && playerHand.Count > 0 && playerHand.Pieces[0].Stack == pieceBeingDragged.Stack) { ICursorLocation cursorLocation = thisPlayer.CursorLocation; // over the hand if (cursorLocation is IHandCursorLocation) { IHandCursorLocation location = (IHandCursorLocation)cursorLocation; int insertionIndex = location.Index; int currentIndex = pieceBeingDragged.IndexInStackFromBottomToTop; // assumption: the stack will remain unchanged in the meantime if (insertionIndex != currentIndex && insertionIndex != currentIndex + 1 && !model.AnimationManager.IsBeingAnimated(pieceBeingDragged.Stack)) { networkClient.Send(new RearrangePlayerHandMessage(model.StateChangeSequenceNumber, currentIndex, insertionIndex)); } else { networkClient.Send(new DragDropAbortedMessage()); } // over the board } else if (cursorLocation is IBoardCursorLocation) { IBoardCursorLocation location = (IBoardCursorLocation)cursorLocation; IPiece pieceAtMousePosition = location.Piece; // over an unattached stack if (model.CurrentGameBox.CurrentGame.StackingEnabled && pieceAtMousePosition != null && !pieceAtMousePosition.Stack.AttachedToCounterSection && pieceAtMousePosition.GetType() == pieceBeingDragged.GetType() && !(pieceBeingDragged is ITerrainClone)) { // assumption: both stacks will remain unchanged in the meantime if (pieceAtMousePosition.Stack != pieceBeingDragged.Stack && !model.AnimationManager.IsBeingAnimated(pieceBeingDragged.Stack) && !model.AnimationManager.IsBeingAnimated(pieceAtMousePosition.Stack)) { networkClient.Send(new DragDropPieceOnTopOfOtherStackMessage(model.StateChangeSequenceNumber, pieceBeingDragged.Id, pieceAtMousePosition.Stack.Id)); } else { networkClient.Send(new DragDropAbortedMessage()); } // over an empty space } else { // assumption: the stack will remain unchanged in the meantime if (!model.AnimationManager.IsBeingAnimated(pieceBeingDragged.Stack)) { PointF newPiecePosition = new PointF( location.ModelPosition.X - thisPlayer.DragAndDropAnchor.X, location.ModelPosition.Y - thisPlayer.DragAndDropAnchor.Y); if (pieceBeingDragged is ITerrainClone) { networkClient.Send(new DragDropTerrainMessage(model.StateChangeSequenceNumber, -1, pieceBeingDragged.IndexInStackFromBottomToTop, newPiecePosition)); } else { networkClient.Send(new DragDropPieceMessage(model.StateChangeSequenceNumber, pieceBeingDragged.Id, newPiecePosition)); } } else { networkClient.Send(new DragDropAbortedMessage()); } } // over the stack inspector } else if (cursorLocation is IStackInspectorCursorLocation) { IStackInspectorCursorLocation location = (IStackInspectorCursorLocation)cursorLocation; // assumption: boths stacks will remain unchanged in the meantime if (model.CurrentSelection != null && model.CurrentSelection.Stack != pieceBeingDragged.Stack && model.CurrentSelection.Stack.Pieces[0].GetType() == pieceBeingDragged.GetType() && !model.AnimationManager.IsBeingAnimated(model.CurrentSelection.Stack) && !model.AnimationManager.IsBeingAnimated(pieceBeingDragged.Stack)) { networkClient.Send(new DragDropPieceIntoOtherStackMessage(model.StateChangeSequenceNumber, pieceBeingDragged.Id, location.Index)); } else { networkClient.Send(new DragDropAbortedMessage()); } // over a counter sheet tab // assumption: the stack will remain unchanged in the meantime } else if (cursorLocation is ITabsCursorLocation && ((ITabsCursorLocation)cursorLocation).Tab is ICounterSheet && !model.AnimationManager.IsBeingAnimated(pieceBeingDragged.Stack)) { if (pieceBeingDragged is ITerrainClone) { networkClient.Send(new RemoveTerrainMessage(model.StateChangeSequenceNumber, -1, pieceBeingDragged.IndexInStackFromBottomToTop)); } else { networkClient.Send(new UnpunchPieceMessage(model.StateChangeSequenceNumber, pieceBeingDragged.Id)); } } else { networkClient.Send(new DragDropAbortedMessage()); } } thisPlayer.PieceBeingDragged = null; controller.State = controller.IdleState; }