public void OnPieceSelected(Type piece) { Move move = null; foreach (Promotion promotion in _promotionMoves) { if (promotion.NewPiece == piece) { move = promotion; } } if (move == null) { throw new ArgumentException($"Pawn cannot be promoted to {piece}"); } Deselect(); MoveSelected?.Invoke(move); ShowMove(move); }
private void UpdateCommands() { RaisePropertyChanged(nameof(EditSelected)); _editSelected?.RaiseCanExecuteChanged(); RaisePropertyChanged(nameof(SendSelectedImageToClipboard)); RaisePropertyChanged(nameof(SendSelectedScaledImageToClipboard)); RaisePropertyChanged(nameof(SendSelectedTextToClipboard)); _sendSelectedToClipboard?.RaiseCanExecuteChanged(); CloneSelected.RaiseCanExecuteChanged(); RaisePropertyChanged(nameof(CloneSelectedToolTip)); CopySelected.RaiseCanExecuteChanged(); RaisePropertyChanged(nameof(CopySelectedToolTip)); MoveSelected.RaiseCanExecuteChanged(); RaisePropertyChanged(nameof(MoveSelectedToolTip)); ExportSelected.RaiseCanExecuteChanged(); RaisePropertyChanged(nameof(ExportSelectedToolTip)); DeleteSelected.RaiseCanExecuteChanged(); RaisePropertyChanged(nameof(DeleteSelectedToolTip)); ResetStylesSelected.RaiseCanExecuteChanged(); RaisePropertyChanged(nameof(ResetStylesSelectedToolTip)); }
private void UpdateCommands() { RaisePropertyChanged("EditSelected"); _editSelected?.RaiseCanExecuteChanged(); RaisePropertyChanged("SendSelectedImageToClipboard"); RaisePropertyChanged("SendSelectedScaledImageToClipboard"); RaisePropertyChanged("SendSelectedTextToClipboard"); _sendSelectedToClipboard?.RaiseCanExecuteChanged(); CloneSelected.RaiseCanExecuteChanged(); RaisePropertyChanged("CloneSelectedToolTip"); CopySelected.RaiseCanExecuteChanged(); RaisePropertyChanged("CopySelectedToolTip"); MoveSelected.RaiseCanExecuteChanged(); RaisePropertyChanged("MoveSelectedToolTip"); ExportSelected.RaiseCanExecuteChanged(); RaisePropertyChanged("ExportSelectedToolTip"); DeleteSelected.RaiseCanExecuteChanged(); RaisePropertyChanged("DeleteSelectedToolTip"); ResetStylesSelected.RaiseCanExecuteChanged(); RaisePropertyChanged("ResetStylesSelectedToolTip"); }
// Method that invokes event indicating that a move was selected via // the UI private void OnMoveSelected(int col) { MoveSelected?.Invoke( new FutureMove(col, selectedShapes[(int)board.Turn])); }
void Update() { if (SaveAndLoad.GetInputField().isFocused) { return; } var ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; //Shortcuts if (Input.GetKeyDown(KeyCode.KeypadPlus) || Input.GetKeyDown(KeyCode.Plus)) { manip.NextVariation(); } if (Input.GetKeyDown(KeyCode.KeypadMinus) || Input.GetKeyDown(KeyCode.Minus)) { manip.PrevVariation(); } if (Input.GetKeyDown(KeyCode.Keypad2)) { var infos = BlockManipulator.GetSelectedInfos(); BlockManipulator.DeselectAll(); for (int i = 0; i < infos.Length; i++) { TileSpawner.SpawnFull(infos [i].Info, infos [i].transform.position + Vector3.back * 4f, infos[i].Blendshapes, infos[i].transform.rotation.eulerAngles); } } if (Input.GetKeyDown(KeyCode.Keypad8)) { var infos = BlockManipulator.GetSelectedInfos(); BlockManipulator.DeselectAll(); for (int i = 0; i < infos.Length; i++) { TileSpawner.SpawnFull(infos [i].Info, infos [i].transform.position + Vector3.forward * 4f, infos[i].Blendshapes, infos[i].transform.rotation.eulerAngles); } } if (Input.GetKeyDown(KeyCode.Keypad4)) { var infos = BlockManipulator.GetSelectedInfos(); BlockManipulator.DeselectAll(); for (int i = 0; i < infos.Length; i++) { TileSpawner.SpawnFull(infos [i].Info, infos [i].transform.position + Vector3.left * 4f, infos[i].Blendshapes, infos[i].transform.rotation.eulerAngles); } } if (Input.GetKeyDown(KeyCode.Keypad6)) { var infos = BlockManipulator.GetSelectedInfos(); BlockManipulator.DeselectAll(); for (int i = 0; i < infos.Length; i++) { TileSpawner.SpawnFull(infos [i].Info, infos [i].transform.position + Vector3.right * 4f, infos[i].Blendshapes, infos[i].transform.rotation.eulerAngles); } } if (Input.GetKeyDown(KeyCode.Keypad7)) { var infos = BlockManipulator.GetSelectedInfos(); BlockManipulator.DeselectAll(); for (int i = 0; i < infos.Length; i++) { TileSpawner.SpawnFull(infos [i].Info, infos [i].transform.position + Vector3.down * 4f, infos[i].Blendshapes, infos[i].transform.rotation.eulerAngles); } } if (Input.GetKeyDown(KeyCode.Keypad9)) { var infos = BlockManipulator.GetSelectedInfos(); BlockManipulator.DeselectAll(); for (int i = 0; i < infos.Length; i++) { TileSpawner.SpawnFull(infos [i].Info, infos [i].transform.position + Vector3.up * 4f, infos[i].Blendshapes, infos[i].transform.rotation.eulerAngles); } } if (Input.GetKeyDown(KeyCode.Delete)) { manip.DestroySelected(); } if (Input.GetKeyDown(KeyCode.X)) { if (Input.GetKey(KeyCode.LeftShift)) { manip.MoveSelectedBy(Vector3.left * 4f); } else { manip.MoveSelectedBy(Vector3.right * 4f); } } if (Input.GetKeyDown(KeyCode.U)) { if (Input.GetKey(KeyCode.LeftShift)) { manip.MoveSelectedBy(Vector3.down * 4f); } else { manip.MoveSelectedBy(Vector3.up * 4f); } } if (Input.GetKeyDown(KeyCode.Z) || Input.GetKeyDown(KeyCode.Y)) { if (Input.GetKey(KeyCode.LeftShift)) { manip.MoveSelectedBy(Vector3.back * 4f); } else { manip.MoveSelectedBy(Vector3.forward * 4f); } } if (Input.GetKeyDown(KeyCode.T)) { manip.SetMoveInGrid(!BlockManipulator.moveInGrid); snapToggle.isOn = !snapToggle.isOn; } if (BlockManipulator.moveInGrid) { if (Input.GetKeyDown(KeyCode.Q)) { manip.RotateSelectedBy(new Vector3(0, -90, 0)); } else if (Input.GetKeyDown(KeyCode.E)) { manip.RotateSelectedBy(new Vector3(0, 90, 0)); } } else { if (Input.GetKey(KeyCode.Q)) { manip.RotateSelectedBy(new Vector3(0, 30 * Time.deltaTime, 0)); } else if (Input.GetKey(KeyCode.E)) { manip.RotateSelectedBy(new Vector3(0, -30 * Time.deltaTime, 0)); } } if (Input.GetMouseButton(0)) { if (moving != null) { moving.Move(); } } if (Input.GetMouseButtonUp(0)) { if (moving != null) { moving.EndMove(); } moving = null; } if (EventSystem.current.IsPointerOverGameObject()) //is mouse over UI { return; } if (Physics.Raycast(ray, out hit, 100f, controlsMask)) { if (Input.GetMouseButton(0)) { manip.SetManipulating(true); } if (Input.GetMouseButtonDown(0)) { var m = hit.collider.GetComponent <MoveSelected> (); if (m != null) { m.StartMove(); } moving = m; } } if (!BlockManipulator.IsManipulating && Physics.Raycast(ray, out hit, 100f, objectMask)) { if (grid != null) { grid.Move(hit.point); } } if (!BlockManipulator.IsManipulating && Input.GetMouseButtonDown(0)) { if (Physics.Raycast(ray, out hit, 100f, objectMask)) { if (Input.GetKey(KeyCode.LeftShift)) { BlockManipulator.AddSelectItem(hit.collider.gameObject); } else { BlockManipulator.SelectItem(hit.collider.gameObject.transform.root.gameObject); } } } }
private void OnClick(Vector2Int square) { if (!_isMoveAllowed) { return; } if (_isSquareSelected && square == _selectedSquare) { Deselect(); } else if (_position.Board[square.x, square.y] != null && _position.Board[square.x, square.y].Color == _position.WhoseMove) { if (_isSquareSelected) { Deselect(); } _selectedPieceHighlight = Instantiate(_selectedPieceHighlightPrefab, _tiles[square.x, square.y]); _selectedPieceHighlight.transform.SetAsFirstSibling(); List <Move> moves = _position.Board[square.x, square.y].GetSmartMoves(); foreach (var move in moves) { _moves[move.TargetSquare.x, move.TargetSquare.y].Add(move); } for (int x = 0; x < Position.Size; x++) { for (int y = 0; y < Position.Size; y++) { if (_moves[x, y].Count != 0) { _possibleMoveHighlights.Add(Instantiate(_possibleMoveHighlightPrefab, _tiles[x, y])); } } } _isSquareSelected = true; _selectedSquare = square; } else if (_moves[square.x, square.y].Count != 0) { _isMoveAllowed = false; if (_moves[square.x, square.y].Count == 1) { Move move = _moves[square.x, square.y][0]; Deselect(); MoveSelected?.Invoke(move); ShowMove(move); } else if (_moves[square.x, square.y].Count == 4) { _promotionMoves = _moves[square.x, square.y]; _pieceSelection.Open(_position.WhoseMove); } else { throw new InvalidOperationException($"Must be only 0 or 1 or 4 possible moves " + $"in one square, but {_moves[square.x, square.y].Count} found"); } } }