XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFEWarframe

【WinUI】基于Warframe游戏本体的公开服务器以及安装器

公开
关注 0 Fork 0 Star 0
UTF-8
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<string> editableCategories, bool riven, bool itemGrant = false)
    {
        foreach (var child in root.MenuItems.OfType<NavigationViewItem>()) Apply(child);
        void Apply(NavigationViewItem item)
        {
            foreach (var child in item.MenuItems.OfType<NavigationViewItem>()) 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<NavigationViewItem>().Any(x => x.Visibility == Visibility.Visible))
            {
                // Keep the group usable when only one of its children is permitted.
                var first = item.MenuItems.OfType<NavigationViewItem>().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;
        }
    }
}