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 HandleGrabKeyPress() { ICursorLocation cursorLocation = model.ThisPlayer.CursorLocation; // over the board if (cursorLocation is IBoardCursorLocation) { IBoardCursorLocation location = (IBoardCursorLocation)cursorLocation; IPiece stackBottom = location.Piece; // assumption: the stack will remain unchanged in the meantime if (stackBottom != null && !model.AnimationManager.IsBeingAnimated(stackBottom.Stack)) { if (stackBottom is ITerrainClone) { networkClient.Send(new GrabTerrainMessage(model.StateChangeSequenceNumber, stackBottom.Stack.Board.Id, stackBottom.Stack.Board.GetZOrder(stackBottom.Stack))); } else { networkClient.Send(new GrabStackMessage(model.StateChangeSequenceNumber, stackBottom.Id)); } } // over the stack inspector } else if (cursorLocation is IStackInspectorCursorLocation) { IStackInspectorCursorLocation location = (IStackInspectorCursorLocation)cursorLocation; IPiece piece = location.Piece; // assumption: the stack will remain unchanged in the meantime if (piece != null && !model.AnimationManager.IsBeingAnimated(piece.Stack)) { if (piece.Stack.Pieces.Length == 1) { networkClient.Send(new GrabStackMessage(model.StateChangeSequenceNumber, piece.Id)); } else { networkClient.Send(new GrabPieceMessage(model.StateChangeSequenceNumber, piece.Id)); } } } }
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; }
/// <summary>Displays the next frame.</summary> public override void Render(IGraphics graphics, long currentTimeInMicroseconds) { ISelection selection = model.CurrentSelection; if (selection != null) { RectangleF area = view.StackInspectorArea; IStackInspectorCursorLocation cursorLocation = model.ThisPlayer.CursorLocation as IStackInspectorCursorLocation; // render background float scale = view.GameDisplayAreaInPixels.Height / 1200.0f; //image.Render(new RectangleF(area.X + 7.0f * scale, area.Y + 6.0f * scale, area.Width - 14.0f * scale, area.Height - 12.0f * scale), 0xb0f0c67d); frameImageElements[0].Render(new RectangleF(area.X, area.Y, 11.0f * scale, 10.0f * scale)); frameImageElements[1].Render(new RectangleF(area.X + 11.0f * scale, area.Y, area.Width - 22.0f * scale, 10.0f * scale)); frameImageElements[2].Render(new RectangleF(area.Right - 11.0f * scale, area.Y, 11.0f * scale, 10.0f * scale)); frameImageElements[3].Render(new RectangleF(area.X, area.Y + 10.0f * scale, 11.0f * scale, area.Height - 20.0f * scale)); frameImageElements[4].Render(new RectangleF(area.X + 11.0f * scale, area.Y + 10.0f * scale, area.Width - 22.0f * scale, area.Height - 20.0f * scale)); frameImageElements[5].Render(new RectangleF(area.Right - 11.0f * scale, area.Y + 10.0f * scale, 11.0f * scale, area.Height - 20.0f * scale)); frameImageElements[6].Render(new RectangleF(area.X, area.Bottom - 10.0f * scale, 11.0f * scale, 10.0f * scale)); frameImageElements[7].Render(new RectangleF(area.X + 11.0f * scale, area.Bottom - 10.0f * scale, area.Width - 22.0f * scale, 10.0f * scale)); frameImageElements[8].Render(new RectangleF(area.Right - 11.0f * scale, area.Bottom - 10.0f * scale, 11.0f * scale, 10.0f * scale)); // render selected pieces float pieceScaling = PieceScaling; float positionScaling = PositionScaling; IPiece[] piecesInStack = selection.Stack.Pieces; PointF[] piecePositions = model.StackInspectorPositions; // computes modulation color for blinking uint blinkFactor = (uint)(128 * Math.Sin((double)(currentTimeInMicroseconds % (long)400000) * (Math.PI / 200000.0)) + 128); uint blinkModulationColor = 0xFF000000 | blinkFactor << 16 | blinkFactor << 8 | blinkFactor; // render each selection hint (from back to front) float xOffset = area.X + area.Width * 0.5f; float yOffset = area.Y + piecesInStack[piecesInStack.Length - 1].Diagonal * 0.5f * pieceScaling; for (int i = 0; i < piecesInStack.Length; ++i) { if (piecePositions[i].X != 1.0f) { IPiece piece = piecesInStack[i]; if (selection.Contains(piece)) { SizeF pieceSize = piece.Size; PointF position = new PointF(xOffset, yOffset + piecePositions[i].Y * positionScaling); float flipAngleCosinus = piece.FlipAngleCosinus; RectangleF localisation = new RectangleF( position.X - (pieceSize.Width * flipAngleCosinus * pieceScaling) * 0.5f - 2.0f, position.Y - (pieceSize.Height * pieceScaling) * 0.5f - 2.0f, pieceSize.Width * flipAngleCosinus * pieceScaling + 4.0f, pieceSize.Height * pieceScaling + 4.0f); piece.Graphics.RenderSilhouette(localisation, piece.RotationAngle, blinkModulationColor); } } } // render each piece in order (from back to front) for (int i = 0; i < piecesInStack.Length; ++i) { if (piecePositions[i].X != 1.0f) { IPiece piece = piecesInStack[i]; SizeF pieceSize = piece.Size; PointF position = new PointF(xOffset, yOffset + piecePositions[i].Y * positionScaling); float flipAngleCosinus = piece.FlipAngleCosinus; RectangleF localisation = new RectangleF( position.X - (pieceSize.Width * flipAngleCosinus * pieceScaling) * 0.5f, position.Y - (pieceSize.Height * pieceScaling) * 0.5f, pieceSize.Width * flipAngleCosinus * pieceScaling, pieceSize.Height * pieceScaling); piece.Graphics.Render(localisation, piece.RotationAngle); } } // render insertion mark, if needed if (cursorLocation != null && (model.ThisPlayer.PieceBeingDragged != null || model.ThisPlayer.StackBeingDragged != null)) { int insertionIndex = cursorLocation.Index; // ideal arrangement of pieces in stack inspector (to avoid too much wobbling) float yPos; if (insertionIndex == 0) { float bottomPieceYPos = yOffset + piecePositions[0].Y * positionScaling; float bottomPieceDiagonal = piecesInStack[0].Diagonal; yPos = bottomPieceYPos + bottomPieceDiagonal * 0.5f * pieceScaling - 3.0f; } else if (insertionIndex == piecesInStack.Length) { yPos = area.Top + 3.0f; } else { float precedingPieceYPos = yOffset + piecePositions[insertionIndex - 1].Y * positionScaling; float nextPieceYPos = yOffset + piecePositions[insertionIndex].Y * positionScaling; float precedingPieceDiagonal = piecesInStack[insertionIndex - 1].Diagonal; float nextPieceDiagonal = piecesInStack[insertionIndex].Diagonal; yPos = nextPieceYPos + (precedingPieceYPos - nextPieceYPos) * precedingPieceDiagonal / (precedingPieceDiagonal + nextPieceDiagonal); } IImage image = graphics.MonochromaticImage; image.Render(new RectangleF(area.X + 2.0f, yPos - 1.0f, area.Width - 4.0f, 3.0f)); } // icons closeIcon.Render(new RectangleF(area.Right - 11.0f * scale - 13.0f, area.Y + 10.0f * scale, 13.0f, 12.0f), (cursorLocation != null && cursorLocation.Icon == StackInspectorIcon.Close && model.ThisPlayer.StackBeingDragged == null && model.ThisPlayer.PieceBeingDragged == null ? 0xff7fff7f : 0xffffffff)); invertIcon.Render(new RectangleF(area.Left + 11.0f * scale, area.Y + 10.0f * scale, 11.0f, 12.0f), (selection.Stack.Pieces.Length < 2 ? 0xff7f7f7f : (cursorLocation != null && cursorLocation.Icon == StackInspectorIcon.Invert && model.ThisPlayer.StackBeingDragged == null && model.ThisPlayer.PieceBeingDragged == null ? 0xff7fff7f : 0xffffffff))); shuffleIcon.Render(new RectangleF(area.Left + 2 * 11.0f * scale + 11.0f, area.Y + 10.0f * scale, 16.0f, 13.0f), (selection.Stack.Pieces.Length < 2 ? 0xff7f7f7f : (cursorLocation != null && cursorLocation.Icon == StackInspectorIcon.Shuffle && model.ThisPlayer.StackBeingDragged == null && model.ThisPlayer.PieceBeingDragged == null ? 0xff7fff7f : 0xffffffff))); recycleIcon.Render(new RectangleF(area.Left + 3 * 11.0f * scale + 27.0f, area.Y + 10.0f * scale, 13.0f, 12.0f), (selection.Empty || selection.Stack.AttachedToCounterSection ? 0xff7f7f7f : (cursorLocation != null && cursorLocation.Icon == StackInspectorIcon.Recycle && model.ThisPlayer.StackBeingDragged == null && model.ThisPlayer.PieceBeingDragged == null ? 0xff7fff7f : 0xffffffff))); // tool tips if (cursorLocation != null && model.ThisPlayer.StackBeingDragged == null && model.ThisPlayer.PieceBeingDragged == null) { if (cursorLocation.Icon == StackInspectorIcon.Close) { graphics.DrawText(font, 0xff7fff7f, new RectangleF(area.Right - 11.0f * scale - 13.0f, area.Y + 10.0f * scale - 17.0f, 13.0f, 17.0f), StringAlignment.Near, Resources.ToolTipClose); } else if (cursorLocation.Icon == StackInspectorIcon.Recycle) { graphics.DrawText(font, (selection.Empty || selection.Stack.AttachedToCounterSection ? 0xff7f7f7f : 0xff7fff7f), new RectangleF(area.Left + 3 * 11.0f * scale + 27.0f, area.Y + 10.0f * scale - 17.0f, 13.0f, 17.0f), StringAlignment.Near, Resources.ToolTipRecycle); } else if (cursorLocation.Icon == StackInspectorIcon.Shuffle) { graphics.DrawText(font, (selection.Stack.Pieces.Length < 2 ? 0xff7f7f7f : 0xff7fff7f), new RectangleF(area.Left + 2 * 11.0f * scale + 11.0f, area.Y + 10.0f * scale - 17.0f, 13.0f, 17.0f), StringAlignment.Near, Resources.ToolTipShuffle); } else if (cursorLocation.Icon == StackInspectorIcon.Invert) { graphics.DrawText(font, (selection.Stack.Pieces.Length < 2 ? 0xff7f7f7f : 0xff7fff7f), new RectangleF(area.Left + 11.0f * scale, area.Y + 10.0f * scale - 17.0f, 13.0f, 17.0f), StringAlignment.Near, Resources.ToolTipInvert); } } } }
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; }