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; }