Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add HowLongToBeat progress #4

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

Add HowLongToBeat progress #4

wants to merge 1 commit into from

Conversation

bburky
Copy link
Owner

@bburky bburky commented Sep 29, 2021

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 bburky changed the title Add HowLongToBeat menus Add HowLongToBeat progress Sep 29, 2021
@bburky
Copy link
Owner Author

bburky commented Sep 29, 2021

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
Copy link

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
Copy link
Owner Author

bburky commented Sep 29, 2021

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
Copy link

open issue

@JosefNemec
Copy link

JosefNemec commented Sep 29, 2021

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
Copy link

Lacro59 commented Sep 29, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature Request] HowLongToBeat inclusion in Playlist view
3 participants