using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; using Microsoft.UI.Xaml; using Newtonsoft.Json.Linq; using XFEWarframe.Desktop.Editing; namespace XFEWarframe.Admin.ViewModels; public partial class EditorPageViewModel { [ObservableProperty] [NotifyPropertyChangedFor(nameof(QuestCreationVisibility))] public partial EditorAction? QuestCreation { get; set; } [ObservableProperty] public partial IReadOnlyList QuestFields { get; set; } = []; public Visibility QuestCreationVisibility => Category?.Key == "QuestKeys" && QuestCreation is not null ? Visibility.Visible : Visibility.Collapsed; partial void OnQuestCreationChanged(EditorAction? value) => QuestFields = value?.Fields.OfType().Select(x => new EditorField(x)).ToArray() ?? []; [RelayCommand] private Task PrepareQuestAsync() => RunAsync(() => ReadAsync(SelectedItem?.Key)); [RelayCommand] private Task AddQuestAsync() => RunAsync(async () => { if (QuestCreation is null || Category?.Key != "QuestKeys") throw new InvalidOperationException(UiText.Translate("没有可添加的任务,或管理员未授权此操作。")); var values = new JObject(QuestFields.Select(x => new JProperty(x.Key, x.Serialize()))); var type = values.Value("type")!; await Submit("create.quest", values); Query = type; offset = 0; await ReadAsync(type); Notify(UiText.Translate("已添加任务,已有任务进度保持不变")); }); }