using XFEEDToolBox.ViewModels;
namespace XFEEDToolBox.Views;
public sealed partial class MainPage : Page
{
public ToolboxViewModel ViewModel => App.ViewModel;
private (bool stack,bool metrics,bool tiny)? layout;
public MainPage()
{
InitializeComponent();NavigationCacheMode=Microsoft.UI.Xaml.Navigation.NavigationCacheMode.Required;
SizeChanged+=(_,_)=>UpdateDashboardLayout();Loaded+=(_,_)=>UpdateDashboardLayout();
}
private void UpdateDashboardLayout()
{
var width=ActualWidth;if(width<=0)return;
NavigationIllustration.Height=Math.Clamp(width*.24,300,440);
var next=(stack:width<1050,metrics:width<900,tiny:width<700);
if(layout==next)return;layout=next;
Grid.SetColumnSpan(PrimaryColumn,next.stack?2:1);
Grid.SetRow(SecondaryColumn,next.stack?1:0);Grid.SetColumn(SecondaryColumn,next.stack?0:1);Grid.SetColumnSpan(SecondaryColumn,next.stack?2:1);
var cards=new[]{CashCard,CargoCard,MaterialCard,MarketCard};
for(var i=0;i<cards.Length;i++){Grid.SetColumn(cards[i],next.metrics?i%2*2:i);Grid.SetRow(cards[i],next.metrics?i/2:0);Grid.SetColumnSpan(cards[i],next.metrics?2:1);}
ShipSchematic.Visibility=Visibility.Visible;SchematicColumn.Width=next.tiny?new GridLength(1,GridUnitType.Star):new GridLength(1.1,GridUnitType.Star);
Grid.SetColumnSpan(ShipSchematic,next.tiny?2:1);Grid.SetRow(ShipDetails,next.tiny?1:0);Grid.SetColumn(ShipDetails,next.tiny?0:1);Grid.SetColumnSpan(ShipDetails,next.tiny?2:1);
Grid.SetRow(HeroNavigation,next.tiny?1:0);Grid.SetColumn(HeroNavigation,next.tiny?1:2);Grid.SetColumnSpan(HeroNavigation,next.tiny?2:1);
NavigationActions.Orientation=next.tiny?Orientation.Vertical:Orientation.Horizontal;
}
protected override void OnNavigatedTo(Microsoft.UI.Xaml.Navigation.NavigationEventArgs e) { base.OnNavigatedTo(e); HomeGalaxyMap.ResumePage(); ShipSchematic.ResumePage();HomeNews.ResumePage();ViewModel.GalaxyDisplayReady+=RefreshGalaxyDisplay; }
protected override async void OnNavigatedFrom(Microsoft.UI.Xaml.Navigation.NavigationEventArgs e) { base.OnNavigatedFrom(e); HomeGalaxyMap.SuspendPage();HomeNews.SuspendPage(); await ShipSchematic.SuspendPageAsync();ViewModel.GalaxyDisplayReady-=RefreshGalaxyDisplay; }
private void RefreshGalaxyDisplay()=>HomeGalaxyMap.RefreshDisplay();
private void OpenGalaxyMap(object sender,RoutedEventArgs e)=>AppShellPage.Current!.Navigate(typeof(GalaxyMapPage));
private void OpenPlanner(object sender, RoutedEventArgs e) => AppShellPage.Current!.Navigate(typeof(PlannerPage));
private void OpenNavigation(object sender,RoutedEventArgs e)=>AppShellPage.Current!.Navigate(typeof(NavigationPage));
private void OpenMarket(object sender, RoutedEventArgs e) => AppShellPage.Current!.Navigate(typeof(MarketPage));
private void OpenSettings(object sender, RoutedEventArgs e) => AppShellPage.Current!.Navigate(typeof(SettingPage));
private void OpenExecution(object sender, RoutedEventArgs e) => AppShellPage.Current!.Navigate(typeof(ExecutionPage));
private void OpenFleet(object sender,RoutedEventArgs e)=>AppShellPage.Current!.Navigate(typeof(ShipPage));
private void OpenMaterials(object sender,RoutedEventArgs e)=>AppShellPage.Current!.Navigate(typeof(MaterialsPage));
private void OpenRefit(object sender,RoutedEventArgs e)=>AppShellPage.Current!.Navigate(typeof(RefitPage));
private void OpenEngineering(object sender,RoutedEventArgs e)=>AppShellPage.Current!.Navigate(typeof(EngineeringPage));
private void OpenRead(object sender,RoutedEventArgs e)=>AppShellPage.Current!.Navigate(typeof(ReadPage));
}
using XFEEDToolBox.ViewModels;
namespace XFEEDToolBox.Views;
public sealed partial class MainPage : Page
{
public ToolboxViewModel ViewModel => App.ViewModel;
private (bool stack,bool metrics,bool tiny)? layout;
public MainPage()
{
InitializeComponent();NavigationCacheMode=Microsoft.UI.Xaml.Navigation.NavigationCacheMode.Required;
SizeChanged+=(_,_)=>UpdateDashboardLayout();Loaded+=(_,_)=>UpdateDashboardLayout();
}
private void UpdateDashboardLayout()
{
var width=ActualWidth;if(width<=0)return;
NavigationIllustration.Height=Math.Clamp(width*.24,300,440);
var next=(stack:width<1050,metrics:width<900,tiny:width<700);
if(layout==next)return;layout=next;
Grid.SetColumnSpan(PrimaryColumn,next.stack?2:1);
Grid.SetRow(SecondaryColumn,next.stack?1:0);Grid.SetColumn(SecondaryColumn,next.stack?0:1);Grid.SetColumnSpan(SecondaryColumn,next.stack?2:1);
var cards=new[]{CashCard,CargoCard,MaterialCard,MarketCard};
for(var i=0;i<cards.Length;i++){Grid.SetColumn(cards[i],next.metrics?i%2*2:i);Grid.SetRow(cards[i],next.metrics?i/2:0);Grid.SetColumnSpan(cards[i],next.metrics?2:1);}
ShipSchematic.Visibility=Visibility.Visible;SchematicColumn.Width=next.tiny?new GridLength(1,GridUnitType.Star):new GridLength(1.1,GridUnitType.Star);
Grid.SetColumnSpan(ShipSchematic,next.tiny?2:1);Grid.SetRow(ShipDetails,next.tiny?1:0);Grid.SetColumn(ShipDetails,next.tiny?0:1);Grid.SetColumnSpan(ShipDetails,next.tiny?2:1);
Grid.SetRow(HeroNavigation,next.tiny?1:0);Grid.SetColumn(HeroNavigation,next.tiny?1:2);Grid.SetColumnSpan(HeroNavigation,next.tiny?2:1);
NavigationActions.Orientation=next.tiny?Orientation.Vertical:Orientation.Horizontal;
}
protected override void OnNavigatedTo(Microsoft.UI.Xaml.Navigation.NavigationEventArgs e) { base.OnNavigatedTo(e); HomeGalaxyMap.ResumePage(); ShipSchematic.ResumePage();HomeNews.ResumePage();ViewModel.GalaxyDisplayReady+=RefreshGalaxyDisplay; }
protected override async void OnNavigatedFrom(Microsoft.UI.Xaml.Navigation.NavigationEventArgs e) { base.OnNavigatedFrom(e); HomeGalaxyMap.SuspendPage();HomeNews.SuspendPage(); await ShipSchematic.SuspendPageAsync();ViewModel.GalaxyDisplayReady-=RefreshGalaxyDisplay; }
private void RefreshGalaxyDisplay()=>HomeGalaxyMap.RefreshDisplay();
private void OpenGalaxyMap(object sender,RoutedEventArgs e)=>AppShellPage.Current!.Navigate(typeof(GalaxyMapPage));
private void OpenPlanner(object sender, RoutedEventArgs e) => AppShellPage.Current!.Navigate(typeof(PlannerPage));
private void OpenNavigation(object sender,RoutedEventArgs e)=>AppShellPage.Current!.Navigate(typeof(NavigationPage));
private void OpenMarket(object sender, RoutedEventArgs e) => AppShellPage.Current!.Navigate(typeof(MarketPage));
private void OpenSettings(object sender, RoutedEventArgs e) => AppShellPage.Current!.Navigate(typeof(SettingPage));
private void OpenExecution(object sender, RoutedEventArgs e) => AppShellPage.Current!.Navigate(typeof(ExecutionPage));
private void OpenFleet(object sender,RoutedEventArgs e)=>AppShellPage.Current!.Navigate(typeof(ShipPage));
private void OpenMaterials(object sender,RoutedEventArgs e)=>AppShellPage.Current!.Navigate(typeof(MaterialsPage));
private void OpenRefit(object sender,RoutedEventArgs e)=>AppShellPage.Current!.Navigate(typeof(RefitPage));
private void OpenEngineering(object sender,RoutedEventArgs e)=>AppShellPage.Current!.Navigate(typeof(EngineeringPage));
private void OpenRead(object sender,RoutedEventArgs e)=>AppShellPage.Current!.Navigate(typeof(ReadPage));
}