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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions HowLongToBeatControl.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
using Playnite.SDK;
using Playnite.SDK.Controls;
using Playnite.SDK.Models;
using Playnite.SDK.Plugins;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;

namespace Playlist
{
public class HowLongToBeatControl : ContentControl
{
private static Plugin _plugin;
private static Plugin Plugin
{
get
{
if (_plugin == null)
{
_plugin = Playlist.StaticPlayniteApi.Addons.Plugins.FirstOrDefault(p => p.Id == Guid.Parse("e08cd51f-9c9a-4ee3-a094-fde03b55492f"));
}
return _plugin;
}
}

public static bool HowLongToBeatIsInstalled => Plugin != null;

public HowLongToBeatControl(string controlName)
{
if (Plugin == null)
{
return;
}

control = Plugin.GetGameViewControl(new GetGameViewControlArgs
{
Name = controlName,
Mode = ApplicationMode.Desktop,
}) as PluginUserControl;
if (control == null)
{
return;
}

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

Content = control;
}

private PluginUserControl control;
}

public class HowLongToBeatProgressBar : HowLongToBeatControl
{
public HowLongToBeatProgressBar() : base("PluginProgressBar")
{

}
}
public class HowLongToBeatPluginButton : HowLongToBeatControl
{
public HowLongToBeatPluginButton() : base("PluginButton")
{

}
}

}
4 changes: 4 additions & 0 deletions Playlist.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public class Playlist : GenericPlugin
{
private static readonly ILogger logger = LogManager.GetLogger();

public static IPlayniteAPI StaticPlayniteApi { get; set; }

private PlaylistViewModel PlaylistViewModel { get; set; }

private PlaylistView PlaylistView { get; set; }
Expand Down Expand Up @@ -62,6 +64,8 @@ public Playlist(IPlayniteAPI api) : base(api)
// Ensure the library loaded now, relative to the extension DLL.
// If the XAML trys to load it later it will incorrectly load it relative to Playnite's executable
Assembly.Load("GongSolutions.WPF.DragDrop");

StaticPlayniteApi = api;
}

private IEnumerable<Game> LoadPlaylistFile()
Expand Down
1 change: 1 addition & 0 deletions Playlist.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
<Compile Include="HowLongToBeatControl.cs" />
<Compile Include="PlaylistViewModel.cs" />
<Compile Include="Playlist.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Expand Down
10 changes: 10 additions & 0 deletions PlaylistView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:dd="urn:gong-wpf-dragdrop"
xmlns:local="clr-namespace:Playlist"
mc:Ignorable="d"
d:DesignHeight="400" d:DesignWidth="600">

Expand Down Expand Up @@ -167,6 +168,14 @@
</Style.Triggers>
</Style>

<DataTemplate x:Key="howLongToBeatColumn" DataType="GridViewColumn.CellTemplate">
<DockPanel >
<!-- TODO: Hide button except on hover/selection -->
<local:HowLongToBeatPluginButton Margin="10,0,0,0" DockPanel.Dock="Right"/>
<local:HowLongToBeatProgressBar Height="30"/>
</DockPanel>
</DataTemplate>

</UserControl.Resources>

<DockPanel>
Expand Down Expand Up @@ -220,6 +229,7 @@
<GridViewColumn Header="{DynamicResource LOCNameLabel}" Width="500" DisplayMemberBinding="{Binding Name}" />
<GridViewColumn Width="150" Header="{DynamicResource LOCTimePlayed}" DisplayMemberBinding="{Binding Playtime, Converter={StaticResource PlayTimeToStringConverter}}"/>
<GridViewColumn Width="150" Header="{DynamicResource LOCCompletionStatus}" DisplayMemberBinding="{Binding CompletionStatus}" />
<GridViewColumn Width="400" Header="{DynamicResource LOCHowLongToBeat}" CellTemplate="{StaticResource howLongToBeatColumn}" />
</GridView>
</ListView.View>
</ListView>
Expand Down