bburky / playnite-playlist

A Playnite extension providing a reorderable queue of games
Other
5 stars 1 forks source link

Add HowLongToBeat progress #4

Open bburky opened 3 years ago

bburky commented 3 years ago

Closes #2

This is a kind of hacky implementation, but does work. The normal <ContentControl x:Name="HowLongToBeat_PluginProgressBar"/> way doesn't work because Playnite only provides custom control integration in library views.

Instead, it's possible to manually access a different extension and call it's GetGameViewControl() methods to instantiate the custom controls it provides. This control can be loaded into a ContentControl and it's GameContext manually bound.

The code is roughly this plus some additional error checking:

Plugin plugin = PlayniteApi.Addons.Plugins.FirstOrDefault(p => p.Id == Guid.Parse("e08cd51f-9c9a-4ee3-a094-fde03b55492f"));

PluginUserControl control = plugin.GetGameViewControl(new GetGameViewControlArgs
{
    Name = "PluginProgressBar",
    Mode = ApplicationMode.Desktop,
}) as PluginUserControl;

control.GameContext = DataContext as Game;
DataContextChanged += (sender, e) =>
{
    control.GameContext = e.NewValue as Game;
};

Content = control;

image

It mostly works well. This change introduced a short lag when first loading my Playlist sidebar view. Also when each HowLongToBeat progress bar shows up it takes a second to "pop in", it shows up unstyled and then resizes and loads. I'm not sure if that's avoidable?

@Lacro59 Are you okay with me using your plugin like this? Will anything break if I load lots of controls like this (it seems to work fine though). The button even works too. It gets loaded basically the same way as the library views use it. Is there any thing I should be doing to reduce the loading time for each control?

@JosefNemec I looked at ControlTemplateTools.InitializePluginControls() and it doesn't look like it could be easily extended to support sidebar views like I'm trying to do. Is loading another extension's control like I'm doing here a good idea, or should I expect this to break horribly?

bburky commented 3 years ago

It also appears to be causing the drag and drop behavior to slow down significantly. Perhaps I may need to disable property updates during dragging

JosefNemec commented 3 years ago

I don't know what PlayniteApi object that is, but IPlayniteApi doesn't have Plugins member. This is definitely not supported and expect issues.

bburky commented 3 years ago

Sorry, typo while shortening the sample code.

It's IPlayniteApi.Addons.Plugins. It has a List of all the currently loaded Plugins. https://playnite.link/docs/devel/api/Playnite.SDK.IAddons.html#Playnite_SDK_IAddons_Plugins

Would you consider an API in the future to allow plugin views or Windows to do this in a supported way? Something like <ContentControl x:Name="HowLongToBeat_PluginProgressBar"/> but more generic?

JosefNemec commented 3 years ago

open issue

JosefNemec commented 3 years ago

To be honest I don't remember why that plugin list is exposed there, that should definitely not be done the way it is (exposing the "raw" plugin classes). I'm going to remove it in P9.

Lacro59 commented 3 years ago

@bburky Basically, giving a GameContext to a PluginUserControl is how it works.