Initialize Map Guide Tab

This commit is contained in:
Chev 2021-02-03 18:06:47 -08:00
parent 3962cdb38c
commit 278091b09a
8 changed files with 165 additions and 0 deletions

View file

@ -34,7 +34,10 @@
<ItemGroup>
<Resource Include="appicon.ico" />
<Resource Include="Resources\BOTW\botw_map_quarter_size.jpg" />
<Resource Include="Resources\Icons\document.png" />
<Resource Include="Resources\Icons\hollow-circle.png" />
<Resource Include="Resources\Icons\horn.png" />
<Resource Include="Resources\Icons\letter-z.png" />
<Resource Include="Resources\Icons\mountain.png" />
<Resource Include="Resources\Icons\package.png" />

13
Control/MapPin.cs Normal file
View file

@ -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;
}
}

24
Control/TabMapGuide.xaml Normal file
View file

@ -0,0 +1,24 @@
<UserControl x:Class="BOTWToolset.Control.TabMapGuide"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:BOTWToolset.Control"
mc:Ignorable="d"
d:DesignHeight="600" d:DesignWidth="1280" Width="Auto" Height="Auto">
<Grid>
<Label Content="Map Guide" Margin="10,10,10,0" VerticalAlignment="Top" Height="48" FontSize="28" VerticalContentAlignment="Center" FontFamily="Segoe UI Light"/>
<Border Margin="10,63,0,10" HorizontalAlignment="Left" Width="64">
<StackPanel>
<Button x:Name="ViewMajorToS" Content="ToS Shrines" Height="64" Click="SwitchView"></Button>
<Button x:Name="ViewDragonPaths" Content="Dragon&#xD;&#xA;Paths" Height="64" Click="SwitchView"></Button>
</StackPanel>
</Border>
<Border Margin="79,63,10,10">
<Grid>
<Image x:Name="MapImage" Source="/Resources/BOTW/botw_map_quarter_size.jpg" Stretch="Uniform" HorizontalAlignment="Center"/>
<Canvas x:Name="MapArea" SizeChanged="MapSizeChanged" HorizontalAlignment="Stretch"/>
</Grid>
</Border>
</Grid>
</UserControl>

104
Control/TabMapGuide.xaml.cs Normal file
View file

@ -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
{
/// <summary>
/// Interaction logic for TabMapGuide.xaml
/// </summary>
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));
}
}
}
}

View file

@ -56,6 +56,9 @@
<TabItem x:Name="tabItemRSTB" Header="RSTB">
<local:TabRSTB x:Name="tabRSTB" x:FieldModifier="public"/>
</TabItem>
<TabItem x:Name="tabItemMapGuide" Header="Map Guide">
<local:TabMapGuide x:Name="tabMapGuide" x:FieldModifier="public"/>
</TabItem>
</TabControl>
<Label x:Name="LabelStatus" Content="" Margin="10,0,215,10" Height="26" VerticalAlignment="Bottom"/>
<Label x:Name="LabelVersion" Content="" Margin="0,0,10,10" HorizontalAlignment="Right" Width="200" Height="26" VerticalAlignment="Bottom" HorizontalContentAlignment="Right"/>

View file

@ -0,0 +1,18 @@
namespace BOTWToolset.Resources.BOTW
{
public static class PinLocations
{
//Shrine locations - {x, z} coordinates
public static int[][] MajorToSLocations = new int[][]
{
new int[] { -4400, -3832 },
new int[] { -3704, -3056 },
new int[] { -2808, -2888 },
new int[] { 3776, -2752 },
new int[] { -176, -1208 },
new int[] { -3472, -448 },
new int[] { -4632, 992 },
new int[] { 4016, 2992 }
};
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.9 KiB