using XFEEDToolBox.Core.Outfitting;
using XFEEDToolBox.ViewModels;
namespace XFEEDToolBox.Views;
public sealed partial class RefitModulePickerPage : Page
{
public ToolboxViewModel ViewModel=>App.ViewModel;
private readonly string slot,owner,shipType;
private readonly long? shipId;
public RefitModulePickerPage()
{
slot=ViewModel.RefitSlot?.Slot??"";owner=ViewModel.CurrentPlayer.CommanderId;
shipId=ViewModel.RefitDocument?.ShipId;shipType=ViewModel.RefitDocument?.ShipType??"";
InitializeComponent();
}
private void ChooseType(object sender,ItemClickEventArgs args)
{
if(args.ClickedItem is RefitModuleType type){ViewModel.RefitSelectedModuleType=type;PickerMessage.Text="选择具体型号后装入此槽位。";}
}
private void Back(object sender,RoutedEventArgs args)
{
if(ViewModel.RefitChoosingModel){ViewModel.RefitSelectedModuleType=null;PickerMessage.Text="先选择模块类型,再选择具体型号。";}
else AppShellPage.Current?.Navigate(typeof(RefitPage));
}
private bool HasOriginalSlot()
{
if(owner==ViewModel.CurrentPlayer.CommanderId&&shipId==ViewModel.RefitDocument?.ShipId&&shipType==ViewModel.RefitDocument?.ShipType&&slot==ViewModel.RefitSlot?.Slot)return true;
PickerMessage.Text="当前飞船或槽位已变化,请返回飞船编辑后重新选择。";return false;
}
private void Install(object sender,RoutedEventArgs args)
{
if(!HasOriginalSlot())return;
if(ViewModel.RefitInstallModule is not {} choice){PickerMessage.Text="请选择一个具体型号。";return;}
ViewModel.InstallRefitModuleCommand.Execute(null);
if(ViewModel.RefitSlot?.Module?.Item==choice.Module.Item&&ViewModel.RefitSlot.InstanceKey==choice.InstanceKey)AppShellPage.Current?.Navigate(typeof(RefitPage));
else PickerMessage.Text=ViewModel.RefitResult;
}
private void RemoveModule(object sender,RoutedEventArgs args)
{
if(!HasOriginalSlot())return;ViewModel.UninstallRefitModuleCommand.Execute(null);
if(ViewModel.RefitSlot?.Module is null)AppShellPage.Current?.Navigate(typeof(RefitPage));else PickerMessage.Text=ViewModel.RefitResult;
}
private void ResizeCards(object sender,SizeChangedEventArgs args)
{
if(sender is GridView {ItemsPanelRoot:ItemsWrapGrid panel} grid)
{var width=Math.Max(180,args.NewSize.Width-16);panel.ItemWidth=width/Math.Max(1,(int)(width/240));panel.ItemHeight=grid==ModuleTypes?230:270;}
}
}
using XFEEDToolBox.Core.Outfitting;
using XFEEDToolBox.ViewModels;
namespace XFEEDToolBox.Views;
public sealed partial class RefitModulePickerPage : Page
{
public ToolboxViewModel ViewModel=>App.ViewModel;
private readonly string slot,owner,shipType;
private readonly long? shipId;
public RefitModulePickerPage()
{
slot=ViewModel.RefitSlot?.Slot??"";owner=ViewModel.CurrentPlayer.CommanderId;
shipId=ViewModel.RefitDocument?.ShipId;shipType=ViewModel.RefitDocument?.ShipType??"";
InitializeComponent();
}
private void ChooseType(object sender,ItemClickEventArgs args)
{
if(args.ClickedItem is RefitModuleType type){ViewModel.RefitSelectedModuleType=type;PickerMessage.Text="选择具体型号后装入此槽位。";}
}
private void Back(object sender,RoutedEventArgs args)
{
if(ViewModel.RefitChoosingModel){ViewModel.RefitSelectedModuleType=null;PickerMessage.Text="先选择模块类型,再选择具体型号。";}
else AppShellPage.Current?.Navigate(typeof(RefitPage));
}
private bool HasOriginalSlot()
{
if(owner==ViewModel.CurrentPlayer.CommanderId&&shipId==ViewModel.RefitDocument?.ShipId&&shipType==ViewModel.RefitDocument?.ShipType&&slot==ViewModel.RefitSlot?.Slot)return true;
PickerMessage.Text="当前飞船或槽位已变化,请返回飞船编辑后重新选择。";return false;
}
private void Install(object sender,RoutedEventArgs args)
{
if(!HasOriginalSlot())return;
if(ViewModel.RefitInstallModule is not {} choice){PickerMessage.Text="请选择一个具体型号。";return;}
ViewModel.InstallRefitModuleCommand.Execute(null);
if(ViewModel.RefitSlot?.Module?.Item==choice.Module.Item&&ViewModel.RefitSlot.InstanceKey==choice.InstanceKey)AppShellPage.Current?.Navigate(typeof(RefitPage));
else PickerMessage.Text=ViewModel.RefitResult;
}
private void RemoveModule(object sender,RoutedEventArgs args)
{
if(!HasOriginalSlot())return;ViewModel.UninstallRefitModuleCommand.Execute(null);
if(ViewModel.RefitSlot?.Module is null)AppShellPage.Current?.Navigate(typeof(RefitPage));else PickerMessage.Text=ViewModel.RefitResult;
}
private void ResizeCards(object sender,SizeChangedEventArgs args)
{
if(sender is GridView {ItemsPanelRoot:ItemsWrapGrid panel} grid)
{var width=Math.Max(180,args.NewSize.Width-16);panel.ItemWidth=width/Math.Max(1,(int)(width/240));panel.ItemHeight=grid==ModuleTypes?230:270;}
}
}