Skip to content

Commit

Permalink
Added new features for custom theme integration
Browse files Browse the repository at this point in the history
  • Loading branch information
Lacro59 committed Sep 1, 2020
1 parent c112768 commit dfe6168
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 14 deletions.
82 changes: 72 additions & 10 deletions GameActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
using System.Windows.Media;
using System.Windows.Controls.Primitives;
using GameActivity.Services;
using Playnite.Converters;
using System.Globalization;

namespace GameActivity
{
Expand Down Expand Up @@ -89,6 +91,13 @@ public GameActivity(IPlayniteAPI api) : base(api)
{
Directory.CreateDirectory(pathActivityDetailsDB);
}


// Custom theme button
if (settings.EnableIntegrationInCustomTheme)
{
EventManager.RegisterClassHandler(typeof(Button), Button.ClickEvent, new RoutedEventHandler(OnCustomThemeButtonClick));
}
}

public override IEnumerable<ExtensionFunction> GetFunctions()
Expand Down Expand Up @@ -401,6 +410,24 @@ private void OnBtGameSelectedActionBarClick(object sender, RoutedEventArgs e)
new GameActivityView(settings, PlayniteApi, this.GetPluginUserDataPath(), GameSelected).ShowDialog();
}

private void OnCustomThemeButtonClick(object sender, RoutedEventArgs e)
{
string ButtonName = "";
try
{
ButtonName = ((Button)sender).Name;
if (ButtonName == "PART_GaCustomButton")
{
OnBtGameSelectedActionBarClick(sender, e);
}
}
catch (Exception ex)
{
Common.LogError(ex, "GameActivity", "OnCustomThemeButtonClick() error");
}
}


private void Integration()
{
try
Expand Down Expand Up @@ -436,13 +463,18 @@ private void Integration()
ui.RemoveButtonInGameSelectedActionBarButtonOrToggleButton("PART_GaButton");
ui.RemoveButtonInGameSelectedActionBarButtonOrToggleButton("PART_GaToggleButton");
ui.RemoveElementInGameSelectedDescription("PART_GameActivity");
ui.ClearElementInCustomTheme("PART_GameActivty_Graphic");
ui.ClearElementInCustomTheme("PART_GameActivty_GraphicLog");
ui.ClearElementInCustomTheme("PART_GameActivity_Graphic");
ui.ClearElementInCustomTheme("PART_GameActivity_GraphicLog");


// Reset resources
//List<ResourcesList> resourcesLists = new List<ResourcesList>();
//ui.AddResources(resourcesLists);
List<ResourcesList> resourcesLists = new List<ResourcesList>();
resourcesLists.Add(new ResourcesList { Key = "Ga_HasData", Value = false });
resourcesLists.Add(new ResourcesList { Key = "Ga_HasDataLog", Value = false });
resourcesLists.Add(new ResourcesList { Key = "Ga_LastDateSession", Value = "" });
resourcesLists.Add(new ResourcesList { Key = "Ga_LastDateTimeSession", Value = "" });
resourcesLists.Add(new ResourcesList { Key = "Ga_LastPlaytimeSession", Value = "" });
ui.AddResources(resourcesLists);


// No game activity
Expand All @@ -454,8 +486,38 @@ private void Integration()


// Add resources
//ui.AddResources(resourcesLists);
resourcesLists.Add(new ResourcesList { Key = "Ga_HasData", Value = true });

try
{
var data = SelectedGameGameActivity.GetSessionActivityDetails();
resourcesLists.Add(new ResourcesList { Key = "Ga_HasDataLog", Value = (data.Count > 0) });
}
catch
{
}

try
{
resourcesLists.Add(new ResourcesList { Key = "Ga_LastDateSession", Value = Convert.ToDateTime(SelectedGameGameActivity.GetLastSession()).ToString(Playnite.Common.Constants.DateUiFormat) });
resourcesLists.Add(new ResourcesList { Key = "Ga_LastDateTimeSession", Value = Convert.ToDateTime(SelectedGameGameActivity.GetLastSession()).ToString(Playnite.Common.Constants.DateUiFormat)
+ " " + Convert.ToDateTime(SelectedGameGameActivity.GetLastSession()).ToString(Playnite.Common.Constants.TimeUiFormat) });
}
catch
{
}

try
{
LongToTimePlayedConverter converter = new LongToTimePlayedConverter();
string playtime = (string)converter.Convert((long)SelectedGameGameActivity.GetLastSessionActivity().ElapsedSeconds, null, null, CultureInfo.CurrentCulture);
resourcesLists.Add(new ResourcesList { Key = "Ga_LastPlaytimeSession", Value = playtime });
}
catch
{
}

ui.AddResources(resourcesLists);

// Auto integration
if (settings.EnableIntegrationInDescription || settings.EnableIntegrationInDescriptionWithToggle)
Expand Down Expand Up @@ -527,10 +589,10 @@ private void Integration()
{
// Create
StackPanel spGaG = CreateGa(SelectedGameGameActivity, false, true, false, true);
ui.AddElementInCustomTheme(spGaG, "PART_GameActivty_Graphic");
ui.AddElementInCustomTheme(spGaG, "PART_GameActivity_Graphic");

StackPanel spGaGL = CreateGa(SelectedGameGameActivity, false, false, true, true);
ui.AddElementInCustomTheme(spGaGL, "PART_GameActivty_GraphicLog");
ui.AddElementInCustomTheme(spGaGL, "PART_GameActivity_GraphicLog");
}
}
catch (Exception ex)
Expand Down Expand Up @@ -567,7 +629,7 @@ public StackPanel CreateGa(GameActivityClass gameActivity, bool ShowTitle, bool
StackPanel spGaG = new StackPanel();
if (!IsCustom)
{
spGaG.Name = "PART_GameActivty_Graphic";
spGaG.Name = "PART_GameActivity_Graphic";
spGaG.Height = 120;
spGaG.MaxHeight = 120;
spGaG.Margin = new Thickness(0, 5, 0, 5);
Expand All @@ -584,13 +646,13 @@ public StackPanel CreateGa(GameActivityClass gameActivity, bool ShowTitle, bool
StackPanel spGaGL = new StackPanel();
if (!IsCustom)
{
spGaGL.Name = "PART_GameActivty_GraphicLog";
spGaGL.Name = "PART_GameActivity_GraphicLog";
spGaGL.Height = 120;
spGaGL.MaxHeight = 120;
spGaGL.Margin = new Thickness(0, 5, 0, 5);
}

spGaGL.Children.Add(new GameActivityGameGraphicLog(settings, gameActivity));
spGaGL.Children.Add(new GameActivityGameGraphicLog(settings, gameActivity, "", "", 0, !IsCustom));

spGa.Children.Add(spGaGL);
spGa.UpdateLayout();
Expand Down
2 changes: 1 addition & 1 deletion Views/Interface/GameActivityGameGraphicLog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<StackPanel>
<Label Name="lGameSeriesLog" Visibility="Collapsed"></Label>

<lvc:CartesianChart LegendLocation="none" Name="gameSeriesLog" Loaded="GameSeriesLog_Loaded">
<lvc:CartesianChart LegendLocation="none" Name="gameSeriesLog" Loaded="GameSeriesLog_Loaded" Height="150">
<lvc:CartesianChart.DataTooltip>
<localLVC:CustomerToolTipForMultipleTime ShowIcon="{Binding ShowIcon}"/>
</lvc:CartesianChart.DataTooltip>
Expand Down
20 changes: 19 additions & 1 deletion Views/Interface/GameActivityGameGraphicLog.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,26 @@ public void GetActivityForGamesLogGraphics(GameActivityClass gameActivity, bool

private void GameSeriesLog_Loaded(object sender, RoutedEventArgs e)
{
// Define height & width
var parent = ((FrameworkElement)((FrameworkElement)((FrameworkElement)gameSeriesLog.Parent).Parent).Parent);
gameSeriesLog.Height = parent.ActualHeight - lGameSeriesLog.ActualHeight;

if (!double.IsNaN(parent.Height))
{
gameSeriesLog.Height = parent.Height;
}
else
{
gameSeriesLog.Height = parent.ActualHeight;
}

if (!double.IsNaN(parent.Width))
{
gameSeriesLog.Width = parent.Width;
}
else
{
gameSeriesLog.Height = parent.ActualHeight;
}
}
}
}
2 changes: 1 addition & 1 deletion Views/Interface/GameActivityGameGraphicTime.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
xmlns:localLVC="clr-namespace:PluginCommon.LiveChartsCommon;assembly=PluginCommon"
mc:Ignorable="d">

<lvc:CartesianChart LegendLocation="none" Name="gameSeries" Loaded="GameSeries_Loaded" DataClick="GameSeries_DataClick">
<lvc:CartesianChart LegendLocation="none" Name="gameSeries" Loaded="GameSeries_Loaded" DataClick="GameSeries_DataClick" Height="150">
<lvc:CartesianChart.DataTooltip>
<localLVC:CustomerToolTipForTime ShowIcon="{Binding ShowIcon}"/>
</lvc:CartesianChart.DataTooltip>
Expand Down
20 changes: 19 additions & 1 deletion Views/Interface/GameActivityGameGraphicTime.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,26 @@ public void GetActivityForGamesTimeGraphics(GameActivityClass gameActivity, int

private void GameSeries_Loaded(object sender, RoutedEventArgs e)
{
// Define height & width
var parent = ((FrameworkElement)((FrameworkElement)gameSeries.Parent).Parent);
gameSeries.Height = parent.ActualHeight;

if (!double.IsNaN(parent.Height))
{
gameSeries.Height = parent.Height;
}
else
{
gameSeries.Height = parent.ActualHeight;
}

if (!double.IsNaN(parent.Width))
{
gameSeries.Width = parent.Width;
}
else
{
gameSeries.Width = parent.ActualWidth;
}
}

private void GameSeries_DataClick(object sender, ChartPoint chartPoint)
Expand Down

0 comments on commit dfe6168

Please sign in to comment.