script group ui 2

This commit is contained in:
辉鸭蛋
2024-08-10 19:16:35 +08:00
parent 308d398036
commit ad288c60cc
11 changed files with 219 additions and 71 deletions

View File

@@ -61,6 +61,7 @@
<PackageReference Include="WPF-UI" Version="3.0.4" />
<PackageReference Include="WPF-UI.Tray" Version="3.0.4" />
<PackageReference Include="YoloV8" Version="4.1.7" />
<PackageReference Include="gong-wpf-dragdrop" Version="3.2.1" />
</ItemGroup>
<ItemGroup Condition=" '$(Configuration)' == 'Debug'">

View File

@@ -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;

View File

@@ -14,13 +14,13 @@ public partial class ScriptGroup : ObservableObject
[ObservableProperty]
private ObservableCollection<ScriptGroupProject> _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));
}
}

View File

@@ -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;
/// <summary>
/// 执行周期
@@ -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";

View File

@@ -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))

View File

@@ -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();
}
}

View File

@@ -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" />
</Border>
<ui:ListView Grid.Row="1"
dd:DragDrop.IsDragSource="True"
dd:DragDrop.IsDropTarget="True"
ItemsSource="{Binding ScriptGroups, Mode=TwoWay}"
SelectedItem="{Binding SelectedScriptGroup, Mode=TwoWay}"
SelectionMode="Single">
@@ -85,9 +86,11 @@
<Grid.Style>
<Style TargetType="Grid">
<Setter Property="Visibility" Value="Visible" />
<Setter Property="IsHitTestVisible" Value="True" />
<Style.Triggers>
<DataTrigger Binding="{Binding SelectedScriptGroup, Converter={StaticResource NotNullConverter}}" Value="True">
<Setter Property="Visibility" Value="Collapsed" />
<Setter Property="IsHitTestVisible" Value="False" />
</DataTrigger>
</Style.Triggers>
</Style>
@@ -99,10 +102,25 @@
<ui:TextBlock Margin="0,0,0,8"
Foreground="{ui:ThemeResource TextFillColorTertiaryBrush}"
TextWrapping="Wrap">
支持 Javascript 编写的脚本<Hyperlink Command="{Binding GoToAutoDomainUrlCommand}" Foreground="{ui:ThemeResource TextFillColorSecondaryBrush}">
点击查看使用教程
脚本组可以导入并配置软件内的脚本,并进行连续执行。当前脚本语言为 Javascript<Hyperlink Command="{Binding GoToScriptGroupUrlCommand}" Foreground="{ui:ThemeResource TextFillColorSecondaryBrush}">
点击查看脚本组使用教程
</Hyperlink>
</ui:TextBlock>
<!-- 示例脚本组 -->
<ui:TextBlock Margin="0,0,0,8"
FontTypography="BodyStrong"
Text="也可以直接点击导入下面的示例脚本组" />
<ui:TextBlock Margin="0,0,0,8"
Foreground="{ui:ThemeResource TextFillColorTertiaryBrush}"
TextWrapping="Wrap">
<Hyperlink Command="{Binding ImportScriptGroupCommand}"
CommandParameter="AutoCrystalflyExampleGroup"
Foreground="{ui:ThemeResource TextFillColorSecondaryBrush}">
自动晶蝶脚本组
</Hyperlink>
</ui:TextBlock>
<ui:Button Content="111" />
</StackPanel>
</Grid>
@@ -118,9 +136,11 @@
<Grid.Style>
<Style TargetType="Grid">
<Setter Property="Visibility" Value="Visible" />
<Setter Property="IsHitTestVisible" Value="True" />
<Style.Triggers>
<DataTrigger Binding="{Binding SelectedScriptGroup}" Value="{x:Null}">
<Setter Property="Visibility" Value="Collapsed" />
<Setter Property="IsHitTestVisible" Value="False" />
</DataTrigger>
</Style.Triggers>
</Style>
@@ -142,7 +162,7 @@
Margin="0,0,0,8"
Foreground="{ui:ThemeResource TextFillColorTertiaryBrush}"
TextWrapping="Wrap">
支持 Javascript 编写的脚本,<Hyperlink Command="{Binding GoToScriptUrlCommand}" Foreground="{ui:ThemeResource TextFillColorSecondaryBrush}">
支持 Javascript 编写的脚本,<Hyperlink Command="{Binding GoToScriptProjectUrlCommand}" Foreground="{ui:ThemeResource TextFillColorSecondaryBrush}">
点击查看使用教程
</Hyperlink>
</ui:TextBlock>
@@ -182,11 +202,13 @@
<ui:ListView Grid.Row="5"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
ItemsSource="{Binding SelectedScriptGroup.Projects, Mode=OneWay}"
dd:DragDrop.IsDragSource="True"
dd:DragDrop.IsDropTarget="True"
ItemsSource="{Binding SelectedScriptGroup.Projects, Mode=TwoWay}"
SelectionMode="Single">
<ListView.View>
<GridView ColumnHeaderContainerStyle="{StaticResource GridViewColumnHeaderDarkStyle}">
<GridViewColumn DisplayMemberBinding="{Binding Order}" Header="执行优先级" />
<GridViewColumn DisplayMemberBinding="{Binding Order}" Header="#" />
<GridViewColumn DisplayMemberBinding="{Binding Name}" Header="脚本名称" />
<GridViewColumn DisplayMemberBinding="{Binding ScheduleDesc}" Header="执行周期" />
<GridViewColumn DisplayMemberBinding="{Binding StatusDesc}" Header="启用状态" />
@@ -194,10 +216,10 @@
</ListView.View>
<ListBox.ContextMenu>
<ContextMenu>
<MenuItem Command="{Binding AddScriptCommand}" Header="新增配置" />
<MenuItem Command="{Binding AddScriptCommand}" Header="添加配置" />
<MenuItem Command="{Binding DeleteScriptCommand}"
CommandParameter="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ContextMenu}, Path=PlacementTarget.SelectedItem}"
Header="除配置" />
Header="除配置" />
</ContextMenu>
</ListBox.ContextMenu>
<ListView.Style>

View File

@@ -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 @@
<StackPanel Grid.Row="1" Margin="12">
<ui:TextBlock Name="TxtQuestion" Margin="5" />
<ui:TextBox Name="TxtResponse" Margin="5" />
<!-- <ui:TextBox Name="TxtResponse" Margin="5" /> -->
<ContentControl Name="DynamicContent" Margin="5" />
<StackPanel Margin="5"
HorizontalAlignment="Right"
Orientation="Horizontal">
@@ -43,7 +43,7 @@
</StackPanel>
</StackPanel>
<ui:TitleBar Title="配置" Grid.Row="0">
<ui:TitleBar Name="MyTitleBar" Grid.Row="0">
<ui:TitleBar.Icon>
<ui:ImageIcon Source="pack://application:,,,/Assets/Kirara.png" />
</ui:TitleBar.Icon>

View File

@@ -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)
{

View File

@@ -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<ScriptProject> 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);
}
}

View File

@@ -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()