public sealed override void HandleAccept(Controller controller) { IGame game = controller.Model.CurrentGameBox.CurrentGame; if (mode >= 0 && mode <= 1 && mode != (byte)game.Mode) { game.Mode = (Mode)mode; foreach (IPlayer player in controller.Model.Players) { player.StackBeingDragged = null; player.PieceBeingDragged = null; } if (game.Mode == Mode.Terrain) { controller.Model.CurrentSelection = null; } else { ICounterSheet visibleSheet = game.VisibleBoard as ICounterSheet; if (visibleSheet != null && visibleSheet.Properties.Type == CounterSheetType.Terrain) { IBoard[] boards = game.Boards; for (int i = 0; i < boards.Length; ++i) { ICounterSheet counterSheet = boards[i] as ICounterSheet; if (counterSheet == null || counterSheet.Properties.Type != CounterSheetType.Terrain) { game.VisibleBoard = boards[i]; break; } } } } } }
private void onKeyDown(object o, KeyEventArgs e) { if (state != DialogState) { if (e.Control && !model.ThisPlayer.DeckAutoInspect) { model.ThisPlayer.DeckAutoInspect = true; networkClient.Send(new EnableDeckAutoInspectMessage()); } if (e.KeyData == Keys.Delete) { // Del was pressed State.HandleDeleteKeyPress(); e.Handled = true; } else if (e.KeyCode == Keys.Enter && e.Alt) { // Alt+Enter was pressed e.Handled = true; view.Fullscreen = !view.Fullscreen; } else if (e.KeyCode == Keys.Tab && e.Control) { // Ctrl+Tab or Shift+Ctrl+Tab was pressed e.Handled = true; IBoard visibleBoard = model.CurrentGameBox.CurrentGame.VisibleBoard; IBoard[] boards = model.CurrentGameBox.CurrentGame.Boards; for (int i = 0; i < boards.Length; ++i) { if (boards[i] == visibleBoard) { int selectedBoardIndex = (i + (e.Shift ? boards.Length - 1 : 1)) % boards.Length; if (model.CurrentGameBox.CurrentGame.Mode != Mode.Terrain) { while (true) { ICounterSheet selectedCounterSheet = boards[selectedBoardIndex] as ICounterSheet; if (selectedCounterSheet == null || selectedCounterSheet.Properties.Type != CounterSheetType.Terrain) { break; } selectedBoardIndex = (selectedBoardIndex + (e.Shift ? boards.Length - 1 : 1)) % boards.Length; } } networkClient.Send(new VisibleBoardChangedMessage(model.StateChangeSequenceNumber, boards[selectedBoardIndex].Id)); break; } } } else if (e.KeyData == Keys.Up || e.KeyData == Keys.Down) { if (state != DialogState) { State.HandleMouseWheel(e.KeyData == Keys.Up ? 120 : -120); e.Handled = true; } } } }
public sealed override void HandleAccept(Controller controller) { ICounterSheet visibleBoard = (ICounterSheet)controller.Model.CurrentGameBox.CurrentGame.VisibleBoard; if (visibleBoard != null && visibleBoard.Properties.BackImageFileName != null) { visibleBoard.Side = (Side)(1 - (int)visibleBoard.Side); // deselect any one-sided attached piece IModel model = controller.Model; if (model.CurrentSelection != null && model.CurrentSelection.Stack.AttachedToCounterSection) { IPiece piece = model.CurrentSelection.Stack.Pieces[0]; if (piece.CounterSection.CounterSheet == visibleBoard && (piece is ICard || piece is ICounter && piece.CounterSection.Type != CounterSectionType.TwoSided)) { model.CurrentSelection = null; } } } }
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)); } } } } }
/// <summary>Retrieves the board for the tab at the given position.</summary> /// <param name="position">A position in screen coordinates.</param> /// <returns>A board, or null if none is found.</returns> private IBoard getTabAtPosition(PointF position) { IGame game = model.CurrentGameBox.CurrentGame; IBoard[] boards = game.Boards; int boardCount = tabCount; if (boardCount > 1) { RectangleF area = view.TabsArea; if (new RectangleF(area.X, area.Y + 6, area.Width, 20.0f).Contains(position)) { position.X -= area.X; position.Y -= area.Y + 6; if (scrollersNeeded) { position.X += scrollOffset - 63.0f; } IBoard visibleBoard = game.VisibleBoard; int boardIndex = 0; IBoard previousBoard = null; 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) { if (position.X < 0.0f) { break; } if (position.X < 13.0f) { if (boardIndex == 0) { if (position.X >= position.Y * (13.0f / 20.0f)) { return(board); } } else { if (board == visibleBoard) { if (position.X >= position.Y * (13.0f / 20.0f)) { return(board); } else if (position.X < 16.0f - position.Y * (13.0f / 20.0f)) { return(previousBoard); } } else { if (position.X < 13.0f - position.Y * (13.0f / 20.0f)) { return(previousBoard); } else if (position.X >= -3.0f + position.Y * (13.0f / 20.0f)) { return(board); } } } return(null); } position.X -= 13.0f; float textWidth = graphics.GetTextWidthInPixels(font, board.Name); if (position.X < textWidth) { return(board); } position.X -= textWidth - 3.0f; if (boardIndex == boardCount - 1) { if (position.X < 13.0f - position.Y * (13.0f / 20.0f)) { return(board); } else { return(null); } } previousBoard = board; ++boardIndex; } } } } return(null); }
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)); } } }