diff --git a/RustTools/ApiFox/mod.cs b/RustTools/ApiFox/mod.cs index a39ec98..fa7682c 100644 --- a/RustTools/ApiFox/mod.cs +++ b/RustTools/ApiFox/mod.cs @@ -1,15 +1,19 @@ -using RustTools.muqing; +using System.Diagnostics; +using RustTools.muqing; namespace RustTools.ApiFox; -class mod + +#pragma warning disable CS8981 // 该类型名称仅包含小写 ascii 字符。此类名称可能会成为该语言的保留值。 +#pragma warning disable IDE1006 // 命名样式 +public class mod { //最新时间 下载数量 投币数量 更新数量 //latestTime downloadNumber,coinNumber ,updateNumber - public static string latestTime = "latestTime"; - public static string downloadNumber = "downloadNumber"; - public static string coinNumber = "coinNumber"; - public static string updateNumber = "updateNumber"; + public const string latestTime = "latestTime"; + public const string downloadNumber = "downloadNumber"; + public const string coinNumber = "coinNumber"; + public const string updateNumber = "updateNumber"; /// diff --git a/RustTools/ApiFox/search.cs b/RustTools/ApiFox/search.cs new file mode 100644 index 0000000..0d14710 --- /dev/null +++ b/RustTools/ApiFox/search.cs @@ -0,0 +1,17 @@ + +using RustTools.muqing; +using static IniHelper; + +namespace RustTools.ApiFox; +#pragma warning disable CS8981 // 该类型名称仅包含小写 ascii 字符。此类名称可能会成为该语言的保留值。 +#pragma warning disable IDE1006 // 命名样式 +public class search +{ + public static async Task searchAll(string key) + { + return await wl.postAsync("/php/search.php?action=searchAll", new string[][] + { + new string[]{ "key", key}, + }); + } +} diff --git a/RustTools/App.xaml b/RustTools/App.xaml index 8ff8621..c65234b 100644 --- a/RustTools/App.xaml +++ b/RustTools/App.xaml @@ -39,8 +39,13 @@ - + + + + + - + + TextTrimming="CharacterEllipsis" /> - - + diff --git a/RustTools/DataList/SearchAllList.cs b/RustTools/DataList/SearchAllList.cs new file mode 100644 index 0000000..9910b54 --- /dev/null +++ b/RustTools/DataList/SearchAllList.cs @@ -0,0 +1,88 @@ +using Newtonsoft.Json; +namespace RustTools.DataList; +#pragma warning disable CS8618 // 在退出构造函数时,不可为 null 的字段必须包含非 null 值。请考虑声明为可以为 null。 +#pragma warning disable IDE1006 // 命名样式 +public class SearchAllList +{ + + [JsonProperty("code")] + public int Code + { + get; set; + } + + [JsonProperty("message")] + public string Message + { + get; set; + } + + [JsonProperty("data")] + public Data data + { + get; set; + } + + public class Data + { + [JsonProperty("total")] + public List Total + { + get; set; + } + + [JsonProperty("type")] + public List Type + { + get; set; + } + } + + public class TotalItem + { + [JsonProperty("title")] + public string Title + { + get; set; + } + + [JsonProperty("type")] + public string Type + { + get; set; + } + + [JsonProperty("content")] + public string Content + { + get; set; + } + + [JsonProperty("icon")] + public string Icon + { + get; set; + } + + [JsonProperty("id")] + public string Id + { + get; set; + } + } + + public class TypeItem + { + [JsonProperty("typeName")] + public string TypeName + { + get; set; + } + + [JsonProperty("num")] + public int Num + { + get; set; + } + } +} \ No newline at end of file diff --git a/RustTools/MainWindow.xaml b/RustTools/MainWindow.xaml index 923a05c..e920d7d 100644 --- a/RustTools/MainWindow.xaml +++ b/RustTools/MainWindow.xaml @@ -6,7 +6,7 @@ xmlns:local="using:RustTools" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:windowex="using:WinUIEx" - MinWidth="500" + MinWidth="600" MinHeight="500" PersistenceId="MainWindow" mc:Ignorable="d" /> diff --git a/RustTools/RustTools.csproj b/RustTools/RustTools.csproj index 5dea719..3462999 100644 --- a/RustTools/RustTools.csproj +++ b/RustTools/RustTools.csproj @@ -71,4 +71,5 @@ + \ No newline at end of file diff --git a/RustTools/ViewModels/ShellViewModel.cs b/RustTools/ViewModels/ShellViewModel.cs index 19fa0d5..53db6d0 100644 --- a/RustTools/ViewModels/ShellViewModel.cs +++ b/RustTools/ViewModels/ShellViewModel.cs @@ -3,6 +3,7 @@ using Microsoft.UI.Xaml.Navigation; using RustTools.Contracts.Services; +using RustTools.muqing; using RustTools.Views; namespace RustTools.ViewModels; @@ -35,9 +36,8 @@ public partial class ShellViewModel : ObservableRecipient private void OnNavigated(object sender, NavigationEventArgs e) { - System.GC.Collect(); + GC.Collect(); IsBackEnabled = NavigationService.CanGoBack; - if (e.SourcePageType == typeof(SettingsPage)) { Selected = NavigationViewService.SettingsItem; @@ -49,5 +49,9 @@ public partial class ShellViewModel : ObservableRecipient { Selected = selectedItem; } + else + { + Selected = null; + } } } diff --git a/RustTools/Views/CodeTablePage.xaml.cs b/RustTools/Views/CodeTablePage.xaml.cs index 60172b3..133273c 100644 --- a/RustTools/Views/CodeTablePage.xaml.cs +++ b/RustTools/Views/CodeTablePage.xaml.cs @@ -34,7 +34,7 @@ using static RustTools.DataList.DataBaseManifest; namespace RustTools.Views; /// -/// An empty page that can be used on its own or navigated to within a Frame. +/// Ƭ /// public sealed partial class CodeTablePage : Page { @@ -250,4 +250,4 @@ public sealed partial class CodeTablePage : Page //Debug.WriteLine("Ctrl+J pressed "+ a?.Count); } } -} +} \ No newline at end of file diff --git a/RustTools/Views/HomePage.xaml.cs b/RustTools/Views/HomePage.xaml.cs index f52b853..1f2a683 100644 --- a/RustTools/Views/HomePage.xaml.cs +++ b/RustTools/Views/HomePage.xaml.cs @@ -31,7 +31,7 @@ public sealed partial class HomePage : Page ListA.ItemClick += ListAClick; ListB.ItemClick += ListAClick; //Ϊ˽ʡԵʱ򲻼Щ - if (true) + if (false) { ViewModel.random(); ViewModel.Latest(); diff --git a/RustTools/Views/RankingPage.xaml b/RustTools/Views/RankingPage.xaml index 3694f72..37f750b 100644 --- a/RustTools/Views/RankingPage.xaml +++ b/RustTools/Views/RankingPage.xaml @@ -12,8 +12,7 @@ mc:Ignorable="d"> - - + @@ -22,7 +21,6 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/RustTools/Views/SearchModPage.xaml.cs b/RustTools/Views/SearchModPage.xaml.cs new file mode 100644 index 0000000..4598dd8 --- /dev/null +++ b/RustTools/Views/SearchModPage.xaml.cs @@ -0,0 +1,95 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.IO; +using System.Linq; +using System.Runtime.InteropServices.WindowsRuntime; +using CommunityToolkit.Mvvm.ComponentModel; +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 RustTools.DataList; +using RustTools.muqing; +using RustTools.WindowUI; +using Windows.Foundation; +using Windows.Foundation.Collections; + +// 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; +/// +/// ģƬ +/// +public sealed partial class SearchModPage : Page +{ + public ObservableCollection ListSearch + { + get; set; + } = new(); + public SearchModPage() + { + InitializeComponent(); + list.ItemClick += List_ItemClick; ; + } + + private void List_ItemClick(object sender, ItemClickEventArgs e) + { + + if (e.ClickedItem is not SearchAllList.TotalItem item) { return; } + if (item.Type == "mod") + { + // Ѵڵ ModulePage򼤻 + var existingWindow = ModuleInfoWin.ModulePageList.FirstOrDefault(window => window.Mod.Id == item.Id); + if (existingWindow != null) + { + existingWindow.Activate(); + } + else + { + var newWindow = new ModuleInfoWin(item.Id); + newWindow.Activate(); + ModuleInfoWin.ModulePageList.Add(newWindow); + } + } + } + + protected async override void OnNavigatedTo(NavigationEventArgs e) + { + base.OnNavigatedTo(e); + + if (e.Parameter is string param) + { + try + { + var v = await ApiFox.search.searchAll(param); + //gj.sc(v); + var searchAllList = JsonConvert.DeserializeObject(v); + if (searchAllList.Code == 0) + { + foreach (var item in searchAllList.data.Total) + { + if (item.Type == "mod") + { + item.Icon = string.IsNullOrEmpty(item.Icon) ? "/Assets/image/image.svg" : item.Icon.Replace("..", wl.api); + ListSearch.Add(item); + } + } + } + } + catch (Exception ex) + { + await Dialog.DialogWarn(ex.Message,XamlRoot); + } + } + } + protected override void OnNavigatedFrom(NavigationEventArgs e){ + + base.OnNavigatedFrom(e); + } +} diff --git a/RustTools/Views/SettingsPage.xaml b/RustTools/Views/SettingsPage.xaml index edbc958..c3b6a17 100644 --- a/RustTools/Views/SettingsPage.xaml +++ b/RustTools/Views/SettingsPage.xaml @@ -104,8 +104,17 @@ + + + + + - diff --git a/RustTools/Views/ShellPage.xaml b/RustTools/Views/ShellPage.xaml index 1b0b348..7986656 100644 --- a/RustTools/Views/ShellPage.xaml +++ b/RustTools/Views/ShellPage.xaml @@ -7,34 +7,60 @@ xmlns:helpers="using:RustTools.Helpers" xmlns:i="using:Microsoft.Xaml.Interactivity" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - Loaded="OnLoaded"> + Loaded="OnLoaded" + SizeChanged="Page_SizeChanged"> - + + + + + + + + + + @@ -84,7 +110,7 @@ - + diff --git a/RustTools/Views/ShellPage.xaml.cs b/RustTools/Views/ShellPage.xaml.cs index 6a6c00e..5d6ac29 100644 --- a/RustTools/Views/ShellPage.xaml.cs +++ b/RustTools/Views/ShellPage.xaml.cs @@ -1,4 +1,5 @@  +using Microsoft.UI.Input; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Input; @@ -7,7 +8,7 @@ using RustTools.Contracts.Services; using RustTools.Helpers; using RustTools.muqing; using RustTools.ViewModels; - +using Windows.Foundation; using Windows.System; namespace RustTools.Views; @@ -26,7 +27,7 @@ public sealed partial class ShellPage : Page InitializeComponent(); ViewModel.NavigationService.Frame = NavigationFrame; - //ViewModel.NavigationService.Frame.ElementSoundMode.isna = "False"; + //ViewModel.NavigationService.UnregisterFrameEvents(); ViewModel.NavigationViewService.Initialize(NavigationViewControl); // TODO: Set the title bar icon by updating /Assets/WindowIcon.ico. @@ -37,46 +38,48 @@ public sealed partial class ShellPage : Page App.MainWindow.SetTitleBar(AppTitleBar); App.MainWindow.Activated += MainWindow_Activated; } - AppTitleBarText.Text = "app_name".GetLocalized() + " " + "app_version".GetLocalized(); - //NavigationViewControl.SelectedItem = NavigationViewControl.MenuItems[0]; - //NavigationViewControl.SelectionChanged += NavigationViewControl_SelectionChanged; - //NavigateToPage("Home"); - } - private void NavigationViewControl_SelectionChanged(NavigationView sender, NavigationViewSelectionChangedEventArgs args) - { - - System.GC.Collect(); - if (args.SelectedItem is NavigationViewItem selectedItem) - { - var tag = selectedItem.Tag.ToString(); - gj.sc(tag); - if (tag != null) - { - NavigateToPage(tag); - } - } - } - private void NavigateToPage(string pageTag) - { - var pageType = pageTag switch - { - "Home" => typeof(HomePage), - "Concern" => typeof(ConcernPage), - "Ranking" => typeof(RankingPage), - "User"=>typeof(UserPage), - "Module" => typeof(ModulePage), - "Settings" => typeof(SettingsPage), - _ => typeof(HomePage), - }; - NavigationFrame.Navigate(pageType); + AppTitleBarText.Text = "app_name".GetLocalized() + " PC";//+ "app_version".GetLocalized(); } private void OnLoaded(object sender, Microsoft.UI.Xaml.RoutedEventArgs e) { - //gj.sc(RequestedTheme); - TitleBarHelper.UpdateTitleBar(RequestedTheme); + if (App.MainWindow?.ExtendsContentIntoTitleBar == true) + { + // Update interactive regions if the size of the window changes. + SetRegionsForCustomTitleBar(); + } + //TitleBarHelper.UpdateTitleBar(RequestedTheme); - KeyboardAccelerators.Add(BuildKeyboardAccelerator(VirtualKey.Left, VirtualKeyModifiers.Menu)); - KeyboardAccelerators.Add(BuildKeyboardAccelerator(VirtualKey.GoBack)); + //KeyboardAccelerators.Add(BuildKeyboardAccelerator(VirtualKey.Left, VirtualKeyModifiers.Menu)); + //KeyboardAccelerators.Add(BuildKeyboardAccelerator(VirtualKey.GoBack)); + } + + private void SetRegionsForCustomTitleBar() + { + // Specify the interactive regions of the title bar. + var m_AppWindow = App.MainWindow?.AppWindow; + if (m_AppWindow == null) { return; } + var scaleAdjustment = AppTitleBar.XamlRoot.RasterizationScale; + var transform = TitleBarSearchBox.TransformToVisual(null); + var bounds = transform.TransformBounds(new Rect(0, 0, + TitleBarSearchBox.ActualWidth, + TitleBarSearchBox.ActualHeight)); + Windows.Graphics.RectInt32 SearchBoxRect = GetRect(bounds, scaleAdjustment); + + var rectArray = new Windows.Graphics.RectInt32[] { SearchBoxRect }; + + InputNonClientPointerSource nonClientInputSrc = + InputNonClientPointerSource.GetForWindowId(m_AppWindow.Id); + nonClientInputSrc.SetRegionRects(NonClientRegionKind.Passthrough, rectArray); + } + + private Windows.Graphics.RectInt32 GetRect(Rect bounds, double scale) + { + return new Windows.Graphics.RectInt32( + _X: (int)Math.Round(bounds.X * scale), + _Y: (int)Math.Round(bounds.Y * scale), + _Width: (int)Math.Round(bounds.Width * scale), + _Height: (int)Math.Round(bounds.Height * scale) + ); } private void MainWindow_Activated(object sender, WindowActivatedEventArgs args) @@ -84,11 +87,13 @@ public sealed partial class ShellPage : Page App.AppTitlebar = AppTitleBarText; } + //DisplayModeChanged="NavigationViewControl_DisplayModeChanged" private void NavigationViewControl_DisplayModeChanged(NavigationView sender, NavigationViewDisplayModeChangedEventArgs args) { AppTitleBar.Margin = new Thickness() { Left = sender.CompactPaneLength * (sender.DisplayMode == NavigationViewDisplayMode.Minimal ? 2 : 1), + //Left = sender.CompactPaneLength, Top = AppTitleBar.Margin.Top, Right = AppTitleBar.Margin.Right, Bottom = AppTitleBar.Margin.Bottom @@ -118,4 +123,21 @@ public sealed partial class ShellPage : Page args.Handled = result; } + private void Page_SizeChanged(object sender, SizeChangedEventArgs e) + { + if (App.MainWindow?.ExtendsContentIntoTitleBar == true) + { + // Update interactive regions if the size of the window changes. + SetRegionsForCustomTitleBar(); + } + + } + + private void TitleBarSearchBox_QuerySubmitted(AutoSuggestBox sender, AutoSuggestBoxQuerySubmittedEventArgs args) + { + var text = sender.Text; + NavigationFrame.Navigate(typeof(SearchModPage),text); + NavigationFrame.BackStack.Clear(); + //ViewModel.NavigationService.Frame.Visibility= Visibility.Collapsed; + } } diff --git a/RustTools/muqing/wl.cs b/RustTools/muqing/wl.cs index 0eacbc8..c886df2 100644 --- a/RustTools/muqing/wl.cs +++ b/RustTools/muqing/wl.cs @@ -4,7 +4,7 @@ namespace RustTools.muqing; #pragma warning disable CS8981 // 该类型名称仅包含小写 ascii 字符。此类名称可能会成为该语言的保留值。 class wl { - public static string api = "https://rust.coldmint.top"; + public const string api = "https://rust.coldmint.top"; /// /// 异步Post请求 @@ -28,7 +28,7 @@ class wl if (response != null) { var str = response.Content; - return str; + return str ?? string.Empty; } return string.Empty; }