From 6e8a4b287c228d6978ce67a461929105c18d0327 Mon Sep 17 00:00:00 2001 From: Wlowscha <54003515+Wlowscha@users.noreply.github.com> Date: Wed, 26 Feb 2025 07:05:39 +0100 Subject: [PATCH] [UI/UX] Pressing B on filter bar resets filters (#5404) * Make dropdown update selection when reset to default * Function to resect selection in filter bar * Pressing B on filter now closes it or resets instead of going to top of starters * Filter changes to starter select screen * Method to get column at a given index in filter bar * Specific reset behavior for caught filter in starter select menu * Apply suggestions from code review Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com> * Update src/ui/starter-select-ui-handler.ts Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com> --------- Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com> Co-authored-by: damocleas Co-authored-by: Madmadness65 <59298170+Madmadness65@users.noreply.github.com> --- src/ui/dropdown.ts | 2 ++ src/ui/filter-bar.ts | 14 ++++++++++++++ src/ui/pokedex-ui-handler.ts | 13 ++++--------- src/ui/starter-select-ui-handler.ts | 29 ++++++++++++++++++----------- 4 files changed, 38 insertions(+), 20 deletions(-) diff --git a/src/ui/dropdown.ts b/src/ui/dropdown.ts index 718058c7f99..ec433a35733 100644 --- a/src/ui/dropdown.ts +++ b/src/ui/dropdown.ts @@ -629,6 +629,8 @@ export class DropDown extends Phaser.GameObjects.Container { } } } + + this.onChange(); } } diff --git a/src/ui/filter-bar.ts b/src/ui/filter-bar.ts index 1eba81247d4..8ef910f954a 100644 --- a/src/ui/filter-bar.ts +++ b/src/ui/filter-bar.ts @@ -86,6 +86,15 @@ export class FilterBar extends Phaser.GameObjects.Container { return this.dropDowns[this.columns.indexOf(col)]; } + /** + * Get the DropDownColumn associated to a given index + * @param index the index of the column to retrieve + * @returns the associated DropDownColumn if it exists, undefined otherwise + */ + public getColumn(index: number): DropDownColumn { + return this.columns[index]; + } + /** * Highlight the labels of the FilterBar if the filters are different from their default values */ @@ -185,6 +194,11 @@ export class FilterBar extends Phaser.GameObjects.Container { return this.getFilter(col).getVals(); } + public resetSelection(col: DropDownColumn): void { + this.dropDowns[col].resetToDefault(); + this.updateFilterLabels(); + } + setValsToDefault(): void { for (const dropDown of this.dropDowns) { dropDown.resetToDefault(); diff --git a/src/ui/pokedex-ui-handler.ts b/src/ui/pokedex-ui-handler.ts index b3655d80fa1..a18f138e4f7 100644 --- a/src/ui/pokedex-ui-handler.ts +++ b/src/ui/pokedex-ui-handler.ts @@ -898,16 +898,11 @@ export default class PokedexUiHandler extends MessageUiHandler { if (this.filterMode && this.filterBar.openDropDown) { // CANCEL with a filter menu open > close it this.filterBar.toggleDropDown(this.filterBarCursor); - - // if there are possible pokemon go the first one of the list - if (numberOfStarters > 0) { - this.setFilterMode(false); - this.scrollCursor = 0; - this.updateScroll(); - this.setCursor(0); - } success = true; - + } else if (this.filterMode && !this.filterBar.getFilter(this.filterBarCursor).hasDefaultValues()) { + this.filterBar.resetSelection(this.filterBarCursor); + this.updateStarters(); + success = true; } else if (this.filterTextMode && !(this.filterText.getValue(this.filterTextCursor) === this.filterText.defaultText)) { this.filterText.resetSelection(this.filterTextCursor); success = true; diff --git a/src/ui/starter-select-ui-handler.ts b/src/ui/starter-select-ui-handler.ts index 80a2baf7f55..771554f18de 100644 --- a/src/ui/starter-select-ui-handler.ts +++ b/src/ui/starter-select-ui-handler.ts @@ -1080,10 +1080,18 @@ export default class StarterSelectUiHandler extends MessageUiHandler { /** * Set the selections for all filters to their default starting value */ - resetFilters() : void { + public resetFilters(): void { + this.filterBar.setValsToDefault(); + this.resetCaughtDropdown(); + } + + /** + * Set default value for the caught dropdown, which only shows caught mons + */ + public resetCaughtDropdown(): void { const caughtDropDown: DropDown = this.filterBar.getFilter(DropDownColumn.CAUGHT); - this.filterBar.setValsToDefault(); + caughtDropDown.resetToDefault(); // initial setting, in caught filter, select the options excluding the uncaught option for (let i = 0; i < caughtDropDown.options.length; i++) { @@ -1323,16 +1331,15 @@ export default class StarterSelectUiHandler extends MessageUiHandler { if (this.filterMode && this.filterBar.openDropDown) { // CANCEL with a filter menu open > close it this.filterBar.toggleDropDown(this.filterBarCursor); - - // if there are possible starters go the first one of the list - if (numberOfStarters > 0) { - this.setFilterMode(false); - this.scrollCursor = 0; - this.updateScroll(); - this.setCursor(0); - } success = true; - + } else if (this.filterMode && !this.filterBar.getFilter(this.filterBar.getColumn(this.filterBarCursor)).hasDefaultValues()) { + if (this.filterBar.getColumn(this.filterBarCursor) === DropDownColumn.CAUGHT) { + this.resetCaughtDropdown(); + } else { + this.filterBar.resetSelection(this.filterBarCursor); + } + this.updateStarters(); + success = true; } else if (this.statsMode) { this.toggleStatsMode(false); success = true;