Skip to content

Commit

Permalink
feat: add save and copy options for personal bests embed
Browse files Browse the repository at this point in the history
  • Loading branch information
DorielRivalet committed Jun 16, 2023
1 parent 5761e2d commit 450bd76
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 25 deletions.
24 changes: 18 additions & 6 deletions MHFZ_Overlay/ConfigWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@
</DataTemplate>
<DataTemplate x:Key="PersonalBestTemplate">
<!-- Grid structure for the "Personal Best" option -->
<Grid>
<Grid Loaded="PersonalBestMainGridLoaded">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
Expand Down Expand Up @@ -317,7 +317,7 @@
</DataTemplate>
<DataTemplate x:Key="Top20Template">
<!-- Grid structure for the "Top 20" option -->
<Grid>
<Grid Loaded="Top20MainGridLoaded">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
Expand Down Expand Up @@ -432,7 +432,7 @@
</DataTemplate>
<DataTemplate x:Key="WeaponStatsTemplate">
<!-- Grid structure for the "Weapon Stats" option -->
<Grid>
<Grid Loaded="WeaponStatsMainGrid_Loaded">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
Expand Down Expand Up @@ -1285,15 +1285,15 @@
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />

<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>

<Grid Grid.RowSpan="11" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="3" Background="#7f1e1e2e"/>
<Grid Grid.RowSpan="12" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="3" Background="#7f1e1e2e"/>

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

Expand Down Expand Up @@ -1421,7 +1421,19 @@
<TextBlock FontSize="12" x:Name="SpeedrunnerInfoTextBlock" Text="Personal bests by you ·" FontFamily="{StaticResource Open Sans}" Margin="0,0,5,0"/>
<TextBlock FontSize="12" x:Name="CurrentTimeTextBlock" Text="2019/12/25 00:00" FontFamily="{StaticResource Open Sans}" Margin="0,0,5,0"/>
</StackPanel>
</Grid>
<StackPanel Orientation="Horizontal" Grid.Row="11" Grid.Column="1" Grid.ColumnSpan="2" Margin="5">
<ui:Button Background="Transparent" Margin="10,0,0,0" VerticalAlignment="Center" HorizontalAlignment="Center" ToolTip="Save summary of stats to text file" Click="PersonalBestsOverviewButtonSaveFile_Click">
<Button.Content>
<ui:SymbolIcon Symbol="ArrowDownload24" FontSize="24" Foreground="{StaticResource Green}"/>
</Button.Content>
</ui:Button>
<ui:Button Background="Transparent" Margin="10,0,0,0" VerticalAlignment="Center" HorizontalAlignment="Center" ToolTip="Copy stats to clipboard as image (recommended to maximize configuration window)" Click="PersonalBestsOverviewButtonCopyFile_Click">
<Button.Content>
<ui:SymbolIcon Symbol="Copy24" Foreground="{StaticResource Sapphire}" FontSize="24"/>
</Button.Content>
</ui:Button>
</StackPanel>
</Grid>
<ContentControl x:Name="QuestLogsContentControl" Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="3" Content="{Binding SelectedOption}" ContentTemplateSelector="{StaticResource OptionToTemplateConverter}" />
</Grid>
</Grid>
Expand Down
79 changes: 60 additions & 19 deletions MHFZ_Overlay/ConfigWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1449,6 +1449,10 @@ private void weaponUsageChart_Loaded(object sender, RoutedEventArgs e)
private Grid? statsGraphsGrid;
private TextBlock? personalBestDescriptionTextBlock;
private TextBlock? top20RunsDescriptionTextblock;
private Grid? personalBestMainGrid;
private Grid? top20MainGrid;
private Grid? weaponStatsMainGrid;



// TODO: it works. i need to put this somewhere else
Expand Down Expand Up @@ -1771,18 +1775,18 @@ private void CalendarButtonCopyFile_Click(object sender, RoutedEventArgs e)

private void PersonalBestButtonSaveFile_Click(object sender, RoutedEventArgs e)
{
if (personalBestChart == null || personalBestChartGrid == null) return;
if (personalBestChart == null || personalBestChartGrid == null || personalBestMainGrid == null) return;
var fileName = $"PersonalBest-Quest_{QuestIDTextBox.Text}-{OverlayModeComboBox.Text}-{personalBestSelectedType}-{personalBestSelectedWeapon}".Trim().Replace(" ","_");
FileManager.SaveElementAsImageFile(personalBestChartGrid, fileName, ConfigWindowSnackBar, false);
FileManager.SaveElementAsImageFile(personalBestMainGrid, fileName, ConfigWindowSnackBar, false);
}

private void PersonalBestButtonCopyFile_Click(object sender, RoutedEventArgs e)
{
if (personalBestChartGrid == null) return;
var previousBackground = personalBestChartGrid.Background;
personalBestChartGrid.Background = new SolidColorBrush(Color.FromArgb(0xFF, 0x1E, 0x1E, 0x2E));
FileManager.CopyUIElementToClipboard(personalBestChartGrid, ConfigWindowSnackBar);
personalBestChartGrid.Background = previousBackground;
if (personalBestChartGrid == null || personalBestMainGrid == null) return;
var previousBackground = personalBestMainGrid.Background;
personalBestMainGrid.Background = new SolidColorBrush(Color.FromArgb(0xFF, 0x1E, 0x1E, 0x2E));
FileManager.CopyUIElementToClipboard(personalBestMainGrid, ConfigWindowSnackBar);
personalBestMainGrid.Background = previousBackground;
}

private void Top20ButtonSaveFile_Click(object sender, RoutedEventArgs e)
Expand Down Expand Up @@ -1817,16 +1821,16 @@ private void Top20ButtonSaveFile_Click(object sender, RoutedEventArgs e)

private void Top20ButtonCopyFile_Click(object sender, RoutedEventArgs e)
{
if (top20RunsDataGrid == null) return;
var previousBackground = top20RunsDataGrid.Background;
top20RunsDataGrid.Background = new SolidColorBrush(Color.FromArgb(0xFF, 0x1E, 0x1E, 0x2E));
FileManager.CopyUIElementToClipboard(top20RunsDataGrid, ConfigWindowSnackBar);
top20RunsDataGrid.Background = previousBackground;
if (top20RunsDataGrid == null || top20MainGrid == null) return;
var previousBackground = top20MainGrid.Background;
top20MainGrid.Background = new SolidColorBrush(Color.FromArgb(0xFF, 0x1E, 0x1E, 0x2E));
FileManager.CopyUIElementToClipboard(top20MainGrid, ConfigWindowSnackBar);
top20MainGrid.Background = previousBackground;
}

private void WeaponStatsButtonSaveFile_Click(object sender, RoutedEventArgs e)
{
if (weaponUsageChartGrid == null || weaponUsageChart == null || weaponUsageData == null) return;
if (weaponUsageChartGrid == null || weaponUsageChart == null || weaponUsageData == null || weaponStatsMainGrid == null) return;
try
{
var data = MainWindow.DataLoader.model.CalendarRuns;
Expand Down Expand Up @@ -1856,11 +1860,11 @@ private void WeaponStatsButtonSaveFile_Click(object sender, RoutedEventArgs e)

private void WeaponStatsButtonCopyFile_Click(object sender, RoutedEventArgs e)
{
if (weaponUsageChartGrid == null) return;
var previousBackground = weaponUsageChartGrid.Background;
weaponUsageChartGrid.Background = new SolidColorBrush(Color.FromArgb(0xFF, 0x1E, 0x1E, 0x2E));
FileManager.CopyUIElementToClipboard(weaponUsageChartGrid, ConfigWindowSnackBar);
weaponUsageChartGrid.Background = previousBackground;
if (weaponUsageChartGrid == null || weaponStatsMainGrid == null) return;
var previousBackground = weaponStatsMainGrid.Background;
weaponStatsMainGrid.Background = new SolidColorBrush(Color.FromArgb(0xFF, 0x1E, 0x1E, 0x2E));
FileManager.CopyUIElementToClipboard(weaponStatsMainGrid, ConfigWindowSnackBar);
weaponStatsMainGrid.Background = previousBackground;
}

private void MostRecentButtonSaveFile_Click(object sender, RoutedEventArgs e)
Expand Down Expand Up @@ -1934,6 +1938,22 @@ private void StatsTextButtonCopyFile_Click(object sender, RoutedEventArgs e)
statsTextTextBlock.Background = previousBackground;
}

private void PersonalBestsOverviewButtonSaveFile_Click(object sender, RoutedEventArgs e)
{
if (DiscordEmbedWeaponPersonalBest == null || QuestIDTextBox == null) return;
var fileName = $"PersonalBestsOverview-Quest_{QuestIDTextBox.Text}-{DateTime.UtcNow.ToString("yy/MM/dd").Replace("/","-")}";
FileManager.SaveElementAsImageFile(DiscordEmbedWeaponPersonalBest, fileName, ConfigWindowSnackBar, false);
}

private void PersonalBestsOverviewButtonCopyFile_Click(object sender, RoutedEventArgs e)
{
if (DiscordEmbedWeaponPersonalBest == null) return;
var previousBackground = DiscordEmbedWeaponPersonalBest.Background;
DiscordEmbedWeaponPersonalBest.Background = new SolidColorBrush(Color.FromArgb(0xFF, 0x1E, 0x1E, 0x2E));
FileManager.CopyUIElementToClipboard(DiscordEmbedWeaponPersonalBest, ConfigWindowSnackBar);
DiscordEmbedWeaponPersonalBest.Background = previousBackground;
}

private ISeries[]? Series { get; set; }
private Axis[]? XAxes { get; set; }
private Axis[]? YAxes { get; set; }
Expand Down Expand Up @@ -3487,7 +3507,7 @@ private void CalendarDatePicker_SelectedDateChanged(object sender, SelectionChan
{
if (calendarDataGrid == null || sender == null) return;

DatePicker datePicker = sender as DatePicker;
DatePicker? datePicker = sender as DatePicker;

if (datePicker == null) return;

Expand Down Expand Up @@ -3657,6 +3677,27 @@ private void OverlayModeComboBox_SelectionChanged(object sender, SelectionChange
top20RunsDescriptionTextblock.Text = $"Top 20 fastest solo runs of quest ID {QuestIDTextBox.Text} by category {selectedOption}";
}
}

private void PersonalBestMainGridLoaded(object sender, RoutedEventArgs e)
{
var obj = (Grid)sender;
if (obj != null)
personalBestMainGrid = obj;
}

private void Top20MainGridLoaded(object sender, RoutedEventArgs e)
{
var obj = (Grid)sender;
if (obj != null)
top20MainGrid = obj;
}

private void WeaponStatsMainGrid_Loaded(object sender, RoutedEventArgs e)
{
var obj = (Grid)sender;
if (obj != null)
weaponStatsMainGrid = obj;
}
}
/* LoadConfig on startup
* Load Config on window open to have extra copy
Expand Down

0 comments on commit 450bd76

Please sign in to comment.