diff --git a/src/game_logic/ui.rs b/src/game_logic/ui.rs index c7a0862..5de1525 100644 --- a/src/game_logic/ui.rs +++ b/src/game_logic/ui.rs @@ -111,11 +111,26 @@ impl UI { } // CURSOR MOVEMENT + + pub fn cursor_custom_column(&mut self, to_move_col: u8) { + if !self.is_cell_selected() { + self.cursor_coordinates.col = to_move_col; + } + } + + pub fn cursor_custom_row(&mut self, to_move_row: u8) { + if !self.is_cell_selected() { + self.cursor_coordinates.row = to_move_row; + } + } + /// Move the cursor up pub fn cursor_up(&mut self, authorized_positions: Vec) { if self.is_cell_selected() { self.move_selected_piece_cursor(false, -1, authorized_positions); - } else if self.cursor_coordinates.row > 0 { + } else if self.cursor_coordinates.row == 0 { + self.cursor_coordinates.row = 7; + } else { self.cursor_coordinates.row -= 1; } } @@ -124,16 +139,17 @@ impl UI { pub fn cursor_down(&mut self, authorized_positions: Vec) { if self.is_cell_selected() { self.move_selected_piece_cursor(false, 1, authorized_positions); - } else if self.cursor_coordinates.row < 7 { - self.cursor_coordinates.row += 1; } + self.cursor_coordinates.row = (self.cursor_coordinates.row + 1) % 8; } /// Move the cursor to the left pub fn cursor_left(&mut self, authorized_positions: Vec) { if self.is_cell_selected() { self.move_selected_piece_cursor(false, -1, authorized_positions); - } else if self.cursor_coordinates.col > 0 { + } else if self.cursor_coordinates.col == 0 { + self.cursor_coordinates.col = 7; + } else { self.cursor_coordinates.col -= 1; } } @@ -151,9 +167,8 @@ impl UI { pub fn cursor_right(&mut self, authorized_positions: Vec) { if self.is_cell_selected() { self.move_selected_piece_cursor(false, 1, authorized_positions); - } else if self.cursor_coordinates.col < 7 { - self.cursor_coordinates.col += 1; } + self.cursor_coordinates.col = (self.cursor_coordinates.col + 1) % 8; } /// Move the cursor to the right when we are doing a promotion diff --git a/src/handler.rs b/src/handler.rs index abcfbf7..ecafa22 100644 --- a/src/handler.rs +++ b/src/handler.rs @@ -59,14 +59,34 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> { app.quit(); } // Exit application on `Ctrl-C` - KeyCode::Char('c' | 'C') => { + KeyCode::Char('C') => { if key_event.modifiers == KeyModifiers::CONTROL { app.quit(); } } // Counter handlers // Counter handlers - KeyCode::Right | KeyCode::Char('l') => { + KeyCode::Char(c) if ('a'..='h').contains(&c) => { + let to_move_col: u8 = c as u8 - 97; + + if !(app.game.game_state == GameState::Checkmate) + && !(app.game.game_state == GameState::Draw) + { + app.game.ui.cursor_custom_column(to_move_col); + } + } + + KeyCode::Char(r) if ('1'..='8').contains(&r) => { + let to_move_row: u8 = r as u8 - 48 - 1; + + if !(app.game.game_state == GameState::Checkmate) + && !(app.game.game_state == GameState::Draw) + { + app.game.ui.cursor_custom_row(to_move_row); + } + } + + KeyCode::Right | KeyCode::Char('r') => { if (app.current_page == Pages::Multiplayer && (app.hosting.is_none() || app.selected_color.is_none())) || (app.current_page == Pages::Bot && app.selected_color.is_none()) @@ -85,7 +105,7 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> { } } - KeyCode::Left | KeyCode::Char('h') => { + KeyCode::Left | KeyCode::Char('e') => { if (app.current_page == Pages::Multiplayer && (app.hosting.is_none() || app.selected_color.is_none())) || (app.current_page == Pages::Bot && app.selected_color.is_none()) @@ -104,7 +124,7 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> { app.game.ui.cursor_left(authorized_positions); } } - KeyCode::Up | KeyCode::Char('k') => { + KeyCode::Up | KeyCode::Char('w') => { if app.current_page == Pages::Home { app.menu_cursor_up(Pages::variant_count() as u8); } else if !(app.game.game_state == GameState::Checkmate) @@ -118,7 +138,7 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> { app.game.ui.cursor_up(authorized_positions); } } - KeyCode::Down | KeyCode::Char('j') => { + KeyCode::Down | KeyCode::Char('s') => { if app.current_page == Pages::Home { app.menu_cursor_down(Pages::variant_count() as u8); } else if !(app.game.game_state == GameState::Checkmate) @@ -168,7 +188,7 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> { app.toggle_help_popup(); } } - KeyCode::Char('r') => { + KeyCode::Char('h') => { // We can't restart the game if it's a multiplayer one if app.game.opponent.is_none() { app.restart();