WIn_RustTools/RustTools/Views/HomePage.xaml.cs

156 lines
4.5 KiB
C#
Raw Permalink Normal View History

2024-07-19 07:36:44 +00:00
using System.Collections.ObjectModel;
2024-07-23 12:23:55 +00:00
using System.Diagnostics;
2024-08-15 01:40:33 +00:00
using System.Text.RegularExpressions;
2024-07-14 11:24:10 +00:00
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
2024-07-19 14:29:49 +00:00
using Newtonsoft.Json;
2024-07-23 12:23:55 +00:00
using RustTools.DataList;
2024-07-14 11:24:10 +00:00
using RustTools.ViewModels;
2024-07-28 13:33:21 +00:00
using RustTools.WindowUI;
2024-07-23 12:23:55 +00:00
namespace RustTools.Views;
2024-07-14 11:24:10 +00:00
public sealed partial class HomePage : Page
{
2024-07-23 12:23:55 +00:00
public HomePageViewModel ViewModel
{
2024-07-14 11:24:10 +00:00
get;
}
public ObservableCollection<HomeBanner.Data> Pictures = new();
2024-07-14 11:24:10 +00:00
public HomePage()
{
2024-07-23 12:23:55 +00:00
ViewModel = App.GetService<HomePageViewModel>();
//<2F>ֲ<EFBFBD>ͼ
var lunbo = JsonConvert.DeserializeObject<HomeBanner>(ViewModel.lunbo);
if (lunbo != null)
{
foreach (var item in lunbo.data)
{
Pictures.Add(item);
2024-07-23 12:23:55 +00:00
}
}
2024-07-14 11:24:10 +00:00
InitializeComponent();
ListA.ItemClick += ListAClick;
ListB.ItemClick += ListAClick;
2024-08-08 04:29:27 +00:00
//Ϊ<>˽<EFBFBD>ʡ<EFBFBD><CAA1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ե<EFBFBD>ʱ<EFBFBD>򲻼<EFBFBD><F2B2BBBC><EFBFBD><EFBFBD><EFBFBD>Щ
2024-08-22 23:59:16 +00:00
if (false)
2024-08-08 04:29:27 +00:00
{
ViewModel.random();
ViewModel.Latest();
}
2024-07-14 11:24:10 +00:00
}
2024-07-24 02:53:16 +00:00
2024-07-23 12:23:55 +00:00
private void Page_SizeChanged(object sender, SizeChangedEventArgs e)
{
//var height = DisplayArea.Primary.WorkArea.Height;
//double a = height / 5;
//Debug.WriteLine(a);
//// <20><><EFBFBD><EFBFBD>FlipView<65>ĸ߶<C4B8>
//Banner.Height = a;
2024-07-19 07:36:44 +00:00
2024-07-23 12:23:55 +00:00
}
public static void ListAClick(object sender, ItemClickEventArgs e)
2024-07-23 12:23:55 +00:00
{
if (e.ClickedItem is not ModListResponse.ModData item) { return; }
// <20><><EFBFBD><EFBFBD><EFBFBD>Ѵ<EFBFBD><D1B4>ڵ<EFBFBD> ModulePage<67><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>򼤻<EFBFBD><F2BCA4BB><EFBFBD>
var existingWindow = ModuleInfoWin.ModulePageList.FirstOrDefault(window => window.Mod.Id == item.Id);
if (existingWindow != null)
{
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD>ڣ<EFBFBD><DAA3>򼤻<EFBFBD><F2BCA4BB><EFBFBD>
existingWindow.Activate();
}
else
{
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><DAB2><EFBFBD><EFBFBD>ڣ<EFBFBD><DAA3>򴴽<EFBFBD><F2B4B4BD>´<EFBFBD><C2B4>ڲ<EFBFBD><DAB2><EFBFBD><EFBFBD>ӵ<EFBFBD><D3B5>б<EFBFBD><D0B1><EFBFBD>
var newWindow = new ModuleInfoWin(item.Id);
//newWindow.Activated += (s, args) =>
//{
// // <20><><EFBFBD><EFBFBD><EFBFBD>ڱ<EFBFBD><DAB1><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>ȷ<EFBFBD><C8B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD><D0B1><EFBFBD>
// if (!ModulePage.ModulePageList.Contains(newWindow))
// {
// ModulePage.ModulePageList.Add(newWindow);
// }
//};
newWindow.Activate();
ModuleInfoWin.ModulePageList.Add(newWindow);
}
}
2024-08-15 01:40:33 +00:00
private void RefreshRandom(object sender, RoutedEventArgs e)
{
ViewModel.random();
}
private void RefreshLatest(object sender, RoutedEventArgs e)
{
ViewModel.Latest();
}
private void Image_PointerPressed(object sender, Microsoft.UI.Xaml.Input.PointerRoutedEventArgs e)
{
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD> Image <20>ؼ<EFBFBD>
var image = sender as Image;
if (image != null)
2024-07-23 12:23:55 +00:00
{
// <20><>ȡ Image <20>ؼ<EFBFBD><D8BC>İ<EFBFBD><C4B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
var item = image.DataContext as HomeBanner.Data;
var link1 = item?.link;
if (link1 != null)
{
// ʹ<><CAB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽƥ<CABD><C6A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD><DAB5><EFBFBD><EFBFBD><EFBFBD>
var match = MyRegex().Match(link1);
if (match.Success)
{
var link = match.Groups[1].Value;
Process.Start(new ProcessStartInfo
{
FileName = link,
UseShellExecute = true,
Verb = "open"
});
}
else
{
Debug.WriteLine("No match found.");
}
}
2024-07-23 12:23:55 +00:00
}
2024-07-23 12:23:55 +00:00
}
[GeneratedRegex("\\{(.+?)\\}")]
private static partial Regex MyRegex();
2024-07-28 13:33:21 +00:00
private void Image_Tapped(object sender, Microsoft.UI.Xaml.Input.TappedRoutedEventArgs e)
{
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD> Image <20>ؼ<EFBFBD>
var image = sender as Image;
if (image != null)
{
// <20><>ȡ Image <20>ؼ<EFBFBD><D8BC>İ<EFBFBD><C4B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
var item = image.DataContext as HomeBanner.Data;
var link1 = item?.link;
if (link1 != null)
{
// ʹ<><CAB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽƥ<CABD><C6A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD><DAB5><EFBFBD><EFBFBD><EFBFBD>
var match = MyRegex().Match(link1);
if (match.Success)
{
var link = match.Groups[1].Value;
Process.Start(new ProcessStartInfo
{
FileName = link,
UseShellExecute = true,
Verb = "open"
});
}
else
{
Debug.WriteLine("No match found.");
}
}
}
}
2024-07-14 11:24:10 +00:00
}