[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 <damocleas25@gmail.com> Co-authored-by: Madmadness65 <59298170+Madmadness65@users.noreply.github.com>
This commit is contained in:
parent
b9a853ed2e
commit
6e8a4b287c
|
@ -629,6 +629,8 @@ export class DropDown extends Phaser.GameObjects.Container {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.onChange();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue