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 HandleMouseMove(Point previousMouseScreenPosition, Point currentMouseScreenPosition) { base.HandleMouseMove(previousMouseScreenPosition, currentMouseScreenPosition); ICursorLocation cursorLocation = model.ThisPlayer.CursorLocation; if (!WaitingForBoardChange && cursorLocation is ITabsCursorLocation) { ITabsCursorLocation location = (ITabsCursorLocation)cursorLocation; IMap tab = location.Tab as IMap; if (tab != null && tab != model.CurrentGameBox.CurrentGame.VisibleBoard) { WaitingForBoardChange = true; networkClient.Send(new VisibleBoardChangedMessage(model.StateChangeSequenceNumber, tab.Id)); } } }
public override void UpdateCursor(System.Windows.Forms.Form mainForm, IView view) { IPiece pieceBeingDragged = model.ThisPlayer.PieceBeingDragged; if (pieceBeingDragged == null) { controller.State = controller.IdleState; controller.IdleState.UpdateCursor(mainForm, view); } else { ICursorLocation cursorLocation = model.ThisPlayer.CursorLocation; if (cursorLocation is IHandCursorLocation) { mainForm.Cursor = view.FingerCursor; } else if (cursorLocation is IBoardCursorLocation) { IBoardCursorLocation location = (IBoardCursorLocation)cursorLocation; mainForm.Cursor = (!model.CurrentGameBox.CurrentGame.StackingEnabled || location.Piece == null || location.Piece.Stack.AttachedToCounterSection || location.Piece.GetType() != pieceBeingDragged.GetType() || pieceBeingDragged is ITerrainClone ? view.FingerCursor : view.FingerAddCursor); } else if (cursorLocation is IStackInspectorCursorLocation) { mainForm.Cursor = (model.CurrentSelection == null || model.CurrentSelection.Stack.Pieces[0].GetType() != pieceBeingDragged.GetType() ? System.Windows.Forms.Cursors.No : view.FingerAddCursor); } else if (cursorLocation is ITabsCursorLocation) { ITabsCursorLocation location = (ITabsCursorLocation)cursorLocation; mainForm.Cursor = (location.Tab is ICounterSheet ? view.FingerRemoveCursor : view.FingerCursor); } else { mainForm.Cursor = System.Windows.Forms.Cursors.No; } } }
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 Render(IGraphics graphics, long currentTimeInMicroseconds) { RectangleF area = view.TabsArea; IGame game = model.CurrentGameBox.CurrentGame; IBoard[] boards = game.Boards; int boardCount = tabCount; if (boardCount > 1) { float position = area.X; IBoard visibleBoard = game.VisibleBoard; IBoard tabAtMousePosition = null; if (model.ThisPlayer.CursorLocation is ITabsCursorLocation) { tabAtMousePosition = ((ITabsCursorLocation)model.ThisPlayer.CursorLocation).Tab; } float tabShownOffset = 0.0f; // calculate total width float totalWidth = 16.0f; for (int i = 0; i < boards.Length; ++i) { IBoard board = boards[i]; ICounterSheet counterSheet = board as ICounterSheet; if (counterSheet == null || counterSheet.Properties.Type != CounterSheetType.Terrain || game.Mode == Mode.Terrain) { string boardName = board.Name; float textWidth = graphics.GetTextWidthInPixels(font, boardName); totalWidth += textWidth + 10.0f; if (i < tabShown) { tabShownOffset += textWidth + 10.0f; } } } // if total width exceeds screen width (minus margin), display scrollers float widthOverflow = totalWidth + 150.0f - area.Width; scrollersNeeded = (widthOverflow > 0.0f); if (scrollersNeeded) { // calculate last tab stop widthOverflow += 63.0f; for (int i = 0; i < boards.Length; ++i) { IBoard board = boards[i]; ICounterSheet counterSheet = board as ICounterSheet; if (counterSheet == null || counterSheet.Properties.Type != CounterSheetType.Terrain || game.Mode == Mode.Terrain) { string boardName = board.Name; float textWidth = graphics.GetTextWidthInPixels(font, boardName); widthOverflow -= textWidth + 10.0f; if (widthOverflow <= 0.0f) { lastTabStop = i + 1; break; } } } scrollOffset = (scrollOffset < tabShownOffset ? Math.Min(scrollOffset + 40.0f, tabShownOffset) : Math.Max(scrollOffset - 40.0f, tabShownOffset)); position -= scrollOffset; tabsImageElements[7].Render(new RectangleF(position, area.Y, 63.0f, 26.0f)); position += 63.0f; } else { scrollOffset = 0.0f; lastTabStop = 0; tabShown = 0; } bool previousBoardIsVisible = false; bool previousBoardIsOwned = false; uint previousBoardOwnerColor = 0; int boardIndex = 0; for (int i = 0; i < boards.Length; ++i) { IBoard board = boards[i]; ICounterSheet counterSheet = board as ICounterSheet; if (counterSheet == null || counterSheet.Properties.Type != CounterSheetType.Terrain || game.Mode == Mode.Terrain) { string boardName = board.Name; float textWidth = graphics.GetTextWidthInPixels(font, boardName); if (boardIndex == 0) { tabsImageElements[board == visibleBoard ? 8 : 0].Render(new RectangleF(position, area.Y, 16.0f, 26.0f)); } else if (board != visibleBoard) { tabsImageElements[previousBoardIsVisible ? 5 : 2].Render(new RectangleF(position, area.Y, 16.0f, 26.0f)); } if (previousBoardIsOwned) { hiddenIcon.Render(new RectangleF(position - 9.0f, area.Y + 4.0f, 17.0f, 11.0f), previousBoardOwnerColor); } if (boardIndex != 0 && board == visibleBoard) { tabsImageElements[3].Render(new RectangleF(position, area.Y, 16.0f, 26.0f)); } position += 16.0f; tabsImageElements[board == visibleBoard ? 4 : 1].Render(new RectangleF(position, area.Y, textWidth - 6.0f, 26.0f)); graphics.DrawText(font, (board == tabAtMousePosition ? 0xFF7FFF7F : (board == visibleBoard ? 0xFFFFFFFF : 0xFFBFBFBF)), new RectangleF(position - 3.0f, area.Y + 7.0f, textWidth, 26.0f), StringAlignment.Center, boardName); position += textWidth - 6.0f; if (board.Owner != Guid.Empty) { previousBoardIsOwned = true; IPlayer player = model.GetPlayerByGuid(board.Owner); previousBoardOwnerColor = (player != null ? player.Color : 0xffffffff); } else { previousBoardIsOwned = false; } if (boardIndex == boardCount - 1) { tabsImageElements[board == visibleBoard ? 9 : 6].Render(new RectangleF(position, area.Y, 16.0f, 26.0f)); } else { previousBoardIsVisible = (board == visibleBoard); } ++boardIndex; } } if (previousBoardIsOwned) { hiddenIcon.Render(new RectangleF(position - 7.0f, area.Y + 4.0f, 17.0f, 11.0f), previousBoardOwnerColor); } position += 16.0f; tabsImageElements[7].Render(new RectangleF(position, area.Y, area.Right - position, 26.0f)); } else { scrollersNeeded = false; } // icons ITabsCursorLocation cursorLocation = model.ThisPlayer.CursorLocation as ITabsCursorLocation; if (scrollersNeeded) { for (int i = 0; i < 4; ++i) { tabScrollers[i].Render(new RectangleF(area.Left + i * 16.0f + 1.0f, area.Bottom - 20.0f, 15.0f, 15.0f), (cursorLocation != null && cursorLocation.Icon == (TabsIcon.FirstTab + i) && model.ThisPlayer.StackBeingDragged == null && model.ThisPlayer.PieceBeingDragged == null ? 0xff7fff7f : 0xffffffff)); } } hideRevealIcon.Render(new RectangleF(area.Right - 154.0f, area.Bottom - 19.0f, 21.0f, 17.0f), (model.CurrentGameBox.Reference == model.GameLibrary.DefaultGameBox || model.ThisPlayer.Guid == Guid.Empty || (game.VisibleBoard.Owner != Guid.Empty && game.VisibleBoard.Owner != model.ThisPlayer.Guid) ? 0xFF7F7F7F : (cursorLocation != null && cursorLocation.Icon == TabsIcon.HideReveal && model.ThisPlayer.StackBeingDragged == null && model.ThisPlayer.PieceBeingDragged == null ? 0xff7fff7f : 0xffffffff))); if (game.StackingEnabled) { stackingEnabledIcon.Render(new RectangleF(area.Right - 127.0f, area.Bottom - 19.0f, 21.0f, 18.0f), (cursorLocation != null && cursorLocation.Icon == TabsIcon.Stacking && model.ThisPlayer.StackBeingDragged == null && model.ThisPlayer.PieceBeingDragged == null ? 0xff7fff7f : 0xffffffff)); } else { stackingDisabledIcon.Render(new RectangleF(area.Right - 127.0f, area.Bottom - 19.0f, 21.0f, 18.0f), (cursorLocation != null && cursorLocation.Icon == TabsIcon.Stacking && model.ThisPlayer.StackBeingDragged == null && model.ThisPlayer.PieceBeingDragged == null ? 0xff7fff7f : 0xffffffff)); } if (game.Mode == Mode.Terrain) { // computes pulsation float pulsation = 1.15f + 0.15f * (float)Math.Sin((double)(currentTimeInMicroseconds % (long)400000) * (Math.PI / 200000.0)); terrainModeIcon.Render(new RectangleF(area.Right - 100.0f + 13.5f * (1.0f - pulsation), area.Bottom - 19.0f + 9.5f * (1.0f - pulsation), 27.0f * pulsation, 19.0f * pulsation), (cursorLocation != null && cursorLocation.Icon == TabsIcon.TerrainMode && model.ThisPlayer.StackBeingDragged == null && model.ThisPlayer.PieceBeingDragged == null ? 0xff7fff7f : 0xffffffff)); } else { terrainModeIcon.Render(new RectangleF(area.Right - 100.0f, area.Bottom - 19.0f, 27.0f, 19.0f), (cursorLocation != null && cursorLocation.Icon == TabsIcon.TerrainMode && model.ThisPlayer.StackBeingDragged == null && model.ThisPlayer.PieceBeingDragged == null ? 0xff7fff7f : 0xffffffff)); } handIcon.Render(new RectangleF(area.Right - 66.0f, area.Bottom - 19.0f, 17.0f, 18.0f), (model.ThisPlayer.Guid == Guid.Empty ? 0xFF7F7F7F : (cursorLocation != null && cursorLocation.Icon == TabsIcon.Hand && model.ThisPlayer.StackBeingDragged == null && model.ThisPlayer.PieceBeingDragged == null ? 0xff7fff7f : 0xffffffff))); undoIcon.Render(new RectangleF(area.Right - 42.0f, area.Bottom - 19.0f, 16.0f, 16.0f), (!model.CommandManager.CanUndo ? 0xFF7F7F7F : (cursorLocation != null && cursorLocation.Icon == TabsIcon.Undo && model.ThisPlayer.StackBeingDragged == null && model.ThisPlayer.PieceBeingDragged == null ? 0xff7fff7f : 0xffffffff))); redoIcon.Render(new RectangleF(area.Right - 19.0f, area.Bottom - 19.0f, 16.0f, 16.0f), (!model.CommandManager.CanRedo ? 0xFF7F7F7F : (cursorLocation != null && cursorLocation.Icon == TabsIcon.Redo && 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 == TabsIcon.Undo) { graphics.DrawText(font, (!model.CommandManager.CanUndo ? 0xFF7F7F7F : 0xff7fff7f), new RectangleF(area.Right - 42.0f, area.Bottom - 19.0f - 17.0f, 16.0f, 17.0f), StringAlignment.Far, Resources.ToolTipUndo); } else if (cursorLocation.Icon == TabsIcon.Redo) { graphics.DrawText(font, (!model.CommandManager.CanRedo ? 0xFF7F7F7F : 0xff7fff7f), new RectangleF(area.Right - 19.0f, area.Bottom - 19.0f - 17.0f, 16.0f, 17.0f), StringAlignment.Far, Resources.ToolTipRedo); } else if (cursorLocation.Icon == TabsIcon.Hand) { graphics.DrawText(font, (model.ThisPlayer.Guid == Guid.Empty ? 0xFF7F7F7F : 0xff7fff7f), new RectangleF(area.Right - 66.0f, area.Bottom - 19.0f - 17.0f, 16.0f, 17.0f), StringAlignment.Far, (view.Hand.IsVisible ? Resources.ToolTipHideHand : Resources.ToolTipShowHand)); } else if (cursorLocation.Icon == TabsIcon.TerrainMode) { graphics.DrawText(font, 0xff7fff7f, new RectangleF(area.Right - 100.0f, area.Bottom - 19.0f - 17.0f, 16.0f, 17.0f), StringAlignment.Far, Resources.ToolTipTerrainMode); } else if (cursorLocation.Icon == TabsIcon.Stacking) { graphics.DrawText(font, 0xff7fff7f, new RectangleF(area.Right - 127.0f, area.Bottom - 19.0f - 17.0f, 16.0f, 17.0f), StringAlignment.Far, Resources.ToolTipStacking); } else if (cursorLocation.Icon == TabsIcon.HideReveal) { graphics.DrawText(font, (model.CurrentGameBox.Reference == model.GameLibrary.DefaultGameBox || model.ThisPlayer.Guid == Guid.Empty || (game.VisibleBoard.Owner != Guid.Empty && game.VisibleBoard.Owner != model.ThisPlayer.Guid) ? 0xFF7F7F7F : 0xff7fff7f), new RectangleF(area.Right - 154.0f, area.Bottom - 19.0f - 17.0f, 16.0f, 17.0f), StringAlignment.Far, (game.VisibleBoard.Owner == Guid.Empty ? Resources.ToolTipHideBoard : Resources.ToolTipRevealBoard)); } } }