From 278091b09ac351a1cb4617d4b114a4d236333958 Mon Sep 17 00:00:00 2001 From: Chev <11602755+chev2@users.noreply.github.com> Date: Wed, 3 Feb 2021 18:06:47 -0800 Subject: [PATCH] Initialize Map Guide Tab --- BOTWToolset.csproj | 3 + Control/MapPin.cs | 13 +++ Control/TabMapGuide.xaml | 24 ++++++ Control/TabMapGuide.xaml.cs | 104 +++++++++++++++++++++++ Dashboard.xaml | 3 + Resources/BOTW/PinLocations.cs | 18 ++++ Resources/BOTW/botw_map_quarter_size.jpg | Bin 0 -> 2252267 bytes Resources/Icons/hollow-circle.png | Bin 0 -> 7061 bytes 8 files changed, 165 insertions(+) create mode 100644 Control/MapPin.cs create mode 100644 Control/TabMapGuide.xaml create mode 100644 Control/TabMapGuide.xaml.cs create mode 100644 Resources/BOTW/PinLocations.cs create mode 100644 Resources/BOTW/botw_map_quarter_size.jpg create mode 100644 Resources/Icons/hollow-circle.png diff --git a/BOTWToolset.csproj b/BOTWToolset.csproj index 42144cf..d0bebed 100644 --- a/BOTWToolset.csproj +++ b/BOTWToolset.csproj @@ -34,7 +34,10 @@ + + + diff --git a/Control/MapPin.cs b/Control/MapPin.cs new file mode 100644 index 0000000..6b1b2e0 --- /dev/null +++ b/Control/MapPin.cs @@ -0,0 +1,13 @@ +using System.Windows.Controls; +using System.Windows.Media; + +namespace BOTWToolset.Control +{ + class MapPin : Image + { + public int X { get; set; } + public int Z { get; set; } + + public Color Color; + } +} diff --git a/Control/TabMapGuide.xaml b/Control/TabMapGuide.xaml new file mode 100644 index 0000000..5e794c6 --- /dev/null +++ b/Control/TabMapGuide.xaml @@ -0,0 +1,24 @@ + + + + diff --git a/Control/TabMapGuide.xaml.cs b/Control/TabMapGuide.xaml.cs new file mode 100644 index 0000000..b5968e1 --- /dev/null +++ b/Control/TabMapGuide.xaml.cs @@ -0,0 +1,104 @@ +using BOTWToolset.Resources.BOTW; +using System; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Media; +using System.Windows.Media.Imaging; + +namespace BOTWToolset.Control +{ + /// + /// Interaction logic for TabMapGuide.xaml + /// + public partial class TabMapGuide : UserControl + { + public TabMapGuide() + { + InitializeComponent(); + } + + private void SwitchView(object sender, RoutedEventArgs e) + { + ClearPins(); + + var sender_button = (Button)sender; + switch (sender_button.Name) + { + case "ViewMajorToS": + foreach (int[] coords in PinLocations.MajorToSLocations) + { + AddPin(coords, 16, @"Resources/Icons/hollow-circle.png", Color.FromRgb(255, 255, 255)); + } + break; + case "ViewYigaDeadzone": + break; + case "ViewDragonPaths": + break; + } + } + + private void AddPin(int[] coords, int pin_size, string pin_image, Color color) + { + var img_src = new BitmapImage(new Uri(@$"pack://application:,,,/{pin_image}")); + + // Initialize new image control, which will represent the map marker + MapPin pin = new MapPin(); + + // Set image properties + pin.Source = img_src; + pin.Width = pin_size; + pin.Height = pin_size; + pin.VerticalAlignment = VerticalAlignment.Top; + pin.HorizontalAlignment = HorizontalAlignment.Left; + + // Use proper aliasing + RenderOptions.SetBitmapScalingMode(pin, BitmapScalingMode.HighQuality); + + pin.X = coords[0]; + pin.Z = coords[1]; + + int[] pin_coords = FromBOTWCoordinate(pin.X, pin.Z); + + Canvas.SetLeft(pin, pin_coords[0] - (pin.Width / 2)); + Canvas.SetTop(pin, pin_coords[1] - (pin.Width / 2)); + + // Add the image control to the map area + MapArea.Children.Add(pin); + } + + private void ClearPins() + { + //Remove all map area children, excluding the map image itself + //MapArea.Children.RemoveRange(1, MapArea.Children.Count - 1); + MapArea.Children.Clear(); + } + + private int[] FromBOTWCoordinate(int x, int z) + { + // Difference between canvas and canvas background - used due to uniform bg resizing + double difference_width = (MapArea.ActualWidth - MapImage.ActualWidth) / 2; + double difference_height = (MapArea.ActualHeight - MapImage.ActualHeight) / 2; + + // -6000, -5000 top left, 6000, 5000 bottom right + double botw_img_ratio = 12000 / MapImage.ActualWidth; + + return new int[] { (int)(((x + 6000) / botw_img_ratio) + difference_width), (int)(((z + 5000) / botw_img_ratio) + difference_height) }; + } + + private void MapSizeChanged(object sender, SizeChangedEventArgs e) + { + // If the control doesn't have proper sizes yet, to prevent errors + if (e.PreviousSize.Width == 0 || e.PreviousSize.Height == 0) + return; + + foreach (var child in MapArea.Children) + { + var child_elem = (MapPin)child; + + int[] img_coords = FromBOTWCoordinate(child_elem.X, child_elem.Z); + Canvas.SetLeft(child_elem, img_coords[0] - (child_elem.Width / 2)); + Canvas.SetTop(child_elem, img_coords[1] - (child_elem.Width / 2)); + } + } + } +} diff --git a/Dashboard.xaml b/Dashboard.xaml index 25407b6..9271ef4 100644 --- a/Dashboard.xaml +++ b/Dashboard.xaml @@ -56,6 +56,9 @@ + + +