睡觉了QWQ代码表和代码集

This commit is contained in:
muqing 2024-08-19 22:30:11 +08:00
parent 7e891b0df8
commit 582f4f2652
19 changed files with 927 additions and 27 deletions

View File

@ -1,10 +1,15 @@

using System.Diagnostics;
using System.IO.Compression;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.UI.Xaml;
using Microsoft.Windows.AppLifecycle;
using Newtonsoft.Json;
using RustTools.Activation;
using RustTools.Contracts.Services;
using RustTools.DataList;
using RustTools.Helpers;
using RustTools.Models;
using RustTools.muqing;
using RustTools.Services;
@ -12,6 +17,7 @@ using RustTools.ViewModels;
using RustTools.Views;
using RustTools.WindowUI;
using Windows.ApplicationModel.Activation;
using Windows.Storage;
namespace RustTools;
@ -77,16 +83,19 @@ public partial class App : Microsoft.UI.Xaml.Application
services.AddTransient<SettingsPage>();
services.AddTransient<HomePageViewModel>();
services.AddTransient<HomePage>();
//services.AddTransient<HomePage>();
services.AddTransient<ConcernViewModel>();
services.AddTransient<ConcernPage>();
//services.AddTransient<ConcernPage>();
services.AddTransient<RankingViewModel>();
services.AddTransient<RankingPage>();
//services.AddTransient<RankingPage>();
services.AddTransient<UserViewModel>();
services.AddTransient<UserPage>();
//services.AddTransient<UserPage>();
//模组碎片
services.AddTransient<ModuleViewModel>();
services.AddTransient<ModulePage>();
//services.AddTransient<ModulePage>();
services.AddTransient<CodeTableViewModel>();
//services.AddTransient<CodeTablePage>();
services.AddTransient<ShellPage>();
services.AddTransient<ShellViewModel>();
@ -97,6 +106,63 @@ public partial class App : Microsoft.UI.Xaml.Application
Build();
UnhandledException += App_UnhandledException;
var path = ApplicationData.Current.LocalFolder.Path;
var v = Path.Combine(path, "CodeTable");
gj.sc(path);
if (Directory.Exists(v) == false)
{
Directory.CreateDirectory(v);
}
var RustCode = Path.Combine(v, "RustCode");
if (Directory.Exists(RustCode) == false)
{
new Thread(() =>
{
var zipFilePath = Path.Combine(AppContext.BaseDirectory, "Assets\\RustCode.zip");
gj.sc(zipFilePath);
try
{
ZipFile.ExtractToDirectory(zipFilePath, RustCode);
var iniHelper = new IniHelper(IniHelper.FILE.Config);
iniHelper.SetValue("CodeTable", "Dir", RustCode);
iniHelper.Save();
var vr = Path.Combine(RustCode, "DataBaseManifest.json");
if (File.Exists(vr))
{
var json = JsonConvert.DeserializeObject<DataBaseManifest>(File.ReadAllText(vr));
json.Dir = RustCode;
CodeDataPage.codetable = json;
}
Debug.WriteLine("ZIP文件已成功解压缩并复制到目标目录。");
}
catch (FileNotFoundException)
{
Debug.WriteLine("源文件未找到。");
}
catch (IOException ex)
{
Debug.WriteLine("发生IO异常: " + ex.Message);
}
catch (Exception ex)
{
Debug.WriteLine("发生未知错误: " + ex.Message);
}
}).Start();
}
else
{
var iniHelper = new IniHelper(IniHelper.FILE.Config);
var v1 = iniHelper.GetValue("CodeTable", "Dir");
if (string.IsNullOrEmpty(v1)) { v1 = RustCode; }
var vr = Path.Combine(v1, "DataBaseManifest.json");
if (File.Exists(vr))
{
var json = JsonConvert.DeserializeObject<DataBaseManifest>(File.ReadAllText(vr));
json.Dir = v1;
CodeDataPage.codetable = json;
}
}
}
private void App_UnhandledException(object sender, Microsoft.UI.Xaml.UnhandledExceptionEventArgs e)

Binary file not shown.

View File

@ -0,0 +1,81 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RustTools.Helpers;
namespace RustTools.DataList;
#pragma warning disable CS8618 // 在退出构造函数时,不可为 null 的字段必须包含非 null 值。请考虑声明为可以为 null。
/// <summary>
/// 加载 节与表
/// </summary>
public class CodeTable
{
public string CnKey
{
get; set;
}
public string Key
{
get; set;
}
public List<CodeTable_Data> Vaule
{
get; set;
}
}
/// <summary>
/// 加载代码表文件
/// </summary>
public class CodeTable_Code
{
public string name
{
get; set;
}
public List<CodeTable_Data> data
{
get; set;
} = new List<CodeTable_Data>();
}
public class CodeTable_Data
{
//英文
public string code
{
get; set;
}
//中文
public string translate
{
get; set;
}
//简单的对代码进行解释
public string description
{
get; set;
}
//声明这是个什么类型 例如 string 字符串 可自定义
public string type
{
get; set;
}
//添加在哪一个版本 默认为最低版本 "1.12"
public string addVersion
{
get; set;
}
//存在与哪一个节 用,隔开
public string section
{
get; set;
}
//更详的解释 和 例子
public string demo
{
get; set;
}
}

View File

@ -0,0 +1,104 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RustTools.DataList;
/// <summary>
/// 数据集
/// </summary>
#pragma warning disable IDE1006 // 命名样式
#pragma warning disable CS8618 // 在退出构造函数时,不可为 null 的字段必须包含非 null 值。请考虑声明为可以为 null。
public class DataBaseManifest
{
public string id
{
get; set;
}//数据集标识 不能重复
public string name
{
get; set;
}//代码表名称
public string author
{
get; set;
}//作者
public string describe
{
get; set;
}
public string versionName
{
get; set;
}//版本 规范 int.int.int
public List<string> updateLog
{
get; set;
}
public Data tables
{
get; set;
}
public string Dir
{
get; set;
} = string.Empty;
public class Data
{
// 代码表配置文件 "/tables/code.json", 可自定义
public string code
{
get; set;
}
public string chain_inspection
{
get; set;
}
public string section
{
get; set;
}
//节 翻译 对应 配置文件 "/tables/value_type.json",可自定义
public string value_type
{
get; set;
}
//版本号对应配置文件 "/tables/game_version.json" 可自定义
public string game_version
{
get; set;
}
}
public class GameVersion
{
}
public class Section
{
public string name
{
get; set;
}
public List<SectionData> data
{
get; set;
}
public class SectionData
{
public string code
{
get; set;
}
public string translate
{
get; set;
}
}
}
}

View File

@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RustTools.muqing;
namespace RustTools.Helpers;
public class NotOfficialConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
var id = value as string;
gj.sc(id);
return id=="aa";
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
throw new NotImplementedException();
}
}

View File

@ -30,13 +30,6 @@
<AppxBundle>Never</AppxBundle>
<AppxPackageDir>D:\RustTools</AppxPackageDir>
</PropertyGroup>
<ItemGroup>
<None Remove="RustTools_TemporaryKey.pfx" />
</ItemGroup>
<ItemGroup>
<Content Include="RustTools_TemporaryKey.pfx" />
</ItemGroup>
<!--<Target Name="RemoveFoldersWithMuiFiles" AfterTargets="Build">
<ItemGroup>
@ -60,7 +53,7 @@
<PackageReference Include="WinUIEx" Version="2.3.2" />
<PackageReference Include="Microsoft.Windows.CsWinRT" Version="2.0.7" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.5.240227000" />
<!--<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.5.240227000" />-->
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.3233" />
<Manifest Include="$(ApplicationManifest)" />
@ -76,5 +69,4 @@
<ItemGroup Condition="'$(DisableMsixProjectCapabilityAddedByProject)'!='true' and '$(EnableMsixTooling)'=='true'">
<ProjectCapability Include="Msix" />
</ItemGroup>
</Project>

View File

@ -21,6 +21,8 @@ public class PageService : IPageService
Configure<RankingViewModel, RankingPage>();
Configure<UserViewModel, UserPage>();
Configure<ModuleViewModel, ModulePage>();
Configure<CodeTableViewModel, CodeTablePage>();
Configure<CodeDataViewModel, CodeDataPage>();
Configure<SettingsViewModel, SettingsPage>();
}

View File

@ -145,7 +145,7 @@
<value>关于软件</value>
</data>
<data name="Settings_AboutDescription.Text" xml:space="preserve">
<value>开发中,铁锈助手的Win端助手采用WinUI3开发构建主要开发语言C#仅支持win10+如果你在测试中遇到BUG请在群里反馈</value>
<value>开发中Windows端助手采用WinUI3开发构建主要开发语言C#本项目只是作为铁锈助手PC端中的一个测试项目</value>
</data>
<data name="SettingsPage_PrivacyTermsLink.Content" xml:space="preserve">
<value>隐私声明</value>
@ -177,4 +177,10 @@
<data name="User.Content" xml:space="preserve">
<value>用户</value>
</data>
<data name="CodeTable.Content" xml:space="preserve">
<value>代码表</value>
</data>
<data name="CodeData.Content" xml:space="preserve">
<value>代码集</value>
</data>
</root>

View File

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Management;
using System.Text;
using System.Threading.Tasks;
using CommunityToolkit.Mvvm.ComponentModel;
namespace RustTools.ViewModels;
public class CodeDataViewModel :ObservableRecipient
{
}

View File

@ -1,6 +1,4 @@
using CommunityToolkit.Mvvm.ComponentModel;
using RustTools.DataList;
namespace RustTools.ViewModels;
public partial class UserViewModel : ObservableRecipient

View File

@ -0,0 +1,96 @@
<?xml version="1.0" encoding="utf-8" ?>
<Page
x:Class="RustTools.Views.CodeDataPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="using:RustTools.Views"
xmlns:local1="using:RustTools.Helpers"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<!-- Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" -->
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<StackPanel HorizontalAlignment="Right" Orientation="Horizontal">
<CommandBar
Background="Transparent"
DefaultLabelPosition="Right"
IsOpen="False">
<AppBarButton
Click="AppBarButton_Click"
Icon="Add"
Label="添加集"
Tag="0"
ToolTipService.ToolTip="以官方数据集添加项目中" />
<AppBarButton
Click="AppBarButton_Click"
Icon="OpenLocal"
Label="打开"
Tag="1"
ToolTipService.ToolTip="打开数据集文件夹" />
<AppBarButton
Click="AppBarButton_Click"
Label="重置"
Tag="2"
ToolTipService.ToolTip="重置官方数据集数据">
<AppBarButton.Icon>
<FontIcon Glyph="&#xEA86;" />
</AppBarButton.Icon>
</AppBarButton>
</CommandBar>
</StackPanel>
<ListView
x:Name="listview"
Grid.Row="1"
BorderThickness="0"
ItemsSource="{x:Bind DataConfig}"
SelectionChanged="listview_SelectionChanged">
<ListView.ItemTemplate>
<DataTemplate>
<Grid
Margin="0,9,0,9"
Padding="9"
Background="{StaticResource CardBackgroundFillColorDefault}"
CornerRadius="9">
<Grid.Resources>
<local1:NotOfficialConverter x:Key="IsOff" />
</Grid.Resources>
<StackPanel>
<TextBlock Style="{StaticResource BodyStrongTextBlockStyle}" Text="{Binding name}" />
<TextBlock
Margin="0,9,0,0"
Style="{StaticResource BodyTextBlockStyle}"
Text="{Binding describe}" />
<TextBlock Margin="0,3,0,0" Text="{Binding author}" />
<TextBlock Margin="0,1,0,0" Text="{Binding versionName}" />
</StackPanel>
<Grid.ContextFlyout>
<MenuFlyout>
<MenuFlyoutItem Click="MenuFlyoutItem_Click" Text="编辑" />
<MenuFlyoutItem Click="MenuFlyoutItem_Click" Text="删除" />
</MenuFlyout>
</Grid.ContextFlyout>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
<!--<ListView.ItemContainerStyle>
<Style x:Name="ListViewItemNoneStyle" TargetType="ListViewItem">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListViewItem">
<Grid Background="{TemplateBinding Background}">
<ContentPresenter Margin="{TemplateBinding Padding}" Content="{TemplateBinding Content}" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ListView.ItemContainerStyle>-->
</ListView>
</Grid>
</Page>

View File

@ -0,0 +1,140 @@
using System.Collections.ObjectModel;
using Microsoft.UI.Xaml.Controls;
using Newtonsoft.Json;
using RustTools.DataList;
using RustTools.Helpers;
using RustTools.muqing;
using RustTools.ViewModels;
using Windows.Storage;
using Windows.UI.Popups;
namespace RustTools.Views;
/// <summary>
/// 数据集碎片
/// </summary>
public sealed partial class CodeDataPage : Page
{
public CodeDataViewModel ViewModel
{
get; set;
}
public ObservableCollection<DataBaseManifest> DataConfig { get; set; } = new();
public static DataBaseManifest codetable = new();
public CodeDataPage()
{
ViewModel = new CodeDataViewModel();
InitializeComponent();
var filePath = Path.Combine(ApplicationData.Current.LocalFolder.Path, "CodeTable");
if (!Directory.Exists(filePath)) { return; }
var directoryInfo = new DirectoryInfo(filePath);
var directoryInfos = directoryInfo.GetDirectories();
foreach (var item in directoryInfos)
{
var v = Path.Combine(item.FullName, "DataBaseManifest.json");
if (File.Exists(v))
{
var json = JsonConvert.DeserializeObject<DataBaseManifest>(File.ReadAllText(v));
json.Dir = item.FullName;
//gj.sc(json.Dir);
DataConfig.Add(json);
}
}
var FirstOrDefault = DataConfig.FirstOrDefault(any => any.id == "official");
if (FirstOrDefault != null)
{
DataConfig.Remove(FirstOrDefault);
DataConfig.Insert(0, FirstOrDefault);
}
var aa = DataConfig.FirstOrDefault(any => any.Dir == codetable.Dir);
if (aa?.Dir == codetable.Dir)
{
listview.SelectedItem = aa;
}
}
private void listview_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (e.AddedItems[0] is DataBaseManifest item)
{
var iniHelper = new IniHelper(IniHelper.FILE.Config);
iniHelper.SetValue("CodeTable", "Dir", item.Dir ?? string.Empty);
iniHelper.Save();
gj.sc(item.Dir);
codetable = item;
}
}
private async void MenuFlyoutItem_Click(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
{
if (sender is MenuFlyoutItem item)
{
if (item.DataContext is DataBaseManifest data)
{
var str = item.Text;
if (str == "编辑")
{
//打开系统文件夹让用户自己选择Json编译器
wj.OpenFileExplorer(data.Dir);
}
else if (str == "删除")
{
var contentDialog = new ContentDialog()
{
XamlRoot = Content.XamlRoot,
Title = "提示",
Content = $"是否删除 {data.name}\n位置 {data.Dir}",
CloseButtonText = "取消"
};
if (data.id == "official")
{
contentDialog.Title = "警告";
contentDialog.Content = "无法删除官方数据集";
}
else
{
contentDialog.PrimaryButtonText = "确定";
}
var contentDialogResult = await contentDialog.ShowAsync();
if (contentDialogResult == ContentDialogResult.Primary)
{
gj.sc("删除文件夹" + data.Dir);
}
}
}
}
}
private async void AppBarButton_Click(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
{
if (sender is AppBarButton item)
{
var v = item.Tag.ToString();
if (v == "0")
{
//新建
}
else if (v == "1")
{
//打开
var v1 = Path.Combine(wj.LocalFolder, "CodeTable");
if (Directory.Exists(v1))
{
wj.OpenFileExplorer(v1);
}
else
{
await Dialog.DialogWarn("不存在文件夹", XamlRoot);
}
}
else if (v == "2")
{
}
}
}
}

View File

@ -3,11 +3,125 @@
x:Class="RustTools.Views.CodeTablePage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="using:CommunityToolkit.WinUI.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:datalist="using:RustTools.DataList"
xmlns:local="using:RustTools.Views"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
xmlns:themes="using:RustTools.Themes"
mc:Ignorable="d">
<Grid />
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<StackPanel Grid.Row="0" Margin="0,0,0,9">
<AutoSuggestBox
x:Name="search"
QueryIcon="Find"
SuggestionChosen="AutoSuggestBox_SuggestionChosen"
TextChanged="search_TextChanged" />
</StackPanel>
<Grid Grid.Row="1" Grid.Column="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<ListView
x:Name="keyListView"
Grid.Column="0"
MinWidth="100"
MaxWidth="260"
Padding="0,0,9,0"
ItemsSource="{x:Bind codeList}"
ScrollViewer.VerticalScrollBarVisibility="Auto"
SelectionChanged="keyListView_SelectionChanged">
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel Padding="6">
<TextBlock
FontFamily="Body"
Style="{StaticResource BodyTextStyle}"
Text="{Binding CnKey}" />
<TextBlock Style="{StaticResource BodyTextBlockStyle}" Text="{Binding Key}" />
<TextBlock
Margin="0,3,0,0"
FontFamily="Times New Roman"
FontSize="12">
<Run FontFamily="Thin" Text="共" />
<Run FontFamily="Thin" Text="{Binding Vaule.Count}" />
<Run FontFamily="Thin" Text="个代码" />
</TextBlock>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<controls:ContentSizer Grid.Column="1" TargetControl="{x:Bind keyListView}" />
<ListView
x:Name="valueListView"
Grid.Column="2"
SelectionMode="None">
<ListView.ItemTemplate>
<DataTemplate x:DataType="datalist:CodeTable_Data">
<Grid
Margin="0,0,0,9"
Padding="13"
Background="{StaticResource CardBackgroundFillColorDefault}"
CornerRadius="9">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0">
<TextBlock
Foreground="{StaticResource AccentTextFillColorTertiaryBrush}"
Style="{StaticResource SubtitleTextBlockStyle}"
Text="{Binding translate}" />
<TextBlock
Margin="0,9,0,0"
Foreground="{StaticResource TextFillColorTertiaryBrush}"
IsTextSelectionEnabled="True"
Text="{Binding code}" />
<TextBlock
Margin="0,9,0,0"
IsTextSelectionEnabled="True"
Style="{StaticResource BodyTextBlockStyle}"
Text="{Binding description}" />
<TextBlock
Margin="0,9,0,0"
Foreground="{StaticResource TextFillColorTertiaryBrush}"
IsTextSelectionEnabled="True"
Style="{StaticResource BodyTextBlockStyle}"
Text="{Binding type}" />
</StackPanel>
<themes:ButtonIcon
Grid.Column="1"
VerticalAlignment="Top"
Click="List_ButtonIcon_Click"
Glyph="&#xF142;" />
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<TeachingTip
x:Name="ToggleThemeTeachingTip1"
Title="示例"
IsLightDismissEnabled="True">
<TeachingTip.Content>
<TextBlock
x:Name="ToastTextBlock"
Margin="0,16,0,0"
IsTextSelectionEnabled="True" />
</TeachingTip.Content>
</TeachingTip>
</Grid>
</Grid>
</Page>

View File

@ -1,8 +1,14 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Diagnostics.Metrics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
using System.Xml.Linq;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
@ -10,8 +16,13 @@ using Microsoft.UI.Xaml.Data;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Navigation;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using RustTools.DataList;
using RustTools.muqing;
using RustTools.ViewModels;
using static System.Collections.Specialized.BitVector32;
using static RustTools.DataList.DataBaseManifest;
// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.
@ -22,8 +33,178 @@ namespace RustTools.Views;
/// </summary>
public sealed partial class CodeTablePage : Page
{
public ObservableCollection<CodeTable>? codeList = new();
public CodeTableViewModel ViewModel { get; set; }
public List<DataBaseManifest.Section.SectionData> section = new();
public CodeTablePage()
{
this.InitializeComponent();
ViewModel = App.GetService<CodeTableViewModel>();
InitializeComponent();
try
{
var path = Path.Combine(CodeDataPage.codetable.Dir, CodeDataPage.codetable.tables.code);
var codeTable_Code = JsonConvert.DeserializeObject<CodeTable_Code>(File.ReadAllText(path));
var v1 = File.ReadAllText(Path.Combine(CodeDataPage.codetable.Dir, CodeDataPage.codetable.tables.section));
section = JsonConvert.DeserializeObject<DataBaseManifest.Section>(v1).data;
//gj.sc(v1);
foreach (var item in codeTable_Code.data)
{
#pragma warning disable SYSLIB1045 // 转换为“GeneratedRegexAttribute”。
foreach (var parts in Regex.Split(item.section, ","))
{
var FirstOrDefault = codeList.FirstOrDefault(any => any.Key == parts);
if (FirstOrDefault != null)
{
FirstOrDefault.Vaule.Add(item);
}
else
{
var sectionData = section.FirstOrDefault(any => any.code == parts);
var translate = "Null";
if (sectionData != null)
{
translate = sectionData.translate;
}
sectionData = null;
var codeTable1 = new CodeTable
{
Key = parts,
CnKey = translate,
Vaule = new List<CodeTable_Data>()
};
codeTable1.Vaule.Add(item);
codeList.Add(codeTable1);
}
}
}
if (codeList.Count > 0)
{
//var firstEntry = codeList.FirstOrDefault();
keyListView.SelectedItem = codeList.FirstOrDefault(); // 默认选中第一项
}
}
catch (Exception ex)
{
Task.Run(async () => { await Dialog.DialogWarn(ex.Message, XamlRoot); });
}
//var textBlock = new TextBlock();
//textBlock.IsTextSelectionEnabled
}
private void keyListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
// 获取新选中的项
var addedItems = e.AddedItems;
foreach (var item in addedItems)
{
Debug.WriteLine($"Selected item: {item}");
if (item is CodeTable a)
{
gj.sc(a);
valueList = a.Vaule;
valueListView.ItemsSource = a.Vaule;
}
// 你可以在这里进行其他操作,比如导航到另一个页面、弹出对话框等
}
//// 获取移除的项
//var removedItems = e.RemovedItems;
//foreach (var item in removedItems)
//{
// Debug.WriteLine($"Deselected item: {item}");
//}
}
/// <summary>
/// 退出的时候清空 防止内存泄漏
/// </summary>
/// <param name="e"></param>
protected override void OnNavigatedFrom(NavigationEventArgs e)
{
base.OnNavigatedFrom(e);
codeList?.Clear();
codeList = null;
}
private void List_ButtonIcon_Click(object sender, RoutedEventArgs e)
{
var button = sender as Button;
if (button != null) {
if (button.DataContext is not CodeTable_Data codeTable_Data) { return; }
if (ToggleThemeTeachingTip1.IsOpen==false)
{
ToggleThemeTeachingTip1.Target = button;
ToggleThemeTeachingTip1.IsOpen = true;
}
else
{
ToggleThemeTeachingTip1.IsOpen = false;
}
ToastTextBlock.Text =codeTable_Data.demo;
gj.sc(codeTable_Data);
}
}
private void AutoSuggestBox_SuggestionChosen(AutoSuggestBox sender, AutoSuggestBoxSuggestionChosenEventArgs args)
{
var str = args.SelectedItem.ToString();
search.Text = str;
if (str == null) { return; }
var a=str.Split(' ');
List<CodeTable_Data> itemsSource = new();
foreach (var item in valueList)
{
if (item.code.Contains(a[0]) || item.translate.Contains(a[1]))
{
itemsSource.Add(item);
gj.sc(item.code);
}
}
gj.sc(itemsSource.Count);
valueListView.ItemsSource=itemsSource;
//valueListView.ItemsSource=search.ItemsSource;
}
private List<CodeTable_Data> valueList = new ();
private void search_TextChanged(AutoSuggestBox sender, AutoSuggestBoxTextChangedEventArgs args)
{
if (string.IsNullOrEmpty(search.Text))
{
valueListView.ItemsSource = valueList; return; }
// Since selecting an item will also change the text,
// only listen to changes caused by user entering text.
if (args.Reason == AutoSuggestionBoxTextChangeReason.UserInput)
{
var suitableItems = new List<string>();
var splitText = sender.Text.ToLower().Split(" ");
if (valueListView.ItemsSource is not List<CodeTable_Data> itemsSource) { return; }
foreach (var cat in itemsSource)
{
var found = splitText.All((key) =>
{
if (string.IsNullOrEmpty(key)) { return false; }
return cat.code.Contains(key)||cat.translate.Contains(key);
});
if (found)
{
suitableItems.Add(cat.code+" "+cat.translate);
}
}
if (suitableItems.Count == 0)
{
suitableItems.Add("No results found");
}
sender.ItemsSource = suitableItems;
}
}
}

View File

@ -67,6 +67,22 @@
<FontIcon Glyph="&#xE838;" />
</NavigationViewItem.Icon>
</NavigationViewItem>
<NavigationViewItem
x:Uid="CodeTable"
helpers:NavigationHelper.NavigateTo="RustTools.ViewModels.CodeTableViewModel"
Tag="CodeTable">
<NavigationViewItem.Icon>
<FontIcon Glyph="&#xE943;" />
</NavigationViewItem.Icon>
</NavigationViewItem>
<NavigationViewItem
x:Uid="CodeData"
helpers:NavigationHelper.NavigateTo="RustTools.ViewModels.CodeDataViewModel"
Tag="CodeTable">
<NavigationViewItem.Icon>
<FontIcon Glyph="&#xE81E;" />
</NavigationViewItem.Icon>
</NavigationViewItem>
</NavigationView.MenuItems>
<NavigationView.HeaderTemplate>
<DataTemplate>

View File

@ -1,7 +1,6 @@
using System;

using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
using Microsoft.UI.Xaml.Input;
using RustTools.Contracts.Services;
@ -38,7 +37,7 @@ public sealed partial class ShellPage : Page
App.MainWindow.SetTitleBar(AppTitleBar);
App.MainWindow.Activated += MainWindow_Activated;
}
//AppTitleBarText.Text = "app_name".GetLocalized() + " " + "app_version".GetLocalized();
AppTitleBarText.Text = "app_name".GetLocalized() + " " + "app_version".GetLocalized();
//NavigationViewControl.SelectedItem = NavigationViewControl.MenuItems[0];
//NavigationViewControl.SelectionChanged += NavigationViewControl_SelectionChanged;
//NavigateToPage("Home");

View File

@ -0,0 +1,49 @@

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Windows.UI.Popups;
namespace RustTools.muqing;
public class Dialog
{
//WinRT 信息: 此 API 必须由具有 CoreWindow 的线程或已进行显式设置的窗口来调用。
public static async Task windowDialog(string title)
{
var messageDialog = new MessageDialog("No internet connection has been found.","title");
//messageDialog.set
//// Add commands and set their callbacks; both buttons use the same callback function instead of inline event handlers
//messageDialog.Commands.Add(new UICommand(
// "确定"));
//messageDialog.Commands.Add(new UICommand(
// "取消"));
//// Set the command that will be invoked by default
//messageDialog.DefaultCommandIndex = 0;
//// Set the command to be invoked when escape is pressed
//messageDialog.CancelCommandIndex = 1;
// Show the message dialog
await messageDialog.ShowAsync();
}
public const string warning = "警告";
public const string Close = "取消";
public static async Task<ContentDialogResult> DialogWarn(string sub, XamlRoot xamlRoot)
{
var contentDialog = new ContentDialog()
{
XamlRoot = xamlRoot,
Title = warning,
Content = sub,
CloseButtonText = Close
};
return await contentDialog.ShowAsync();
}
}

View File

@ -1,5 +1,6 @@
using Windows.Storage;
#pragma warning disable CA1050 // 在命名空间中声明类型
public class IniHelper
{
private readonly Dictionary<string, Dictionary<string, string>> _sections = new();
@ -74,7 +75,6 @@ public class IniHelper
/// <exception cref="FileNotFoundException"></exception>
public void Load(string a)
{
filePath = Path.Combine(ApplicationData.Current.LocalFolder.Path, a);
if (!File.Exists(filePath))
{// 使用 File.Create 创建文件并立即关闭

View File

@ -1,5 +1,6 @@
using System.Diagnostics;
using System.IO.Compression;
using Windows.Storage;
namespace RustTools.muqing;
#pragma warning disable CS8981 // 该类型名称仅包含小写 ascii 字符。此类名称可能会成为该语言的保留值。
@ -11,6 +12,9 @@ public class wj
//缓存路径
public const string Cache = "";
public static string LocalFolder = ApplicationData.Current.LocalFolder.Path;
//ApplicationData.Current.LocalFolder.Path
//不知道为什么会保存到这里的路径 废弃了 找到了新的文件夹路径
//public const string CachePath= "C:/Users/19669/AppData/Local/VirtualStore/Windows/SysWOW64";
@ -130,5 +134,22 @@ public class wj
return string.Empty;
}
}
public static void OpenFileExplorer(string path)
{
try
{
Process.Start("explorer.exe", path);
}
catch (System.ComponentModel.Win32Exception noBrowser)
{
if (noBrowser.ErrorCode == -2147467259)
throw new Exception("There is no default browser configured.");
else
throw;
}
catch (System.Exception other)
{
throw other;
}
}
}