using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; using XFEExtension.NetCore.WinUIHelper.Utilities.Additions; namespace XFEWarframe.Desktop.Editing; public static class InventoryNavigationMenu { public static void Populate(NavigationViewItem root, string pageNamespace) { root.MenuItems.Clear(); var overview = new NavigationViewItem { Content = UiText.Translate("总览与存档"), Tag = "overview" }; overview.SetValue(NavigationAddition.NavigateToProperty, pageNamespace + ".InventoryPage"); root.MenuItems.Add(overview); foreach (var section in InventoryNavigation.Sections) root.MenuItems.Add(Create(section, pageNamespace)); } private static NavigationViewItem Create(InventorySection section, string pageNamespace) { var item = new NavigationViewItem { Content = section.Label, Tag = section.Key }; var page = section.Key == "riven" ? ".RivenPage" : section.Key == "catalog" ? (pageNamespace.Contains(".Player.", StringComparison.Ordinal) ? ".ItemCatalogPage" : ".CatalogPage") : ".EditorPage"; item.SetValue(NavigationAddition.NavigateToProperty, pageNamespace + page); if (section.Key is not ("riven" or "catalog")) item.SetValue(NavigationAddition.NavigateParameterProperty, InventoryNavigation.Route(section.Key)); foreach (var child in section.Children) item.MenuItems.Add(Create(child, pageNamespace)); return item; } public static void ApplyPermissions(NavigationViewItem root, IReadOnlySet editableCategories, bool riven, bool itemGrant = false) { foreach (var child in root.MenuItems.OfType()) Apply(child); void Apply(NavigationViewItem item) { foreach (var child in item.MenuItems.OfType()) Apply(child); var key = (string)item.Tag; var allowed = key == "riven" ? riven : key == "catalog" ? itemGrant : !InventoryNavigation.RequiresEditing(key) || editableCategories.Contains(key); if (!allowed && item.MenuItems.OfType().Any(x => x.Visibility == Visibility.Visible)) { // Keep the group usable when only one of its children is permitted. var first = item.MenuItems.OfType().First(x => x.Visibility == Visibility.Visible); item.SetValue(NavigationAddition.NavigateParameterProperty, first.GetValue(NavigationAddition.NavigateParameterProperty)); allowed = true; } else if (key is not ("overview" or "riven" or "catalog")) item.SetValue(NavigationAddition.NavigateParameterProperty, InventoryNavigation.Route(key)); item.Visibility = allowed ? Visibility.Visible : Visibility.Collapsed; } } }