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

XFEWarframe

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

公开
关注 0 Fork 0 Star 0
UTF-8
using XFEWarframe.Desktop.Editing;

namespace XFEWarframe.Player.ViewModels;

public partial class EditorPageViewModel
{
    private bool permissionRefreshPending;
    private string? permissionSelectedItem;
    private int permissionSelectedIndex;
    public string PermissionNotice => !Account.IsLoggedIn || IsCatalogMode ? "" : !Account.EditingEnabled
        ? UiText.Translate("当前为只读库存。请管理员在“玩家编辑权限”中开启“允许用户编辑物品”并保存;添加物品权限与编辑权限分别设置。")
        : !permissionRefreshPending && SelectedItem?.CanEdit == false
            ? UiText.Translate("当前物品没有已授权的编辑操作。管理员保存权限后,此页面会自动更新。") : "";
    public bool HasPermissionNotice => PermissionNotice.Length > 0;
    private void NotifyPermissionNotice()
    {
        OnPropertyChanged(nameof(PermissionNotice));
        OnPropertyChanged(nameof(HasPermissionNotice));
    }
    private void InvalidatePermissions()
    {
        // Keep the selected identity across consecutive notifications from one account response.
        if (!permissionRefreshPending)
        {
            permissionSelectedItem = SelectedItem?.Key;
            permissionSelectedIndex = offset + Math.Max(0, SelectedItem is null ? 0 : Items.IndexOf(SelectedItem));
        }
        Reset();
        permissionRefreshPending = Account.IsLoggedIn;
        if (!Account.IsLoggedIn) permissionSelectedItem = null;
        NotifyDetailNavigation(); NotifyPermissionNotice();
    }
    private Task RefreshPermissionsAsync() => RunAsync(async () =>
    {
        if (!permissionRefreshPending || !Account.IsLoggedIn) return;
        permissionRefreshPending = false;
        var item = permissionSelectedItem; permissionSelectedItem = null;
        SelectedAccount = new(Account.AccountId, Account.DisplayName);
        offset = permissionSelectedIndex / PageSize * PageSize;
        try { await ReadAsync(item); }
        catch
        {
            if (!permissionRefreshPending && Account.IsLoggedIn)
            {
                permissionRefreshPending = true; permissionSelectedItem = item;
            }
            throw;
        }
        finally { NotifyDetailNavigation(); NotifyPermissionNotice(); }
    });
}