Skip to content

Commit

Permalink
Merge branch 'set-status'
Browse files Browse the repository at this point in the history
  • Loading branch information
erys committed Nov 9, 2021
2 parents eddb5ff + cb50f7f commit c164a94
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 8 deletions.
2 changes: 1 addition & 1 deletion FriendlySetPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ private void DoSetTime(Game game)
ShowMinimizeButton = false,
});

window.Height = 110;
window.Height = 140;
window.Width = 520;
window.Title = "Set Time";
window.Content = view;
Expand Down
10 changes: 8 additions & 2 deletions FriendlySetTime.SetTimeWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:c="clr-namespace:FriendlySetTime"
mc:Ignorable="d"
d:DesignHeight="80" d:DesignWidth="500"
d:DesignHeight="110" d:DesignWidth="500"
x:Name="_window">
<Grid Margin="5">
<Grid.ColumnDefinitions>
Expand All @@ -14,6 +14,7 @@
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="30" />
<RowDefinition Height="30" />
<RowDefinition Height="35" />
</Grid.RowDefinitions>
Expand Down Expand Up @@ -54,7 +55,12 @@
</TextBox>
<Label Margin="5,0,0,0" Content="seconds"/>
</StackPanel>
<StackPanel Grid.Row="1" Grid.ColumnSpan="3" Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,5,0,0">
<StackPanel Grid.Row="1" Grid.ColumnSpan="3" Orientation="Horizontal">
<CheckBox VerticalAlignment="Center" x:Name="updateStatus" IsChecked="False"/>
<Label Content="Set status to:" Margin="5,5,0,0"/>
<ComboBox ItemsSource="{Binding statuses, ElementName=_window}" Name="newStatus" SelectionChanged="statusChanged" Margin="0,5,0,0"/>
</StackPanel>
<StackPanel Grid.Row="2" Grid.ColumnSpan="3" Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,5,0,0">
<Button Width="100" Margin="5,0" Content="Set" Click="Button_Click"/>
<Button Width="100" Margin="5,0" Content="Cancel" IsCancel="True"/>
</StackPanel>
Expand Down
24 changes: 24 additions & 0 deletions FriendlySetTime.SetTimeWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using Playnite.SDK;
using Playnite.SDK.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;

Expand All @@ -15,6 +17,8 @@ public partial class SetTimeWindow : UserControl
public string Hours { get; set; }
public string Minutes { get; set; }
public string Seconds { get; set; }

public List<string> statuses { get; set; } = new List<string>();
private readonly FriendlySetPlugin plugin;
private readonly Game game;

Expand All @@ -27,7 +31,14 @@ public SetTimeWindow(FriendlySetPlugin plugin, Game game)
Minutes = (bigMinutes % 60).ToString();
Hours = (bigMinutes / 60).ToString();
this.plugin = plugin;

foreach (CompletionStatus completionStatus in plugin.PlayniteApi.Database.CompletionStatuses)
{
statuses.Add(completionStatus.Name);
}

InitializeComponent();
newStatus.SelectedIndex = statuses.IndexOf(game.CompletionStatus.Name);
}

private void Button_Click(object sender, RoutedEventArgs e)
Expand All @@ -40,6 +51,11 @@ private void Button_Click(object sender, RoutedEventArgs e)
scnds += mins * 60;
scnds += hrs * 3600;
game.Playtime = scnds;
if ((bool)updateStatus.IsChecked)
{
string status = newStatus.SelectedItem.ToString();
game.CompletionStatusId = plugin.PlayniteApi.Database.CompletionStatuses.Where(x => x.Name == status).DefaultIfEmpty(game.CompletionStatus).First().Id;
}
plugin.PlayniteApi.Database.Games.Update(game);
((Window)this.Parent).Close();
} catch (Exception E)
Expand All @@ -48,5 +64,13 @@ private void Button_Click(object sender, RoutedEventArgs e)
plugin.PlayniteApi.Dialogs.ShowErrorMessage(E.Message, "Error when parsing time");
}
}

private void statusChanged(object sender, SelectionChangedEventArgs e)
{
if (game.CompletionStatus.Name != newStatus.SelectedItem.ToString())
{
updateStatus.IsChecked = true;
}
}
}
}
4 changes: 2 additions & 2 deletions FriendlySetTime.sln
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ Global
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{4FDF1E89-5BC3-4C72-8FDA-0D580E7A5D5F}.Debug|Any CPU.ActiveCfg = Release|Any CPU
{4FDF1E89-5BC3-4C72-8FDA-0D580E7A5D5F}.Debug|Any CPU.Build.0 = Release|Any CPU
{4FDF1E89-5BC3-4C72-8FDA-0D580E7A5D5F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4FDF1E89-5BC3-4C72-8FDA-0D580E7A5D5F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4FDF1E89-5BC3-4C72-8FDA-0D580E7A5D5F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4FDF1E89-5BC3-4C72-8FDA-0D580E7A5D5F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
Expand Down
2 changes: 1 addition & 1 deletion NumberValidation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public override ValidationResult Validate(object value, CultureInfo cultureInfo)
}
return ValidationResult.ValidResult;
} catch (Exception e)
{
{ //TODO: this isn't working/being used
return new ValidationResult(false, $"{value} is not a number");
}
}
Expand Down
7 changes: 5 additions & 2 deletions extension.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
Id: FriendlySetTime_1f05ed2e-f22d-45e0-8e81-16378a8464c7
Name: Friendly Set Playtime
Author: erys
Version: 0.1
Version: 0.2
Module: FriendlySetTime.dll
Type: GenericPlugin
Icon: icon.png
Icon: icon.png
Links:
- Name: GitHub
Url: https://github.com/erys/FriendlySetTimePlaynitePlugin

0 comments on commit c164a94

Please sign in to comment.