From b9a6bf891d7ab13d25d14f1f505743e7b163d40e Mon Sep 17 00:00:00 2001 From: X4Lo Date: Mon, 2 Nov 2026 21:33:44 +0000 Subject: [PATCH] feat: add group by, theme-specific placement and matching section titles - Add a per-collection Group by option to the collection page, saved with the collection. Games with several values appear in each group, and games with no value go in a "Not set" group at the end. - Turn off manual reordering while a grouping is active. - Add an optional theme-specific placement for Stardust, Nova X, Helium and Harmony, off by default. - Copy the Collections title and separator from the neighbouring section in the game details view so they match the theme. - Add top margin to the Collections page so Create Collection no longer overlaps the window controls. - Bump the version to 1.2.0 and update the docs, changelog and manifest. --- CHANGELOG.md | 9 + docs/developer-guide.md | 23 +- docs/theme-integration.md | 8 + docs/user-guide.md | 8 +- manifests/installer_manifest.yaml | 9 + source/GameCollections/GameCollections.csproj | 2 +- .../GameCollections/Localization/en_US.xaml | 13 +- source/GameCollections/Models/DynamicRules.cs | 19 + .../GameCollections/Models/GameCollection.cs | 5 + .../Services/CollectionManager.cs | 13 + .../Services/DetailsViewIntegration.cs | 357 ++++++++++++++++-- .../Settings/GameCollectionsSettings.cs | 3 + .../Settings/GameCollectionsSettingsView.xaml | 7 + .../ViewModels/CollectionDetailsViewModel.cs | 128 ++++++- .../Views/CollectionDetailsView.xaml | 45 ++- .../Views/CollectionDetailsView.xaml.cs | 25 +- .../Views/CollectionsHomeView.xaml | 3 +- .../Views/GameCollectionsControl.xaml | 6 +- .../Views/GameCollectionsControl.xaml.cs | 54 ++- source/GameCollections/extension.yaml | 2 +- 20 files changed, 680 insertions(+), 59 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d6fcd6..cd06bc8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,15 @@ Every release must also be added to [manifests/installer_manifest.yaml](manifests/installer_manifest.yaml), which is what Playnite reads to offer updates. +## 1.2.0 – 2026-11-02 + +- Added: Group games on a collection's page by platform, series, genre, developer, publisher, category, feature, tag, + completion status, release year or install status. Each collection remembers its own choice. +- Added: Optional setting (off by default) that places the game details list next to the Game Relations section in + Stardust, Nova X, Helium and Harmony, whose layouts don't have a normal spot for it. +- Improved: The game details list now uses the same title style as the theme's other sections. +- Fixed: Create Collection button overlapping the window buttons on the Collections page. + ## 1.1.0 – 2026-11-02 - Added: Reorder games in a collection by dragging, from the right-click menu, or with Alt+arrow keys. diff --git a/docs/developer-guide.md b/docs/developer-guide.md index 39dad86..f75940f 100644 --- a/docs/developer-guide.md +++ b/docs/developer-guide.md @@ -125,14 +125,22 @@ The order is simply the order of `GameCollection.GameIds`, which is also what th `CollectionManager.MoveGames(collectionId, gameIds, anchorId, after)` is the single move operation. Selected games keep their relative order. -On the page, `CollectionDetailsViewModel.CanReorder` requires the *Collection order, ascending* sort, because a moved -game wouldn't stay put in any other. Moves relate to *visible* games, so with a filter active, "move earlier" passes the +On the page, `CollectionDetailsViewModel.CanReorder` requires the *Collection order, ascending* sort with no grouping, +because a moved game wouldn't stay put otherwise. Moves relate to *visible* games, so with a filter active, "move earlier" passes the previous visible game. Dragging is in `CollectionDetailsView.xaml.cs`. A click on an already selected game in a multi-selection delays collapsing the selection until the mouse button is released, otherwise several games couldn't be dragged. `FindDropTarget` picks the closest tile on the pointer's row and which side of it to use. +## Grouping + +`GameCollection.GroupBy` holds the choice, set through `CollectionManager.SetGroupBy`. It has a safe default, so old +files need no migration. `GameGroupDescription` returns a list of names for a multi-value field, which makes WPF put +the same tile in several groups. That's why `RequestVisibleCovers` reads tiles from the visual tree: with groups, +`ContainerFromItem` doesn't reach them. To add a grouping, add it to the end of `GameGroupField`, then to +`GroupNameFromItem` and `GroupOptions`. + ## Dynamic collections A collection is dynamic when `Rules` is not null. `GameIds` stores the latest matches, so no page has to search the @@ -215,6 +223,17 @@ The integration's safeguards: `ListBoxItem`s, which hold most of the tree. A 1 second timer only compares `ActiveDesktopView`. - Every error is caught and logged, and stops further searching until the next trigger. +Behind the `UseThemeSpecificPlacement` setting (off by default), and only when `ApplicationSettings.DesktopTheme` is in +`ThemesUsingGameRelationsSection`, it instead goes next to the element whose `Visibility` binding names +`GameRelationsVisibilityProxy`, in that element's form: a new `TabItem` beside a tab, a new row in a `Grid`, a copy of a +`Border`'s style, or a plain sibling in a panel. It only needs that element's parent to be visible, so it works without +Game Relations installed. This is a temporary workaround that depends on these themes' XAML. The injected control stays +subscribed to events because a control in an unselected tab never loads. + +The section title is copied from the theme, not defined here: `FindTitle` and `FindSeparator` look in the neighbouring +section (the anchor or Game Relations section), and `CloneTitle` copies its current style values. A section that's an +`Expander` gets an `Expander` of its own with the title in its header. + **This relies on Playnite's internal part names.** Check it after Playnite updates. The default layouts are `Themes/Desktop/Default/Views/DetailsViewGameOverview.xaml` and `GridViewGameOverview.xaml` in Playnite's repository. diff --git a/docs/theme-integration.md b/docs/theme-integration.md index fc27f83..808bbaf 100644 --- a/docs/theme-integration.md +++ b/docs/theme-integration.md @@ -18,6 +18,13 @@ When your theme has this element, the extension doesn't insert a second list, an user turns off **Show collections in details view**. The list shown there includes dynamic collections unless the user turns off **Display dynamic collections in details view**. +## Temporary placement for specific themes + +Stardust, Nova X, Helium and Harmony don't keep the description in a plain panel, so the default insertion can't work +well there. When the user turns on **Use special placement** and one of these is the active theme, the list goes next +to the element whose `Visibility` is bound to `GameRelationsVisibilityProxy`. Adding the `ContentControl` above to one +of these themes replaces this, because the theme's own element always takes priority. + ## Settings available to themes Bind to these with `PluginSettings`: @@ -27,6 +34,7 @@ Bind to these with `PluginSettings`: | `IsDetailsControlVisible` | `bool` | The list currently has collections to show. Use it to hide a surrounding header or panel. | | `ShowDynamicCollectionsInDetails` | `bool` | The user's choice for listing dynamic collections. | | `AddDetailsListToAnyTheme` | `bool` | The user's choice for inserting the list automatically. | +| `UseThemeSpecificPlacement` | `bool` | The user's choice for the temporary placement above. | ```xml diff --git a/docs/user-guide.md b/docs/user-guide.md index bf64690..c409f0c 100644 --- a/docs/user-guide.md +++ b/docs/user-guide.md @@ -89,6 +89,9 @@ Click one to open it in a window, where **Open in Collections** takes you to its In the extension's settings: - **Show collections in details view** turns the automatic list on or off. +- **Use special placement for Stardust, Nova X, Helium and Harmony** (off by default) is a temporary fix for these + themes, whose layouts don't have a normal spot for the list. It goes next to their Game Relations section: as a + **Collections** tab in Harmony's Details view, a section in the others, and at the end of the panel in Grid view. - **Display dynamic collections in details view** lists dynamic collections as well as manual ones. The list is added to the theme's layout automatically, because Playnite has no official way to do this. It needs the @@ -103,13 +106,16 @@ not show it. List view has no details panel, so it doesn't appear there. Theme a - **Search** the collection's games by name. - **Sort** by collection order (the order you arranged, or the order games were added), name, release date, last played, time played or date added, ascending or descending. +- **Group by** shows the games in labelled groups, such as by platform, series, genre or release year. Each collection + remembers its own choice. A game with several values, such as two genres, appears in each group. Games with no + value go in a **Not set** group at the end. - **Installed only** hides games that aren't installed (uninstalled games are dimmed otherwise). - For each game (right-click, or keyboard): - **Play** / **Install** – double-click or **Enter**. - **Show in library** – selects the game in Playnite's library view. - **Remove from collection** – **Delete**. Works on several selected games at once (Ctrl/Shift-click). Not available in dynamic collections. -- **Reorder** while sorted by collection order, ascending: drag games (several at once if selected), use +- **Reorder** while sorted by collection order, ascending, with no grouping: drag games (several at once if selected), use **Move to top / earlier / later / to end** in the right-click menu, or press **Alt+arrow keys**. ## Where data is stored diff --git a/manifests/installer_manifest.yaml b/manifests/installer_manifest.yaml index 85634a7..201a753 100644 --- a/manifests/installer_manifest.yaml +++ b/manifests/installer_manifest.yaml @@ -1,5 +1,14 @@ AddonId: GameCollections_3f6b8d2e-5c41-4a7e-9e0b-6d2f1a8c7b54 Packages: + - Version: 1.2.0 + RequiredApiVersion: 6.11.0 + ReleaseDate: 2026-11-02 + PackageUrl: https://github.com/X4Lo/GameCollections/releases/download/v1.2.0/GameCollections_3f6b8d2e-5c41-4a7e-9e0b-6d2f1a8c7b54_1_2_0.pext + Changelog: + - 'Added: Group games on a collection''s page by platform, series, genre and more, remembered per collection' + - 'Added: Optional setting that places the game details list next to the Game Relations section in Stardust, Nova X, Helium and Harmony' + - 'Improved: The game details list now uses the same title style as the theme''s other sections' + - 'Fixed: Create Collection button overlapping the window buttons on the Collections page' - Version: 1.1.0 RequiredApiVersion: 6.11.0 ReleaseDate: 2026-11-02 diff --git a/source/GameCollections/GameCollections.csproj b/source/GameCollections/GameCollections.csproj index 52d2e7e..1a4f322 100644 --- a/source/GameCollections/GameCollections.csproj +++ b/source/GameCollections/GameCollections.csproj @@ -7,7 +7,7 @@ GameCollections GameCollections 7.3 - 1.1.0 + 1.2.0 Game Collections false false diff --git a/source/GameCollections/Localization/en_US.xaml b/source/GameCollections/Localization/en_US.xaml index 07b0a40..105c48a 100644 --- a/source/GameCollections/Localization/en_US.xaml +++ b/source/GameCollections/Localization/en_US.xaml @@ -146,19 +146,30 @@ is empty has no date + + Group by + None + Not set + Release year + Install status + Installed + Not installed + Move to top Move earlier Move later Move to end Drag games to reorder them - To reorder, sort by Collection order, ascending + To reorder, sort by Collection order, ascending, with no grouping Collections Display dynamic collections in details view When off, game details only list manual collections. Show collections in details view + Use special placement for Stardust, Nova X, Helium and Harmony + Temporary fix. These themes don't have a normal spot for the list, so it goes next to their Game Relations section instead. No effect in other themes. Adds the list below the game description. Turn this off if it looks wrong in your theme. diff --git a/source/GameCollections/Models/DynamicRules.cs b/source/GameCollections/Models/DynamicRules.cs index cd73a78..f35c43a 100644 --- a/source/GameCollections/Models/DynamicRules.cs +++ b/source/GameCollections/Models/DynamicRules.cs @@ -43,6 +43,25 @@ namespace GameCollections.Models IsEmpty = 12 } + /// + /// How a collection's page groups its games. + /// + public enum GameGroupField + { + None = 0, + Platform = 1, + Series = 2, + Genre = 3, + Developer = 4, + Publisher = 5, + Category = 6, + Feature = 7, + Tag = 8, + CompletionStatus = 9, + ReleaseYear = 10, + InstallStatus = 11 + } + public enum BlockJoin { And = 0, diff --git a/source/GameCollections/Models/GameCollection.cs b/source/GameCollections/Models/GameCollection.cs index 2180a56..3025dda 100644 --- a/source/GameCollections/Models/GameCollection.cs +++ b/source/GameCollections/Models/GameCollection.cs @@ -28,6 +28,11 @@ namespace GameCollections.Models /// public DynamicRules Rules { get; set; } + /// + /// How the collection's page groups its games. Only affects how they're shown. + /// + public GameGroupField GroupBy { get; set; } + [DontSerialize] public bool IsDynamic => Rules != null; diff --git a/source/GameCollections/Services/CollectionManager.cs b/source/GameCollections/Services/CollectionManager.cs index bcef594..43740cf 100644 --- a/source/GameCollections/Services/CollectionManager.cs +++ b/source/GameCollections/Services/CollectionManager.cs @@ -310,6 +310,19 @@ namespace GameCollections.Services return true; } + /// + /// Remembers how the collection's page groups its games. A display choice, so it isn't a modification. + /// + public void SetGroupBy(Guid collectionId, GameGroupField groupBy) + { + var collection = GetCollection(collectionId); + if (collection != null && collection.GroupBy != groupBy) + { + collection.GroupBy = groupBy; + Persist(new[] { collectionId }); + } + } + /// /// Re-checks one dynamic collection against the whole library right away. /// diff --git a/source/GameCollections/Services/DetailsViewIntegration.cs b/source/GameCollections/Services/DetailsViewIntegration.cs index e190709..cba37ec 100644 --- a/source/GameCollections/Services/DetailsViewIntegration.cs +++ b/source/GameCollections/Services/DetailsViewIntegration.cs @@ -4,8 +4,11 @@ using Playnite.SDK; using Playnite.SDK.Models; using System; using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; using System.Windows; using System.Windows.Controls; +using System.Windows.Data; using System.Windows.Media; using System.Windows.Threading; @@ -21,7 +24,20 @@ namespace GameCollections.Services { // Named parts Playnite's details views use, in order of preference. The list goes below the first one found. private static readonly string[] AnchorNames = { "PART_ElemDescription", "PART_ElemNotes" }; + + // Temporary, until these themes place the element themselves. Their description isn't in a plain panel, + // so the list goes next to their Game Relations section instead, which they all bind to this proxy. + private static readonly string[] ThemesUsingGameRelationsSection = + { + "Harmony_d49ef7bc-49de-4fd0-9a67-bd1f26b56047", + "8b15c46a-90c2-4fe5-9ebb-1ab25ba7fcb1", // Helium + "Nova_X_0a95b7a3-00e4-412d-b301-f2fa3f98dfad", + "Stardust 2.0_1fb333b2-255b-43dd-aec1-8e2f2d5ea002" + }; + private const string GameRelationsProxyName = "GameRelationsVisibilityProxy"; + private const int MaxSearchAttempts = 3; + private const double MinTopSpacing = 10; private static readonly ILogger logger = LogManager.GetLogger(); private readonly IPlayniteAPI playniteApi; @@ -31,6 +47,9 @@ namespace GameCollections.Services private readonly DispatcherTimer timer; private GameCollectionsControl control; + // What was added to the theme: the list itself, or the tab or box holding it. + private FrameworkElement inserted; + private RowDefinition insertedRow; private Game currentGame; private DesktopView? lastView; private int searchAttemptsLeft = MaxSearchAttempts; @@ -98,7 +117,7 @@ namespace GameCollections.Services } // Already in a visible overview, which is the normal case, so no searching is needed. - if (control?.Parent is Panel host && host.IsVisible) + if (inserted?.Parent is FrameworkElement host && host.IsVisible) { return; } @@ -118,10 +137,18 @@ namespace GameCollections.Services private void Settings_SettingsChanged(object sender, EventArgs e) { + // The placement setting may have changed, so start again from nothing. + Remove(); searchAttemptsLeft = MaxSearchAttempts; Update(); } + private bool UsesGameRelationsSection() + { + return settings.Settings.UseThemeSpecificPlacement && + ThemesUsingGameRelationsSection.Contains(playniteApi.ApplicationSettings?.DesktopTheme, StringComparer.OrdinalIgnoreCase); + } + private void Search() { var window = getWindow(); @@ -130,19 +157,24 @@ namespace GameCollections.Services return; } - var found = new Dictionary(); - var themeHasElement = false; - Walk(window, found, ref themeHasElement); - if (themeHasElement) + var result = new SearchResult(); + Walk(window, result); + if (result.ThemeHasElement) { searchAttemptsLeft = 0; Remove(); return; } + if (UsesGameRelationsSection() && result.GameRelationsSection != null && InsertNextToSection(result.GameRelationsSection)) + { + searchAttemptsLeft = 0; + return; + } + foreach (var name in AnchorNames) { - if (found.TryGetValue(name, out var anchor) && Insert(anchor)) + if (result.Anchors.TryGetValue(name, out var anchor) && InsertBelow(anchor)) { searchAttemptsLeft = 0; return; @@ -150,9 +182,9 @@ namespace GameCollections.Services } } - private void Walk(DependencyObject parent, Dictionary found, ref bool themeHasElement) + private void Walk(DependencyObject parent, SearchResult result) { - for (var i = 0; i < VisualTreeHelper.GetChildrenCount(parent) && !themeHasElement; i++) + for (var i = 0; i < VisualTreeHelper.GetChildrenCount(parent) && !result.ThemeHasElement; i++) { var child = VisualTreeHelper.GetChild(parent, i); @@ -166,25 +198,55 @@ namespace GameCollections.Services { if (!existing.IsInjected) { - themeHasElement = true; + result.ThemeHasElement = true; return; } continue; } - // An overview from a view that isn't showing can still be in the tree, so visibility of the parent counts. - if (child is FrameworkElement element && Array.IndexOf(AnchorNames, element.Name) >= 0 && - !found.ContainsKey(element.Name) && element.Parent is Panel panel && panel.IsVisible) + if (child is FrameworkElement element && element.Parent is FrameworkElement elementParent && elementParent.IsVisible) { - found[element.Name] = element; + // An overview from a view that isn't showing can still be in the tree, so visibility of the parent counts. + if (Array.IndexOf(AnchorNames, element.Name) >= 0 && element.Parent is Panel && !result.Anchors.ContainsKey(element.Name)) + { + result.Anchors[element.Name] = element; + } + + if (result.GameRelationsSection == null && + BindingOperations.GetBinding(element, UIElement.VisibilityProperty)?.ElementName == GameRelationsProxyName) + { + result.GameRelationsSection = element; + } } - Walk(child, found, ref themeHasElement); + Walk(child, result); } } - private bool Insert(FrameworkElement anchor) + private GameCollectionsControl PrepareControl() + { + Remove(); + if (control == null) + { + control = createControl(); + control.IsInjected = true; + + // A tab can't stay selected once it's hidden, or the theme would show an empty panel. + DependencyPropertyDescriptor.FromProperty(UIElement.VisibilityProperty, typeof(UIElement)).AddValueChanged(control, (s, e) => + { + if (inserted is TabItem tab && tab.IsSelected && control.Visibility != Visibility.Visible) + { + ((TabControl)tab.Parent).SelectedIndex = 0; + } + }); + } + + control.Margin = new Thickness(0, 10, 0, 0); + return control; + } + + private bool InsertBelow(FrameworkElement anchor) { // A Grid would need a row of its own, and changing a theme's rows could break its layout. if (!(anchor.Parent is Panel panel) || panel is Grid || panel.IsItemsHost) @@ -192,27 +254,270 @@ namespace GameCollections.Services return false; } - Remove(); - if (control == null) - { - control = createControl(); - control.IsInjected = true; - control.Margin = new Thickness(0, 10, 0, 0); - } + var list = PrepareControl(); + var title = FindTitle(anchor); + list.SetHeader(BuildHeader(title, FindSeparator(anchor))); + // Keeps the theme's spacing, while making sure the list doesn't touch the description. + var top = Math.Max(anchor.Margin.Top, title == null || title.Margin.Top < MinTopSpacing ? MinTopSpacing : 0); + list.Margin = new Thickness(anchor.Margin.Left, top, anchor.Margin.Right, anchor.Margin.Bottom); if (panel is DockPanel) { - DockPanel.SetDock(control, DockPanel.GetDock(anchor)); + DockPanel.SetDock(list, DockPanel.GetDock(anchor)); } - panel.Children.Insert(panel.Children.IndexOf(anchor) + 1, control); - control.GameContext = currentGame; + panel.Children.Insert(panel.Children.IndexOf(anchor) + 1, list); + inserted = list; + list.GameContext = currentGame; return true; } + /// + /// Adds the list as a sibling of the theme's Game Relations section, in the same form as that section. + /// That section's own visibility doesn't matter: only its parent needs to be showing. + /// + private bool InsertNextToSection(FrameworkElement section) + { + if (section.Parent is TabControl tabControl) + { + var list = PrepareControl(); + list.SetHeader(); + list.Margin = new Thickness(0, 15, 0, 0); + var tab = new TabItem { Header = Loc.Get("LOCGameCollections_DetailsHeader"), Content = list }; + BindVisibilityToList(tab, list); + tabControl.Items.Insert(tabControl.Items.IndexOf(section), tab); + inserted = tab; + list.GameContext = currentGame; + return true; + } + + if (section.Parent is Grid grid) + { + // The sections of a Grid view each have a row, so the list gets a new one at the end. + var list = PrepareControl(); + FrameworkElement element = list; + if (section is Expander sectionExpander) + { + // Grid view sections are collapsible, with the title in the expander's header. + var separator = CloneSeparator(FindSeparator(section)); + if (separator != null) + { + list.SetHeader(separator); + } + else + { + list.SetHeader(); + } + + list.Margin = new Thickness(0); + var expander = new Expander + { + Style = sectionExpander.Style, + Margin = sectionExpander.Margin, + IsExpanded = true, + Header = (object)CloneTitle(FindTitle(section)) ?? Loc.Get("LOCGameCollections_DetailsHeader"), + Content = list + }; + BindVisibilityToList(expander, list); + element = expander; + } + else + { + list.SetHeader(BuildHeader(FindTitle(section), FindSeparator(section))); + list.Margin = section.Margin; + } + + insertedRow = new RowDefinition { Height = GridLength.Auto }; + grid.RowDefinitions.Add(insertedRow); + Grid.SetRow(element, grid.RowDefinitions.Count - 1); + grid.Children.Add(element); + inserted = element; + list.GameContext = currentGame; + return true; + } + + if (section.Parent is Panel panel && !panel.IsItemsHost) + { + var list = PrepareControl(); + list.SetHeader(BuildHeader(FindTitle(section), FindSeparator(section))); + FrameworkElement element = list; + if (section is Border sectionBorder) + { + // Keeps the theme's rounded box around the section. Its padding comes from the style. + var box = new Border { Style = sectionBorder.Style, Margin = sectionBorder.Margin, Child = list }; + BindVisibilityToList(box, list); + list.Margin = new Thickness(0); + element = box; + } + else + { + list.Margin = section.Margin; + } + + panel.Children.Insert(panel.Children.IndexOf(section), element); + inserted = element; + list.GameContext = currentGame; + return true; + } + + return false; + } + + /// + /// Finds the title of a theme's section. Hidden text, such as these themes' visibility proxies, doesn't count. + /// + private static FrameworkElement FindTitle(object root) + { + if (root is Expander expander && expander.Header is FrameworkElement header) + { + return header; + } + + return FindFirst(root, e => (e is TextBlock || e is Label) && e.Visibility != Visibility.Collapsed); + } + + private static Separator FindSeparator(object root) + { + return FindFirst(root, e => e is Separator) as Separator; + } + + private static FrameworkElement FindFirst(object root, Func predicate) + { + if (root is FrameworkElement element && predicate(element)) + { + return element; + } + + if (root is DependencyObject parent) + { + foreach (var child in LogicalTreeHelper.GetChildren(parent)) + { + var match = FindFirst(child, predicate); + if (match != null) + { + return match; + } + } + } + + return null; + } + + private static UIElement[] BuildHeader(FrameworkElement title, Separator separator) + { + var header = new List(); + var titleClone = CloneTitle(title); + if (titleClone != null) + { + header.Add(titleClone); + } + + var separatorClone = CloneSeparator(separator); + if (separatorClone != null) + { + header.Add(separatorClone); + } + + // A theme with no title of its own to copy still gets one. + if (titleClone == null) + { + header.Insert(0, new TextBlock + { + Text = Loc.Get("LOCGameCollections_DetailsHeader"), + Style = ResourceProvider.GetResource("BaseTextBlockStyle") as Style, + FontWeight = FontWeights.SemiBold + }); + } + + return header.ToArray(); + } + + /// + /// Copies how a theme's section title looks, using its current values: a theme's own values + /// can't be reused as they are, because many are set directly on the title rather than in a style. + /// + private static FrameworkElement CloneTitle(FrameworkElement title) + { + var text = Loc.Get("LOCGameCollections_DetailsHeader"); + switch (title) + { + case TextBlock block: + return new TextBlock + { + Text = text, + Style = block.Style, + FontSize = block.FontSize, + FontWeight = block.FontWeight, + FontFamily = block.FontFamily, + Foreground = block.Foreground, + Margin = block.Margin, + Cursor = block.Cursor + }; + case Label label: + return new Label + { + Content = text, + Style = label.Style, + FontSize = label.FontSize, + FontWeight = label.FontWeight, + FontFamily = label.FontFamily, + Foreground = label.Foreground, + Padding = label.Padding, + Margin = label.Margin, + HorizontalAlignment = label.HorizontalAlignment + }; + default: + return null; + } + } + + private static Separator CloneSeparator(Separator separator) + { + return separator == null + ? null + : new Separator { Style = separator.Style, Background = separator.Background, Margin = separator.Margin }; + } + + private static void BindVisibilityToList(FrameworkElement element, GameCollectionsControl list) + { + element.SetBinding(UIElement.VisibilityProperty, new Binding(nameof(UIElement.Visibility)) { Source = list }); + } + private void Remove() { - (control?.Parent as Panel)?.Children.Remove(control); + if (inserted is TabItem tab) + { + tab.Content = null; + (tab.Parent as TabControl)?.Items.Remove(tab); + } + else + { + if (inserted is Border box) + { + box.Child = null; + } + else if (inserted is Expander expander) + { + expander.Content = null; + } + + var panel = inserted?.Parent as Panel; + panel?.Children.Remove(inserted); + if (insertedRow != null) + { + (panel as Grid)?.RowDefinitions.Remove(insertedRow); + } + } + + inserted = null; + insertedRow = null; + } + + private class SearchResult + { + public Dictionary Anchors { get; } = new Dictionary(); + public FrameworkElement GameRelationsSection { get; set; } + public bool ThemeHasElement { get; set; } } } } diff --git a/source/GameCollections/Settings/GameCollectionsSettings.cs b/source/GameCollections/Settings/GameCollectionsSettings.cs index c559d9f..a546abf 100644 --- a/source/GameCollections/Settings/GameCollectionsSettings.cs +++ b/source/GameCollections/Settings/GameCollectionsSettings.cs @@ -18,6 +18,9 @@ namespace GameCollections.Settings private bool addDetailsListToAnyTheme = true; public bool AddDetailsListToAnyTheme { get => addDetailsListToAnyTheme; set => SetValue(ref addDetailsListToAnyTheme, value); } + private bool useThemeSpecificPlacement; + public bool UseThemeSpecificPlacement { get => useThemeSpecificPlacement; set => SetValue(ref useThemeSpecificPlacement, value); } + // For themes, which can bind to this to lay out their details view around the list. private bool isDetailsControlVisible; [DontSerialize] diff --git a/source/GameCollections/Settings/GameCollectionsSettingsView.xaml b/source/GameCollections/Settings/GameCollectionsSettingsView.xaml index 31338e6..37ab9ee 100644 --- a/source/GameCollections/Settings/GameCollectionsSettingsView.xaml +++ b/source/GameCollections/Settings/GameCollectionsSettingsView.xaml @@ -12,6 +12,13 @@ Foreground="{DynamicResource TextBrushDarker}" TextWrapping="Wrap" Margin="0,4,0,16" Text="{DynamicResource LOCGameCollections_SettingAddListToAnyThemeHint}" /> + + + /// Puts each game in the groups for its metadata. A game with several genres, for example, is shown in each of them. + /// + public class GameGroupDescription : GroupDescription + { + private readonly IPlayniteAPI playniteApi; + private readonly GameGroupField field; + private readonly string notSetName = Loc.Get("LOCGameCollections_GroupNotSet"); + + public GameGroupDescription(IPlayniteAPI playniteApi, GameGroupField field) + { + this.playniteApi = playniteApi; + this.field = field; + CustomSort = Comparer.Create(CompareGroups); + } + + public override object GroupNameFromItem(object item, int level, CultureInfo culture) + { + var game = ((CollectionGameViewModel)item).Game; + var database = playniteApi.Database; + switch (field) + { + case GameGroupField.Platform: return Names(game.PlatformIds, database.Platforms); + case GameGroupField.Series: return Names(game.SeriesIds, database.Series); + case GameGroupField.Genre: return Names(game.GenreIds, database.Genres); + case GameGroupField.Developer: return Names(game.DeveloperIds, database.Companies); + case GameGroupField.Publisher: return Names(game.PublisherIds, database.Companies); + case GameGroupField.Category: return Names(game.CategoryIds, database.Categories); + case GameGroupField.Feature: return Names(game.FeatureIds, database.Features); + case GameGroupField.Tag: return Names(game.TagIds, database.Tags); + case GameGroupField.CompletionStatus: return database.CompletionStatuses.Get(game.CompletionStatusId)?.Name ?? notSetName; + case GameGroupField.ReleaseYear: return game.ReleaseDate?.Year.ToString(CultureInfo.InvariantCulture) ?? notSetName; + default: return Loc.Get(game.IsInstalled ? "LOCGameCollections_GroupInstalled" : "LOCGameCollections_GroupNotInstalled"); + } + } + + // Returning a collection puts the item in every group it names. + private object Names(List ids, IItemCollection items) where T : DatabaseObject + { + var names = ids?.Select(id => items.Get(id)?.Name).Where(n => !string.IsNullOrEmpty(n)).Distinct().ToList(); + return names != null && names.Count > 0 ? (object)names : notSetName; + } + + private int CompareGroups(CollectionViewGroup first, CollectionViewGroup second) + { + var a = (string)first.Name; + var b = (string)second.Name; + if (a == notSetName || b == notSetName) + { + return (a == notSetName).CompareTo(b == notSetName); + } + + return string.Compare(a, b, StringComparison.CurrentCultureIgnoreCase); + } + } + public class SortOption { public GameSortField Field { get; } @@ -131,9 +202,9 @@ namespace GameCollections.ViewModels /// /// Games can only be reordered while the page shows the collection's own order; - /// in any other sort, a dragged game wouldn't stay where it was dropped. + /// in any other sort or with groups, a dragged game wouldn't stay where it was dropped. /// - public bool CanReorder => SortField == GameSortField.CollectionOrder && !SortDescending; + public bool CanReorder => SortField == GameSortField.CollectionOrder && !SortDescending && GroupBy == GameGroupField.None; public string ReorderHint => Loc.Get(CanReorder ? "LOCGameCollections_ReorderHint" : "LOCGameCollections_ReorderUnavailableHint"); /// @@ -142,11 +213,45 @@ namespace GameCollections.ViewModels public Action CloseWindow { get; set; } public bool IsInWindow => CloseWindow != null; + public IReadOnlyList GroupOptions { get; } = new List + { + new GroupOption(GameGroupField.None, Loc.Get("LOCGameCollections_GroupNone")), + new GroupOption(GameGroupField.Platform, Loc.Get("LOCGameCollections_RuleFieldPlatform")), + new GroupOption(GameGroupField.Series, Loc.Get("LOCGameCollections_RuleFieldSeries")), + new GroupOption(GameGroupField.Genre, Loc.Get("LOCGameCollections_RuleFieldGenre")), + new GroupOption(GameGroupField.Developer, Loc.Get("LOCGameCollections_RuleFieldDeveloper")), + new GroupOption(GameGroupField.Publisher, Loc.Get("LOCGameCollections_RuleFieldPublisher")), + new GroupOption(GameGroupField.Category, Loc.Get("LOCGameCollections_RuleFieldCategory")), + new GroupOption(GameGroupField.Feature, Loc.Get("LOCGameCollections_RuleFieldFeature")), + new GroupOption(GameGroupField.Tag, Loc.Get("LOCGameCollections_RuleFieldTag")), + new GroupOption(GameGroupField.CompletionStatus, Loc.Get("LOCGameCollections_RuleFieldCompletionStatus")), + new GroupOption(GameGroupField.ReleaseYear, Loc.Get("LOCGameCollections_GroupReleaseYear")), + new GroupOption(GameGroupField.InstallStatus, Loc.Get("LOCGameCollections_GroupInstallStatus")) + }; + + /// + /// Saved with the collection, so each collection remembers its own grouping. + /// + public GameGroupField GroupBy + { + get => manager.GetCollection(CollectionId)?.GroupBy ?? GameGroupField.None; + set + { + manager.SetGroupBy(CollectionId, value); + ApplyGrouping(); + OnPropertyChanged(); + RaiseReorderChanged(); + } + } + public bool IsEmpty => Games.Count == 0; public bool HasNoResults => !IsEmpty && GamesView.Count == 0; - public string VisibleCountText => GamesView.Count == Games.Count + // With groups, a game can be in the view several times but is still one game. + private int VisibleGameCount => GamesView.Cast().Distinct().Count(); + + public string VisibleCountText => VisibleGameCount == Games.Count ? Loc.GameCount(Games.Count) - : Loc.Format("LOCGameCollections_FilteredGameCount", GamesView.Count, Games.Count); + : Loc.Format("LOCGameCollections_FilteredGameCount", VisibleGameCount, Games.Count); public RelayCommand BackCommand { get; } public RelayCommand ToggleSortDirectionCommand { get; } @@ -165,6 +270,7 @@ namespace GameCollections.ViewModels GamesView = new ListCollectionView(Games) { Filter = FilterGame }; ApplySort(); + ApplyGrouping(); BackCommand = new RelayCommand(() => { @@ -398,6 +504,20 @@ namespace GameCollections.ViewModels CultureInfo.CurrentCulture.CompareInfo.IndexOf(tile.Name ?? string.Empty, query, CompareOptions.IgnoreCase) >= 0; } + private void ApplyGrouping() + { + using (GamesView.DeferRefresh()) + { + GamesView.GroupDescriptions.Clear(); + if (GroupBy != GameGroupField.None) + { + GamesView.GroupDescriptions.Add(new GameGroupDescription(playniteApi, GroupBy)); + } + } + + RaiseStateChanged(); + } + private void ApplySort() { GamesView.CustomSort = new GameTileComparer(SortField, SortDescending); diff --git a/source/GameCollections/Views/CollectionDetailsView.xaml b/source/GameCollections/Views/CollectionDetailsView.xaml index f6272cf..95bcc8c 100644 --- a/source/GameCollections/Views/CollectionDetailsView.xaml +++ b/source/GameCollections/Views/CollectionDetailsView.xaml @@ -129,31 +129,40 @@ - - + + + - - -