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. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
690a79b014
commit
c41b4ad548
20 files changed
+680
-59
No files matched your search
@@ -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.
|
||||
|
||||
+21
-2
@@ -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.
|
||||
|
||||
|
||||
@@ -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
|
||||
<Border Visibility="{PluginSettings Plugin=GameCollections, Path=IsDetailsControlVisible, Converter={StaticResource BooleanToVisibilityConverter}}">
|
||||
|
||||
+7
-1
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<RootNamespace>GameCollections</RootNamespace>
|
||||
<AssemblyName>GameCollections</AssemblyName>
|
||||
<LangVersion>7.3</LangVersion>
|
||||
<Version>1.1.0</Version>
|
||||
<Version>1.2.0</Version>
|
||||
<Product>Game Collections</Product>
|
||||
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
|
||||
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
|
||||
|
||||
@@ -146,19 +146,30 @@
|
||||
<sys:String x:Key="LOCGameCollections_RuleOperatorIsEmpty">is empty</sys:String>
|
||||
<sys:String x:Key="LOCGameCollections_RuleOperatorNoDate">has no date</sys:String>
|
||||
|
||||
<!-- Grouping on a collection's page -->
|
||||
<sys:String x:Key="LOCGameCollections_GroupBy">Group by</sys:String>
|
||||
<sys:String x:Key="LOCGameCollections_GroupNone">None</sys:String>
|
||||
<sys:String x:Key="LOCGameCollections_GroupNotSet">Not set</sys:String>
|
||||
<sys:String x:Key="LOCGameCollections_GroupReleaseYear">Release year</sys:String>
|
||||
<sys:String x:Key="LOCGameCollections_GroupInstallStatus">Install status</sys:String>
|
||||
<sys:String x:Key="LOCGameCollections_GroupInstalled">Installed</sys:String>
|
||||
<sys:String x:Key="LOCGameCollections_GroupNotInstalled">Not installed</sys:String>
|
||||
|
||||
<!-- Manual order -->
|
||||
<sys:String x:Key="LOCGameCollections_MoveToTop">Move to top</sys:String>
|
||||
<sys:String x:Key="LOCGameCollections_MoveUp">Move earlier</sys:String>
|
||||
<sys:String x:Key="LOCGameCollections_MoveDown">Move later</sys:String>
|
||||
<sys:String x:Key="LOCGameCollections_MoveToBottom">Move to end</sys:String>
|
||||
<sys:String x:Key="LOCGameCollections_ReorderHint">Drag games to reorder them</sys:String>
|
||||
<sys:String x:Key="LOCGameCollections_ReorderUnavailableHint">To reorder, sort by Collection order, ascending</sys:String>
|
||||
<sys:String x:Key="LOCGameCollections_ReorderUnavailableHint">To reorder, sort by Collection order, ascending, with no grouping</sys:String>
|
||||
|
||||
<!-- Game details and settings -->
|
||||
<sys:String x:Key="LOCGameCollections_DetailsHeader">Collections</sys:String>
|
||||
<sys:String x:Key="LOCGameCollections_SettingShowDynamicInDetails">Display dynamic collections in details view</sys:String>
|
||||
<sys:String x:Key="LOCGameCollections_SettingShowDynamicInDetailsHint">When off, game details only list manual collections.</sys:String>
|
||||
<sys:String x:Key="LOCGameCollections_SettingAddListToAnyTheme">Show collections in details view</sys:String>
|
||||
<sys:String x:Key="LOCGameCollections_SettingThemeSpecificPlacement">Use special placement for Stardust, Nova X, Helium and Harmony</sys:String>
|
||||
<sys:String x:Key="LOCGameCollections_SettingThemeSpecificPlacementHint">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.</sys:String>
|
||||
<sys:String x:Key="LOCGameCollections_SettingAddListToAnyThemeHint">Adds the list below the game description. Turn this off if it looks wrong in your theme.</sys:String>
|
||||
|
||||
<!-- Opening a collection from game details -->
|
||||
|
||||
@@ -43,6 +43,25 @@ namespace GameCollections.Models
|
||||
IsEmpty = 12
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// How a collection's page groups its games.
|
||||
/// </summary>
|
||||
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,
|
||||
|
||||
@@ -28,6 +28,11 @@ namespace GameCollections.Models
|
||||
/// </summary>
|
||||
public DynamicRules Rules { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// How the collection's page groups its games. Only affects how they're shown.
|
||||
/// </summary>
|
||||
public GameGroupField GroupBy { get; set; }
|
||||
|
||||
[DontSerialize]
|
||||
public bool IsDynamic => Rules != null;
|
||||
|
||||
|
||||
@@ -310,6 +310,19 @@ namespace GameCollections.Services
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remembers how the collection's page groups its games. A display choice, so it isn't a modification.
|
||||
/// </summary>
|
||||
public void SetGroupBy(Guid collectionId, GameGroupField groupBy)
|
||||
{
|
||||
var collection = GetCollection(collectionId);
|
||||
if (collection != null && collection.GroupBy != groupBy)
|
||||
{
|
||||
collection.GroupBy = groupBy;
|
||||
Persist(new[] { collectionId });
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Re-checks one dynamic collection against the whole library right away.
|
||||
/// </summary>
|
||||
|
||||
@@ -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<string, FrameworkElement>();
|
||||
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<string, FrameworkElement> 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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Finds the title of a theme's section. Hidden text, such as these themes' visibility proxies, doesn't count.
|
||||
/// </summary>
|
||||
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<FrameworkElement, bool> 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<UIElement>();
|
||||
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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
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<string, FrameworkElement> Anchors { get; } = new Dictionary<string, FrameworkElement>();
|
||||
public FrameworkElement GameRelationsSection { get; set; }
|
||||
public bool ThemeHasElement { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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]
|
||||
|
||||
@@ -12,6 +12,13 @@
|
||||
Foreground="{DynamicResource TextBrushDarker}"
|
||||
TextWrapping="Wrap" Margin="0,4,0,16"
|
||||
Text="{DynamicResource LOCGameCollections_SettingAddListToAnyThemeHint}" />
|
||||
<CheckBox IsChecked="{Binding Settings.UseThemeSpecificPlacement}"
|
||||
IsEnabled="{Binding Settings.AddDetailsListToAnyTheme}"
|
||||
Content="{DynamicResource LOCGameCollections_SettingThemeSpecificPlacement}" />
|
||||
<TextBlock Style="{StaticResource BaseTextBlockStyle}"
|
||||
Foreground="{DynamicResource TextBrushDarker}"
|
||||
TextWrapping="Wrap" Margin="0,4,0,16"
|
||||
Text="{DynamicResource LOCGameCollections_SettingThemeSpecificPlacementHint}" />
|
||||
<CheckBox IsChecked="{Binding Settings.ShowDynamicCollectionsInDetails}"
|
||||
Content="{DynamicResource LOCGameCollections_SettingShowDynamicInDetails}" />
|
||||
<TextBlock Style="{StaticResource BaseTextBlockStyle}"
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
using GameCollections.Models;
|
||||
using GameCollections.Services;
|
||||
using Playnite.SDK;
|
||||
using Playnite.SDK.Models;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Windows.Data;
|
||||
@@ -21,6 +24,74 @@ namespace GameCollections.ViewModels
|
||||
DateAdded
|
||||
}
|
||||
|
||||
public class GroupOption
|
||||
{
|
||||
public GameGroupField Field { get; }
|
||||
public string Label { get; }
|
||||
|
||||
public GroupOption(GameGroupField field, string label)
|
||||
{
|
||||
Field = field;
|
||||
Label = label;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Puts each game in the groups for its metadata. A game with several genres, for example, is shown in each of them.
|
||||
/// </summary>
|
||||
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<CollectionViewGroup>.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<T>(List<Guid> ids, IItemCollection<T> 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
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
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");
|
||||
|
||||
/// <summary>
|
||||
@@ -142,11 +213,45 @@ namespace GameCollections.ViewModels
|
||||
public Action CloseWindow { get; set; }
|
||||
public bool IsInWindow => CloseWindow != null;
|
||||
|
||||
public IReadOnlyList<GroupOption> GroupOptions { get; } = new List<GroupOption>
|
||||
{
|
||||
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"))
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Saved with the collection, so each collection remembers its own grouping.
|
||||
/// </summary>
|
||||
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<CollectionGameViewModel>().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);
|
||||
|
||||
@@ -129,31 +129,40 @@
|
||||
</Grid>
|
||||
|
||||
<!-- Toolbar: search, sort, filter -->
|
||||
<DockPanel DockPanel.Dock="Top" Margin="0,0,0,10" LastChildFill="False">
|
||||
<local:SearchBox DockPanel.Dock="Left" Width="240" Height="32"
|
||||
<DockPanel DockPanel.Dock="Top" Margin="0,0,0,10">
|
||||
<TextBlock DockPanel.Dock="Right" Text="{Binding VisibleCountText}" Style="{StaticResource GcMutedText}"
|
||||
VerticalAlignment="Top" Margin="10,8,0,0" />
|
||||
<WrapPanel Orientation="Horizontal">
|
||||
<local:SearchBox Width="240" Height="32" Margin="0,0,0,4"
|
||||
Text="{Binding SearchText}"
|
||||
Placeholder="{DynamicResource LOCGameCollections_SearchGames}" />
|
||||
<TextBlock DockPanel.Dock="Left" Text="{DynamicResource LOCGameCollections_SortBy}" Style="{StaticResource GcText}"
|
||||
<TextBlock Text="{DynamicResource LOCGameCollections_SortBy}" Style="{StaticResource GcText}"
|
||||
VerticalAlignment="Center" Margin="16,0,8,0" />
|
||||
<ComboBox DockPanel.Dock="Left" MinWidth="150" VerticalAlignment="Center"
|
||||
<ComboBox MinWidth="150" VerticalAlignment="Center"
|
||||
ItemsSource="{Binding SortOptions}"
|
||||
DisplayMemberPath="Label"
|
||||
SelectedValuePath="Field"
|
||||
SelectedValue="{Binding SortField}"
|
||||
AutomationProperties.Name="{DynamicResource LOCGameCollections_SortBy}" />
|
||||
<Button DockPanel.Dock="Left" Style="{StaticResource GcIconButton}" Height="32" Margin="5,0,0,0"
|
||||
<Button Style="{StaticResource GcIconButton}" Height="32" Margin="5,0,0,0"
|
||||
Content="{Binding SortDirectionGlyph}"
|
||||
Command="{Binding ToggleSortDirectionCommand}"
|
||||
ToolTip="{Binding SortDirectionTooltip}"
|
||||
AutomationProperties.Name="{Binding SortDirectionTooltip}" />
|
||||
<CheckBox DockPanel.Dock="Left" VerticalAlignment="Center" Margin="16,0,0,0"
|
||||
<TextBlock Text="{DynamicResource LOCGameCollections_GroupBy}" Style="{StaticResource GcText}"
|
||||
VerticalAlignment="Center" Margin="16,0,8,0" />
|
||||
<ComboBox MinWidth="130" VerticalAlignment="Center"
|
||||
ItemsSource="{Binding GroupOptions}"
|
||||
DisplayMemberPath="Label"
|
||||
SelectedValuePath="Field"
|
||||
SelectedValue="{Binding GroupBy}"
|
||||
AutomationProperties.Name="{DynamicResource LOCGameCollections_GroupBy}" />
|
||||
<CheckBox VerticalAlignment="Center" Margin="16,0,0,0"
|
||||
IsChecked="{Binding InstalledOnly}"
|
||||
Content="{DynamicResource LOCGameCollections_InstalledOnly}" />
|
||||
<TextBlock DockPanel.Dock="Right" Text="{Binding VisibleCountText}" Style="{StaticResource GcMutedText}"
|
||||
VerticalAlignment="Center" Margin="10,0,0,0" />
|
||||
<TextBlock DockPanel.Dock="Right" Text="{Binding ReorderHint}" Style="{StaticResource GcMutedText}"
|
||||
FontSize="{DynamicResource FontSizeSmall}" VerticalAlignment="Center" Margin="10,0,0,0"
|
||||
TextTrimming="CharacterEllipsis" />
|
||||
<TextBlock Text="{Binding ReorderHint}" Style="{StaticResource GcMutedText}"
|
||||
FontSize="{DynamicResource FontSizeSmall}" VerticalAlignment="Center" Margin="16,0,0,0" />
|
||||
</WrapPanel>
|
||||
</DockPanel>
|
||||
|
||||
<Grid>
|
||||
@@ -173,6 +182,20 @@
|
||||
Drop="GamesList_Drop"
|
||||
SizeChanged="GamesList_SizeChanged"
|
||||
AutomationProperties.Name="{Binding Header.Title}">
|
||||
<ListBox.GroupStyle>
|
||||
<GroupStyle>
|
||||
<GroupStyle.HeaderTemplate>
|
||||
<DataTemplate>
|
||||
<StackPanel Orientation="Horizontal" Margin="0,8,0,8">
|
||||
<TextBlock Text="{Binding Name}" Style="{StaticResource GcItemTitleText}"
|
||||
FontSize="{DynamicResource FontSizeLarge}" />
|
||||
<TextBlock Text="{Binding ItemCount}" Style="{StaticResource GcMutedText}"
|
||||
VerticalAlignment="Center" Margin="8,0,0,0" />
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
</GroupStyle.HeaderTemplate>
|
||||
</GroupStyle>
|
||||
</ListBox.GroupStyle>
|
||||
<ListBox.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<WrapPanel Orientation="Horizontal" Margin="0,0,0,10" />
|
||||
|
||||
@@ -89,9 +89,12 @@ namespace GameCollections.Views
|
||||
|
||||
// Load one extra screen above and below so covers are ready before they scroll in.
|
||||
var margin = scrollViewer.ViewportHeight;
|
||||
foreach (var item in GamesList.Items)
|
||||
// Tiles are read from the visual tree because with groups they're nested, and a game can appear more than once.
|
||||
var containers = new List<ListBoxItem>();
|
||||
CollectItems(GamesList, containers);
|
||||
foreach (var container in containers)
|
||||
{
|
||||
if (!(GamesList.ItemContainerGenerator.ContainerFromItem(item) is FrameworkElement container) || !container.IsVisible)
|
||||
if (!container.IsVisible || !(container.DataContext is CollectionGameViewModel tile))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -101,7 +104,7 @@ namespace GameCollections.Views
|
||||
var top = container.TransformToAncestor(scrollViewer).Transform(new Point(0, 0)).Y;
|
||||
if (top + container.ActualHeight >= -margin && top <= scrollViewer.ViewportHeight + margin)
|
||||
{
|
||||
((CollectionGameViewModel)item).RequestCover();
|
||||
tile.RequestCover();
|
||||
}
|
||||
}
|
||||
catch (InvalidOperationException)
|
||||
@@ -345,6 +348,22 @@ namespace GameCollections.Views
|
||||
public bool After { get; set; }
|
||||
}
|
||||
|
||||
private static void CollectItems(DependencyObject parent, List<ListBoxItem> items)
|
||||
{
|
||||
for (var i = 0; i < VisualTreeHelper.GetChildrenCount(parent); i++)
|
||||
{
|
||||
var child = VisualTreeHelper.GetChild(parent, i);
|
||||
if (child is ListBoxItem item)
|
||||
{
|
||||
items.Add(item);
|
||||
}
|
||||
else
|
||||
{
|
||||
CollectItems(child, items);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static T FindDescendant<T>(DependencyObject parent) where T : DependencyObject
|
||||
{
|
||||
for (var i = 0; i < VisualTreeHelper.GetChildrenCount(parent); i++)
|
||||
|
||||
@@ -113,7 +113,8 @@
|
||||
</ResourceDictionary>
|
||||
</UserControl.Resources>
|
||||
|
||||
<DockPanel Margin="20,15,20,0">
|
||||
<!-- The top margin keeps the toolbar clear of Playnite's window buttons, which sit over this view. -->
|
||||
<DockPanel Margin="20,35,20,0">
|
||||
<!-- Header -->
|
||||
<Grid DockPanel.Dock="Top" Margin="0,0,0,15">
|
||||
<Grid.ColumnDefinitions>
|
||||
|
||||
@@ -16,8 +16,10 @@
|
||||
</controls:PluginUserControl.Resources>
|
||||
|
||||
<StackPanel>
|
||||
<TextBlock Text="{DynamicResource LOCGameCollections_DetailsHeader}" Style="{StaticResource GcItemTitleText}" Margin="0,0,0,6" />
|
||||
<ItemsControl x:Name="ItemsList" Focusable="False">
|
||||
<StackPanel x:Name="HeaderHost">
|
||||
<TextBlock x:Name="HeaderText" Text="{DynamicResource LOCGameCollections_DetailsHeader}" Style="{StaticResource GcItemTitleText}" />
|
||||
</StackPanel>
|
||||
<ItemsControl x:Name="ItemsList" Focusable="False" Margin="0,6,0,0">
|
||||
<ItemsControl.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<WrapPanel Orientation="Horizontal" />
|
||||
|
||||
@@ -60,10 +60,37 @@ namespace GameCollections.Views
|
||||
private readonly GameCollectionsSettingsViewModel settings;
|
||||
private readonly Action<Guid> openCollection;
|
||||
|
||||
private bool isInjected;
|
||||
|
||||
/// <summary>
|
||||
/// True for the instance this extension added itself, rather than one placed by a theme.
|
||||
/// True for the instance this extension added itself, rather than one placed by a theme. It lasts for
|
||||
/// the whole session and may sit in an unselected tab, which is never loaded, so it stays subscribed.
|
||||
/// </summary>
|
||||
public bool IsInjected { get; set; }
|
||||
public bool IsInjected
|
||||
{
|
||||
get => isInjected;
|
||||
set
|
||||
{
|
||||
isInjected = value;
|
||||
if (value)
|
||||
{
|
||||
Subscribe();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Replaces the header with elements made to match the theme. With none, only the list remains, for
|
||||
/// when something around it, such as a tab, already names it.
|
||||
/// </summary>
|
||||
public void SetHeader(params UIElement[] elements)
|
||||
{
|
||||
HeaderHost.Children.Clear();
|
||||
foreach (var element in elements)
|
||||
{
|
||||
HeaderHost.Children.Add(element);
|
||||
}
|
||||
}
|
||||
|
||||
public GameCollectionsControl(CollectionManager manager, GameCollectionsSettingsViewModel settings, Action<Guid> openCollection)
|
||||
{
|
||||
@@ -76,17 +103,32 @@ namespace GameCollections.Views
|
||||
// Subscribed only while shown, so a control the theme discards doesn't stay alive through these events.
|
||||
Loaded += (s, e) =>
|
||||
{
|
||||
manager.CollectionsChanged += Manager_CollectionsChanged;
|
||||
settings.SettingsChanged += Settings_SettingsChanged;
|
||||
Subscribe();
|
||||
UpdateItems();
|
||||
};
|
||||
Unloaded += (s, e) =>
|
||||
{
|
||||
manager.CollectionsChanged -= Manager_CollectionsChanged;
|
||||
settings.SettingsChanged -= Settings_SettingsChanged;
|
||||
if (!IsInjected)
|
||||
{
|
||||
Unsubscribe();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private void Subscribe()
|
||||
{
|
||||
// Removing first keeps this safe to call more than once.
|
||||
Unsubscribe();
|
||||
manager.CollectionsChanged += Manager_CollectionsChanged;
|
||||
settings.SettingsChanged += Settings_SettingsChanged;
|
||||
}
|
||||
|
||||
private void Unsubscribe()
|
||||
{
|
||||
manager.CollectionsChanged -= Manager_CollectionsChanged;
|
||||
settings.SettingsChanged -= Settings_SettingsChanged;
|
||||
}
|
||||
|
||||
public override void GameContextChanged(Game oldContext, Game newContext)
|
||||
{
|
||||
UpdateItems();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
Id: GameCollections_3f6b8d2e-5c41-4a7e-9e0b-6d2f1a8c7b54
|
||||
Name: Game Collections
|
||||
Author: X4Lo
|
||||
Version: 1.1.0
|
||||
Version: 1.2.0
|
||||
Module: GameCollections.dll
|
||||
Type: GenericPlugin
|
||||
Icon: icon.png
|
||||
|
||||
Reference in new issue
Block a user