Skip to content

Commit

Permalink
feat: improve quest logs youtube section
Browse files Browse the repository at this point in the history
closes #256
  • Loading branch information
DorielRivalet committed Jan 26, 2024
1 parent d701a3a commit 4745ef2
Show file tree
Hide file tree
Showing 5 changed files with 192 additions and 25 deletions.
2 changes: 1 addition & 1 deletion MHFZ_Overlay/Models/FastestRun.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public sealed class FastestRun

public long QuestID { get; set; }

public string YoutubeID { get; set; } = Messages.RickRollID;
public string YouTubeID { get; set; } = Messages.RickRollID;

public string FinalTimeDisplay { get; set; } = Messages.MaximumTimerPlaceholder;

Expand Down
2 changes: 1 addition & 1 deletion MHFZ_Overlay/Models/RecentRuns.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public sealed class RecentRuns

public long QuestID { get; set; }

public string YoutubeID { get; set; } = Messages.RickRollID;
public string YouTubeID { get; set; } = Messages.RickRollID;

public string FinalTimeDisplay { get; set; } = Messages.MaximumTimerPlaceholder;

Expand Down
105 changes: 94 additions & 11 deletions MHFZ_Overlay/Services/DatabaseService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2860,7 +2860,7 @@ BEFORE UPDATE ON Quests
cmd.CommandText = @"CREATE TRIGGER IF NOT EXISTS prevent_quest_updates
AFTER UPDATE ON Quests
FOR EACH ROW
WHEN NEW.YoutubeID = OLD.YoutubeID
WHEN NEW.YouTubeID = OLD.YouTubeID
BEGIN
SELECT RAISE(ABORT, 'Cannot update quest fields');
END;";
Expand Down Expand Up @@ -5672,15 +5672,15 @@ public string GetYoutubeLinkForRunID(long runID)
{
try
{
using (var cmd = new SQLiteCommand("SELECT YoutubeID FROM Quests WHERE RunID = @runID", conn))
using (var cmd = new SQLiteCommand("SELECT YouTubeID FROM Quests WHERE RunID = @runID", conn))
{
cmd.Parameters.AddWithValue("@runID", runID);

using (var reader = cmd.ExecuteReader())
{
if (reader.Read())
{
youtubeLink = (string)reader["YoutubeID"];
youtubeLink = (string)reader["YouTubeID"];
}
else
{
Expand Down Expand Up @@ -5726,7 +5726,7 @@ public bool UpdateYoutubeLink(object sender, RoutedEventArgs e, long runID, stri
var count = (long)cmd.ExecuteScalar();
if (count > 0)
{
using (var cmd2 = new SQLiteCommand("UPDATE Quests SET YoutubeID = @youtubeLink WHERE RunID = @runID", conn))
using (var cmd2 = new SQLiteCommand("UPDATE Quests SET YouTubeID = @youtubeLink WHERE RunID = @runID", conn))
{
cmd2.Parameters.AddWithValue("@youtubeLink", youtubeLink);
cmd2.Parameters.AddWithValue("@runID", runID);
Expand Down Expand Up @@ -10167,7 +10167,7 @@ public List<FastestRun> GetFastestRuns(ConfigWindow configWindow, string weaponN
qn.QuestNameName,
q.RunID,
QuestID,
YoutubeID,
YouTubeID,
FinalTimeDisplay,
Date,
ActualOverlayMode,
Expand All @@ -10191,7 +10191,7 @@ FinalTimeValue ASC
qn.QuestNameName,
q.RunID,
QuestID,
YoutubeID,
YouTubeID,
FinalTimeDisplay,
Date,
ActualOverlayMode,
Expand Down Expand Up @@ -10249,7 +10249,7 @@ FinalTimeValue ASC
QuestName = (string)reader["QuestNameName"],
RunID = (long)reader["RunID"],
QuestID = (long)reader["QuestID"],
YoutubeID = (string)reader["YoutubeID"],
YouTubeID = (string)reader["YouTubeID"],
FinalTimeDisplay = (string)reader["FinalTimeDisplay"],
Date = DateTime.Parse((string)reader["Date"], CultureInfo.InvariantCulture),
});
Expand All @@ -10271,6 +10271,89 @@ FinalTimeValue ASC
return fastestRuns;
}

/// <summary>
/// TODO: Filter by run buffs and overlay mode speedrun. Speedruns only.
/// </summary>
/// <param name="configWindow"></param>
/// <param name="weaponName"></param>
/// <returns></returns>
public List<FastestRun> GetUneditedYouTubeLinkRuns()
{
var runs = new List<FastestRun>();
if (string.IsNullOrEmpty(this.dataSource))
{
Logger.Warn(CultureInfo.InvariantCulture, "Cannot get unedited youtube link runs. dataSource: {0}", this.dataSource);
return runs;
}

using (var conn = new SQLiteConnection(this.dataSource))
{
conn.Open();
using (var transaction = conn.BeginTransaction())
{
try
{
var sql = @"SELECT
ObjectiveImage,
qn.QuestNameName,
q.RunID,
QuestID,
YouTubeID,
FinalTimeDisplay,
Date,
ActualOverlayMode,
PartySize
FROM
Quests q
JOIN
QuestName qn ON q.QuestID = qn.QuestNameID
WHERE
q.PartySize = 1
AND q.YouTubeID = 'dQw4w9WgXcQ'
AND q.ActualOverlayMode != 'Standard'
ORDER BY
q.RunID DESC";

using (var cmd = new SQLiteCommand(sql, conn))
{
using (var reader = cmd.ExecuteReader())
{
if (reader == null || !reader.HasRows)
{
return runs;
}

if (reader.HasRows)
{
while (reader.Read())
{
runs.Add(new FastestRun
{
ObjectiveImage = (string)reader["ObjectiveImage"],
QuestName = (string)reader["QuestNameName"],
RunID = (long)reader["RunID"],
QuestID = (long)reader["QuestID"],
YouTubeID = (string)reader["YouTubeID"],
FinalTimeDisplay = (string)reader["FinalTimeDisplay"],
Date = DateTime.Parse((string)reader["Date"], CultureInfo.InvariantCulture),
});
}
}
}
}

transaction.Commit();
}
catch (Exception ex)
{
HandleError(transaction, ex);
}
}
}

return runs;
}

/// <summary>
/// Get a list of all achievements where the completion date is set or not by the player.
/// </summary>
Expand Down Expand Up @@ -10430,7 +10513,7 @@ public ObservableCollection<RecentRuns> GetRecentRuns()
qn.QuestNameName,
RunID,
QuestID,
YoutubeID,
YouTubeID,
FinalTimeDisplay,
Date,
ActualOverlayMode,
Expand Down Expand Up @@ -10460,7 +10543,7 @@ Date DESC
QuestName = (string)reader["QuestNameName"],
RunID = (long)reader["RunID"],
QuestID = (long)reader["QuestID"],
YoutubeID = (string)reader["YoutubeID"],
YouTubeID = (string)reader["YouTubeID"],
FinalTimeDisplay = (string)reader["FinalTimeDisplay"],
Date = DateTime.Parse((string)reader["Date"], CultureInfo.InvariantCulture),
ActualOverlayMode = (string)reader["ActualOverlayMode"],
Expand Down Expand Up @@ -10511,7 +10594,7 @@ public List<RecentRuns> GetCalendarRuns(DateTime? selectedDate)
qn.QuestNameName,
RunID,
QuestID,
YoutubeID,
YouTubeID,
FinalTimeDisplay,
Date,
ActualOverlayMode,
Expand Down Expand Up @@ -10543,7 +10626,7 @@ ORDER BY
QuestName = (string)reader["QuestNameName"],
RunID = (long)reader["RunID"],
QuestID = (long)reader["QuestID"],
YoutubeID = (string)reader["YoutubeID"],
YouTubeID = (string)reader["YouTubeID"],
FinalTimeDisplay = (string)reader["FinalTimeDisplay"],
Date = DateTime.Parse((string)reader["Date"], CultureInfo.InvariantCulture),
ActualOverlayMode = (string)reader["ActualOverlayMode"],
Expand Down
85 changes: 76 additions & 9 deletions MHFZ_Overlay/Views/Windows/ConfigWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
<DataGridTextColumn Header="Youtube ID" Binding="{Binding YoutubeID}" Width="128">
<DataGridTextColumn Header="Youtube ID" Binding="{Binding YouTubeID}" Width="128">
<DataGridTextColumn.ElementStyle>
<Style TargetType="TextBlock">
<Setter Property="TextWrapping" Value="Wrap" />
Expand Down Expand Up @@ -492,7 +492,7 @@
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
<DataGridTextColumn Header="Youtube ID" Binding="{Binding YoutubeID}" Width="128">
<DataGridTextColumn Header="Youtube ID" Binding="{Binding YouTubeID}" Width="128">
<DataGridTextColumn.ElementStyle>
<Style TargetType="TextBlock">
<Setter Property="TextWrapping" Value="Wrap" />
Expand Down Expand Up @@ -642,7 +642,7 @@
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
<DataGridTextColumn Header="Youtube ID" Binding="{Binding YoutubeID}" Width="128">
<DataGridTextColumn Header="Youtube ID" Binding="{Binding YouTubeID}" Width="128">
<DataGridTextColumn.ElementStyle>
<Style TargetType="TextBlock">
<Setter Property="TextWrapping" Value="Wrap" />
Expand Down Expand Up @@ -702,17 +702,84 @@

<Border CornerRadius="5,0,0,5" Grid.Row="0" Grid.Column="0" Grid.RowSpan="25" Width="5" Margin="0,0,5,0" Background="#f38ba8" />

<StackPanel Grid.Row="0" Grid.Column="1" Orientation="Horizontal" Margin="5">
<TextBlock VerticalAlignment="Center" Text="YouTube ID for the Run ID" Margin="5"/>
<ui:TextBox VerticalContentAlignment="Center" Margin="5" ToolTip="Enter the YouTube video ID for the Run ID entered at the top" PlaceholderText="YouTube video ID" MinWidth="20" IsUndoEnabled="False" TextAlignment="Center" MaxLength="12" Loaded="YoutubeLinkTextBox_Loaded"/>
<StackPanel Orientation="Horizontal">
<StackPanel Grid.Row="0" Grid.Column="1" Orientation="Vertical" Margin="5">
<StackPanel Orientation="Horizontal" Margin="5">
<TextBlock VerticalAlignment="Center" Foreground="{StaticResource Text}" Text="Find runs to update"/>
<ui:Button Background="Transparent" Margin="5,0,0,0" VerticalAlignment="Center" HorizontalAlignment="Center" ToolTip="Find speedruns to update" Click="YouTubeFindRuns_Click">
<Button.Content>
<ui:SymbolIcon Symbol="Search24" FontSize="24" Foreground="{StaticResource Green}"/>
</Button.Content>
</ui:Button>
<TextBlock VerticalAlignment="Center" Text="YouTube ID for the Run ID" Margin="5"/>
<ui:TextBox VerticalContentAlignment="Center" Margin="5" ToolTip="Enter the YouTube video ID for the Run ID entered at the top" PlaceholderText="YouTube video ID" MinWidth="20" IsUndoEnabled="False" TextAlignment="Center" MaxLength="12" Loaded="YoutubeLinkTextBox_Loaded"/>
<TextBlock VerticalAlignment="Center" Foreground="{StaticResource Text}" Text="Add ID"/>
<ui:Button BorderThickness="0" Foreground="#f38ba8" Background="Transparent" Margin="5" Content="&#xf03d;" FontFamily="/FontAwesome.Sharp;component/fonts/#Font Awesome 6 Free Solid" Click="UpdateYoutubeLink_ButtonClick"/>
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="5,0,0,0">
<TextBlock VerticalAlignment="Center" Foreground="{StaticResource Text}" Text="Open Link in Browser"/>
<ui:Button BorderThickness="0" Foreground="Red" Background="Transparent" Margin="5" Content="&#xf167;" FontFamily="/FontAwesome.Sharp;component/fonts/#Font Awesome 6 Brands Regular" Click="YoutubeIconButton_Click"/>
</StackPanel>
<ui:DataGrid x:Name="UneditedYouTubeLinkRunsDataGrid" AutoGenerateColumns="False" Loaded="UneditedYouTubeLinkRuns_DataGridLoaded" IsReadOnly="True">
<DataGrid.ColumnHeaderStyle>
<StaticResource ResourceKey="DefaultDataGridColumnHeaderStyle"/>
</DataGrid.ColumnHeaderStyle>
<DataGrid.Columns>
<DataGridTemplateColumn Header="Objective" Width="128">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Image Source="{Binding ObjectiveImage}" Width="64" Height="64" HorizontalAlignment="Center" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Header="Quest Name" Binding="{Binding QuestName}" Width="250">
<DataGridTextColumn.ElementStyle>
<Style TargetType="TextBlock">
<Setter Property="TextWrapping" Value="Wrap" />
<Setter Property="HorizontalAlignment" Value="Center"/>
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
<DataGridTextColumn Header="Run ID" Binding="{Binding RunID}" Width="128">
<DataGridTextColumn.ElementStyle>
<Style TargetType="TextBlock">
<Setter Property="TextWrapping" Value="Wrap" />
<Setter Property="HorizontalAlignment" Value="Center"/>
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
<DataGridTextColumn Header="Quest ID" Binding="{Binding QuestID}" Width="128">
<DataGridTextColumn.ElementStyle>
<Style TargetType="TextBlock">
<Setter Property="TextWrapping" Value="Wrap" />
<Setter Property="HorizontalAlignment" Value="Center"/>
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
<DataGridTextColumn Header="Youtube ID" Binding="{Binding YouTubeID}" Width="128">
<DataGridTextColumn.ElementStyle>
<Style TargetType="TextBlock">
<Setter Property="TextWrapping" Value="Wrap" />
<Setter Property="HorizontalAlignment" Value="Center"/>
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
<DataGridTextColumn Header="Time Elapsed" Binding="{Binding FinalTimeDisplay}" Width="128">
<DataGridTextColumn.ElementStyle>
<Style TargetType="TextBlock">
<Setter Property="TextWrapping" Value="Wrap" />
<Setter Property="HorizontalAlignment" Value="Center"/>
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
<DataGridTextColumn Header="Date" Binding="{Binding Date}" Width="128">
<DataGridTextColumn.ElementStyle>
<Style TargetType="TextBlock">
<Setter Property="TextWrapping" Value="Wrap" />
<Setter Property="HorizontalAlignment" Value="Center"/>
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
<!-- Add more columns with custom headers as needed -->
</DataGrid.Columns>
</ui:DataGrid>
</StackPanel>
</Grid>
</DataTemplate>
Expand Down
Loading

0 comments on commit 4745ef2

Please sign in to comment.