From 97b55338a429dad138b2f8e3180f018d875261f8 Mon Sep 17 00:00:00 2001
From: Doriel Rivalet <100863878+DorielRivalet@users.noreply.github.com>
Date: Wed, 26 Oct 2022 11:51:48 -0300
Subject: [PATCH] feat: implement save file dialogs to gear export options
---
MHFZ_Overlay/ConfigWindow.xaml | 4 +--
MHFZ_Overlay/ConfigWindow.xaml.cs | 55 ++++++++++++++++++++++++++-----
2 files changed, 48 insertions(+), 11 deletions(-)
diff --git a/MHFZ_Overlay/ConfigWindow.xaml b/MHFZ_Overlay/ConfigWindow.xaml
index c49f2c91..6018c279 100644
--- a/MHFZ_Overlay/ConfigWindow.xaml
+++ b/MHFZ_Overlay/ConfigWindow.xaml
@@ -346,8 +346,8 @@
-
-
+
+
diff --git a/MHFZ_Overlay/ConfigWindow.xaml.cs b/MHFZ_Overlay/ConfigWindow.xaml.cs
index 52b1709b..294e738f 100644
--- a/MHFZ_Overlay/ConfigWindow.xaml.cs
+++ b/MHFZ_Overlay/ConfigWindow.xaml.cs
@@ -826,12 +826,22 @@ private void BtnCopyFile_Click(object sender, RoutedEventArgs e)
private void BtnImageFile_Click(object sender, RoutedEventArgs e)
{
- System.Windows.MessageBoxResult messageBoxResult = System.Windows.MessageBox.Show("Overwrite current file?", "Gear Stats", System.Windows.MessageBoxButton.YesNo, System.Windows.MessageBoxImage.Asterisk, MessageBoxResult.No); if (messageBoxResult.ToString() == "No") { return; }
+ //System.Windows.MessageBoxResult messageBoxResult = System.Windows.MessageBox.Show("Overwrite current file?", "Gear Stats", System.Windows.MessageBoxButton.YesNo, System.Windows.MessageBoxImage.Asterisk, MessageBoxResult.No); if (messageBoxResult.ToString() == "No") { return; }
- string dir = System.AppDomain.CurrentDomain.BaseDirectory + @"USERDATA\HunterSets\currentSet.png";
+ SaveFileDialog savefile = new SaveFileDialog();
+ string dateTime = DateTime.Now.ToString();
+ dateTime = dateTime.Replace("/", "-");
+ dateTime = dateTime.Replace(" ", "_");
+ dateTime = dateTime.Replace(":", "-");
+ savefile.FileName = "HuntedLog-" + dateTime + ".png";
+ savefile.Filter = "PNG files (*.png)|*.png";
+ savefile.InitialDirectory = System.AppDomain.CurrentDomain.BaseDirectory + @"USERDATA\HunterSets\";
- CreateBitmapFromVisual(GearTextGrid, dir);
- CopyUIElementToClipboard(GearTextGrid);
+ if (savefile.ShowDialog() == true)
+ {
+ CreateBitmapFromVisual(GearTextGrid, savefile.FileName);
+ CopyUIElementToClipboard(GearTextGrid);
+ }
}
///
@@ -843,7 +853,11 @@ public static void CopyUIElementToClipboard(FrameworkElement element)
double width = element.ActualWidth;
double height = element.ActualHeight;
if (width <= 0 || height <= 0)
+ {
+ System.Windows.MessageBox.Show("Please load the gear stats by visiting the text tab in the configuration window", "Error", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error);
return;
+ }
+
RenderTargetBitmap bmpCopied = new RenderTargetBitmap((int)Math.Round(width), (int)Math.Round(height), 96, 96, PixelFormats.Default);
DrawingVisual dv = new DrawingVisual();
using (DrawingContext dc = dv.RenderOpen())
@@ -864,6 +878,12 @@ public static void CreateBitmapFromVisual(Visual target, string fileName)
Rect bounds = VisualTreeHelper.GetDescendantBounds(target);
+ if (bounds.Width <= 0 || bounds.Height <= 0)
+ {
+ System.Windows.MessageBox.Show("Please load the gear stats by visiting the text tab in the configuration window", "Error", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error);
+ return;
+ }
+
RenderTargetBitmap renderTarget = new RenderTargetBitmap((Int32)bounds.Width, (Int32)bounds.Height, 96, 96, PixelFormats.Pbgra32);
DrawingVisual visual = new DrawingVisual();
@@ -893,14 +913,31 @@ private void FilterBox_SelectionChanged(object sender, SelectionChangedEventArgs
// on generate csv button click
protected void BtnLogFile_Click(object sender, EventArgs e)
{
- System.Windows.MessageBoxResult messageBoxResult = System.Windows.MessageBox.Show("Overwrite current file?", "Gear Stats", System.Windows.MessageBoxButton.YesNo, System.Windows.MessageBoxImage.Asterisk, MessageBoxResult.No); if (messageBoxResult.ToString() == "No") { return; }
+ //System.Windows.MessageBoxResult messageBoxResult = System.Windows.MessageBox.Show("Overwrite current file?", "Gear Stats", System.Windows.MessageBoxButton.YesNo, System.Windows.MessageBoxImage.Asterisk, MessageBoxResult.No); if (messageBoxResult.ToString() == "No") { return; }
- string dir = System.AppDomain.CurrentDomain.BaseDirectory + @"USERDATA\HuntedLogs\log.csv";
+ SaveFileDialog savefile = new SaveFileDialog();
+ string dateTime = DateTime.Now.ToString();
+ dateTime = dateTime.Replace("/", "-");
+ dateTime = dateTime.Replace(" ", "_");
+ dateTime = dateTime.Replace(":", "-");
+ savefile.FileName = "HuntedLog-"+dateTime+".csv";
+ savefile.Filter = "CSV files (*.csv)|*.csv";
+ savefile.InitialDirectory = System.AppDomain.CurrentDomain.BaseDirectory + @"USERDATA\HuntedLogs\";
- using (var writer = new StreamWriter(dir))
- using (var csv = new CsvWriter(writer, CultureInfo.InvariantCulture))
+ if (savefile.ShowDialog() == true)
{
- csv.WriteRecords(Monsters);
+ //using (StreamWriter sw = new StreamWriter(savefile.FileName,
+ // false, System.Text.Encoding.Unicode))
+ //{
+ // sw.WriteLine("Test line");
+ // sw.WriteLine("Test line2");
+ // sw.WriteLine("Test line3");
+ //}
+ using (var writer = new StreamWriter(savefile.FileName))
+ using (var csv = new CsvWriter(writer, CultureInfo.InvariantCulture))
+ {
+ csv.WriteRecords(Monsters);
+ }
}
}
};