diff --git a/LarkatorGUI/App.xaml.cs b/LarkatorGUI/App.xaml.cs index 40c517a..cf52910 100644 --- a/LarkatorGUI/App.xaml.cs +++ b/LarkatorGUI/App.xaml.cs @@ -46,7 +46,7 @@ protected override void OnStartup(StartupEventArgs e) RegisterExceptionHandlers(); #endif } - + private void RegisterExceptionHandlers() { AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; diff --git a/LarkatorGUI/ArkReader.cs b/LarkatorGUI/ArkReader.cs index bc24c88..2bebb50 100644 --- a/LarkatorGUI/ArkReader.cs +++ b/LarkatorGUI/ArkReader.cs @@ -38,8 +38,7 @@ public void SetArkData(ArkData data) private static Task<(GameObjectContainer gameObjects, float gameTime)> ReadSavegameFile(string fileName) { - return Task.Run(() => - { + return Task.Run(() => { if (new FileInfo(fileName).Length > int.MaxValue) throw new Exception("Input file is too large."); @@ -109,7 +108,7 @@ public async Task PerformConversion(string saveFile) // Read objects directly from the savegame (GameObjectContainer gameObjectContainer, float gameTime) = await ReadSavegameFile(saveFile); - var containers = gameObjectContainer.Select(o => IdentifyCalibrationBox(o)).Where(v => v != null).Cast<(Position,string)>().ToList(); + var containers = gameObjectContainer.Select(o => IdentifyCalibrationBox(o)).Where(v => v != null).Cast<(Position, string)>().ToList(); return containers; } @@ -160,7 +159,7 @@ private Dino ConvertCreature(GameObject obj) Location = ConvertCoordsToLatLong(obj.Location), WildLevels = new StatPoints(), }; - + var status = obj.CharacterStatusComponent(); if (status != null) { diff --git a/LarkatorGUI/CalibrationWindow.xaml.cs b/LarkatorGUI/CalibrationWindow.xaml.cs index 25e9de5..96419e4 100644 --- a/LarkatorGUI/CalibrationWindow.xaml.cs +++ b/LarkatorGUI/CalibrationWindow.xaml.cs @@ -1,5 +1,4 @@ -using Newtonsoft.Json; -using System; +using System; using System.Diagnostics; using System.Windows; using System.Windows.Controls; @@ -45,7 +44,8 @@ private void Image_MouseDown(object sender, MouseButtonEventArgs e) private void Image_MouseUp(object sender, MouseButtonEventArgs e) { - if (!dragging) return; + if (!dragging) + return; var img = (Image)sender; img.ReleaseMouseCapture(); dragging = false; @@ -53,7 +53,8 @@ private void Image_MouseUp(object sender, MouseButtonEventArgs e) private void Image_MouseMove(object sender, MouseEventArgs e) { - if (!dragging) return; + if (!dragging) + return; var img = (Image)sender; var pos = Mouse.GetPosition(img); @@ -73,7 +74,7 @@ private double UpdateBound(double cal, double mult, double x) private void Filename_TextChanged(object sender, TextChangedEventArgs e) { - calibration.Image = $"imgs\\map_{((TextBox)sender).Text}.jpg"; + calibration.Image = $"imgs\\map_{((TextBox)sender).Text}.jpg"; } private void UpdateOutput_TextChanged(object sender, TextChangedEventArgs e) @@ -199,7 +200,7 @@ public string Output public static readonly DependencyProperty ImageProperty = DependencyProperty.Register("Image", typeof(string), typeof(Calibration), new PropertyMetadata("")); - + public static readonly DependencyProperty FilenameProperty = DependencyProperty.Register("Filename", typeof(string), typeof(Calibration), new PropertyMetadata("")); @@ -208,7 +209,8 @@ public string Output public void Recalculate() { - if (Bounds == null) return; + if (Bounds == null) + return; var minX = Math.Min(Bounds.X1, Bounds.X2); var minY = Math.Min(Bounds.Y1, Bounds.Y2); diff --git a/LarkatorGUI/Converters.cs b/LarkatorGUI/Converters.cs index 9b2dc39..616b5c6 100644 --- a/LarkatorGUI/Converters.cs +++ b/LarkatorGUI/Converters.cs @@ -1,4 +1,5 @@ using Larkator.Common; + using System; using System.Collections.Generic; using System.Globalization; @@ -11,8 +12,10 @@ public class BoolToVisibilityConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { - if (value is bool asBool) return asBool ? Visibility.Visible : Visibility.Collapsed; - if (value is int asInt) return asInt != 0 ? Visibility.Visible : Visibility.Collapsed; + if (value is bool asBool) + return asBool ? Visibility.Visible : Visibility.Collapsed; + if (value is int asInt) + return asInt != 0 ? Visibility.Visible : Visibility.Collapsed; return Visibility.Collapsed; } @@ -83,7 +86,8 @@ public class GenderToImageConverter : IValueConverter public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { bool? gender = (bool?)value; - if (!gender.HasValue) return "imgs/nogender.png"; + if (!gender.HasValue) + return "imgs/nogender.png"; if (gender.Value) return "imgs/female.png"; else @@ -101,7 +105,8 @@ public class GenderToLetterConverter : IValueConverter public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { bool? gender = (bool?)value; - if (!gender.HasValue) return ""; + if (!gender.HasValue) + return ""; if (gender.Value) return "F"; else diff --git a/LarkatorGUI/DebounceDispatcher.cs b/LarkatorGUI/DebounceDispatcher.cs index e3a1c3e..f7b34a7 100644 --- a/LarkatorGUI/DebounceDispatcher.cs +++ b/LarkatorGUI/DebounceDispatcher.cs @@ -53,8 +53,7 @@ public void Debounce(int interval, Action action, // timer is recreated for each event and effectively // resets the timeout. Action only fires after timeout has fully // elapsed without other events firing in between - timer = new DispatcherTimer(TimeSpan.FromMilliseconds(interval), priority, (s, e) => - { + timer = new DispatcherTimer(TimeSpan.FromMilliseconds(interval), priority, (s, e) => { if (timer == null) return; @@ -97,8 +96,7 @@ public void Throttle(int interval, Action action, if (curTime.Subtract(timerStarted).TotalMilliseconds < interval) interval -= (int)curTime.Subtract(timerStarted).TotalMilliseconds; - timer = new DispatcherTimer(TimeSpan.FromMilliseconds(interval), priority, (s, e) => - { + timer = new DispatcherTimer(TimeSpan.FromMilliseconds(interval), priority, (s, e) => { if (timer == null) return; diff --git a/LarkatorGUI/DinoViewModel.cs b/LarkatorGUI/DinoViewModel.cs index fbfcc00..790cc8d 100644 --- a/LarkatorGUI/DinoViewModel.cs +++ b/LarkatorGUI/DinoViewModel.cs @@ -1,4 +1,5 @@ using Larkator.Common; + using System.Windows; using System.Windows.Media; diff --git a/LarkatorGUI/DummyMainWindow.cs b/LarkatorGUI/DummyMainWindow.cs index ca7c4f7..1c041a0 100644 --- a/LarkatorGUI/DummyMainWindow.cs +++ b/LarkatorGUI/DummyMainWindow.cs @@ -1,4 +1,5 @@ using Larkator.Common; + using System; using System.Collections.ObjectModel; using System.Linq; diff --git a/LarkatorGUI/FontSizeHelper.cs b/LarkatorGUI/FontSizeHelper.cs index 8810716..010208a 100644 --- a/LarkatorGUI/FontSizeHelper.cs +++ b/LarkatorGUI/FontSizeHelper.cs @@ -11,21 +11,24 @@ public sealed class FontSizeHelper public static double GetRelativeFontSize(DependencyObject d) { - if (d == null) throw new ArgumentNullException(nameof(d), "in GetRelativeFontSize"); + if (d == null) + throw new ArgumentNullException(nameof(d), "in GetRelativeFontSize"); return (double)d.GetValue(RelativeFontSizeProperty); } public static void SetRelativeFontSize(DependencyObject d, double value) { - if (d == null) throw new ArgumentNullException(nameof(d), "in SetRelativeFontSize"); + if (d == null) + throw new ArgumentNullException(nameof(d), "in SetRelativeFontSize"); d.SetValue(RelativeFontSizeProperty, value); } private static void RelativeFontSizeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { - if (d == null) throw new ArgumentNullException(nameof(d), "in RelativeFontSizeChanged"); + if (d == null) + throw new ArgumentNullException(nameof(d), "in RelativeFontSizeChanged"); d.ClearValue(TextBlock.FontSizeProperty); var old = (double)d.GetValue(TextBlock.FontSizeProperty); diff --git a/LarkatorGUI/LinearRegression.cs b/LarkatorGUI/LinearRegression.cs index cafcd70..a592ee3 100644 --- a/LarkatorGUI/LinearRegression.cs +++ b/LarkatorGUI/LinearRegression.cs @@ -1,8 +1,5 @@ using System; -using System.Collections.Generic; using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace LarkatorGUI { diff --git a/LarkatorGUI/MainWindow.xaml.cs b/LarkatorGUI/MainWindow.xaml.cs index b5b9706..d2041ac 100644 --- a/LarkatorGUI/MainWindow.xaml.cs +++ b/LarkatorGUI/MainWindow.xaml.cs @@ -1,8 +1,13 @@ using FastMember; + using GongSolutions.Wpf.DragDrop; + using Larkator.Common; + using Newtonsoft.Json; + using SavegameToolkitAdditions; + using System; using System.Collections.Generic; using System.Collections.ObjectModel; @@ -203,8 +208,7 @@ public MainWindow() InitializeComponent(); - Dispatcher.Invoke(async () => - { + Dispatcher.Invoke(async () => { await Task.Yield(); Properties.Settings.Default.MainWindowWidth = CalculateWidthFromHeight((int)Math.Round(Properties.Settings.Default.MainWindowHeight)); }, DispatcherPriority.Loaded); @@ -233,7 +237,8 @@ private static string CalculateApplicationVersion() private void SetupFileWatcher() { - if (fileWatcher != null) fileWatcher.EnableRaisingEvents = false; + if (fileWatcher != null) + fileWatcher.EnableRaisingEvents = false; fileWatcher = new FileSystemWatcher(Path.GetDirectoryName(Properties.Settings.Default.SaveFile)); fileWatcher.Renamed += FileWatcher_Changed; fileWatcher.Changed += FileWatcher_Changed; @@ -264,7 +269,8 @@ private void DiscoverCalibration() var imgFilename = $"pack://application:,,,/imgs/map_{MapCalibration.Filename}.jpg"; MapImage = (new ImageSourceConverter()).ConvertFromString(imgFilename) as ImageSource; - if (image != null) image.Source = MapImage; + if (image != null) + image.Source = MapImage; arkReader.MapCalibration = MapCalibration; } @@ -288,16 +294,17 @@ private void ValidateWindowPositionAndSize() private void FileWatcher_Changed(object sender, FileSystemEventArgs e) { - if (!String.Equals(e.FullPath, Properties.Settings.Default.SaveFile)) return; + if (!String.Equals(e.FullPath, Properties.Settings.Default.SaveFile)) + return; - Dispatcher.Invoke(() => - { + Dispatcher.Invoke(() => { StatusText = "Detected change to saved ARK..."; StatusDetailText = "...waiting"; }); // Cancel any existing timer to ensure we're not called multiple times - if (reloadTimer.IsEnabled) reloadTimer.Stop(); + if (reloadTimer.IsEnabled) + reloadTimer.Stop(); reloadTimer.Start(); } @@ -328,7 +335,8 @@ private async Task UpdateArkToolsData() var fetchOkay = await FetchArkData(targetFile); var loadOkay = await LoadArkData(targetFile); - if (!loadOkay) throw new ApplicationException("No species data available"); + if (!loadOkay) + throw new ApplicationException("No species data available"); if (fetchOkay) StatusText = "Species data loaded"; else @@ -377,8 +385,7 @@ private async Task FetchArkData(string targetFile) private async Task LoadArkData(string targetFile) { - return await Task.Run(() => - { + return await Task.Run(() => { try { arkReader.SetArkData(ArkDataReader.ReadFromFile(targetFile)); @@ -398,10 +405,12 @@ private void Searches_SelectionChanged(object sender, SelectionChangedEventArgs private void RemoveSearch_Click(object sender, RoutedEventArgs e) { - if (ShowTames) return; + if (ShowTames) + return; var button = sender as Button; - if (button?.DataContext is SearchCriteria search) ListSearches.Remove(search); + if (button?.DataContext is SearchCriteria search) + ListSearches.Remove(search); UpdateCurrentSearch(); MarkSearchesChanged(); @@ -430,7 +439,8 @@ private void MapPin_Click(object sender, MouseButtonEventArgs ev) if (sender is FrameworkElement e && e.DataContext is DinoViewModel dvm) { dvm.Highlight = !dvm.Highlight; - if (dvm.Highlight) resultsList.ScrollIntoView(dvm); + if (dvm.Highlight) + resultsList.ScrollIntoView(dvm); } } @@ -444,7 +454,8 @@ private void CopyTeleport_Click(object sender, RoutedEventArgs e) if (Properties.Settings.Default.TeleportFly) { clipboard += " | cheat fly"; - if (Properties.Settings.Default.TeleportGhost) clipboard += " | cheat ghost"; + if (Properties.Settings.Default.TeleportGhost) + clipboard += " | cheat ghost"; } try @@ -626,7 +637,8 @@ public static ((double xOffset, double xDiv, double xCorr), (double yOffset, dou private void SaveSearch_Click(object sender, RoutedEventArgs e) { - if (String.IsNullOrWhiteSpace(NewSearch.Species)) return; + if (String.IsNullOrWhiteSpace(NewSearch.Species)) + return; List NewSearchList = new List(AllSpecies.Where(species => species.Contains(NewSearch.Species))); SearchCriteria tempSearch; @@ -642,7 +654,7 @@ private void SaveSearch_Click(object sender, RoutedEventArgs e) Properties.Settings.Default.LastGroup = "Shopping List"; } //Set and save property - Properties.Settings.Default.GroupSearch = (bool) groupCheck.IsChecked; + Properties.Settings.Default.GroupSearch = (bool)groupCheck.IsChecked; Properties.Settings.Default.Save(); @@ -668,7 +680,8 @@ private void SaveSearch_Click(object sender, RoutedEventArgs e) tempSearch.GroupSearch = Properties.Settings.Default.GroupSearch; ListSearches.Add(tempSearch); } - else { + else + { try { foreach (String newDino in NewSearchList) @@ -746,7 +759,8 @@ private void AdjustableInteger_MouseWheel(object sender, MouseWheelEventArgs e) if (value.HasValue) { value = value + diff; - if (value < 0 || value > Properties.Settings.Default.MaxLevel) value = null; + if (value < 0 || value > Properties.Settings.Default.MaxLevel) + value = null; } else { @@ -812,15 +826,19 @@ private void CycleAdjustableGender(Image im, int diff) private void Result_MouseEnter(object sender, MouseEventArgs e) { - if (!(sender is FrameworkElement fe)) return; - if (!(fe.DataContext is DinoViewModel dino)) return; + if (!(sender is FrameworkElement fe)) + return; + if (!(fe.DataContext is DinoViewModel dino)) + return; //dino.Highlight = true; } private void Result_MouseLeave(object sender, MouseEventArgs e) { - if (!(sender is FrameworkElement fe)) return; - if (!(fe.DataContext is DinoViewModel dino)) return; + if (!(sender is FrameworkElement fe)) + return; + if (!(fe.DataContext is DinoViewModel dino)) + return; //dino.ClearValue(DinoViewModel.HighlightProperty); } @@ -876,7 +894,8 @@ private void LoadSavedSearches() private async Task ReReadArk() { - if (IsLoading) return; + if (IsLoading) + return; lastArk = Properties.Settings.Default.SaveFile; await PerformConversion(); @@ -980,7 +999,8 @@ void updateSearch(object o) { var search = (SearchCriteria)searchesList.SelectedItem; var searches = new List(); - if (search != null) searches.Add(search); + if (search != null) + searches.Add(search); UpdateSearchResults(searches); } diff --git a/LarkatorGUI/MapPositionConverter.cs b/LarkatorGUI/MapPositionConverter.cs index 5bc9168..250f4e3 100644 --- a/LarkatorGUI/MapPositionConverter.cs +++ b/LarkatorGUI/MapPositionConverter.cs @@ -1,9 +1,6 @@ using Larkator.Common; + using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using System.Windows; using System.Windows.Media; @@ -31,7 +28,7 @@ public static void SetPosition(DependencyObject obj, Position value) { obj.SetValue(PositionProperty, value); } - + public static readonly DependencyProperty PositionProperty = DependencyProperty.RegisterAttached("Position", typeof(Position), typeof(MapPositionConverter), new PropertyMetadata(null, OnChanged)); @@ -45,7 +42,8 @@ public static void OnChanged(DependencyObject d, DependencyPropertyChangedEventA { var cal = GetCalibration(d); var pos = GetPosition(d); - if (cal == null || pos == null) return; + if (cal == null || pos == null) + return; tx.X = pos.Lon * cal.PixelScaleX + cal.PixelOffsetX; tx.Y = pos.Lat * cal.PixelScaleY + cal.PixelOffsetY; @@ -60,7 +58,7 @@ public static void OnChanged(DependencyObject d, DependencyPropertyChangedEventA public class MapCalibration { public string Filename { get; set; } - + public double PixelOffsetX { get; set; } public double PixelOffsetY { get; set; } diff --git a/LarkatorGUI/Welcome.xaml.cs b/LarkatorGUI/Welcome.xaml.cs index 69525cd..27efec7 100644 --- a/LarkatorGUI/Welcome.xaml.cs +++ b/LarkatorGUI/Welcome.xaml.cs @@ -1,4 +1,5 @@ using Microsoft.Win32; + using System; using System.ComponentModel; using System.IO; @@ -30,7 +31,8 @@ public Welcome() // Skip the Welcome window if we're already configured UpdateValidation(); - if (LetsGoButton.IsEnabled) SwitchToMainWindow(); + if (LetsGoButton.IsEnabled) + SwitchToMainWindow(); } private void UpdateValidation() diff --git a/LarkatorGUI/WindowAspectRatio.cs b/LarkatorGUI/WindowAspectRatio.cs index 14ce52c..5dd3975 100644 --- a/LarkatorGUI/WindowAspectRatio.cs +++ b/LarkatorGUI/WindowAspectRatio.cs @@ -12,13 +12,13 @@ public class WindowAspectRatio { private Func calculateWidthFromHeightFn; - private WindowAspectRatio(Window window, Func calculateWidthFromHeight) + private WindowAspectRatio(Window window, Func calculateWidthFromHeight) { this.calculateWidthFromHeightFn = calculateWidthFromHeight; ((HwndSource)HwndSource.FromVisual(window)).AddHook(DragHook); } - public static void Register(Window window, Func calculateWidthFromHeight) + public static void Register(Window window, Func calculateWidthFromHeight) { new WindowAspectRatio(window, calculateWidthFromHeight); } @@ -54,7 +54,8 @@ private IntPtr DragHook(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref WINDOWPOS position = (WINDOWPOS)Marshal.PtrToStructure(lParam, typeof(WINDOWPOS)); if ((position.flags & (int)SWP.NoMove) != 0 || - HwndSource.FromHwnd(hwnd).RootVisual == null) return IntPtr.Zero; + HwndSource.FromHwnd(hwnd).RootVisual == null) + return IntPtr.Zero; position.cx = calculateWidthFromHeightFn(position.cy); @@ -66,4 +67,4 @@ private IntPtr DragHook(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref } } -} \ No newline at end of file +}