From 3f6e43a12dfd7cb4ae487686a77e63e45a86b7c0 Mon Sep 17 00:00:00 2001 From: Ronn <12510911+zronn@users.noreply.github.com> Date: Fri, 31 May 2024 00:27:53 +0200 Subject: [PATCH] Starter select - Implement up and down offset navigation (#1480) * Handle offset up and down navigation * add comments --- src/ui/starter-select-ui-handler.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/ui/starter-select-ui-handler.ts b/src/ui/starter-select-ui-handler.ts index c54bc1924b9..c739804609a 100644 --- a/src/ui/starter-select-ui-handler.ts +++ b/src/ui/starter-select-ui-handler.ts @@ -1339,11 +1339,27 @@ export default class StarterSelectUiHandler extends MessageUiHandler { case Button.UP: if (row) { success = this.setCursor(this.cursor - 9); + } else { + // when strictly opposite starter based on rows length + // does not exits, set cursor on the second to last row + if (this.cursor + (rows - 1) * 9 > genStarters - 1) { + success = this.setCursor(this.cursor + (rows - 2) * 9); + } else { + success = this.setCursor(this.cursor + (rows - 1) * 9); + } } break; case Button.DOWN: if (row < rows - 2 || (row < rows - 1 && this.cursor % 9 <= (genStarters - 1) % 9)) { success = this.setCursor(this.cursor + 9); + } else { + // if there is no starter below while being on the second to + // last row, adjust cursor position with one line less + if (row === rows - 2 && this.cursor + 9 > genStarters - 1) { + success = this.setCursor(this.cursor - (rows - 2) * 9); + } else { + success = this.setCursor(this.cursor - (rows - 1) * 9); + } } break; case Button.LEFT: