Rework tab initialization system

This commit is contained in:
Chev 2021-05-30 19:20:03 -07:00
parent 0052ebc5c5
commit 048f99da9f
3 changed files with 40 additions and 19 deletions

View file

@ -44,18 +44,6 @@
</WrapPanel>
</Grid>
</TabItem>
<TabItem x:Name="tabItemTSCB" Header="TSCB">
<local:TabTSCB x:Name="tabTSCB" x:FieldModifier="public"/>
</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="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

@ -14,6 +14,15 @@ namespace BOTWToolset
public static string VERSION = System.Diagnostics.FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).ProductVersion;
public static string UserDesktop = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
// All tabs used in the toolset
// Adding a new tool to the program requires its tab control to be added here
public static readonly UserControl[] toolsetTabs = new UserControl[]
{
new Control.TabTSCB(),
new Control.TabYaz0(),
new Control.TabSARC(),
new Control.TabRSTB()
};
public Dashboard()
{
@ -22,18 +31,41 @@ namespace BOTWToolset
BOTWConsole.Log($"Breath of the Wild Toolkit - Version {VERSION}");
LabelVersion.Content = $"Version v{VERSION}";
// Initialize and add all tool tabs to the tab controller
foreach (UserControl tab in toolsetTabs)
{
// Initialize the new tab
TabItem tabItem = new TabItem();
// Set the tab's content to whatever the tool's control is
tabItem.Content = tab;
// Give the header (tab name) a proper name based off its class name
tabItem.Header = tab.GetType().Name.Replace("Tab", "");
TabController.Items.Add(tabItem);
}
}
/// <summary>
/// Selects the tab depending on what control was clicked on.
/// </summary>
private void TabSelect(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
var sender_border = (Border)sender;
switch (sender_border.Name)
// Get the name of the tab from the dashboard button's name
string tab_name = sender_border.Name.Replace("DashboardButton", "");
foreach (TabItem tab in TabController.Items)
{
case "DashboardButtonTSCB": tabItemTSCB.IsSelected = true; break;
case "DashboardButtonYaz0": tabItemYaz0.IsSelected = true; break;
case "DashboardButtonSARC": tabItemSARC.IsSelected = true; break;
case "DashboardButtonRSTB": tabItemRSTB.IsSelected = true; break;
string tab_control_name = tab.Content.GetType().Name.Replace("Tab", "");
if (tab_name == tab_control_name)
{
tab.IsSelected = true;
break;
}
}
}
}

View file

@ -19,8 +19,9 @@ namespace BOTWToolset.Debugging
static BOTWConsole()
{
var dashboard = Application.Current.Windows.OfType<Dashboard>().ToArray()[0];
var tabControl = dashboard.tabTSCB;
_console = tabControl.TSCBConsole;
// Get the TSCB control
var tabControl = Dashboard.toolsetTabs[0];
_console = ((Control.TabTSCB)tabControl).TSCBConsole;
_status = dashboard.LabelStatus;
}