mirror of
				https://github.com/chev2/botw-toolset.git
				synced 2025-10-30 08:12:17 +00:00 
			
		
		
		
	UI new tabs
Updated TSCB to have a pixel view. Added SARC, Yaz0 & RSTB tabs.
This commit is contained in:
		
							parent
							
								
									3faa4b3d90
								
							
						
					
					
						commit
						e8332067d1
					
				
					 12 changed files with 942 additions and 34 deletions
				
			
		
							
								
								
									
										14
									
								
								botw-toolset/Control/TSCBAreaExpander.xaml
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								botw-toolset/Control/TSCBAreaExpander.xaml
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,14 @@ | |||
| <UserControl x:Class="BOTWToolset.Control.TSCBAreaExpander" | ||||
|              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="450" d:DesignWidth="250"> | ||||
|     <Grid> | ||||
|         <Expander x:Name="AreaExpander" Header="Expander"> | ||||
|             <Grid Background="Transparent"/> | ||||
|         </Expander> | ||||
|     </Grid> | ||||
| </UserControl> | ||||
							
								
								
									
										15
									
								
								botw-toolset/Control/TSCBAreaExpander.xaml.cs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								botw-toolset/Control/TSCBAreaExpander.xaml.cs
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,15 @@ | |||
| using System.Windows.Controls; | ||||
| 
 | ||||
| namespace BOTWToolset.Control | ||||
| { | ||||
|     /// <summary> | ||||
|     /// Interaction logic for TSCBAreaExpander.xaml | ||||
|     /// </summary> | ||||
|     public partial class TSCBAreaExpander : UserControl | ||||
|     { | ||||
|         public TSCBAreaExpander() | ||||
|         { | ||||
|             InitializeComponent(); | ||||
|         } | ||||
|     } | ||||
| } | ||||
							
								
								
									
										12
									
								
								botw-toolset/Control/TabRSTB.xaml
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								botw-toolset/Control/TabRSTB.xaml
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,12 @@ | |||
| <UserControl x:Class="BOTWToolset.Control.TabRSTB" | ||||
|              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="597" d:DesignWidth="1246 " Width="Auto" Height="Auto"> | ||||
|     <Grid> | ||||
|         <Label Content="RSTB Editor" Margin="10,10,10,0" VerticalAlignment="Top" Height="48" FontSize="28" VerticalContentAlignment="Center" FontFamily="Segoe UI Light"/> | ||||
|     </Grid> | ||||
| </UserControl> | ||||
							
								
								
									
										15
									
								
								botw-toolset/Control/TabRSTB.xaml.cs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								botw-toolset/Control/TabRSTB.xaml.cs
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,15 @@ | |||
| using System.Windows.Controls; | ||||
| 
 | ||||
| namespace BOTWToolset.Control | ||||
| { | ||||
|     /// <summary> | ||||
|     /// Interaction logic for TabRSTB.xaml | ||||
|     /// </summary> | ||||
|     public partial class TabRSTB : UserControl | ||||
|     { | ||||
|         public TabRSTB() | ||||
|         { | ||||
|             InitializeComponent(); | ||||
|         } | ||||
|     } | ||||
| } | ||||
							
								
								
									
										67
									
								
								botw-toolset/Control/TabSARC.xaml
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										67
									
								
								botw-toolset/Control/TabSARC.xaml
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,67 @@ | |||
| <UserControl x:Class="BOTWToolset.Control.TabSARC" | ||||
|              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="597" d:DesignWidth="1246 " Width="Auto" Height="Auto"> | ||||
|     <Grid> | ||||
|         <Label Content="SARC Packer/Extractor" Margin="10,10,10,0" VerticalAlignment="Top" Height="48" FontSize="28" VerticalContentAlignment="Center" FontFamily="Segoe UI Light"/> | ||||
| 
 | ||||
|         <Menu Margin="10,58,10,0" VerticalAlignment="Top"> | ||||
|             <MenuItem Header="_File" Foreground="White"> | ||||
|                 <MenuItem x:Name="MenuFileOpen" Header="_Open" InputGestureText="Ctrl+O" Click="Menu_FileOpen"/> | ||||
|                 <MenuItem x:Name="MenuFileSave" Header="_Save" InputGestureText="Ctrl+S" Click="Menu_FileSave" IsEnabled="False"/> | ||||
|                 <MenuItem x:Name="MenuFileSaveAs" Header="_Save As" InputGestureText="Ctrl+Shift+S" Click="Menu_FileSaveAs" IsEnabled="False"/> | ||||
|                 <MenuItem x:Name="MenuFileClose" Header="_Close" Click="Menu_FileClose" IsEnabled="False"/> | ||||
|             </MenuItem> | ||||
|         </Menu> | ||||
|         <Border Margin="10,81,10,10"> | ||||
|             <Grid> | ||||
|                 <Grid Margin="0,0,628,0"> | ||||
|                     <Label x:Name="FileCount" Margin="10,10,10,0" VerticalAlignment="Top" Height="48" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" FontSize="24" Content=""/> | ||||
|                     <Border Margin="10,63,10,10"> | ||||
|                         <ScrollViewer VerticalScrollBarVisibility="Auto"> | ||||
|                             <StackPanel x:Name="FileDisplay" HorizontalAlignment="Left" Margin="9,9,0,9" Width="556" CanVerticallyScroll="True" ScrollViewer.VerticalScrollBarVisibility="Auto"/> | ||||
|                         </ScrollViewer> | ||||
|                     </Border> | ||||
|                 </Grid> | ||||
|                 <Grid HorizontalAlignment="Right" Width="629"> | ||||
|                     <Label Content="SARC Header" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Height="32" Width="609" FontSize="18" VerticalContentAlignment="Center"/> | ||||
| 
 | ||||
|                     <Label Content="Magic" Margin="10,47,317,0" VerticalAlignment="Top"/> | ||||
|                     <TextBox x:Name="SARCMagic" Height="23" Margin="10,78,317,0" TextWrapping="Wrap" VerticalAlignment="Top" IsReadOnly="True" VerticalContentAlignment="Center"/> | ||||
|                     <Label Content="Header Length" Margin="317,47,10,0" VerticalAlignment="Top" HorizontalContentAlignment="Right"/> | ||||
|                     <TextBox x:Name="SARCHeaderLength" Height="23" Margin="0,78,10,0" TextWrapping="Wrap" VerticalAlignment="Top" IsReadOnly="True" VerticalContentAlignment="Center" HorizontalContentAlignment="Right" HorizontalAlignment="Right" Width="302"/> | ||||
|                     <Label Content="Uses Big Endian" Margin="10,106,317,0" VerticalAlignment="Top"/> | ||||
|                     <TextBox x:Name="SARCIsBigEndian" Height="23" Margin="10,137,317,0" TextWrapping="Wrap" VerticalAlignment="Top" IsReadOnly="True" VerticalContentAlignment="Center"/> | ||||
|                     <Label Content="File Size" Margin="317,106,10,0" VerticalAlignment="Top" HorizontalContentAlignment="Right"/> | ||||
|                     <TextBox x:Name="SARCFileSize" Height="23" Margin="0,137,10,0" TextWrapping="Wrap" VerticalAlignment="Top" IsReadOnly="True" VerticalContentAlignment="Center" HorizontalContentAlignment="Right" HorizontalAlignment="Right" Width="302"/> | ||||
|                     <Label Content="Data Offset" Margin="10,165,317,0" VerticalAlignment="Top"/> | ||||
|                     <TextBox x:Name="SARCDataOffset" Height="23" Margin="10,196,317,0" TextWrapping="Wrap" VerticalAlignment="Top" IsReadOnly="True" VerticalContentAlignment="Center"/> | ||||
|                     <Label Content="Version" Margin="317,165,10,0" VerticalAlignment="Top" HorizontalContentAlignment="Right"/> | ||||
|                     <TextBox x:Name="SARCVersion" Height="23" Margin="0,196,10,0" TextWrapping="Wrap" VerticalAlignment="Top" IsReadOnly="True" VerticalContentAlignment="Center" HorizontalContentAlignment="Right" HorizontalAlignment="Right" Width="302"/> | ||||
| 
 | ||||
|                     <Label Content="SFAT Header" HorizontalAlignment="Left" Margin="10,224,0,0" VerticalAlignment="Top" Height="32" Width="609" FontSize="18" VerticalContentAlignment="Center"/> | ||||
| 
 | ||||
|                     <Label Content="Magic" Margin="10,261,317,0" VerticalAlignment="Top"/> | ||||
|                     <TextBox x:Name="SFATMagic" Height="23" Margin="10,292,317,0" TextWrapping="Wrap" VerticalAlignment="Top" IsReadOnly="True" VerticalContentAlignment="Center"/> | ||||
|                     <Label Content="Header Length" Margin="317,261,10,0" VerticalAlignment="Top" HorizontalContentAlignment="Right"/> | ||||
|                     <TextBox x:Name="SFATHeaderLength" Height="23" Margin="0,292,10,0" TextWrapping="Wrap" VerticalAlignment="Top" IsReadOnly="True" VerticalContentAlignment="Center" HorizontalContentAlignment="Right" HorizontalAlignment="Right" Width="302"/> | ||||
|                     <Label Content="Node Count" Margin="10,320,317,0" VerticalAlignment="Top"/> | ||||
|                     <TextBox x:Name="SFATNodeCount" Height="23" Margin="10,351,317,0" TextWrapping="Wrap" VerticalAlignment="Top" IsReadOnly="True" VerticalContentAlignment="Center"/> | ||||
|                     <Label Content="Hash Key" Margin="317,320,10,0" VerticalAlignment="Top" HorizontalContentAlignment="Right"/> | ||||
|                     <TextBox x:Name="SFATHashKey" Height="23" Margin="0,351,10,0" TextWrapping="Wrap" VerticalAlignment="Top" IsReadOnly="True" VerticalContentAlignment="Center" HorizontalContentAlignment="Right" HorizontalAlignment="Right" Width="302"/> | ||||
|                     <Label Content="Magic" Margin="10,416,317,0" VerticalAlignment="Top"/> | ||||
| 
 | ||||
|                     <Label Content="SFNT Header" HorizontalAlignment="Left" Margin="10,379,0,0" VerticalAlignment="Top" Height="32" Width="609" FontSize="18" VerticalContentAlignment="Center"/> | ||||
| 
 | ||||
|                     <TextBox x:Name="SFNTMagic" Height="23" Margin="10,447,317,0" TextWrapping="Wrap" VerticalAlignment="Top" IsReadOnly="True" VerticalContentAlignment="Center"/> | ||||
|                     <Label Content="Header Length" Margin="317,416,10,0" VerticalAlignment="Top" HorizontalContentAlignment="Right"/> | ||||
|                     <TextBox x:Name="SFNTHeaderLength" Height="23" Margin="0,447,10,0" TextWrapping="Wrap" VerticalAlignment="Top" IsReadOnly="True" VerticalContentAlignment="Center" HorizontalContentAlignment="Right" HorizontalAlignment="Right" Width="302"/> | ||||
|                 </Grid> | ||||
|             </Grid> | ||||
|         </Border> | ||||
|     </Grid> | ||||
| </UserControl> | ||||
							
								
								
									
										168
									
								
								botw-toolset/Control/TabSARC.xaml.cs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										168
									
								
								botw-toolset/Control/TabSARC.xaml.cs
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,168 @@ | |||
| using BOTWToolset.Debugging; | ||||
| using BOTWToolset.IO.SARC; | ||||
| using Microsoft.Win32; | ||||
| using System.Windows; | ||||
| using System.Windows.Controls; | ||||
| 
 | ||||
| namespace BOTWToolset.Control | ||||
| { | ||||
|     /// <summary> | ||||
|     /// Interaction logic for TabSARC.xaml | ||||
|     /// </summary> | ||||
|     public partial class TabSARC : UserControl | ||||
|     { | ||||
|         public static string fileLocation; | ||||
|         public static SARC currentSARC; | ||||
| 
 | ||||
|         public TabSARC() | ||||
|         { | ||||
|             InitializeComponent(); | ||||
|         } | ||||
| 
 | ||||
|         public void SetEnabled(SARC s) | ||||
|         { | ||||
|             // SARC header | ||||
|             SARCMagic.Text = s.Magic; | ||||
|             SARCHeaderLength.Text = s.HeaderLength.ToString(); | ||||
|             SARCIsBigEndian.Text = s.IsBigEndian ? "Yes" : "No"; | ||||
|             SARCFileSize.Text = s.FileSize.ToString(); | ||||
|             SARCDataOffset.Text = s.DataOffset.ToString(); | ||||
|             SARCVersion.Text = s.Version.ToString(); | ||||
| 
 | ||||
|             // SFAT header | ||||
|             SFATMagic.Text = s.SFAT.Magic; | ||||
|             SFATHeaderLength.Text = s.SFAT.HeaderLength.ToString(); | ||||
|             SFATNodeCount.Text = s.SFAT.NodeCount.ToString(); | ||||
|             SFATHashKey.Text = s.SFAT.HashKey.ToString(); | ||||
| 
 | ||||
|             // SFNT header | ||||
|             SFNTMagic.Text = s.SFNT.Magic; | ||||
|             SFNTHeaderLength.Text = s.SFNT.HeaderLength.ToString(); | ||||
| 
 | ||||
|             // Show file count | ||||
|             FileCount.Content = $"SARC file count: {s.SFAT.NodeCount}"; | ||||
| 
 | ||||
|             for (int i = 0; i < s.SFNT.FileNames.Length; i++) | ||||
|             { | ||||
|                 string file_name = s.SFNT.FileNames[i]; | ||||
|                 int file_size = s.Files[i].Length; | ||||
| 
 | ||||
|                 Grid grid = new Grid | ||||
|                 { | ||||
|                     Height = 112 | ||||
|                 }; | ||||
| 
 | ||||
|                 Label title = new Label | ||||
|                 { | ||||
|                     Height = 44, | ||||
|                     Content = file_name, | ||||
|                     FontSize = 20, | ||||
|                     Margin = new Thickness(10, 10, 10, 0), | ||||
|                     VerticalAlignment = VerticalAlignment.Top, | ||||
|                     VerticalContentAlignment = VerticalAlignment.Center | ||||
|                 }; | ||||
| 
 | ||||
|                 Label desc = new Label | ||||
|                 { | ||||
|                     Content = $"{file_size:n0} bytes", | ||||
|                     Margin = new Thickness(10, 59, 10, 10), | ||||
|                     FontSize = 16, | ||||
|                     VerticalContentAlignment = VerticalAlignment.Center | ||||
|                 }; | ||||
| 
 | ||||
|                 grid.Children.Add(title); | ||||
|                 grid.Children.Add(desc); | ||||
| 
 | ||||
|                 FileDisplay.Children.Add(grid); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         public void SetDisabled() | ||||
|         { | ||||
|             // SARC header | ||||
|             SARCMagic.Clear(); | ||||
|             SARCHeaderLength.Clear(); | ||||
|             SARCIsBigEndian.Clear(); | ||||
|             SARCFileSize.Clear(); | ||||
|             SARCDataOffset.Clear(); | ||||
|             SARCVersion.Clear(); | ||||
| 
 | ||||
|             // SFAT header | ||||
|             SFATMagic.Clear(); | ||||
|             SFATHeaderLength.Clear(); | ||||
|             SFATNodeCount.Clear(); | ||||
|             SFATHashKey.Clear(); | ||||
| 
 | ||||
|             // SFNT header | ||||
|             SFNTMagic.Clear(); | ||||
|             SFNTHeaderLength.Clear(); | ||||
| 
 | ||||
|             // SARC Files | ||||
|             FileCount.Content = ""; | ||||
|             FileDisplay.Children.Clear(); | ||||
|         } | ||||
| 
 | ||||
|         private void Menu_FileOpen(object sender, RoutedEventArgs e) | ||||
|         { | ||||
|             BOTWConsole.Log("Clicked File -> Open button"); | ||||
| 
 | ||||
|             var openFileDialog = new OpenFileDialog | ||||
|             { | ||||
|                 InitialDirectory = @"C:\", | ||||
|                 RestoreDirectory = true, | ||||
|                 Title = "Select SARC file", | ||||
|                 DefaultExt = "sarc", | ||||
|                 Filter = "SARC files (*.arc;*.sarc;*.blarc;*.bgenv;*.genvb;*.pack;*.bars;*.stera)|*.arc;*.sarc;*.blarc;*.bgenv;*.genvb;*.pack;*.bars;*.stera|All files (*.*)|*.*", | ||||
|                 CheckFileExists = true | ||||
|             }; | ||||
| 
 | ||||
|             if ((bool)openFileDialog.ShowDialog()) | ||||
|             { | ||||
|                 BOTWConsole.Log("Opening file"); | ||||
| 
 | ||||
|                 SARC s = SARC.ReadFile(openFileDialog.FileName); | ||||
| 
 | ||||
|                 // Set the current file location to the chosen file's location | ||||
|                 fileLocation = openFileDialog.FileName; | ||||
| 
 | ||||
|                 currentSARC = s; | ||||
| 
 | ||||
|                 // Display info in the tab | ||||
|                 SetEnabled(s); | ||||
| 
 | ||||
|                 // Enable file edits | ||||
|                 MenuFileClose.IsEnabled = true; | ||||
|                 MenuFileSave.IsEnabled = true; | ||||
|                 MenuFileSaveAs.IsEnabled = true; | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         private void Menu_FileClose(object sender, RoutedEventArgs e) | ||||
|         { | ||||
|             BOTWConsole.Log("Clicked File -> Close button"); | ||||
| 
 | ||||
|             fileLocation = null; | ||||
| 
 | ||||
|             // Set the current TSCB info to nothing | ||||
|             currentSARC = null; | ||||
| 
 | ||||
|             // Set the tab as disabled | ||||
|             SetDisabled(); | ||||
| 
 | ||||
|             // Disable file edits | ||||
|             MenuFileClose.IsEnabled = false; | ||||
|             MenuFileSave.IsEnabled = false; | ||||
|             MenuFileSaveAs.IsEnabled = false; | ||||
|         } | ||||
| 
 | ||||
|         private void Menu_FileSave(object sender, RoutedEventArgs e) | ||||
|         { | ||||
| 
 | ||||
|         } | ||||
| 
 | ||||
|         private void Menu_FileSaveAs(object sender, RoutedEventArgs e) | ||||
|         { | ||||
| 
 | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | @ -1,9 +1,9 @@ | |||
| <UserControl x:Class="BOTWToolset.TabTSCB" | ||||
| <UserControl x:Class="BOTWToolset.Control.TabTSCB" | ||||
|              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" | ||||
|              xmlns:local="clr-namespace:BOTWToolset.Control" | ||||
|              mc:Ignorable="d"  | ||||
|              d:DesignHeight="597" d:DesignWidth="1246 " Width="Auto" Height="Auto"> | ||||
|     <Grid> | ||||
|  | @ -11,12 +11,16 @@ | |||
| 
 | ||||
|         <Menu Margin="10,58,10,0" VerticalAlignment="Top"> | ||||
|             <MenuItem Header="_File" Foreground="White"> | ||||
|                 <MenuItem x:Name="MenuFileOpen" Header="_Open" InputGestureText="Ctrl+O" Click="Menu_OpenFile"/> | ||||
|                 <MenuItem x:Name="MenuFileClose" Header="_Close" Click="Menu_CloseFile"/> | ||||
|                 <MenuItem x:Name="MenuFileSave" Header="_Save" InputGestureText="Ctrl+S" Click="Menu_SaveFile" IsEnabled="False"/> | ||||
|                 <MenuItem x:Name="MenuFileOpen" Header="_Open" Click="Menu_FileOpen" InputGestureText="Ctrl+O"/> | ||||
|                 <MenuItem x:Name="MenuFileSave" Header="_Save" Click="Menu_FileSave" InputGestureText="Ctrl+S" IsEnabled="False"/> | ||||
|                 <MenuItem x:Name="MenuFileClose" Header="_Close" Click="Menu_FileClose" IsEnabled="False"/> | ||||
|             </MenuItem> | ||||
|         </Menu> | ||||
|         <Border BorderThickness="1" Margin="10,81,293,145"/> | ||||
|         <Border BorderThickness="1" Margin="10,81,536,145"> | ||||
|             <Grid x:Name="PixelViewBorder"> | ||||
|                 <Image x:Name="PixelView" Margin="10"/> | ||||
|             </Grid> | ||||
|         </Border> | ||||
|         <Border BorderThickness="1" Margin="0,81,10,10" HorizontalAlignment="Right" Width="278"> | ||||
|             <Grid> | ||||
|                 <Label Content="Signature" HorizontalAlignment="Left" Margin="10,0,0,195" Width="120" Height="26" VerticalAlignment="Bottom"/> | ||||
|  | @ -36,10 +40,32 @@ | |||
|                 <Label Content="Tile Size" HorizontalAlignment="Left" Margin="146,0,0,33" Width="120" HorizontalContentAlignment="Right" Height="26" VerticalAlignment="Bottom"/> | ||||
|                 <TextBox x:Name="TileSize" x:FieldModifier="public" Margin="146,0,10,10" TextWrapping="Wrap" Text="" VerticalContentAlignment="Center" IsReadOnly="True" Height="23" VerticalAlignment="Bottom"/> | ||||
|                 <Border BorderThickness="1" HorizontalAlignment="Left" Margin="10,10,0,226" Width="256"> | ||||
|                     <ScrollViewer VerticalScrollBarVisibility="Auto"> | ||||
|                         <StackPanel x:Name="TSCBAreaViewer" x:FieldModifier="public"/> | ||||
|                     </ScrollViewer> | ||||
|                 </Border> | ||||
|             </Grid> | ||||
|         </Border> | ||||
|         <TextBox x:Name="TSCBConsole" x:FieldModifier="public" TextWrapping="Wrap" Text="" Margin="10,0,293,10" Height="130" VerticalAlignment="Bottom" UndoLimit="1" AllowDrop="False" FontFamily="Consolas" VerticalScrollBarVisibility="Auto" IsReadOnly="True"/> | ||||
|         <Border Margin="0,81,293,145" HorizontalAlignment="Right" Width="238"> | ||||
|             <Grid x:Name="PixelViewTypes"> | ||||
|                 <Button x:Name="PixelViewMATE" Content="Texture View" Margin="10,10,10,0" Height="32" VerticalAlignment="Top" IsEnabled="False" Click="PixelView_UpdateView"/> | ||||
|                 <Button x:Name="PixelViewHGHT" Content="Height View" Margin="10,47,10,0" Height="32" VerticalAlignment="Top" IsEnabled="False" Click="PixelView_UpdateView"/> | ||||
|                 <Button x:Name="PixelViewGrassEXTM" Content="Grass Height View" Margin="10,84,10,0" Height="32" VerticalAlignment="Top" IsEnabled="False" Click="PixelView_UpdateView"/> | ||||
|                 <Button x:Name="PixelViewWaterEXTM" Content="Water Height View" Margin="10,121,10,0" Height="32" VerticalAlignment="Top" IsEnabled="False" Click="PixelView_UpdateView"/> | ||||
| 
 | ||||
|                 <Label Content="Zoom" Margin="10,0,10,162" Height="26" VerticalAlignment="Bottom" HorizontalContentAlignment="Center"/> | ||||
|                 <Slider x:Name="SliderZoomLevel" Margin="10,0,10,129" Height="28" VerticalAlignment="Bottom" Maximum="8" SmallChange="1" IsSnapToTickEnabled="True" TickPlacement="TopLeft"/> | ||||
|                  | ||||
|                 <Label Content="Min Terrain Height" Margin="10,0,69,103" Height="26" VerticalAlignment="Bottom"/> | ||||
|                 <TextBox x:Name="OverrideMinTerrainHeight" Margin="172,0,10,103" VerticalContentAlignment="Center" Height="26" VerticalAlignment="Bottom" KeyDown="OverrideKeyDown" IsEnabled="False"/> | ||||
|                 <Label Content="Max Terrain Height" Margin="10,0,69,72" Height="26" VerticalAlignment="Bottom"/> | ||||
|                 <TextBox x:Name="OverrideMaxTerrainHeight" Margin="172,0,10,72" VerticalContentAlignment="Center" Height="26" VerticalAlignment="Bottom" KeyDown="OverrideKeyDown" IsEnabled="False"/> | ||||
|                 <Label Content="Min Water Height" Margin="10,0,69,41" Height="26" VerticalAlignment="Bottom"/> | ||||
|                 <TextBox x:Name="OverrideMinWaterHeight" Margin="172,0,10,41" VerticalContentAlignment="Center" Height="26" VerticalAlignment="Bottom" KeyDown="OverrideKeyDown" IsEnabled="False"/> | ||||
|                 <Label Content="Max Water Height" Margin="10,0,69,10" Height="26" VerticalAlignment="Bottom"/> | ||||
|                 <TextBox x:Name="OverrideMaxWaterHeight" Margin="172,0,10,10" VerticalContentAlignment="Center" Height="26" VerticalAlignment="Bottom"  KeyDown="OverrideKeyDown" IsEnabled="False"/> | ||||
|             </Grid> | ||||
|         </Border> | ||||
|     </Grid> | ||||
| </UserControl> | ||||
|  |  | |||
|  | @ -1,9 +1,19 @@ | |||
| using BOTWToolset.Debugging; | ||||
| using BOTWToolset.IO; | ||||
| using BOTWToolset.IO.EXTM; | ||||
| using BOTWToolset.IO.SARC; | ||||
| using BOTWToolset.IO.TSCB; | ||||
| using BOTWToolset.IO.Yaz0; | ||||
| using Microsoft.Win32; | ||||
| using System; | ||||
| using System.IO; | ||||
| using System.Windows; | ||||
| using System.Windows.Controls; | ||||
| using System.Windows.Input; | ||||
| using System.Windows.Media; | ||||
| using System.Windows.Media.Imaging; | ||||
| 
 | ||||
| namespace BOTWToolset | ||||
| namespace BOTWToolset.Control | ||||
| { | ||||
|     /// <summary> | ||||
|     /// Control tab for TSCB management | ||||
|  | @ -11,26 +21,314 @@ namespace BOTWToolset | |||
|     public partial class TabTSCB : UserControl | ||||
|     { | ||||
|         public static string fileLocation; | ||||
|         public static TSCBInfo currentTSCBInfo; | ||||
|         public static TSCB currentTSCB; | ||||
| 
 | ||||
|         public static WriteableBitmap writeableBitmap; //used for pixel-like display | ||||
| 
 | ||||
|         public TabTSCB() | ||||
|         { | ||||
|             InitializeComponent(); | ||||
| 
 | ||||
|             RenderOptions.SetBitmapScalingMode(PixelView, BitmapScalingMode.NearestNeighbor); // Nearest-neighbor sampling | ||||
|             //RenderOptions.SetEdgeMode(i, EdgeMode.Unspecified); | ||||
| 
 | ||||
|             //Placeholder image | ||||
|             writeableBitmap = new WriteableBitmap(4, 4, 16, 16, PixelFormats.Rgb24, null); | ||||
| 
 | ||||
|             PixelView.Source = writeableBitmap; | ||||
|             PixelView.Stretch = Stretch.Uniform; | ||||
| 
 | ||||
|             PixelView.MouseLeftButtonDown += new MouseButtonEventHandler(PixelView_MouseLeft); | ||||
|             //PixelViewBorder.MouseWheel += new MouseWheelEventHandler(PixelViewBorder_MouseWheel); | ||||
|         } | ||||
| 
 | ||||
|         public void SetSidebarHeaderInfo(TSCBInfo t) | ||||
|         private void ClearBitmap() | ||||
|         { | ||||
|             PixelView.Source = null; | ||||
|             writeableBitmap = null; | ||||
|             GC.Collect(); | ||||
|         } | ||||
| 
 | ||||
|         private void DrawPixel(MouseEventArgs e) | ||||
|         { | ||||
| 
 | ||||
|         } | ||||
| 
 | ||||
|         private void ErasePixel(MouseEventArgs e) | ||||
|         { | ||||
| 
 | ||||
|         } | ||||
| 
 | ||||
|         private void PixelView_MouseLeft(object sender, MouseButtonEventArgs e) | ||||
|         { | ||||
|             DrawPixel(e); | ||||
|         } | ||||
| 
 | ||||
|         public void PixelViewBorder_MouseWheel(object sender, MouseWheelEventArgs e) | ||||
|         { | ||||
|             Matrix m = PixelView.RenderTransform.Value; | ||||
| 
 | ||||
|             if (e.Delta > 0) | ||||
|             { | ||||
|                 m.ScaleAt(1.5f, 1.5f, e.GetPosition(PixelViewBorder).X, e.GetPosition(PixelViewBorder).Y); | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 m.ScaleAt(2 / 3, 2 / 3, e.GetPosition(PixelViewBorder).X, e.GetPosition(PixelViewBorder).Y); | ||||
|             } | ||||
| 
 | ||||
|             PixelView.RenderTransform = new MatrixTransform(m); | ||||
|         } | ||||
| 
 | ||||
|         private void PixelView_UpdateView(object sender, RoutedEventArgs e) | ||||
|         { | ||||
|             byte zoom = (byte)SliderZoomLevel.Value; | ||||
| 
 | ||||
|             // Get the parent directory of the files directory | ||||
|             DirectoryInfo parent = Directory.GetParent(fileLocation); | ||||
|             string main_field_dir = Path.Combine(parent.FullName, "MainField"); | ||||
| 
 | ||||
|             Button sender_button = (Button)sender; | ||||
| 
 | ||||
|             if (Directory.Exists(main_field_dir)) | ||||
|             { | ||||
|                 switch (sender_button.Name) | ||||
|                 { | ||||
|                     case "PixelViewMATE": | ||||
|                         { | ||||
|                             string extension = ".mate.sstera"; | ||||
|                             int img_size = (int)Math.Pow(2, 8 + zoom); | ||||
| 
 | ||||
|                             ClearBitmap(); | ||||
|                             writeableBitmap = new WriteableBitmap(img_size, img_size, 16, 16, PixelFormats.Rgb24, null); | ||||
|                             PixelView.Source = writeableBitmap; | ||||
| 
 | ||||
|                             PixelView_SetMATE(main_field_dir, extension, zoom, 256); | ||||
|                         } | ||||
|                         break; | ||||
|                     case "PixelViewHGHT": | ||||
|                         { | ||||
|                             string extension = ".hght.sstera"; | ||||
|                             int img_size = (int)Math.Pow(2, 8 + zoom); | ||||
| 
 | ||||
|                             ClearBitmap(); | ||||
|                             writeableBitmap = new WriteableBitmap(img_size, img_size, 16, 16, PixelFormats.Gray8, null); | ||||
|                             PixelView.Source = writeableBitmap; | ||||
| 
 | ||||
|                             PixelView_SetHGHT(main_field_dir, extension, zoom, 256); | ||||
|                         } | ||||
|                         break; | ||||
|                     case "PixelViewGrassEXTM": | ||||
|                         { | ||||
|                             string extension = ".grass.extm.sstera"; | ||||
|                             int img_size = (int)Math.Pow(2, 6 + zoom); | ||||
| 
 | ||||
|                             ClearBitmap(); | ||||
|                             writeableBitmap = new WriteableBitmap(img_size, img_size, 16, 16, PixelFormats.Rgb24, null); | ||||
|                             PixelView.Source = writeableBitmap; | ||||
| 
 | ||||
|                             PixelView_SetGrassEXTM(main_field_dir, extension, zoom, 64); | ||||
|                         } | ||||
|                         break; | ||||
|                     case "PixelViewWaterEXTM": | ||||
|                         { | ||||
|                             string extension = ".water.extm.sstera"; | ||||
|                             int img_size = (int)Math.Pow(2, 6 + zoom); | ||||
| 
 | ||||
|                             ClearBitmap(); | ||||
|                             writeableBitmap = new WriteableBitmap(img_size, img_size, 16, 16, PixelFormats.Rgb24, null); | ||||
|                             PixelView.Source = writeableBitmap; | ||||
| 
 | ||||
|                             PixelView_SetWaterEXTM(main_field_dir, extension, zoom, 64); | ||||
|                         } | ||||
|                         break; | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         private void PixelView_SetMATE(string folder, string extension, byte zoom_level, int grid_size) | ||||
|         { | ||||
|             BOTWConsole.Log("Setting view to texture"); | ||||
|             string[] ext_files = Directory.GetFiles(folder, $"5{zoom_level}*{extension}"); | ||||
| 
 | ||||
|             foreach (string ext_file in ext_files) | ||||
|             { | ||||
|                 byte[] yaz0_bytes = File.ReadAllBytes(Path.Combine(folder, ext_file)); | ||||
|                 byte[] yaz0_decomp = Yaz0.Decompress(yaz0_bytes); | ||||
|                 SARC s = SARC.FromBytes(new MemoryStream(yaz0_decomp)); | ||||
| 
 | ||||
|                 for (int i = 0; i < s.Files.Length; i++) | ||||
|                 { | ||||
|                     // Get grid index from filename | ||||
|                     string grid_index_str = s.SFNT.FileNames[i].Replace($"5{zoom_level}", "").Replace(extension.Replace(".sstera", ""), "").Replace(folder + "\\", ""); | ||||
|                     int grid_index = int.Parse(grid_index_str, System.Globalization.NumberStyles.HexNumber); | ||||
|                     int[] xyoffs = GridConverter.ZCurveToXY(grid_index); | ||||
|                     MATE[] mats = MATE.FromBytes(s.Files[i]); | ||||
| 
 | ||||
|                     for (int j = 0; j < mats.Length; j++) | ||||
|                     { | ||||
|                         MATE m = mats[j]; | ||||
| 
 | ||||
|                         int x = j % grid_size; | ||||
|                         int y = j / grid_size; | ||||
| 
 | ||||
|                         // Draw pixel at the correct X, Y coordinate | ||||
|                         Int32Rect rect = new Int32Rect(x + (xyoffs[0] * grid_size), y + (xyoffs[1] * grid_size), 1, 1); | ||||
|                         // Get this water's color based off its material index/water type | ||||
|                         System.Drawing.Color c = GridColors.MaterialColors[m.Material0]; | ||||
|                         // Use water type color + brightness adjust | ||||
|                         byte[] color = new byte[] { c.R, c.G, c.B }; | ||||
| 
 | ||||
|                         writeableBitmap.WritePixels(rect, color, writeableBitmap.BackBufferStride, 0); | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         private void PixelView_SetHGHT(string folder, string extension, byte zoom_level, int grid_size) | ||||
|         { | ||||
|             BOTWConsole.Log("Setting view to heightmap"); | ||||
|             string[] ext_files = Directory.GetFiles(folder, $"5{zoom_level}*{extension}"); | ||||
| 
 | ||||
|             foreach (string ext_file in ext_files) | ||||
|             { | ||||
|                 byte[] yaz0_bytes = File.ReadAllBytes(Path.Combine(folder, ext_file)); | ||||
|                 byte[] yaz0_decomp = Yaz0.Decompress(yaz0_bytes); | ||||
|                 SARC s = SARC.FromBytes(new MemoryStream(yaz0_decomp)); | ||||
| 
 | ||||
|                 for (int i = 0; i < s.Files.Length; i++) | ||||
|                 { | ||||
|                     // Get grid index from filename | ||||
|                     string grid_index_str = s.SFNT.FileNames[i].Replace($"5{zoom_level}", "").Replace(extension.Replace(".sstera", ""), "").Replace(folder + "\\", ""); | ||||
|                     int grid_index = int.Parse(grid_index_str, System.Globalization.NumberStyles.HexNumber); | ||||
|                     int[] xyoffs = GridConverter.ZCurveToXY(grid_index); | ||||
|                     HGHT h = HGHT.FromBytes(s.Files[i]); | ||||
| 
 | ||||
|                     for (int j = 0; j < h.Heights.Length; j++) | ||||
|                     { | ||||
|                         ushort height = h.Heights[j]; | ||||
| 
 | ||||
|                         int x = j % grid_size; | ||||
|                         int y = j / grid_size; | ||||
| 
 | ||||
|                         // Draw pixel at the correct X, Y coordinate | ||||
|                         Int32Rect rect = new Int32Rect(x + (xyoffs[0] * grid_size), y + (xyoffs[1] * grid_size), 1, 1); | ||||
|                         // Brightness | ||||
|                         byte brightness = (byte)(height / 65535f * 255f); | ||||
|                         // Use water type color + brightness adjust | ||||
|                         byte[] color = new byte[] { brightness }; | ||||
| 
 | ||||
|                         writeableBitmap.WritePixels(rect, color, writeableBitmap.BackBufferStride, 0); | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         private void PixelView_SetGrassEXTM(string folder, string extension, byte zoom_level, int grid_size) | ||||
|         { | ||||
|             BOTWConsole.Log("Setting view to grass"); | ||||
|             string[] ext_files = Directory.GetFiles(folder, $"5{zoom_level}*{extension}"); | ||||
| 
 | ||||
|             foreach (string ext_file in ext_files) | ||||
|             { | ||||
|                 byte[] yaz0_bytes = File.ReadAllBytes(Path.Combine(folder, ext_file)); | ||||
|                 byte[] yaz0_decomp = Yaz0.Decompress(yaz0_bytes); | ||||
|                 SARC s = SARC.FromBytes(new MemoryStream(yaz0_decomp)); | ||||
| 
 | ||||
|                 for (int i = 0; i < s.Files.Length; i++) | ||||
|                 { | ||||
|                     // Get grid index from filename | ||||
|                     string grid_index_str = s.SFNT.FileNames[i].Replace($"5{zoom_level}", "").Replace(extension.Replace(".sstera", ""), "").Replace(folder + "\\", ""); | ||||
|                     int grid_index = int.Parse(grid_index_str, System.Globalization.NumberStyles.HexNumber); | ||||
|                     int[] xyoffs = GridConverter.ZCurveToXY(grid_index); | ||||
|                     Grass[] grasses = Grass.FromBytes(s.Files[i]); | ||||
| 
 | ||||
|                     for (int j = 0; j < grasses.Length; j++) | ||||
|                     { | ||||
|                         Grass g = grasses[j]; | ||||
| 
 | ||||
|                         int x = j % grid_size; | ||||
|                         int y = j / grid_size; | ||||
| 
 | ||||
|                         // Draw pixel at the correct X, Y coordinate | ||||
|                         Int32Rect rect = new Int32Rect(x + (xyoffs[0] * grid_size), y + (xyoffs[1] * grid_size), 1, 1); | ||||
|                         // Brightness - clamp values so colors don't become completely muted | ||||
|                         float brightness = (g.Height / 255f); | ||||
|                         // Use water type color + brightness adjust | ||||
|                         byte[] color = new byte[] { (byte)(g.R * brightness), (byte)(g.G * brightness), (byte)(g.B * brightness) }; | ||||
| 
 | ||||
|                         writeableBitmap.WritePixels(rect, color, writeableBitmap.BackBufferStride, 0); | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         private void PixelView_SetWaterEXTM(string folder, string extension, byte zoom_level, int grid_size) | ||||
|         { | ||||
|             BOTWConsole.Log("Setting view to water"); | ||||
|             string[] ext_files = Directory.GetFiles(folder, $"5{zoom_level}*{extension}"); | ||||
| 
 | ||||
|             foreach (string ext_file in ext_files) | ||||
|             { | ||||
|                 byte[] yaz0_bytes = File.ReadAllBytes(Path.Combine(folder, ext_file)); | ||||
|                 byte[] yaz0_decomp = Yaz0.Decompress(yaz0_bytes); | ||||
|                 SARC s = SARC.FromBytes(new MemoryStream(yaz0_decomp)); | ||||
| 
 | ||||
|                 for (int i = 0; i < s.Files.Length; i++) | ||||
|                 { | ||||
|                     // Get grid index from filename | ||||
|                     string grid_index_str = s.SFNT.FileNames[i].Replace($"5{zoom_level}", "").Replace(extension.Replace(".sstera", ""), "").Replace(folder + "\\", ""); | ||||
|                     int grid_index = int.Parse(grid_index_str, System.Globalization.NumberStyles.HexNumber); | ||||
|                     int[] xyoffs = GridConverter.ZCurveToXY(grid_index); | ||||
|                     Water[] waters = Water.FromBytes(s.Files[i]); | ||||
| 
 | ||||
|                     for (int j = 0; j < waters.Length; j++) | ||||
|                     { | ||||
|                         Water w = waters[j]; | ||||
| 
 | ||||
|                         int x = j % grid_size; | ||||
|                         int y = j / grid_size; | ||||
| 
 | ||||
|                         // Draw pixel at the correct X, Y coordinate | ||||
|                         Int32Rect rect = new Int32Rect(x + (xyoffs[0] * grid_size), y + (xyoffs[1] * grid_size), 1, 1); | ||||
|                         // Brightness - clamp values so colors don't become completely muted | ||||
|                         float brightness = (w.Height / 65535f).Clamp(0.2f, 0.8f); | ||||
|                         // Get this water's color based off its material index/water type | ||||
|                         System.Drawing.Color c = GridColors.WaterColors[w.MaterialIndex]; | ||||
|                         // Use water type color + brightness adjust | ||||
|                         byte[] color = new byte[] { (byte)(c.R * brightness), (byte)(c.G * brightness), (byte)(c.B * brightness) }; | ||||
| 
 | ||||
|                         writeableBitmap.WritePixels(rect, color, writeableBitmap.BackBufferStride, 0); | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         public void SetEnabled(TSCB t) | ||||
|         { | ||||
|             Signature.Text = t.Signature; | ||||
|             Version.Text = t.Version.ToString() + ".0.0.0"; // TODO: An actual version based off bytes should be done later | ||||
|             Version.Text = t.Version.ToString() + ".0.0.0"; | ||||
|             FileBaseOffset.Text = t.FileBaseOffset.ToString(); | ||||
|             WorldScale.Text = t.WorldScale.ToString(); | ||||
|             TerrainMaxHeight.Text = t.TerrainMaxHeight.ToString(); | ||||
|             MaterialInfoLength.Text = t.MaterialInfoLength.ToString(); | ||||
|             AreaArrayLength.Text = t.AreaArrayLength.ToString(); | ||||
|             TileSize.Text = t.TileSize.ToString(); | ||||
| 
 | ||||
|             foreach (var child in PixelViewTypes.Children) | ||||
|             { | ||||
|                 if (child.GetType() == typeof(Button)) | ||||
|                 { | ||||
|                     ((Button)child).IsEnabled = true; | ||||
|                 } | ||||
|                 else if (child.GetType() == typeof(TextBox)) | ||||
|                 { | ||||
|                     ((TextBox)child).IsEnabled = true; | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         public void ClearAllTabInfo() | ||||
|         public void SetDisabled() | ||||
|         { | ||||
|             // Clear sidebar header info | ||||
|             Signature.Clear(); | ||||
|  | @ -44,9 +342,25 @@ namespace BOTWToolset | |||
| 
 | ||||
|             // Clear area display stack panel | ||||
|             TSCBAreaViewer.Children.Clear(); | ||||
| 
 | ||||
|             // Clear pixel view | ||||
|             ClearBitmap(); | ||||
| 
 | ||||
|             // Disable controls | ||||
|             foreach (var child in PixelViewTypes.Children) | ||||
|             { | ||||
|                 if (child.GetType() == typeof(Button)) | ||||
|                 { | ||||
|                     ((Button)child).IsEnabled = false; | ||||
|                 } | ||||
|                 else if (child.GetType() == typeof(TextBox)) | ||||
|                 { | ||||
|                     ((TextBox)child).IsEnabled = false; | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         private void Menu_OpenFile(object sender, System.Windows.RoutedEventArgs e) | ||||
|         private void Menu_FileOpen(object sender, RoutedEventArgs e) | ||||
|         { | ||||
|             BOTWConsole.Log("Clicked File -> Open button"); | ||||
| 
 | ||||
|  | @ -62,41 +376,108 @@ namespace BOTWToolset | |||
| 
 | ||||
|             if ((bool)openFileDialog.ShowDialog()) | ||||
|             { | ||||
|                 // This is to ensure that opening a file when one is already open resets everything in the tab | ||||
|                 SetDisabled(); | ||||
| 
 | ||||
|                 BOTWConsole.Log("Opening file"); | ||||
| 
 | ||||
|                 TSCBInfo t = TSCB.ReadFile(openFileDialog.FileName); | ||||
|                 TSCB t = TSCB.ReadFile(openFileDialog.FileName); | ||||
| 
 | ||||
|                 // Set the current file location to the chosen file's location | ||||
|                 fileLocation = openFileDialog.FileName; | ||||
| 
 | ||||
|                 // Set the current TCSBInfo to the new TSCBInfo | ||||
|                 currentTSCBInfo = t; | ||||
|                 currentTSCB = t; | ||||
| 
 | ||||
|                 // Set UI sidebar to have header info | ||||
|                 SetSidebarHeaderInfo(t); | ||||
|                 // Set UI sidebar to have header info, enable controls | ||||
|                 SetEnabled(t); | ||||
| 
 | ||||
|                 // Allow the file to be saved | ||||
|                 MenuFileClose.IsEnabled = true; | ||||
|                 MenuFileSave.IsEnabled = true; | ||||
| 
 | ||||
|                 // Really laggy, creating 9,000+ controls isn't necessarily a fantastic idea | ||||
|                 // Maybe having a filter would help? | ||||
|                 /*oreach (var area in t.AreaInfo) | ||||
|                 { | ||||
|                     Control.TSCBAreaExpander ae = new Control.TSCBAreaExpander(); | ||||
|                     ae.AreaExpander.Header = $"({area.PositionX}, {area.PositionZ})"; | ||||
|                     ae.AreaExpander.IsExpanded = false; | ||||
| 
 | ||||
|                     TSCBAreaViewer.Children.Add(ae); | ||||
|                 }*/ | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         private void Menu_CloseFile(object sender, System.Windows.RoutedEventArgs e) | ||||
|         private void Menu_FileClose(object sender, RoutedEventArgs e) | ||||
|         { | ||||
|             BOTWConsole.Log("Clicked File -> Close button"); | ||||
| 
 | ||||
|             // Set the current TSCB info to nothing | ||||
|             currentTSCBInfo = null; | ||||
|             currentTSCB = null; | ||||
| 
 | ||||
|             // Clear sidebar header info | ||||
|             ClearAllTabInfo(); | ||||
|             // Set the tab as disabled | ||||
|             SetDisabled(); | ||||
| 
 | ||||
|             // Since there's no file open, don't allow saving | ||||
|             MenuFileClose.IsEnabled = false; | ||||
|             MenuFileSave.IsEnabled = false; | ||||
|         } | ||||
| 
 | ||||
|         private void Menu_SaveFile(object sender, System.Windows.RoutedEventArgs e) | ||||
|         // TODO: split this into "save" and "save as" | ||||
|         private void Menu_FileSave(object sender, RoutedEventArgs e) | ||||
|         { | ||||
|             BOTWConsole.Log("Clicked File -> Save button"); | ||||
| 
 | ||||
|             SaveFileDialog saveFileDialog = new SaveFileDialog | ||||
|             { | ||||
|                 InitialDirectory = @"C;\", | ||||
|                 RestoreDirectory = true, | ||||
|                 Title = "Save TSCB file", | ||||
|                 DefaultExt = "tscb", | ||||
|                 Filter = "TSCB files (*.tscb)|*.tscb" | ||||
|             }; | ||||
| 
 | ||||
|             if ((bool)saveFileDialog.ShowDialog()) | ||||
|             { | ||||
|                 File.WriteAllBytes(saveFileDialog.FileName, TSCB.GetBytes(currentTSCB)); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         private void OverrideKeyDown(object sender, KeyEventArgs e) | ||||
|         { | ||||
|             if (e.Key == Key.Return) | ||||
|             { | ||||
|                 TextBox textSender = (TextBox)sender; | ||||
| 
 | ||||
|                 if (float.TryParse(textSender.Text, out float overrideValue)) | ||||
|                 { | ||||
|                     // Clamp value between 0 and 1 | ||||
|                     overrideValue = MathExt.Clamp(overrideValue, 0.0f, 1.0f); | ||||
| 
 | ||||
|                     BOTWConsole.Log($"Overriding {textSender.Name} with value {overrideValue}"); | ||||
| 
 | ||||
|                     switch (textSender.Name) | ||||
|                     { | ||||
|                         case "OverrideMinTerrainHeight": | ||||
|                             foreach (var area in currentTSCB.AreaInfo) | ||||
|                                 area.MinTerrainHeight = overrideValue; | ||||
|                             break; | ||||
|                         case "OverrideMaxTerrainHeight": | ||||
|                             foreach (var area in currentTSCB.AreaInfo) | ||||
|                                 area.MaxTerrainHeight = overrideValue; | ||||
|                             break; | ||||
|                         case "OverrideMinWaterHeight": | ||||
|                             foreach (var area in currentTSCB.AreaInfo) | ||||
|                                 area.MinWaterHeight = overrideValue; | ||||
|                             break; | ||||
|                         case "OverrideMaxWaterHeight": | ||||
|                             foreach (var area in currentTSCB.AreaInfo) | ||||
|                                 area.MaxWaterHeight = overrideValue; | ||||
|                             break; | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  |  | |||
							
								
								
									
										27
									
								
								botw-toolset/Control/TabYaz0.xaml
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								botw-toolset/Control/TabYaz0.xaml
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,27 @@ | |||
| <UserControl x:Class="BOTWToolset.Control.TabYaz0" | ||||
|              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="597" d:DesignWidth="1246 " Width="Auto" Height="Auto" > | ||||
|     <Grid> | ||||
|         <Label Content="Yaz0 Encoder/Decoder" Margin="10,10,10,0" VerticalAlignment="Top" Height="48" FontSize="28" VerticalContentAlignment="Center" FontFamily="Segoe UI Light"/> | ||||
| 
 | ||||
|         <Menu Margin="10,58,10,0" VerticalAlignment="Top"> | ||||
|             <MenuItem Header="_File" Foreground="White"> | ||||
|                 <MenuItem x:Name="MenuFileDecodeFile" Header="_Decode File" InputGestureText="Ctrl+D" Click="Menu_FileDecode"/> | ||||
|                 <MenuItem x:Name="MenuFileEncodeFile" Header="_Encode File" InputGestureText="Ctrl+E" Click="Menu_FileEncode"/> | ||||
|             </MenuItem> | ||||
|         </Menu> | ||||
|         <Border Margin="10,81,10,10"> | ||||
|             <Grid> | ||||
|                 <Button x:Name="Yaz0Decode" Content="Decode File" Margin="10,10,0,0" VerticalAlignment="Top" Height="36" HorizontalAlignment="Left" Width="196" Click="Menu_FileDecode"/> | ||||
|                 <CheckBox x:Name="Yaz0DecodeAtSource" Content="Decode to source folder" HorizontalAlignment="Left" Margin="211,10,0,0" VerticalAlignment="Top" Height="36" VerticalContentAlignment="Center" IsChecked="True"/> | ||||
|                 <Button x:Name="Yaz0Encode" Content="Encode File" Margin="10,51,0,0" VerticalAlignment="Top" Height="36" HorizontalAlignment="Left" Width="196"  Click="Menu_FileEncode"/> | ||||
|                 <CheckBox x:Name="Yaz0EncodeAtSource" Content="Encode to source folder" HorizontalAlignment="Left" Margin="211,51,0,0" VerticalAlignment="Top" Height="36" VerticalContentAlignment="Center" IsChecked="True"/> | ||||
|             </Grid> | ||||
|         </Border> | ||||
|     </Grid> | ||||
| </UserControl> | ||||
							
								
								
									
										167
									
								
								botw-toolset/Control/TabYaz0.xaml.cs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										167
									
								
								botw-toolset/Control/TabYaz0.xaml.cs
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,167 @@ | |||
| using BOTWToolset.Debugging; | ||||
| using BOTWToolset.Exceptions; | ||||
| using BOTWToolset.IO.Yaz0; | ||||
| using Microsoft.Win32; | ||||
| using System.IO; | ||||
| using System.Windows; | ||||
| using System.Windows.Controls; | ||||
| 
 | ||||
| namespace BOTWToolset.Control | ||||
| { | ||||
|     /// <summary> | ||||
|     /// Interaction logic for TabYaz0.xaml | ||||
|     /// </summary> | ||||
|     public partial class TabYaz0 : UserControl | ||||
|     { | ||||
|         public TabYaz0() | ||||
|         { | ||||
|             InitializeComponent(); | ||||
|         } | ||||
| 
 | ||||
|         private void Menu_FileDecode(object sender, RoutedEventArgs e) | ||||
|         { | ||||
|             var openFileDialog = new OpenFileDialog | ||||
|             { | ||||
|                 InitialDirectory = Dashboard.UserDesktop, | ||||
|                 RestoreDirectory = true, | ||||
|                 Title = "Select Yaz0 file", | ||||
|                 DefaultExt = "yaz0", | ||||
|                 Filter = "All Files (*.*)|*.*", | ||||
|                 CheckFileExists = true | ||||
|             }; | ||||
| 
 | ||||
|             if ((bool)openFileDialog.ShowDialog()) | ||||
|             { | ||||
|                 try | ||||
|                 { | ||||
|                     byte[] decoded = Yaz0.Decompress(File.ReadAllBytes(openFileDialog.FileName)); | ||||
| 
 | ||||
|                     // If decoding at source is checked, don't open a file save picker | ||||
|                     if ((bool)Yaz0DecodeAtSource.IsChecked) | ||||
|                     { | ||||
|                         string decoded_filename = openFileDialog.FileName; | ||||
|                         string ext = Path.GetExtension(openFileDialog.FileName); | ||||
| 
 | ||||
|                         // Replace extension when decoding | ||||
|                         if (ext.StartsWith(".s")) | ||||
|                         { | ||||
|                             ext = ext.Replace(".s", "."); | ||||
|                             decoded_filename = Path.ChangeExtension(decoded_filename, ext); | ||||
|                         } | ||||
| 
 | ||||
|                         File.WriteAllBytes(decoded_filename, decoded); | ||||
|                     } | ||||
|                     else | ||||
|                     { | ||||
|                         var saveFileDialog = new SaveFileDialog | ||||
|                         { | ||||
|                             InitialDirectory = Dashboard.UserDesktop, | ||||
|                             RestoreDirectory = true, | ||||
|                             Title = "Save decoded Yaz0 file", | ||||
|                             Filter = "All Files (*.*)|*.*" | ||||
|                         }; | ||||
| 
 | ||||
|                         if ((bool)saveFileDialog.ShowDialog()) | ||||
|                         { | ||||
|                             File.WriteAllBytes(saveFileDialog.FileName, decoded); | ||||
|                         } | ||||
|                     } | ||||
| 
 | ||||
|                     BOTWConsole.LogStatus("Yaz0 file successfully decoded."); | ||||
|                 } | ||||
|                 catch (InvalidMagicException err) | ||||
|                 { | ||||
|                     BOTWConsole.LogStatus(err.Message); | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         private void Menu_FileEncode(object sender, RoutedEventArgs e) | ||||
|         { | ||||
|             var openFileDialog = new OpenFileDialog | ||||
|             { | ||||
|                 InitialDirectory = Dashboard.UserDesktop, | ||||
|                 RestoreDirectory = true, | ||||
|                 Title = "Select file to Yaz0-encode", | ||||
|                 Filter = "All Files (*.*)|*.*", | ||||
|                 CheckFileExists = true | ||||
|             }; | ||||
| 
 | ||||
|             if ((bool)openFileDialog.ShowDialog()) | ||||
|             { | ||||
|                 try | ||||
|                 { | ||||
|                     byte[] encoded = Yaz0.Compress(File.ReadAllBytes(openFileDialog.FileName)); | ||||
| 
 | ||||
|                     // If decoding at source is checked, don't open a file save picker | ||||
|                     if ((bool)Yaz0DecodeAtSource.IsChecked) | ||||
|                     { | ||||
|                         // Replace extension when encoding | ||||
|                         string ext = Path.GetExtension(openFileDialog.FileName).Replace(".", ".s"); | ||||
|                         string encoded_filename = Path.ChangeExtension(openFileDialog.FileName, ext); | ||||
|                         File.WriteAllBytes(encoded_filename, encoded); | ||||
|                     } | ||||
|                     else | ||||
|                     { | ||||
|                         var saveFileDialog = new SaveFileDialog | ||||
|                         { | ||||
|                             InitialDirectory = Dashboard.UserDesktop, | ||||
|                             RestoreDirectory = true, | ||||
|                             Title = "Save encoded Yaz0 file", | ||||
|                             Filter = "All Files (*.*)|*.*" | ||||
|                         }; | ||||
| 
 | ||||
|                         if ((bool)saveFileDialog.ShowDialog()) | ||||
|                         { | ||||
|                             File.WriteAllBytes(saveFileDialog.FileName, encoded); | ||||
|                         } | ||||
|                     } | ||||
| 
 | ||||
|                     BOTWConsole.LogStatus("Yaz0 file successfully encoded."); | ||||
|                 } | ||||
|                 catch (InvalidMagicException err) | ||||
|                 { | ||||
|                     BOTWConsole.LogStatus(err.Message); | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         /*private void Menu_FileOpen(object sender, RoutedEventArgs e) | ||||
|         { | ||||
|             BOTWConsole.Log("Clicked File -> Open button"); | ||||
| 
 | ||||
|             var openFileDialog = new OpenFileDialog | ||||
|             { | ||||
|                 InitialDirectory = @"C:\", | ||||
|                 RestoreDirectory = true, | ||||
|                 Title = "Select Yaz0 file", | ||||
|                 DefaultExt = "yaz0", | ||||
|                 Filter = "All Files (*.*)|*.*", | ||||
|                 CheckFileExists = true | ||||
|             }; | ||||
| 
 | ||||
|             if ((bool)openFileDialog.ShowDialog()) | ||||
|             { | ||||
|                 // This is to ensure that opening a file when one is already open resets everything in the tab | ||||
|                 SetDisabled(); | ||||
| 
 | ||||
|                 BOTWConsole.Log("Opening file"); | ||||
| 
 | ||||
|                 Yaz0 y = Yaz0.ReadFile(openFileDialog.FileName); | ||||
| 
 | ||||
|                 // Set the current file location to the chosen file's location | ||||
|                 fileLocation = openFileDialog.FileName; | ||||
| 
 | ||||
|                 currentYaz0 = y; | ||||
| 
 | ||||
|                 // Set UI sidebar to have header info, enable controls | ||||
|                 SetEnabled(y); | ||||
| 
 | ||||
|                 // Allow the file to be saved | ||||
|                 MenuFileClose.IsEnabled = true; | ||||
|                 MenuFileSave.IsEnabled = true; | ||||
|                 MenuFileSaveAs.IsEnabled = true; | ||||
|             } | ||||
|         }*/ | ||||
|     } | ||||
| } | ||||
|  | @ -3,38 +3,38 @@ | |||
|         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||||
|         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||||
|         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||||
|         xmlns:local="clr-namespace:BOTWToolset" | ||||
|         xmlns:local="clr-namespace:BOTWToolset.Control" | ||||
|         mc:Ignorable="d" | ||||
|         Title="Breath of the Wild Toolset" Height="720" Width="1280" Icon="Resources/Icons/triforce.png" MinWidth="645" MinHeight="645"> | ||||
|     <Grid Background="#262C35"> | ||||
|         <TabControl Margin="10,10,10,41"> | ||||
|         <TabControl x:Name="TabController"  Margin="10,10,10,41"> | ||||
|             <TabItem Header="Dashboard"> | ||||
|                 <Grid Background="#2C343E"> | ||||
|                     <Label Content="Dashboard" Margin="10,10,10,0" VerticalAlignment="Top" Height="48" FontSize="28" VerticalContentAlignment="Center" FontFamily="Segoe UI Light"/> | ||||
| 
 | ||||
|                     <Border x:Name="DashboardButtonTSCB" BorderBrush="White" HorizontalAlignment="Left" Margin="10,63,0,0" VerticalAlignment="Top" Width="250" Height="165"> | ||||
|                         <Grid> | ||||
|                         <Grid MouseLeftButtonUp="TabSelect_TSCB"> | ||||
|                             <Image Source="Resources/Icons/mountain.png" Margin="10,10,190,0" Width="48" Height="48" VerticalAlignment="Top"/> | ||||
|                             <Label Margin="63,10,10,0" VerticalContentAlignment="Center" FontSize="24" Height="48" VerticalAlignment="Top">TSCB</Label> | ||||
|                             <TextBlock Text="Edits terrain scene binary files." Margin="10,63,10,10" TextWrapping="Wrap"></TextBlock> | ||||
|                         </Grid> | ||||
|                     </Border> | ||||
|                     <Border x:Name="DashboardButtonYaz0" BorderBrush="White" HorizontalAlignment="Left" Margin="265,63,0,0" VerticalAlignment="Top" Width="250" Height="165"> | ||||
|                         <Grid> | ||||
|                         <Grid MouseLeftButtonUp="TabSelect_Yaz0"> | ||||
|                             <Image Source="Resources/Icons/letter-z.png" Margin="10,10,190,0" Width="48" Height="48" VerticalAlignment="Top"/> | ||||
|                             <Label Margin="63,10,10,0" VerticalContentAlignment="Center" FontSize="24" Height="48" VerticalAlignment="Top">Yaz0</Label> | ||||
|                             <TextBlock Text="Allows compression/decompression using Yaz0 encoding." Margin="10,63,10,10" TextWrapping="Wrap"></TextBlock> | ||||
|                         </Grid> | ||||
|                     </Border> | ||||
|                     <Border x:Name="DashboardButtonSARC" BorderBrush="White" HorizontalAlignment="Left" Margin="520,63,0,0" VerticalAlignment="Top" Width="250" Height="165"> | ||||
|                         <Grid> | ||||
|                         <Grid MouseLeftButtonUp="TabSelect_SARC"> | ||||
|                             <Image Source="Resources/Icons/package.png" Margin="10,10,190,0" Width="48" Height="48" VerticalAlignment="Top"/> | ||||
|                             <Label Margin="63,10,10,0" VerticalContentAlignment="Center" FontSize="24" Height="48" VerticalAlignment="Top">SARC</Label> | ||||
|                             <TextBlock Text="Tools to unpack and pack SARC files." Margin="10,63,10,10" TextWrapping="Wrap"></TextBlock> | ||||
|                         </Grid> | ||||
|                     </Border> | ||||
|                     <Border x:Name="DashboardButtonRSTB" BorderBrush="White" HorizontalAlignment="Left" Margin="775,63,0,0" VerticalAlignment="Top" Width="250" Height="165"> | ||||
|                         <Grid> | ||||
|                         <Grid MouseLeftButtonUp="TabSelect_RSTB"> | ||||
|                             <Image Source="Resources/Icons/text-file.png" Margin="10,10,190,0" Width="48" Height="48" VerticalAlignment="Top"/> | ||||
|                             <Label Margin="63,10,10,0" VerticalContentAlignment="Center" FontSize="24" Height="48" VerticalAlignment="Top">RSTB</Label> | ||||
|                             <TextBlock Text="Allows edits to the resource table." Margin="10,63,10,10" TextWrapping="Wrap"></TextBlock> | ||||
|  | @ -42,14 +42,20 @@ | |||
|                     </Border> | ||||
|                 </Grid> | ||||
|             </TabItem> | ||||
|             <TabItem Header="TSCB"> | ||||
|             <TabItem x:Name="tabItemTSCB" Header="TSCB"> | ||||
|                 <local:TabTSCB x:Name="tabTSCB" x:FieldModifier="public"/> | ||||
|             </TabItem> | ||||
|             <TabItem Header="Yaz0"></TabItem> | ||||
|             <TabItem Header="SARC"></TabItem> | ||||
|             <TabItem Header="RSTB"></TabItem> | ||||
|             <TabItem x:Name="tabItemYaz0" Header="Yaz0"> | ||||
|                 <local:TabYaz0 x:Name="tabYaz0" x:FieldModifier="public"/> | ||||
|             </TabItem> | ||||
|             <TabItem x:Name="tabItemSARC" Header="SARC"> | ||||
|                 <local:TabSARC x:Name="tabSARC" x:FieldModifier="public"/> | ||||
|             </TabItem> | ||||
|             <TabItem x:Name="tabItemRSTB" Header="RSTB"> | ||||
|                 <local:TabRSTB x:Name="tabRSTB" x:FieldModifier="public"/> | ||||
|             </TabItem> | ||||
|         </TabControl> | ||||
|         <Label x:Name="LabelVersion" Content="" Margin="0,0,10,10" HorizontalAlignment="Right" Width="1252" Height="26" VerticalAlignment="Bottom" HorizontalContentAlignment="Right"/> | ||||
| 
 | ||||
|         <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"/> | ||||
|     </Grid> | ||||
| </Window> | ||||
|  |  | |||
|  | @ -1,4 +1,5 @@ | |||
| using BOTWToolset.Debugging; | ||||
| using System; | ||||
| using System.Windows; | ||||
| 
 | ||||
| namespace BOTWToolset | ||||
|  | @ -9,6 +10,7 @@ namespace BOTWToolset | |||
|     public partial class Dashboard : Window | ||||
|     { | ||||
|         public const string VERSION = "1.0.0-pre-alpha"; | ||||
|         public static string UserDesktop = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); | ||||
| 
 | ||||
|         public Dashboard() | ||||
|         { | ||||
|  | @ -18,5 +20,13 @@ namespace BOTWToolset | |||
| 
 | ||||
|             LabelVersion.Content = $"Version v{VERSION}"; | ||||
|         } | ||||
| 
 | ||||
|         private void TabSelect_TSCB(object sender, System.Windows.Input.MouseButtonEventArgs e) => tabItemTSCB.IsSelected = true; | ||||
| 
 | ||||
|         private void TabSelect_Yaz0(object sender, System.Windows.Input.MouseButtonEventArgs e) => tabItemYaz0.IsSelected = true; | ||||
| 
 | ||||
|         private void TabSelect_SARC(object sender, System.Windows.Input.MouseButtonEventArgs e) => tabItemSARC.IsSelected = true; | ||||
| 
 | ||||
|         private void TabSelect_RSTB(object sender, System.Windows.Input.MouseButtonEventArgs e) => tabItemRSTB.IsSelected = true; | ||||
|     } | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 Chev
						Chev