Skip to content

Commit

Permalink
Increase / Decrease playtime count when adding / deleting entries #132
Browse files Browse the repository at this point in the history
  • Loading branch information
Lacro59 committed Mar 16, 2022
1 parent 3d2396d commit fbb164d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
29 changes: 18 additions & 11 deletions source/Views/GameActivityViewSingle.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -332,20 +332,23 @@ public void getActivityByListGame(GameActivities gameActivities)
#region Data actions
private void PART_Delete_Click(object sender, RoutedEventArgs e)
{
var result = PluginDatabase.PlayniteApi.Dialogs.ShowMessage(ResourceProvider.GetString("LOCConfirumationAskGeneric"), PluginDatabase.PluginName, MessageBoxButton.YesNo);

MessageBoxResult result = PluginDatabase.PlayniteApi.Dialogs.ShowMessage(ResourceProvider.GetString("LOCConfirumationAskGeneric"), PluginDatabase.PluginName, MessageBoxButton.YesNo);
if (result == MessageBoxResult.Yes)
{
try
{
var GameLastActivity = ((FrameworkElement)sender).Tag;
var activity = ((ObservableCollection<ListActivities>)lvSessions.ItemsSource).Where(x => x.GameLastActivity == (DateTime)GameLastActivity).FirstOrDefault();
object GameLastActivity = ((FrameworkElement)sender).Tag;
ListActivities activity = ((ObservableCollection<ListActivities>)lvSessions.ItemsSource).Where(x => x.GameLastActivity == (DateTime)GameLastActivity).FirstOrDefault();

if (activity.GameElapsedSeconds != 0)
{
if ((long)(game.Playtime - activity.GameElapsedSeconds) >= 0)
{
game.Playtime -= activity.GameElapsedSeconds;
if (game.PlayCount > 1)
{
game.PlayCount--;
}
}
else
{
Expand All @@ -370,7 +373,7 @@ private void PART_Delete_Click(object sender, RoutedEventArgs e)

private void PART_BtAdd_Click(object sender, RoutedEventArgs e)
{
var windowOptions = new WindowOptions
WindowOptions windowOptions = new WindowOptions
{
ShowMinimizeButton = false,
ShowMaximizeButton = false,
Expand All @@ -379,7 +382,7 @@ private void PART_BtAdd_Click(object sender, RoutedEventArgs e)

try
{
var ViewExtension = new GameActivityAddTime(game, null);
GameActivityAddTime ViewExtension = new GameActivityAddTime(game, null);
Window windowExtension = PlayniteUiHelper.CreateExtensionWindow(PluginDatabase.PlayniteApi, resources.GetString("LOCGaAddNewGameSession"), ViewExtension, windowOptions);
windowExtension.ShowDialog();

Expand All @@ -391,6 +394,7 @@ private void PART_BtAdd_Click(object sender, RoutedEventArgs e)
if (ViewExtension.activity.ElapsedSeconds >= 0)
{
game.Playtime += ViewExtension.activity.ElapsedSeconds;
game.PlayCount++;
}

PluginDatabase.PlayniteApi.Database.Games.Update(game);
Expand All @@ -407,19 +411,19 @@ private void PART_BtEdit_Click(object sender, RoutedEventArgs e)
{
try
{
var GameLastActivity = ((FrameworkElement)sender).Tag;
object GameLastActivity = ((FrameworkElement)sender).Tag;
int index = gameActivities.Items.FindIndex(x => x.DateSession == ((DateTime)GameLastActivity).ToUniversalTime());
Activity activity = gameActivities.Items[index];
ulong ElapsedSeconds = activity.ElapsedSeconds;

var windowOptions = new WindowOptions
WindowOptions windowOptions = new WindowOptions
{
ShowMinimizeButton = false,
ShowMaximizeButton = false,
ShowCloseButton = true
};

var ViewExtension = new GameActivityAddTime(game, activity);
GameActivityAddTime ViewExtension = new GameActivityAddTime(game, activity);
Window windowExtension = PlayniteUiHelper.CreateExtensionWindow(PluginDatabase.PlayniteApi, resources.GetString("LOCGaAddNewGameSession"), ViewExtension, windowOptions);
windowExtension.ShowDialog();

Expand Down Expand Up @@ -447,19 +451,22 @@ private void PART_BtMerged_Click(object sender, RoutedEventArgs e)
{
try
{
var windowOptions = new WindowOptions
WindowOptions windowOptions = new WindowOptions
{
ShowMinimizeButton = false,
ShowMaximizeButton = false,
ShowCloseButton = true
};

var ViewExtension = new GameActivityMergeTime(game);
GameActivityMergeTime ViewExtension = new GameActivityMergeTime(game);
Window windowExtension = PlayniteUiHelper.CreateExtensionWindow(PluginDatabase.PlayniteApi, resources.GetString("LOCGaMergeSession"), ViewExtension, windowOptions);
windowExtension.ShowDialog();

gameActivities = PluginDatabase.Get(game);
getActivityByListGame(gameActivities);

game.PlayCount--;
PluginDatabase.PlayniteApi.Database.Games.Update(game);
}
catch (Exception ex)
{
Expand Down
2 changes: 1 addition & 1 deletion source/playnite-plugincommon

0 comments on commit fbb164d

Please sign in to comment.