Ver Fonte

新增光源控制器添加对话框及多语言支持优化

本次提交实现了“添加光源控制器”对话框,支持用户自定义名称和型号,完善了相关MVVM逻辑和UI界面,并在多处界面引入了“通道配置”、“串口配置”、“TCP配置”等本地化资源,提升了多语言适配能力。同时优化了主设置界面添加光源控制器的交互流程及部分布局细节,增强了系统的易用性和国际化体验。
孝锋 徐 há 8 meses atrás
pai
commit
7bf9c65805

+ 27 - 0
TeamAAS-VM/Resources/Languages/Lang.Designer.cs

@@ -726,6 +726,15 @@ namespace TeamAAS_VP.Resources.Languages {
             }
         }
         
+        /// <summary>
+        ///   查找类似 TCP 配置 的本地化字符串。
+        /// </summary>
+        public static string TCP配置 {
+            get {
+                return ResourceManager.GetString("TCP配置", resourceCulture);
+            }
+        }
+        
         /// <summary>
         ///   查找类似 回车 的本地化字符串。
         /// </summary>
@@ -1023,6 +1032,15 @@ namespace TeamAAS_VP.Resources.Languages {
             }
         }
         
+        /// <summary>
+        ///   查找类似 串口配置 的本地化字符串。
+        /// </summary>
+        public static string 串口配置 {
+            get {
+                return ResourceManager.GetString("串口配置", resourceCulture);
+            }
+        }
+        
         /// <summary>
         ///   查找类似 产品 的本地化字符串。
         /// </summary>
@@ -5523,6 +5541,15 @@ namespace TeamAAS_VP.Resources.Languages {
             }
         }
         
+        /// <summary>
+        ///   查找类似 通道配置 的本地化字符串。
+        /// </summary>
+        public static string 通道配置 {
+            get {
+                return ResourceManager.GetString("通道配置", resourceCulture);
+            }
+        }
+        
         /// <summary>
         ///   查找类似 速度 的本地化字符串。
         /// </summary>

+ 9 - 0
TeamAAS-VM/Resources/Languages/Lang.resx

@@ -2078,4 +2078,13 @@
   <data name="光源控制器" xml:space="preserve">
     <value>光源控制器</value>
   </data>
+  <data name="通道配置" xml:space="preserve">
+    <value>通道配置</value>
+  </data>
+  <data name="串口配置" xml:space="preserve">
+    <value>串口配置</value>
+  </data>
+  <data name="TCP配置" xml:space="preserve">
+    <value>TCP 配置</value>
+  </data>
 </root>

+ 8 - 0
TeamAAS-VM/TeamAAS-VP.csproj

@@ -748,6 +748,7 @@
     <Compile Include="ValueConverter\RobotConverter.cs" />
     <Compile Include="ValueConverter\RobotIdToVisibiltyConverter.cs" />
     <Compile Include="ValueConverter\StringFormatConverter.cs" />
+    <Compile Include="ViewModels\Setting\AddLightControllerViewModel.cs" />
     <Compile Include="ViewModels\Setting\AddPlcViewModel.cs" />
     <Compile Include="ViewModels\Product\AfagFeederParamsViewModel.cs" />
     <Compile Include="ViewModels\DebugMod\AfagFeederManualViewModel.cs" />
@@ -943,6 +944,9 @@
     <Compile Include="Views\Setting\AddFeeder.xaml.cs">
       <DependentUpon>AddFeeder.xaml</DependentUpon>
     </Compile>
+    <Compile Include="Views\Setting\AddLightController.xaml.cs">
+      <DependentUpon>AddLightController.xaml</DependentUpon>
+    </Compile>
     <Compile Include="Views\Setting\AddPlc.xaml.cs">
       <DependentUpon>AddPlc.xaml</DependentUpon>
     </Compile>
@@ -1265,6 +1269,10 @@
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>
     </Page>
+    <Page Include="Views\Setting\AddLightController.xaml">
+      <SubType>Designer</SubType>
+      <Generator>MSBuild:Compile</Generator>
+    </Page>
     <Page Include="Views\Setting\AddPlc.xaml">
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>

+ 59 - 0
TeamAAS-VM/ViewModels/Setting/AddLightControllerViewModel.cs

@@ -0,0 +1,59 @@
+using Prism.Commands;
+using Prism.Mvvm;
+using Prism.Services.Dialogs;
+using System;
+using TeamAAS_VP.Models.Lights;
+using TeamAAS_VP.Resources.Languages;
+
+namespace TeamAAS_VP.ViewModels.Setting
+{
+    public class AddLightControllerViewModel : BindableBase, IDialogAware
+    {
+        private LightControllerConfig _LightController;
+        public LightControllerConfig LightController
+        {
+            get => _LightController; set => SetProperty(ref _LightController, value);
+        }
+
+        private DelegateCommand _ConfirmCommand;
+        public DelegateCommand ConfirmCommand => _ConfirmCommand ?? (_ConfirmCommand = new DelegateCommand(ExecuteConfirmCommand, CanExecuteConfirmCommand).ObservesProperty(() => LightController.Name));
+
+        private DelegateCommand _CancelCommand;
+        public DelegateCommand CancelCommand => _CancelCommand ?? (_CancelCommand = new DelegateCommand(ExecuteCancelCommand));
+
+        public AddLightControllerViewModel()
+        {
+
+        }
+
+        public string Title { get; set; } = "Ìí¼Ó¹âÔ´¿ØÖÆÆ÷";
+
+        public event Action<IDialogResult> RequestClose;
+
+        public bool CanCloseDialog() => true;
+
+        public void OnDialogClosed() { }
+
+        public void OnDialogOpened(IDialogParameters parameters)
+        {
+            LightController = new LightControllerConfig() { Id = 0, Name = "New Controller", LightModel = TeamAAS_VP.Core.Lights.LightModel.KCS_KDC_12V60W_4T };
+        }
+
+        bool CanExecuteConfirmCommand()
+        {
+            return LightController != null && !string.IsNullOrEmpty(LightController.Name);
+        }
+
+        void ExecuteConfirmCommand()
+        {
+            var p = new DialogParameters();
+            p.Add("LightController", LightController);
+            RequestClose?.Invoke(new DialogResult(ButtonResult.OK, p));
+        }
+
+        void ExecuteCancelCommand()
+        {
+            RequestClose?.Invoke(new DialogResult(ButtonResult.Cancel));
+        }
+    }
+}

+ 14 - 9
TeamAAS-VM/ViewModels/SettingViewModel.cs

@@ -872,16 +872,21 @@ namespace TeamAAS_VP.ViewModels
         #region Light handlers
         void ExecuteAddLightControllerCommand()
         {
-            // create default controller
-            var ctrl = new LightControllerConfig()
+            // open dialog to add light controller (similar to robots)
+            _dialogService.ShowDialog("AddLightController", rst =>
             {
-                Name = $"Controller {(LightControllerList?.Count ?? 0) + 1}",
-                LightModel = LightModel.KCS_KDC_12V60W_4T
-            };
-            LightControllerList.Add(ctrl);
-            _configService.AddOrUpdateLightController(ctrl);
-            SelectLightController = ctrl;
-            _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "添加完成", Duration = 1 });
+                if (rst.Result == ButtonResult.OK)
+                {
+                    var param = rst.Parameters.GetValue<LightControllerConfig>("LightController");
+                    // assign id and defaults if needed
+                    if (param.Id == 0)
+                        param.Id = (LightControllerList?.Count ?? 0) + 1;
+                    LightControllerList.Add(param);
+                    _configService.AddOrUpdateLightController(param);
+                    SelectLightController = param;
+                    _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "添加完成", Duration = 1 });
+                }
+            });
         }
 
         void ExecuteRemoveLightControllerCommand()

+ 135 - 0
TeamAAS-VM/Views/Setting/AddLightController.xaml

@@ -0,0 +1,135 @@
+<UserControl x:Class="TeamAAS_VP.Views.Setting.AddLightController"
+             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+             xmlns:prism="http://prismlibrary.com/"
+             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+             xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
+             xmlns:b="http://schemas.microsoft.com/xaml/behaviors"
+             xmlns:sys="clr-namespace:System;assembly=mscorlib"
+             xmlns:enums="clr-namespace:TeamAAS_VP.Enums"
+             xmlns:valRules="clr-namespace:TeamAAS_VP.Identity"
+             xmlns:ext="clr-namespace:TeamAAS_VP.Extension"
+             xmlns:c="clr-namespace:TeamAAS_VP.ValueConverter"
+             xmlns:lex="http://wpflocalizeextension.codeplex.com"
+             xmlns:vm="clr-namespace:TeamAAS_VP.ViewModels.Setting"
+             xmlns:coreLights="clr-namespace:TeamAAS_VP.Core.Lights"
+             lex:LocalizeDictionary.DesignCulture="zh-CN"
+             lex:ResxLocalizationProvider.DefaultAssembly="TeamAAS-VP"
+             lex:ResxLocalizationProvider.DefaultDictionary="Lang"
+             mc:Ignorable="d"
+             d:Background="White"
+             d:DataContext="{d:DesignInstance Type=vm:AddLightControllerViewModel}"
+             prism:ViewModelLocator.AutoWireViewModel="True"
+             FontFamily="{DynamicResource DefaultFont}">
+    <prism:Dialog.WindowStyle>
+        <Style TargetType="Window">
+            <Setter Property="prism:Dialog.WindowStartupLocation"
+                    Value="CenterScreen" />
+            <Setter Property="WindowStyle"
+                    Value="None" />
+            <Setter Property="AllowDrop"
+                    Value="True" />
+            <Setter Property="BorderThickness"
+                    Value="0" />
+            <Setter Property="ShowInTaskbar"
+                    Value="False" />
+            <Setter Property="SizeToContent"
+                    Value="WidthAndHeight" />
+            <Setter Property="WindowState"
+                    Value="Normal" />
+            <Setter Property="Topmost"
+                    Value="True" />
+        </Style>
+    </prism:Dialog.WindowStyle>
+
+    <Grid HorizontalAlignment="Center">
+        <Grid.RowDefinitions>
+            <RowDefinition Height="*" />
+            <RowDefinition Height="50" />
+        </Grid.RowDefinitions>
+
+        <Grid Margin="20,20">
+            <Grid.RowDefinitions>
+                <RowDefinition />
+                <RowDefinition />
+                <RowDefinition />
+            </Grid.RowDefinitions>
+            <Grid.ColumnDefinitions>
+                <ColumnDefinition Width="50*" />
+                <ColumnDefinition Width="50*" />
+            </Grid.ColumnDefinitions>
+
+            <TextBlock Text="Id: "
+                       Grid.Row="0"
+                       Grid.Column="0"
+                       Style="{StaticResource MaterialDesignSubtitle1TextBlock}"
+                       HorizontalAlignment="Right"
+                       VerticalAlignment="Center" />
+            <TextBlock x:Name="txt_Id"
+                       Text="{Binding LightController.Id,Mode=TwoWay}"
+                       Grid.Row="0"
+                       Grid.Column="1"
+                       Margin="10,5"
+                       HorizontalAlignment="Left"
+                       VerticalAlignment="Center" />
+
+            <TextBlock Text="{lex:Loc 名称,Converter={StaticResource StringFormatConverter},ConverterParameter='{}{0}: '}"
+                       Grid.Row="1"
+                       Grid.Column="0"
+                       Style="{StaticResource MaterialDesignSubtitle1TextBlock}"
+                       HorizontalAlignment="Right"
+                       VerticalAlignment="Center" />
+            <TextBox x:Name="txt_Name"
+                     Grid.Row="1"
+                     Grid.Column="1"
+                     Margin="10,5"
+                     Width="200"
+                     TextAlignment="Center"
+                     HorizontalAlignment="Left"
+                     VerticalAlignment="Center">
+                <TextBox.Text>
+                    <Binding Path="LightController.Name"
+                             Mode="TwoWay">
+                        <Binding.ValidationRules>
+                            <valRules:NameValidationRule />
+                        </Binding.ValidationRules>
+                    </Binding>
+                </TextBox.Text>
+            </TextBox>
+
+            <TextBlock Text="{lex:Loc 型号,Converter={StaticResource StringFormatConverter},ConverterParameter='{}{0}: '}"
+                       Grid.Row="2"
+                       Grid.Column="0"
+                       Style="{StaticResource MaterialDesignSubtitle1TextBlock}"
+                       HorizontalAlignment="Right"
+                       VerticalAlignment="Center" />
+            <ComboBox Grid.Row="2"
+                      Grid.Column="1"
+                      Margin="10,5"
+                      Width="200"
+                      SelectedItem="{Binding LightController.LightModel,Mode=TwoWay}"
+                      ItemsSource="{ext:EnumBindingSource EnumType=coreLights:LightModel}"
+                      HorizontalAlignment="Left" />
+        </Grid>
+
+        <StackPanel Grid.Row="1"
+                    Orientation="Horizontal"
+                    HorizontalAlignment="Right">
+            <Button Height="30"
+                    materialDesign:ButtonAssist.CornerRadius="10"
+                    ToolTip="{lex:Loc 确定}"
+                    Command="{Binding ConfirmCommand}">
+                <TextBlock Text="{lex:Loc 确定}" />
+            </Button>
+            <Button Height="30"
+                    Margin="20,0"
+                    materialDesign:ButtonAssist.CornerRadius="10"
+                    Style="{StaticResource MaterialDesignRaisedButton}"
+                    ToolTip="{lex:Loc 取消}"
+                    Command="{Binding CancelCommand}">
+                <TextBlock Text="{lex:Loc 取消}" />
+            </Button>
+        </StackPanel>
+    </Grid>
+</UserControl>

+ 15 - 0
TeamAAS-VM/Views/Setting/AddLightController.xaml.cs

@@ -0,0 +1,15 @@
+using System.Windows.Controls;
+
+namespace TeamAAS_VP.Views.Setting
+{
+    /// <summary>
+    /// Interaction logic for AddLightController
+    /// </summary>
+    public partial class AddLightController : UserControl
+    {
+        public AddLightController()
+        {
+            InitializeComponent();
+        }
+    }
+}

+ 3 - 3
TeamAAS-VM/Views/SettingView.xaml

@@ -1335,7 +1335,7 @@
                             </Grid.RowDefinitions>
                             <Grid.ColumnDefinitions>
                                 <ColumnDefinition Width="auto" />
-                                <ColumnDefinition Width="*" />
+                                <ColumnDefinition Width="*"  MinWidth="200"/>
                             </Grid.ColumnDefinitions>
 
                             <!-- Id -->
@@ -1423,7 +1423,7 @@
                             <!-- Serial port config (visible for serial model) -->
                             <GroupBox Grid.Row="5"
                                       Grid.ColumnSpan="2"
-                                      Header="串口配置"
+                                      Header="{lex:Loc 串口配置}"
                                       Margin="0,12,0,0">
                                 <GroupBox.Style>
                                     <Style TargetType="GroupBox">
@@ -1505,7 +1505,7 @@
                             <!-- TCP config (visible for non-serial models) -->
                             <GroupBox Grid.Row="5"
                                       Grid.ColumnSpan="2"
-                                      Header="TCP 配置"
+                                      Header="{lex:Loc TCP配置}"
                                       Margin="0,12,0,0">
                                 <GroupBox.Style>
                                     <Style TargetType="GroupBox">