diff --git a/BetterGenshinImpact/BetterGenshinImpact.csproj b/BetterGenshinImpact/BetterGenshinImpact.csproj index cce43d1f..6f7f76f4 100644 --- a/BetterGenshinImpact/BetterGenshinImpact.csproj +++ b/BetterGenshinImpact/BetterGenshinImpact.csproj @@ -61,6 +61,7 @@ + diff --git a/BetterGenshinImpact/Core/Config/Global.cs b/BetterGenshinImpact/Core/Config/Global.cs index 879ed95c..47e3a692 100644 --- a/BetterGenshinImpact/Core/Config/Global.cs +++ b/BetterGenshinImpact/Core/Config/Global.cs @@ -5,7 +5,7 @@ namespace BetterGenshinImpact.Core.Config; public class Global { - public static string Version { get; } = "0.32.1"; + public static string Version { get; } = "0.32.3"; public static string StartUpPath { get; set; } = AppContext.BaseDirectory; diff --git a/BetterGenshinImpact/Core/Script/Group/ScriptGroup.cs b/BetterGenshinImpact/Core/Script/Group/ScriptGroup.cs index 006f8de3..2d3d4b7d 100644 --- a/BetterGenshinImpact/Core/Script/Group/ScriptGroup.cs +++ b/BetterGenshinImpact/Core/Script/Group/ScriptGroup.cs @@ -14,13 +14,13 @@ public partial class ScriptGroup : ObservableObject [ObservableProperty] private ObservableCollection _projects = []; - // public ScriptGroup() - // { - // Projects.CollectionChanged += ProjectsCollectionChanged; - // } - // - // private void ProjectsCollectionChanged(object? sender, NotifyCollectionChangedEventArgs e) - // { - // OnPropertyChanged(nameof(Projects)); - // } + public ScriptGroup() + { + Projects.CollectionChanged += ProjectsCollectionChanged; + } + + private void ProjectsCollectionChanged(object? sender, NotifyCollectionChangedEventArgs e) + { + OnPropertyChanged(nameof(Projects)); + } } diff --git a/BetterGenshinImpact/Core/Script/Group/ScriptGroupProject.cs b/BetterGenshinImpact/Core/Script/Group/ScriptGroupProject.cs index a3a1657e..6cda0673 100644 --- a/BetterGenshinImpact/Core/Script/Group/ScriptGroupProject.cs +++ b/BetterGenshinImpact/Core/Script/Group/ScriptGroupProject.cs @@ -1,22 +1,26 @@ using BetterGenshinImpact.Core.Script.Project; using CommunityToolkit.Mvvm.ComponentModel; +using System; using System.Collections.Generic; using System.Text.Json.Serialization; namespace BetterGenshinImpact.Core.Script.Group; -public class ScriptGroupProject : ObservableObject +public partial class ScriptGroupProject : ObservableObject { - public int Order { get; set; } + [ObservableProperty] + private int _order; public string Id { get; set; } public string Name { get; set; } - public string Status { get; set; } + [ObservableProperty] + private string _status; [JsonIgnore] - public string StatusDesc { get; set; } + [ObservableProperty] + private string _statusDesc; /// /// 执行周期 @@ -30,9 +34,8 @@ public class ScriptGroupProject : ObservableObject [JsonIgnore] public ScriptProject Project { get; set; } - public ScriptGroupProject(int order, ScriptProject project) + public ScriptGroupProject(ScriptProject project) { - Order = order; Id = project.Manifest.Id; Name = project.Manifest.Name; Status = "Enabled"; diff --git a/BetterGenshinImpact/Core/Script/Project/ScriptProject.cs b/BetterGenshinImpact/Core/Script/Project/ScriptProject.cs index 43e92def..18549e81 100644 --- a/BetterGenshinImpact/Core/Script/Project/ScriptProject.cs +++ b/BetterGenshinImpact/Core/Script/Project/ScriptProject.cs @@ -1,11 +1,10 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; +using BetterGenshinImpact.Core.Config; using Microsoft.ClearScript; using Microsoft.ClearScript.V8; +using System; +using System.Diagnostics; using System.IO; using System.Threading.Tasks; -using BetterGenshinImpact.Core.Config; namespace BetterGenshinImpact.Core.Script.Project; @@ -16,8 +15,11 @@ public class ScriptProject public Manifest Manifest { get; set; } + public string FolderName { get; set; } + public ScriptProject(string folderName) { + FolderName = folderName; ProjectPath = Path.Combine(Global.ScriptPath(), folderName); ManifestFile = Path.GetFullPath(Path.Combine(ProjectPath, "manifest.json")); if (!File.Exists(ManifestFile)) diff --git a/BetterGenshinImpact/View/Converters/ItemIndexConverter.cs b/BetterGenshinImpact/View/Converters/ItemIndexConverter.cs new file mode 100644 index 00000000..497ca582 --- /dev/null +++ b/BetterGenshinImpact/View/Converters/ItemIndexConverter.cs @@ -0,0 +1,31 @@ +using System; +using System.Globalization; +using System.Windows.Controls; +using System.Windows.Data; +using BetterGenshinImpact.Core.Script.Group; + +namespace BetterGenshinImpact.View.Converters; + +public class ItemIndexConverter : IValueConverter +{ + public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture) + { + if (value is ScriptGroupProject project) + { + return project.Order; + } + + var item = value as ListViewItem; + if (ItemsControl.ItemsControlFromItemContainer(item) is ListView listView && item != null) + { + var index = listView.ItemContainerGenerator.IndexFromContainer(item) + 1; + return index.ToString(); + } + return ""; + } + + public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } +} diff --git a/BetterGenshinImpact/View/Pages/ScriptControlPage.xaml b/BetterGenshinImpact/View/Pages/ScriptControlPage.xaml index e1bb0781..4ae538e9 100644 --- a/BetterGenshinImpact/View/Pages/ScriptControlPage.xaml +++ b/BetterGenshinImpact/View/Pages/ScriptControlPage.xaml @@ -3,11 +3,10 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:b="http://schemas.microsoft.com/xaml/behaviors" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" - xmlns:linq="clr-namespace:System.Linq;assembly=System.Linq" + xmlns:dd="urn:gong-wpf-dragdrop" xmlns:local="clr-namespace:BetterGenshinImpact.View.Pages" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:pages="clr-namespace:BetterGenshinImpact.ViewModel.Pages" - xmlns:sys="clr-namespace:System;assembly=mscorlib" xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml" Title="HomePage" d:DataContext="{d:DesignInstance Type=pages:ScriptControlViewModel}" @@ -48,6 +47,8 @@ TextAlignment="Center" /> @@ -85,9 +86,11 @@ @@ -99,10 +102,25 @@ - 支持 Javascript 编写的脚本, - 点击查看使用教程 + 脚本组可以导入并配置软件内的脚本,并进行连续执行。当前脚本语言为 Javascript, + 点击查看脚本组使用教程 + + + + + 自动晶蝶脚本组 + + + + @@ -118,9 +136,11 @@ @@ -142,7 +162,7 @@ Margin="0,0,0,8" Foreground="{ui:ThemeResource TextFillColorTertiaryBrush}" TextWrapping="Wrap"> - 支持 Javascript 编写的脚本, + 支持 Javascript 编写的脚本, 点击查看使用教程 @@ -182,11 +202,13 @@ - + @@ -194,10 +216,10 @@ - + + Header="移除配置" /> diff --git a/BetterGenshinImpact/View/Windows/PromptDialog.xaml b/BetterGenshinImpact/View/Windows/PromptDialog.xaml index 1ded3b65..41b7fd20 100644 --- a/BetterGenshinImpact/View/Windows/PromptDialog.xaml +++ b/BetterGenshinImpact/View/Windows/PromptDialog.xaml @@ -4,7 +4,6 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml" - Title="配置" Width="500" Height="210" MinWidth="400" @@ -25,7 +24,8 @@ - + + @@ -43,7 +43,7 @@ - + diff --git a/BetterGenshinImpact/View/Windows/PromptDialog.xaml.cs b/BetterGenshinImpact/View/Windows/PromptDialog.xaml.cs index 8764c367..83cabbe8 100644 --- a/BetterGenshinImpact/View/Windows/PromptDialog.xaml.cs +++ b/BetterGenshinImpact/View/Windows/PromptDialog.xaml.cs @@ -1,33 +1,64 @@ -using System.Windows; +using System.Drawing; +using System.Windows; +using System.Windows.Controls; namespace BetterGenshinImpact.View.Windows; public partial class PromptDialog { - public string DialogTitle { get; set; } - - public PromptDialog(string question, string title, string defaultValue = "") + public PromptDialog(string question, string title, UIElement uiElement, string defaultValue) { InitializeComponent(); - DialogTitle = title; + MyTitleBar.Title = title; TxtQuestion.Text = question; - TxtResponse.Text = defaultValue; + + DynamicContent.Content = uiElement; + if (DynamicContent.Content is TextBox textBox) + { + textBox.Text = defaultValue; + } + else if (DynamicContent.Content is ComboBox comboBox) + { + comboBox.Text = defaultValue; + } + this.Loaded += PromptDialogLoaded; } private void PromptDialogLoaded(object sender, RoutedEventArgs e) { - TxtResponse.Focus(); + DynamicContent.Focus(); } public static string Prompt(string question, string title, string defaultValue = "") { - var inst = new PromptDialog(question, title, defaultValue); + var inst = new PromptDialog(question, title, new TextBox(), defaultValue); inst.ShowDialog(); return inst.DialogResult == true ? inst.ResponseText : defaultValue; } - public string ResponseText => TxtResponse.Text; + public static string Prompt(string question, string title, UIElement uiElement, string defaultValue = "") + { + var inst = new PromptDialog(question, title, uiElement, defaultValue); + inst.ShowDialog(); + return inst.DialogResult == true ? inst.ResponseText : defaultValue; + } + + public string ResponseText + { + get + { + if (DynamicContent.Content is TextBox textBox) + { + return textBox.Text; + } + else if (DynamicContent.Content is ComboBox comboBox) + { + return comboBox.Text; + } + return string.Empty; + } + } private void BtnOkClick(object sender, RoutedEventArgs e) { diff --git a/BetterGenshinImpact/ViewModel/Pages/ScriptControlViewModel.cs b/BetterGenshinImpact/ViewModel/Pages/ScriptControlViewModel.cs index 2d4a7e86..ce455e99 100644 --- a/BetterGenshinImpact/ViewModel/Pages/ScriptControlViewModel.cs +++ b/BetterGenshinImpact/ViewModel/Pages/ScriptControlViewModel.cs @@ -1,12 +1,17 @@ -using BetterGenshinImpact.Core.Script.Group; +using BetterGenshinImpact.Core.Config; +using BetterGenshinImpact.Core.Script.Group; using BetterGenshinImpact.Core.Script.Project; +using BetterGenshinImpact.View.Windows; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; using System; +using System.Collections.Generic; using System.Collections.ObjectModel; using System.Collections.Specialized; -using System.ComponentModel; using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Windows.Controls; using Wpf.Ui; using Wpf.Ui.Controls; @@ -45,7 +50,11 @@ public partial class ScriptControlViewModel : ObservableObject, INavigationAware [RelayCommand] private void OnAddScriptGroup() { - ScriptGroups.Add(new ScriptGroup { Name = new Random().Next(100, 1000).ToString() }); + var str = PromptDialog.Prompt("请输入脚本组名称", "新增脚本组"); + if (!string.IsNullOrEmpty(str)) + { + ScriptGroups.Add(new ScriptGroup { Name = str }); + } } [RelayCommand] @@ -69,7 +78,30 @@ public partial class ScriptControlViewModel : ObservableObject, INavigationAware [RelayCommand] private void OnAddScript() { - SelectedScriptGroup?.Projects.Add(new ScriptGroupProject(1, new ScriptProject("AutoCrystalfly"))); + var list = LoadAllScriptProjects(); + var combobox = new ComboBox(); + + foreach (var scriptProject in list) + { + combobox.Items.Add(scriptProject.FolderName + " - " + scriptProject.Manifest.Name); + } + + var str = PromptDialog.Prompt("请选择需要添加的脚本", "请选择需要添加的脚本", combobox); + if (!string.IsNullOrEmpty(str)) + { + var folderName = str.Split(" - ")[0]; + SelectedScriptGroup?.Projects.Add(new ScriptGroupProject(new ScriptProject(folderName))); + } + } + + private List LoadAllScriptProjects() + { + var path = Global.ScriptPath(); + // 获取所有脚本项目 + var projects = Directory.GetDirectories(path) + .Select(x => new ScriptProject(Path.GetFileName(x))) + .ToList(); + return projects; } [RelayCommand] @@ -82,8 +114,8 @@ public partial class ScriptControlViewModel : ObservableObject, INavigationAware SelectedScriptGroup?.Projects.Remove(item); _snackbarService.Show( - "脚本配置删除成功", - $"{item.Name} 已经被删除", + "脚本配置移除成功", + $"{item.Name} 的关联配置已经移除", ControlAppearance.Success, null, TimeSpan.FromSeconds(2) @@ -92,27 +124,53 @@ public partial class ScriptControlViewModel : ObservableObject, INavigationAware private void ScriptGroupsCollectionChanged(object? sender, NotifyCollectionChangedEventArgs e) { - // if (e.NewItems != null) - // { - // foreach (ScriptGroup newItem in e.NewItems) - // { - // newItem.PropertyChanged += ScriptGroupPropertyChanged; - // } - // } - // - // if (e.OldItems != null) - // { - // foreach (ScriptGroup oldItem in e.OldItems) - // { - // oldItem.PropertyChanged -= ScriptGroupPropertyChanged; - // } - // } + if (e.NewItems != null) + { + foreach (ScriptGroup newItem in e.NewItems) + { + newItem.Projects.CollectionChanged += ScriptProjectsCollectionChanged; + } + } + if (e.OldItems != null) + { + foreach (ScriptGroup oldItem in e.OldItems) + { + oldItem.Projects.CollectionChanged -= ScriptProjectsCollectionChanged; + } + } Debug.WriteLine("ScriptGroupsCollectionChanged"); } - private void ScriptGroupPropertyChanged(object? sender, PropertyChangedEventArgs e) + private void ScriptProjectsCollectionChanged(object? sender, NotifyCollectionChangedEventArgs e) { - Debug.WriteLine($"ScriptGroupPropertyChanged: {e.PropertyName}"); + // 补充排序字段 + if (SelectedScriptGroup is { Projects.Count: > 0 }) + { + var i = 1; + foreach (var project in SelectedScriptGroup.Projects) + { + project.Order = i++; + } + } + Debug.WriteLine("---ScriptProjectsCollectionChanged"); + } + + [RelayCommand] + public void OnGoToScriptGroupUrl() + { + Process.Start(new ProcessStartInfo("https://bgi.huiyadan.com/") { UseShellExecute = true }); + } + + [RelayCommand] + public void OnGoToScriptProjectUrl() + { + Process.Start(new ProcessStartInfo("https://bgi.huiyadan.com/") { UseShellExecute = true }); + } + + [RelayCommand] + public void OnImportScriptGroup(string scriptGroupExample) + { + Debug.WriteLine(scriptGroupExample); } } diff --git a/BetterGenshinImpact/ViewModel/Pages/TriggerSettingsPageViewModel.cs b/BetterGenshinImpact/ViewModel/Pages/TriggerSettingsPageViewModel.cs index 4a1ab72d..7ba746f0 100644 --- a/BetterGenshinImpact/ViewModel/Pages/TriggerSettingsPageViewModel.cs +++ b/BetterGenshinImpact/ViewModel/Pages/TriggerSettingsPageViewModel.cs @@ -58,13 +58,13 @@ public partial class TriggerSettingsPageViewModel : ObservableObject, INavigatio JsonMonoDialog.Show(@"User\pick_white_lists.json"); } - [RelayCommand] - private void OnOpenReExploreCharacterBox(object sender) - { - var str = PromptDialog.Prompt("请使用派遣界面展示的角色名,英文逗号分割,从左往右优先级依次降低。\n示例:菲谢尔,班尼特,夜兰,申鹤,久岐忍", - "派遣角色优先级配置", Config.AutoSkipConfig.AutoReExploreCharacter); - Config.AutoSkipConfig.AutoReExploreCharacter = str.Replace(",", ",").Replace(" ", ""); - } + // [RelayCommand] + // private void OnOpenReExploreCharacterBox(object sender) + // { + // var str = PromptDialog.Prompt("请使用派遣界面展示的角色名,英文逗号分割,从左往右优先级依次降低。\n示例:菲谢尔,班尼特,夜兰,申鹤,久岐忍", + // "派遣角色优先级配置", Config.AutoSkipConfig.AutoReExploreCharacter); + // Config.AutoSkipConfig.AutoReExploreCharacter = str.Replace(",", ",").Replace(" ", ""); + // } [RelayCommand] public void OnGoToQGroupUrl()