253 lines
8.4 KiB
C#
253 lines
8.4 KiB
C#
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.Input;
|
||
using Microsoft.UI.Xaml;
|
||
using Microsoft.UI.Xaml.Controls;
|
||
using Microsoft.UI.Xaml.Controls.Primitives;
|
||
using Microsoft.UI.Xaml.Data;
|
||
using Microsoft.UI.Xaml.Input;
|
||
using Microsoft.UI.Xaml.Media;
|
||
using Microsoft.UI.Xaml.Navigation;
|
||
using Newtonsoft.Json;
|
||
using Newtonsoft.Json.Linq;
|
||
using RustTools.DataList;
|
||
using RustTools.muqing;
|
||
using RustTools.ViewModels;
|
||
using Windows.ApplicationModel.Core;
|
||
using Windows.System;
|
||
using Windows.UI.Core;
|
||
using static System.Collections.Specialized.BitVector32;
|
||
using static IniHelper;
|
||
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.
|
||
|
||
namespace RustTools.Views;
|
||
/// <summary>
|
||
/// ´úÂë±íËéƬ
|
||
/// </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()
|
||
{
|
||
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
|
||
|
||
// ×¢²á KeyDown ʼþ´¦Àí³ÌÐò
|
||
}
|
||
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();
|
||
//section.Clear();
|
||
//valueList.Clear();
|
||
}
|
||
|
||
|
||
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)
|
||
{
|
||
//gj.sc("AutoSuggestBox_SuggestionChosen "+sender);
|
||
//if (args.SelectedItem is not Search_List str) { return; }
|
||
//search.Text = str.key;
|
||
//List<CodeTable_Data> itemsSource = new();
|
||
//foreach (var item in valueList)
|
||
//{
|
||
// if (item.code.Contains(str.key) || item.translate.Contains(str.value))
|
||
// {
|
||
// itemsSource.Add(item);
|
||
// }
|
||
//}
|
||
//valueListView.ItemsSource=itemsSource;
|
||
//valueListView.ItemsSource=search.ItemsSource;
|
||
}
|
||
class Search_List
|
||
{
|
||
public string key
|
||
{
|
||
get; set;
|
||
}
|
||
public string value
|
||
{
|
||
get; set;
|
||
}
|
||
}
|
||
|
||
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<Search_List>();
|
||
var splitText = sender.Text.ToString();
|
||
if (valueListView.ItemsSource is not List<CodeTable_Data> itemsSource) { return; }
|
||
var i = 0;
|
||
foreach (var cat in itemsSource)
|
||
{
|
||
if (cat.code.Contains(splitText) || cat.translate.Contains(splitText))
|
||
{
|
||
suitableItems.Add(new Search_List
|
||
{
|
||
key=cat.code,value=cat.translate
|
||
});
|
||
}
|
||
//ÏÞÖÆËÑË÷µÄ×î´óÏÔʾ
|
||
if (++i > 30)
|
||
{
|
||
break;
|
||
}
|
||
}
|
||
sender.ItemsSource = suitableItems;
|
||
}
|
||
|
||
}
|
||
|
||
private void search_QuerySubmitted(AutoSuggestBox sender, AutoSuggestBoxQuerySubmittedEventArgs args)
|
||
{
|
||
List<CodeTable_Data> itemsSource = new();
|
||
foreach (var item in valueList)
|
||
{
|
||
if (item.code.Contains(sender.Text) || item.translate.Contains(sender.Text))
|
||
{
|
||
itemsSource.Add(item);
|
||
}
|
||
}
|
||
valueListView.ItemsSource = itemsSource;
|
||
}
|
||
|
||
private void searchBox_KeyDown(object sender, KeyRoutedEventArgs e)
|
||
{
|
||
|
||
// ¼ì²éÊÇ·ñ°´ÏÂÁË Ctrl ¼ü
|
||
var isCtrlPressed = InputKeyboardSource.GetKeyStateForCurrentThread(VirtualKey.Control) == CoreVirtualKeyStates.Down;
|
||
|
||
// ¼ì²éÊÇ·ñ°´ÏÂÁË J ¼ü
|
||
if (e.Key == VirtualKey.J && isCtrlPressed)
|
||
{
|
||
// ÔÚÕâÀïÖ´Ðе± Ctrl+J ±»°´ÏÂʱµÄ²Ù×÷
|
||
var a = search.ItemsSource as List<Search_List>;
|
||
search.ItemsSource = null;
|
||
search.ItemsSource = a;
|
||
//Debug.WriteLine("Ctrl+J pressed "+ a?.Count);
|
||
}
|
||
}
|
||
} |