/// <summary>Uses the Event System to determine when a button is pressed and carry out the appropriate action</summary> /// <param name="id">ID of the button being pressed</param> public void OnClick(int id) { //Ensure buttons are at latest state UpdateButtonStatus(); switch (id) { case 0: //Play if (!GameManager.IsGameOngoing()) { Chessboard.Style style = Chessboard.Style.ANTIPODEAN; //Get the approiate mode switch (display.dropdownStyle.value) { case 0: display.buttonInvert.gameObject.SetActive(true); display.buttonPush.gameObject.SetActive(true); display.buttonPull.gameObject.SetActive(true); style = Chessboard.Style.ANTIPODEAN; break; case 1: display.buttonInvert.gameObject.SetActive(false); display.buttonPush.gameObject.SetActive(false); display.buttonPull.gameObject.SetActive(false); style = Chessboard.Style.SPHERE; break; default: break; } GameManager.SetGameOngoing(true); GameManager.board.Create(style); jail.Create(); } display.menuUI.SetActive(false); display.ingameUI.SetActive(true); break; case 1: //Options break; case 2: //Quit if (Application.isEditor) { GameManager.SetGameOngoing(false); GameManager.board.Clear(); jail.Clear(); } else { Application.Quit(); } break; case 3: //Invert if (display.buttonInvert.interactable) { GameManager.board.isInverted = !GameManager.board.isInverted; BoardAnimation.Inversion(); } break; case 4: //Toggle Names GameManager.board.ToggleTileNames(); break; case 5: //Show Score if (display.buttonShowScore.interactable) { bool jailVisibility = !jail.gameObject.activeSelf; GameManager.board.gameObject.SetActive(!jailVisibility); jail.SetVisible(jailVisibility); } break; case 6: //Push if (display.buttonPush.interactable && Rules.CanPush(selection.selectedPiece)) { //Decolor SetMovementPathsColor(selection.selectedPiece, null); SetAttackPathsColor(selection.selectedPiece, null); //Swap and deselect after animation completed BoardAnimation.onComplete = () => { GameManager.Swap(selection.selectedPiece.GetLocation()); selection.selectedPiece = null; //Use turn GameManager.NextTurn(); }; //Animate push BoardAnimation.PushOrPull(selection.selectedPiece.GetLocation()); } break; case 7: //Pull if (display.buttonPull.interactable && Rules.CanPull(selection.selectedPiece)) { //Decolor SetMovementPathsColor(selection.selectedPiece, null); SetAttackPathsColor(selection.selectedPiece, null); //Swap and deselect after animation completed BoardAnimation.onComplete = () => { GameManager.Swap(selection.selectedPiece.GetLocation()); selection.selectedPiece = null; //Use turn GameManager.NextTurn(); }; //Animate pull or swap Tile tile = selection.selectedPiece.GetTile(); if (tile.GetPiece() && tile.GetInversePiece() && ( (tile.GetPiece().type == Piece.Type.KING && tile.GetInversePiece().type == Piece.Type.QUEEN) || (tile.GetInversePiece().type == Piece.Type.KING && tile.GetPiece().type == Piece.Type.QUEEN)) ) { BoardAnimation.Swap(selection.selectedPiece.GetLocation()); } else { BoardAnimation.PushOrPull(selection.selectedPiece.GetLocation()); } } break; case 8: case 9: case 10: case 11: //Promotion Piece.Type type = Piece.Type.PAWN; //Get type based on button press if (id == 8) { type = Piece.Type.QUEEN; } else if (id == 9) { type = Piece.Type.KNIGHT; } else if (id == 10) { type = Piece.Type.ROOK; } else if (id == 11) { type = Piece.Type.BISHOP; } //Promopte the piece GameManager.Promote(selection.selectedPiece, type); //Change UI display.promotionUI.SetActive(false); display.ingameUI.SetActive(true); //Deselect and end the turn selection.selectedPiece = null; GameManager.NextTurn(); break; case 12: //Rules display.rulesUI.SetActive(true); break; case 13: //Close Rules display.rulesUI.SetActive(false); break; case 14: //Undo GameManager.Undo(); break; default: Debug.Log("Undefined interaction: " + id); break; } }