using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; using RustTools.muqing; using Newtonsoft.Json; using System.Collections.ObjectModel; using Windows.ApplicationModel.Core; using System.Diagnostics; using Windows.UI.ViewManagement; using Microsoft.UI.Xaml.Media; using Microsoft.UI; // To learn more about WinUI, the WinUI project structure, // and more about our project templates, see: http://aka.ms/winui-project-info. namespace RustTools.WindowUI; /// /// An empty page that can be used on its own or navigated to within a Frame. /// public sealed partial class ModulePage : WindowEx { public static List ModulePageList = new(); public ObservableCollection ScreenshotsList = new(); public ModInfo.Data Mod { get; set; } = new(); public ModulePage(string v) { // 设置窗口背景颜色 InitializeComponent(); ExtendsContentIntoTitleBar = true; gj.SetBackTheme(this); init(v); var frame = App.AppTitlebar as FrameworkElement; if (frame != null) { gj.UpdateTitleBar(this, frame.ActualTheme); grid.RequestedTheme = frame.ActualTheme; } } static bool IsColorLight(Windows.UI.Color clr) { return (((5 * clr.G) + (2 * clr.R) + clr.B) > (8 * 128)); } private async void init(string v) { var json = await ApiFox.mod.getInfo("", v); var a = JsonConvert.DeserializeObject(json); if (a != null) { Mod = a.data; Mod.IconUrl = Mod.IconUrl.Equals("") ? "/Assets/image/image_106.svg" : Mod.IconUrl.Replace("..", wl.api); Mod.Link = Mod.Link.Replace("..", wl.api); Title = Mod.Name; var l = " | "; title_b.Text = "单位数" + Mod.UnitNumber + l + Mod.DownloadNumber + "次下载" + l + "版本名称" + Mod.VersionName; title_c.Text = "发布时间:" + Mod.CreationTime + " 最近更新:" + Mod.UpdateTime; var ScrList = Mod.Screenshots.Split(","); foreach (var s in ScrList) { gj.sc(s); if (string.IsNullOrEmpty(s)) { continue; } ScreenshotsList.Add(s.Replace("..", wl.api)); } if (ScreenshotsList.Count > 0) { fliptext.Visibility = Visibility.Visible; flipview.Visibility = Visibility.Visible; } else { fliptext.Visibility = Visibility.Collapsed; flipview.Visibility = Visibility.Collapsed; } grid.DataContext = this; // 设置数据上下文 } } private void WindowEx_SizeChanged(object sender, WindowSizeChangedEventArgs args) { DescriptionText.Width = Width - 50; } private void WindowEx_Closed(object sender, WindowEventArgs args) { // 当窗口关闭时,从列表中移除 ModulePageList.Remove(this); } private void AppBarButton_Click(object sender, RoutedEventArgs e) { var label = ((AppBarButton)sender).Name; gj.sc(label); switch (label) { case "ReportButton": gj.sc("举报这个模组抄袭"); //if (Toast.IsOpen) Toast.IsOpen = false; Toast.Title = "举报此模组"; Toast.Subtitle = "请合理举报,拒接无脑举报!"; Toast.IsOpen = true; break; case "LikeButton": gj.sc("给这个模组投了一个币"); //if (Toast.IsOpen) Toast.IsOpen = false; Toast.Title = "支持此模组"; Toast.Subtitle = "支持后自动扣除你的一个硬币,如果没有则支持失败"; Toast.IsOpen = true; break; case "DownLoadButton": gj.sc("下载此模组:" + Mod.Link); break; } } private void Toast_ActionButtonClick(TeachingTip sender, object args) { } }