update UI experience

在 `App.xaml` 中添加了 `BooleanToEnableTextConverter` 转换器。
在 `ScriptControlPage.xaml` 中:
  * 更新了文本描述,增加了对配置组排序的说明。
  * 添加了一个新的 `TextBlock` 和 `Button`,用于新增配置组。
  * 将“启用状态”列从简单的文本显示改为 `ToggleSwitch` 控件,并使用 `BooleanToEnableTextConverter` 进行绑定。
  * 将 `ListBox.ContextMenu` 更改为 `ListView.ContextMenu`。
  * 为“修改JS脚本自定义配置”菜单项添加了样式和触发器,以根据脚本类型动态显示或隐藏。
在 `ScriptControlViewModel.cs` 中:
  * 添加了 `System.ComponentModel` 的引用。
  * 注释掉了 `WriteScriptGroup` 的循环调用。
  * 修改了 `ShowEditWindow` 方法,将关闭按钮文本从“确定”改为“关闭”。
  * 在 `EditJsScriptSettings` 方法中,添加了对 `LoadSettingUi` 返回值的检查,并在未提供自定义配置时显示警告。
  * 在 `ScriptProjectsCollectionChanged` 方法中,添加了对项目属性变化的事件处理。
  * 添加了 `ScriptProjectsPChanged` 方法,用于处理项目属性变化事件。
  * 更新了 `OnGoToScriptGroupUrl` 方法中的 URL。
新增了 `BooleanToEnableTextConverter.cs` 文件,实现了 `BooleanToEnableTextConverter` 转换器,用于将布尔值与启用状态文本进行转换。
This commit is contained in:
辉鸭蛋 2024-09-07 12:31:07 +08:00
parent 010beebcb6
commit 93250f84cf
4 changed files with 87 additions and 20 deletions

View File

@ -16,6 +16,7 @@
<FontFamily x:Key="DigitalThemeFontFamily">/Assets/Fonts/deluge-led.ttf#Deluge LED</FontFamily>
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
<bgivc:BooleanToVisibilityRevertConverter x:Key="BooleanToVisibilityRevertConverter" />
<bgivc:BooleanToEnableTextConverter x:Key="BooleanToEnableTextConverter" />
<bgivc:InverseBooleanConverter x:Key="InverseBooleanConverter" />
<bgivc:NotNullConverter x:Key="NotNullConverter" />
</ResourceDictionary>

View File

@ -0,0 +1,22 @@
using System;
using System.Windows;
using System.Windows.Data;
namespace BetterGenshinImpact.View.Converters;
/// <summary>
/// ScriptGroupProjectExtensions
/// </summary>
[ValueConversion(typeof(bool), typeof(Visibility))]
public sealed class BooleanToEnableTextConverter : IValueConverter
{
public object Convert(object? value, Type targetType, object? parameter, System.Globalization.CultureInfo culture)
{
return value is "Enabled";
}
public object ConvertBack(object? value, Type targetType, object? parameter, System.Globalization.CultureInfo culture)
{
return value is false ? "Disabled" : "Enabled";
}
}

View File

@ -100,10 +100,16 @@
<ui:TextBlock Margin="0,0,0,8"
Foreground="{ui:ThemeResource TextFillColorTertiaryBrush}"
TextWrapping="Wrap">
左侧配置组栏目右键可以新增配置组,然后可以添加并配置软件内的 Javascript 脚本、键鼠脚本等,并能够控制执行次数、顺序等,<Hyperlink Command="{Binding GoToScriptGroupUrlCommand}" 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:Button Margin="0,0,0,12"
Command="{Binding AddScriptGroupCommand}"
Content="新增配置组" />
<!-- 示例配置组 -->
<ui:TextBlock Margin="0,0,0,8"
FontTypography="BodyStrong"
@ -224,12 +230,16 @@
<GridViewColumn Width="{Binding ElementName=Col5, Path=ActualWidth}"
DisplayMemberBinding="{Binding RunNum}"
Header="执行次数" />
<GridViewColumn Width="{Binding ElementName=Col6, Path=ActualWidth}"
DisplayMemberBinding="{Binding StatusDesc}"
Header="启用状态" />
<GridViewColumn Width="{Binding ElementName=Col6, Path=ActualWidth}" Header="启用状态">
<GridViewColumn.CellTemplate>
<DataTemplate>
<ui:ToggleSwitch IsChecked="{Binding Status, Converter={StaticResource BooleanToEnableTextConverter}, Mode=TwoWay}" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
<ListBox.ContextMenu>
<ListView.ContextMenu>
<ContextMenu>
<MenuItem Command="{Binding AddJsScriptCommand}" Header="添加JS脚本" />
<MenuItem Command="{Binding AddKmScriptCommand}" Header="添加键鼠脚本" />
@ -238,12 +248,23 @@
Header="修改通用配置" />
<MenuItem Command="{Binding EditJsScriptSettingsCommand}"
CommandParameter="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ContextMenu}, Path=PlacementTarget.SelectedItem}"
Header="修改JS脚本自定义配置" />
Header="修改JS脚本自定义配置">
<MenuItem.Style>
<Style TargetType="MenuItem">
<Setter Property="Visibility" Value="Collapsed" />
<Style.Triggers>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ContextMenu}, Path=PlacementTarget.SelectedItem.Type}" Value="Javascript">
<Setter Property="Visibility" Value="Visible" />
</DataTrigger>
</Style.Triggers>
</Style>
</MenuItem.Style>
</MenuItem>
<MenuItem Command="{Binding DeleteScriptCommand}"
CommandParameter="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ContextMenu}, Path=PlacementTarget.SelectedItem}"
Header="移除" />
</ContextMenu>
</ListBox.ContextMenu>
</ListView.ContextMenu>
<ListView.Style>
<Style TargetType="{x:Type ListView}">
<Setter Property="BorderThickness" Value="0" />

View File

@ -11,6 +11,7 @@ using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Diagnostics;
using System.Dynamic;
using System.IO;
@ -189,10 +190,10 @@ public partial class ScriptControlViewModel : ObservableObject, INavigationAware
ShowEditWindow(item);
foreach (var group in ScriptGroups)
{
WriteScriptGroup(group);
}
// foreach (var group in ScriptGroups)
// {
// WriteScriptGroup(group);
// }
}
public static void ShowEditWindow(object viewModel)
@ -201,7 +202,7 @@ public partial class ScriptControlViewModel : ObservableObject, INavigationAware
{
Title = "修改通用设置",
Content = new ScriptGroupProjectEditor { DataContext = viewModel },
CloseButtonText = "确定",
CloseButtonText = "关闭",
Owner = Application.Current.MainWindow,
};
uiMessageBox.ShowDialogAsync();
@ -229,19 +230,25 @@ public partial class ScriptControlViewModel : ObservableObject, INavigationAware
{
item.JsScriptSettingsObject = new ExpandoObject();
}
var ui = item.Project.LoadSettingUi(item.JsScriptSettingsObject);
if (ui == null)
{
Toast.Warning("此脚本未提供自定义配置");
return;
}
var uiMessageBox = new Wpf.Ui.Controls.MessageBox
{
Title = "修改JS脚本自定义设置",
Content = item.Project.LoadSettingUi(item.JsScriptSettingsObject),
CloseButtonText = "确定",
Title = "修改JS脚本自定义设置 ",
Content = ui,
CloseButtonText = "关闭",
Owner = Application.Current.MainWindow,
};
uiMessageBox.ShowDialogAsync();
foreach (var group in ScriptGroups)
{
WriteScriptGroup(group);
}
// foreach (var group in ScriptGroups)
// {
// WriteScriptGroup(group);
// }
}
else
{
@ -274,6 +281,10 @@ public partial class ScriptControlViewModel : ObservableObject, INavigationAware
foreach (ScriptGroup newItem in e.NewItems)
{
newItem.Projects.CollectionChanged += ScriptProjectsCollectionChanged;
foreach (var project in newItem.Projects)
{
project.PropertyChanged += ScriptProjectsPChanged;
}
}
}
@ -281,6 +292,10 @@ public partial class ScriptControlViewModel : ObservableObject, INavigationAware
{
foreach (ScriptGroup oldItem in e.OldItems)
{
foreach (var project in oldItem.Projects)
{
project.PropertyChanged -= ScriptProjectsPChanged;
}
oldItem.Projects.CollectionChanged -= ScriptProjectsCollectionChanged;
}
}
@ -299,6 +314,14 @@ public partial class ScriptControlViewModel : ObservableObject, INavigationAware
}
}
private void ScriptProjectsPChanged(object? sender, PropertyChangedEventArgs e)
{
foreach (var group in ScriptGroups)
{
WriteScriptGroup(group);
}
}
private void ScriptProjectsCollectionChanged(object? sender, NotifyCollectionChangedEventArgs e)
{
// 补充排序字段
@ -399,7 +422,7 @@ public partial class ScriptControlViewModel : ObservableObject, INavigationAware
[RelayCommand]
public void OnGoToScriptGroupUrl()
{
Process.Start(new ProcessStartInfo("https://bgi.huiyadan.com/") { UseShellExecute = true });
Process.Start(new ProcessStartInfo("https://bgi.huiyadan.com/autos/dispatcher.html") { UseShellExecute = true });
}
[RelayCommand]