Skip to content

Commit

Permalink
#259: Allow filtering scan results to show only custom games
Browse files Browse the repository at this point in the history
  • Loading branch information
mtkennerly committed Aug 9, 2024
1 parent 5bffe5d commit cfff3fb
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 9 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
and you can click the icon to display the notes.
The primary manifest does not (yet) contain any notes,
so this mainly applies to secondary manifest authors.
* GUI: You can now filter games by which secondary manifest defined them.
* GUI: You can now filter scan results by which secondary manifest defined each game.
You can also filter to display custom games only.
* CLI: The `api` command now supports a `checkAppUpdate` message.
* Fixed:
* CLI: Some commands would fail with relative path arguments.
Expand Down
2 changes: 2 additions & 0 deletions src/gui/game_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,7 @@ impl GameList {
&x.scan_info,
manifest,
config.is_game_enabled_for_operation(&x.scan_info.game_name, restoring),
config.is_game_customized(&x.scan_info.game_name),
duplicate_detector.is_game_duplicated(&x.scan_info.game_name),
config.scan.show_deselected_games,
)
Expand Down Expand Up @@ -757,6 +758,7 @@ impl GameList {
fn manifests(&self, manifest: &Manifest) -> Vec<game_filter::Manifest> {
let mut manifests = BTreeSet::new();
manifests.insert(&manifest::Source::Primary);
manifests.insert(&manifest::Source::Custom);

for entry in &self.entries {
if let Some(data) = manifest.0.get(&entry.scan_info.game_name) {
Expand Down
40 changes: 34 additions & 6 deletions src/gui/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,26 @@ fn template<'a, T: 'static + Default + Copy + Eq + PartialEq + ToString>(
.into()
}

fn template_noncopy<T: 'static + Default + Clone + Eq + PartialEq + ToString>(
filter: &Filter<T>,
kind: FilterKind,
options: Vec<T>,
message: fn(T) -> Message,
) -> Element {
Row::new()
.spacing(10)
.align_items(Alignment::Center)
.push(
checkbox("", filter.active, move |enabled| Message::ToggledSearchFilter {
filter: kind,
enabled,
})
.spacing(0),
)
.push(pick_list(options, Some(filter.choice.clone()), message))
.into()
}

fn template_with_label<T: 'static + Default + Clone + Eq + PartialEq + ToString>(
filter: &Filter<T>,
label: String,
Expand All @@ -75,6 +95,7 @@ impl FilterComponent {
scan: &ScanInfo,
manifest: &Manifest,
enabled: bool,
customized: bool,
duplicated: Duplication,
show_deselected_games: bool,
) -> bool {
Expand All @@ -87,11 +108,10 @@ impl FilterComponent {
let enable = !show_deselected_games || !self.enablement.active || self.enablement.choice.qualifies(enabled);
let changed = !self.change.active || self.change.choice.qualifies(scan);
let manifest = !self.manifest.active
|| manifest
.0
.get(&scan.game_name)
.map(|game| self.manifest.choice.qualifies(game))
.unwrap_or_default();
|| self
.manifest
.choice
.qualifies(manifest.0.get(&scan.game_name), customized);

fuzzy && unique && complete && changed && enable && manifest
}
Expand Down Expand Up @@ -159,9 +179,17 @@ impl FilterComponent {
game_filter::Enablement::ALL,
Message::EditedSearchFilterEnablement,
)
})
.push_if(manifests.len() == 2, || {
template_noncopy(
&self.manifest,
FilterKind::Manifest,
manifests.clone(),
Message::EditedSearchFilterManifest,
)
}),
)
.push_if(manifests.len() > 1, || {
.push_if(manifests.len() > 2, || {
Row::new()
.padding([0, 20, 20, 20])
.spacing(20)
Expand Down
4 changes: 4 additions & 0 deletions src/lang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,10 @@ impl Translator {
translate("button-nav-custom-games")
}

pub fn custom_games_label(&self) -> String {
title_case(&self.nav_custom_games_button())
}

pub fn nav_other_button(&self) -> String {
translate("button-nav-other")
}
Expand Down
1 change: 1 addition & 0 deletions src/resource/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ pub struct Secondary {
pub enum Source {
#[default]
Primary,
Custom,
Secondary(String),
}

Expand Down
6 changes: 4 additions & 2 deletions src/scan/game_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,15 @@ impl ToString for Manifest {
fn to_string(&self) -> String {
match &self.source {
manifest::Source::Primary => TRANSLATOR.primary_manifest_label(),
manifest::Source::Custom => TRANSLATOR.custom_games_label(),
manifest::Source::Secondary(id) => id.to_string(),
}
}
}

impl Manifest {
pub fn qualifies(&self, game: &manifest::Game) -> bool {
game.sources.contains(&self.source)
pub fn qualifies(&self, game: Option<&manifest::Game>, customized: bool) -> bool {
game.map(|game| game.sources.contains(&self.source)).unwrap_or_default()
|| (self.source == manifest::Source::Custom && customized)
}
}

0 comments on commit cfff3fb

Please sign in to comment.