Skip to content

Commit

Permalink
修复启动任务选择保存问题
Browse files Browse the repository at this point in the history
  • Loading branch information
SweetSmellFox committed Sep 15, 2024
1 parent 851c5d2 commit 4fd1ed5
Show file tree
Hide file tree
Showing 11 changed files with 94 additions and 54 deletions.
8 changes: 4 additions & 4 deletions Controls/CustomAutoListControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
<!-- 第一列的宽度使用 SubtractConverter 动态计算 -->
<ColumnDefinition Width="*" />
<!-- 第二列按钮宽度保持固定 -->
<ColumnDefinition Width="25" />
<ColumnDefinition Width="18" />
</Grid.ColumnDefinitions>

<!-- CustomAutoCompleteTextBox 绑定 ItemSource 和 DataList -->
Expand All @@ -70,14 +70,14 @@
<Binding Path="ActualWidth"
RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType={x:Type ListBoxItem}}"
Converter="{StaticResource SubtractConverter}"
ConverterParameter="60" />
ConverterParameter="45" />
</local:CustomAutoCompleteTextBox.Width>
</local:CustomAutoCompleteTextBox>

<Button Grid.Column="1" ToolTip="{lex:Loc Delete}" Width="15" Height="15"
Style="{StaticResource textBoxButton}" Margin="5 0 0 0"
Style="{StaticResource textBoxButton}"
Foreground="{DynamicResource GrayColor4}"
Click="DeleteButton_Click"
Click="DeleteButton_Click" Margin="8 0 0 0"
Padding="0"
hc:IconElement.Width="12" hc:IconElement.Height="12"
hc:IconElement.Geometry="{StaticResource CloseGeometry}" />
Expand Down
6 changes: 3 additions & 3 deletions Controls/CustomListControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
<!-- 第一列的宽度使用 SubtractConverter 动态计算 -->
<ColumnDefinition Width="*" />
<!-- 第二列按钮宽度保持固定 -->
<ColumnDefinition Width="25" />
<ColumnDefinition Width="18" />
</Grid.ColumnDefinitions>

<!-- TextBox 宽度通过绑定 Grid 的 ActualWidth 减去按钮宽度 -->
Expand All @@ -66,12 +66,12 @@
<Binding Path="ActualWidth"
RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType={x:Type ListBoxItem}}"
Converter="{StaticResource SubtractConverter}"
ConverterParameter="60" />
ConverterParameter="45" />
</TextBox.Width>
</TextBox>

<Button Grid.Column="1" ToolTip="{lex:Loc Delete}" Width="15" Height="15"
Style="{StaticResource textBoxButton}" Margin="5 0 0 0"
Style="{StaticResource textBoxButton}" Margin="8 0 0 0"
Foreground="{DynamicResource GrayColor4}"
Click="DeleteButton_Click"
Padding="0"
Expand Down
15 changes: 15 additions & 0 deletions Controls/CustomWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,21 @@ protected virtual void Close(object? sender = null, RoutedEventArgs? e = null)
base.Close();
}

protected void btnClose_Click(object sender, RoutedEventArgs e)
{
base.Close();
}

protected void btnRestore_Click(object sender, RoutedEventArgs e)
{
WindowState = WindowState == WindowState.Normal ? WindowState.Maximized : WindowState.Normal;
}

protected void btnMinimize_Click(object sender, RoutedEventArgs e)
{
WindowState = WindowState.Minimized;
}

protected void Window_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
_pressedPosition = e.GetPosition(this);
Expand Down
3 changes: 2 additions & 1 deletion Data/DataSet.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

using System.Diagnostics;
using MFAWPF.Utils;
using Newtonsoft.Json.Linq;

Expand Down Expand Up @@ -61,6 +61,7 @@ public static bool TryGetData<T>(string key, out T? value)
{
try
{

if (data is long longValue && typeof(T) == typeof(int))
{
return (T)(object)Convert.ToInt32(longValue);
Expand Down
2 changes: 1 addition & 1 deletion MFAWPF.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<ApplicationVersion>1.1.0</ApplicationVersion>
<Version>1.1</Version>
<FileVersion>0.0.1</FileVersion>
<AssemblyVersion>1.1.4.1</AssemblyVersion>
<AssemblyVersion>1.1.4</AssemblyVersion>
<InformationalVersion>0.0.1</InformationalVersion>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
- [MaaFramework.Binding.CSharp](https://github.com/MaaXYZ/MaaFramework.Binding.CSharp):MaaFramework 的 C# 包装
- [HandyControls](https://github.com/ghost1372/HandyControls):C# WPF 控件库
- [NLog](https://github.com/NLog/NLog):C# 日志记录库
- [Newtonsoft.Json](https://github.com/CommunityToolkit/dotnet):C# C# JSON 库
- [Newtonsoft.Json](https://github.com/CommunityToolkit/dotnet):C# JSON 库

## 画大饼

Expand Down
4 changes: 1 addition & 3 deletions Utils/OCRHelper.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

using MFAWPF.ViewModels;
using MFAWPF.ViewModels;
using MaaFramework.Binding;
using MaaFramework.Binding.Buffers;
using Newtonsoft.Json;
Expand Down Expand Up @@ -59,7 +58,6 @@ public static string ReadTextFromMAARecognition(int x, int y, int width, int hei
}

Console.WriteLine($"识别结果: {result}");
// 拼接结果文本
return result;
}

Expand Down
19 changes: 15 additions & 4 deletions ViewModels/DragItemViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public string Name
}

private bool? _isCheckedWithNull = false;
private bool _isInitialized = false;

/// <summary>
/// Gets or sets a value indicating whether gets or sets whether the key is checked with null.
Expand All @@ -44,12 +45,22 @@ public bool? IsCheckedWithNull
get => _isCheckedWithNull;
set
{
SetProperty(ref _isCheckedWithNull, value);
value ??= false;
if (!_isInitialized)
{
// 这是初始化操作
_isInitialized = true; // 标记已初始化
SetProperty(ref _isCheckedWithNull, value); // 可以选择在初始化时不修改 value
}
else
{
// 这是后续的 set 操作
value ??= false; // 只有在后续 set 时才将 null 设置为 false
SetProperty(ref _isCheckedWithNull, value);
DataSet.SetData("Tasks", MainWindow.Data?.TaskItemViewModels.ToList());
}

if (InterfaceItem != null)
InterfaceItem.check = IsChecked;
JsonHelper.WriteToJsonFilePath(AppDomain.CurrentDomain.BaseDirectory, "interface", MaaInterface.Instance);
DataSet.SetData("Tasks", MainWindow.Data?.TaskItemViewModels.ToList());
}
}

Expand Down
5 changes: 3 additions & 2 deletions Views/EditAttributeDialog.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using ScrollViewer = System.Windows.Controls.ScrollViewer;
using TextBlock = System.Windows.Controls.TextBlock;
using TextBox = System.Windows.Controls.TextBox;
using Window = System.Windows.Window;

namespace MFAWPF.Views;

Expand All @@ -25,9 +26,9 @@ public partial class EditAttributeDialog : CustomWindow
public Attribute Attribute { get; private set; }
private bool IsEdit = true;
private UIElement? Control;
private CustomWindow? ParentDialog;
private Window? ParentDialog;

public EditAttributeDialog(CustomWindow? parentDialog, Attribute? attribute = null, bool isEdit = false) :
public EditAttributeDialog(Window? parentDialog, Attribute? attribute = null, bool isEdit = false) :
base()
{
InitializeComponent();
Expand Down
58 changes: 44 additions & 14 deletions Views/EditTaskDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:hc="https://handyorg.github.io/handycontrol"
xmlns:local="clr-namespace:MFAWPF.Views" IsResizable="True"
xmlns:local="clr-namespace:MFAWPF.Views"
xmlns:models="clr-namespace:MFAWPF.ViewModels"
xmlns:controls="clr-namespace:MFAWPF.Controls"
xmlns:utils="clr-namespace:MFAWPF.Utils"
xmlns:dd="urn:gong-wpf-dragdrop"
xmlns:lex="http://wpflocalizeextension.codeplex.com"
mc:Ignorable="d" MinHeight="230" MinWidth="450"
mc:Ignorable="d" MinHeight="230" MinWidth="450" x:Name="editor"
Icon="../logo.ico"
Title="{lex:Loc EditTaskDialog_Title}" Height="800" Width="1000">
<controls:CustomWindow.DataContext>
<models:EditTaskDialogViewModel />
Expand All @@ -31,23 +32,51 @@
BorderThickness="1">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="35" />
<RowDefinition Height="30" />
<RowDefinition />
<RowDefinition Height="15" />
</Grid.RowDefinitions>

<Border Grid.Row="0" CornerRadius="10 10 0 0" Background="{DynamicResource MainContentBackgroundBrush}"
x:Name="TitleBar"
ClipToBounds="False">
<Grid Height="34">
<TextBlock Text="{lex:Loc EditTaskDialog_Header}" VerticalAlignment="Center"
Foreground="{DynamicResource BlackColor}"
FontWeight="Bold" FontSize="17" HorizontalAlignment="Center"
Margin="0 0 0 0" />
<Button Width="22" Height="22" Click="Close" Style="{StaticResource ButtonIcon}"
Foreground="{DynamicResource PrimaryBrush}"
hc:IconElement.Geometry="{StaticResource ErrorGeometry}"
Padding="0" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,4,4,0" />
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Left" Margin="10 0 0 0 " Height="30">
<Image VerticalAlignment="Center" DockPanel.Dock="Left" Source="/logo.ico" x:Name="logo"
Height="20" Width="20">

</Image>
<TextBlock VerticalAlignment="Center" Margin="6 1 4 0" Text="{lex:Loc EditTaskDialog_Title}"
FontSize="15"
Foreground="{DynamicResource PrimaryTextBrush}">

</TextBlock>
</StackPanel>
<StackPanel HorizontalAlignment="Right" Orientation="Horizontal" FlowDirection="RightToLeft">

<Button x:Name="btnClose" Style="{StaticResource IconButtonsStyle}" Width="40"
ClipToBounds="True"
Content="{DynamicResource close}" Click="btnClose_Click" Tag="IsCloseButton" />
<Button x:Name="btnRestore" Margin="5,0" Click="btnRestore_Click" Width="40">
<Button.Style>
<Style TargetType="{x:Type Button}" BasedOn="{StaticResource IconButtonsStyle}">
<Setter Property="Content" Value="{DynamicResource maximize}" />
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=editor, Path=WindowState}"
Value="Maximized">
<Setter Property="Content"
Value="{DynamicResource WindowRestoreGeometry}" />
</DataTrigger>
</Style.Triggers>
</Style>
</Button.Style>
</Button>
<Button x:Name="btnMinimize" Style="{DynamicResource IconButtonsStyle}" Width="40"
Content="{DynamicResource minimize}" Click="btnMinimize_Click" />
</StackPanel>
</Grid>
</Border>

Expand Down Expand Up @@ -220,8 +249,9 @@
</Grid>
<Border Grid.Row="2" Background="{DynamicResource WhiteColor}" CornerRadius="8" Margin="2 4 2 0"
Padding="4">
<ScrollViewer VerticalScrollBarVisibility="Auto" PreviewMouseWheel="ScrollViewer_PreviewMouseWheel">
<StackPanel>
<ScrollViewer VerticalScrollBarVisibility="Auto"
PreviewMouseWheel="ScrollViewer_PreviewMouseWheel">
<StackPanel>
<hc:PropertyGrid x:Name="PropertyGrid" />
</StackPanel>
</ScrollViewer>
Expand Down
26 changes: 5 additions & 21 deletions Views/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ private bool InitializeData()
}


private bool firstTask = true;
public bool firstTask = true;

private void LoadTasks(IEnumerable<TaskInterfaceItem> tasks)
{
Expand Down Expand Up @@ -203,27 +203,12 @@ private void ToggleTaskButtonsVisibility(bool isRunning)
}
}

protected new void Close()
protected override void OnClosed(EventArgs e)
{
base.Close();
base.OnClosed(e);
Application.Current.Shutdown();
}

private void btnClose_Click(object sender, RoutedEventArgs e)
{
Close();
}

private void btnRestore_Click(object sender, RoutedEventArgs e)
{
WindowState = WindowState == WindowState.Normal ? WindowState.Maximized : WindowState.Normal;
}

private void btnMinimize_Click(object sender, RoutedEventArgs e)
{
WindowState = WindowState.Minimized;
}

private void TaskList_OnPreviewMouseWheel(object sender, MouseWheelEventArgs e)
{
var scrollViewer = FindVisualParent<ScrollViewer>((DependencyObject)sender);
Expand Down Expand Up @@ -276,7 +261,6 @@ private bool LoadTask()
}
}

Console.WriteLine(taskDictionary.Count);
if (taskDictionary.Count == 0)
{
string? directoryPath = Path.GetDirectoryName($"{MaaProcessor.ResourceBase}/pipeline");
Expand Down Expand Up @@ -806,7 +790,7 @@ private void AddOption(MaaInterface.MaaInterfaceSelectOption option, DragItemVie
comboBox.ItemsSource = interfaceOption.cases;

comboBox.Tag = option.name;
comboBox.SelectionChanged += (sender, args) =>
comboBox.SelectionChanged += (_, _) =>
{
option.index = comboBox.SelectedIndex;
Expand Down Expand Up @@ -1013,7 +997,7 @@ private void Delete(object sender, RoutedEventArgs e)
// 获取选中项的索引
int index = Data.TaskItemViewModels.IndexOf(taskItemViewModel);
Data.TaskItemViewModels?.RemoveAt(index);
DataSet.SetData("Tasks", Data?.TaskItemViewModels);
DataSet.SetData("Tasks", Data?.TaskItemViewModels.ToList());
}
}
}
Expand Down

0 comments on commit 4fd1ed5

Please sign in to comment.