把动态的UI写一下,喝一杯咖啡

This commit is contained in:
muqing 2024-08-03 19:49:28 +08:00
parent f0177e5180
commit da65694926
20 changed files with 454 additions and 70 deletions

View File

@ -1,7 +1,9 @@
<Application
x:Class="RustTools.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:RustTools.Views"
xmlns:zy="using:RustTools.DataList">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
@ -9,7 +11,30 @@
<ResourceDictionary Source="/Styles/FontSizes.xaml" />
<ResourceDictionary Source="/Styles/Thickness.xaml" />
<ResourceDictionary Source="/Styles/TextBlock.xaml" />
<ResourceDictionary Source="/Styles/ItemView.xaml" />
</ResourceDictionary.MergedDictionaries>
<!-- 用于动态界面的关注用户视图 -->
<DataTemplate x:Key="ConCernItem">
<ItemContainer Width="260" Margin="0,0,0,9">
<StackPanel Padding="5" Orientation="Horizontal">
<Image
Width="56"
Height="56"
Source="{Binding HeadIcon}"
Stretch="UniformToFill" />
<TextBlock
Margin="3,0,0,0"
VerticalAlignment="Center"
Style="{ThemeResource SubtitleTextBlockStyle}"
Text="{Binding UserName}" />
</StackPanel>
</ItemContainer>
</DataTemplate>
</ResourceDictionary>
</Application.Resources>
</Application>

View File

@ -16,6 +16,8 @@ using Windows.ApplicationModel.Activation;
using Windows.Storage;
using Microsoft.UI.Xaml.Controls;
using Microsoft.Windows.AppLifecycle;
using Windows.ApplicationModel;
using Windows.Management.Core;
namespace RustTools;
@ -51,7 +53,6 @@ public partial class App : Microsoft.UI.Xaml.Application
{
InitializeComponent();
// 注册激活事件处理程序
Host = Microsoft.Extensions.Hosting.Host.
CreateDefaultBuilder().
UseContentRoot(AppContext.BaseDirectory).
@ -81,7 +82,7 @@ public partial class App : Microsoft.UI.Xaml.Application
services.AddTransient<HomePageViewModel>();
services.AddTransient<HomePage>();
services.AddTransient<ConcernViewModel>();
services.AddTransient<Concern>();
services.AddTransient<ConcernPage>();
services.AddTransient<RankingViewModel>();
services.AddTransient<RankingPage>();
services.AddTransient<UserViewModel>();

View File

@ -0,0 +1,111 @@
using System;
using System.Collections.ObjectModel;
using Newtonsoft.Json;
public class CommunityList
{
[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("account")]
public string Account
{
get; set;
}
[JsonProperty("cover")]
public string Cover
{
get; set;
}
[JsonProperty("introduce")]
public string Introduce
{
get; set;
}
[JsonProperty("fans")]
public string Fans
{
get; set;
}
[JsonProperty("follower")]
public string Follower
{
get; set;
}
[JsonProperty("praise")]
public string Praise
{
get; set;
}
[JsonProperty("userName")]
public string UserName
{
get; set;
}
[JsonProperty("headIcon")]
public string HeadIcon
{
get; set;
}
[JsonProperty("email")]
public string Email
{
get; set;
}
[JsonProperty("permission")]
public string Permission
{
get; set;
}
[JsonProperty("loginTime")]
public string LoginTime
{
get; set;
}
[JsonProperty("gender")]
public string Gender
{
get; set;
}
[JsonProperty("enable")]
public bool Enable
{
get; set;
}
[JsonProperty("dynamicColor")]
public string DynamicColor
{
get; set;
}
}
}

View File

@ -12,14 +12,14 @@
<Identity
Name="fd2b2e41-3313-4569-9ada-72a0640e6c21"
Publisher="CN=19669"
Publisher="CN=muqing"
Version="1.0.0.0" />
<mp:PhoneIdentity PhoneProductId="fd2b2e41-3313-4569-9ada-72a0640e6c21" PhonePublisherId="00000000-0000-0000-0000-000000000000"/>
<Properties>
<DisplayName>RustTools</DisplayName>
<PublisherDisplayName>19669</PublisherDisplayName>
<PublisherDisplayName>muqing</PublisherDisplayName>
<Logo>Assets\res\StoreLogo.png</Logo>
</Properties>
@ -74,6 +74,8 @@
<Capabilities>
<rescap:Capability Name="runFullTrust" />
<Capability Name="internetClient" />
<Capability Name="privateNetworkClientServer" />
</Capabilities>
<genTemplate:Metadata>

View File

@ -6,7 +6,6 @@
<RootNamespace>RustTools</RootNamespace>
<Platforms>x86;x64;arm64</Platforms>
<RuntimeIdentifiers>win10-x86;win10-x64;win10-arm64</RuntimeIdentifiers>
<PublishProfile>Properties\PublishProfiles\win10-$(Platform).pubxml</PublishProfile>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<UseWinUI>true</UseWinUI>
@ -17,12 +16,25 @@
<ApplicationIcon>Assets\WindowIcon.ico</ApplicationIcon>
<PackageReadmeFile>README.md</PackageReadmeFile>
<DefaultLanguage>zh-cn</DefaultLanguage>
<GenerateAppInstallerFile>True</GenerateAppInstallerFile>
<AppxPackageSigningEnabled>True</AppxPackageSigningEnabled>
<PackageCertificateThumbprint>3386EC79D3BB9691D0A8DA634167500B242E109D</PackageCertificateThumbprint>
<AppxPackageSigningTimestampDigestAlgorithm>SHA256</AppxPackageSigningTimestampDigestAlgorithm>
<AppxAutoIncrementPackageRevision>False</AppxAutoIncrementPackageRevision>
<AppxSymbolPackageEnabled>False</AppxSymbolPackageEnabled>
<GenerateTestArtifacts>True</GenerateTestArtifacts>
<AppxBundle>Never</AppxBundle>
<AppInstallerUri>C:\\RustTools</AppInstallerUri>
<AppxPackageDir>D:\RustTools</AppxPackageDir>
</PropertyGroup>
<ItemGroup>
</ItemGroup>
<ItemGroup>
<None Remove="Assets\image\image_106.svg" />
<None Remove="Views\Concern.xaml" />
<None Remove="Styles\ItemView.xaml" />
<None Remove="Views\ConcernPage.xaml" />
<None Remove="Views\HomePage.xaml" />
<None Remove="Views\ModulePage.xaml" />
<None Remove="Views\RankingPage.xaml" />
@ -57,13 +69,16 @@
<Pack>True</Pack>
<PackagePath>\</PackagePath>
</None>
<Page Update="Styles\ItemView.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Update="WindowUI\ImportModule.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Update="Views\ModulePage.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Update="Views\Concern.xaml">
<Page Update="Views\ConcernPage.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Update="Views\UserPage.xaml">

View File

@ -17,7 +17,7 @@ public class PageService : IPageService
//Configure<MainViewModel, MainPage>();
Configure<HomePageViewModel, HomePage>();
Configure<ConcernViewModel, Concern>();
Configure<ConcernViewModel, ConcernPage>();
Configure<RankingViewModel, RankingPage>();
Configure<UserViewModel, UserPage>();

View File

@ -160,7 +160,7 @@
<value>Test</value>
</data>
<data name="Concern.Content" xml:space="preserve">
<value>关注</value>
<value>动态</value>
</data>
<data name="HomePage.Content" xml:space="preserve">
<value>主页</value>

View File

@ -0,0 +1,59 @@
<?xml version="1.0" encoding="utf-8" ?>
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<DataTemplate x:Key="MovingInfo">
<StackPanel
Margin="0,0,0,16"
Padding="16"
Background="{ThemeResource CardBackgroundFillColorDefaultBrush}"
BorderBrush="{ThemeResource CardStrokeColorDefaultBrush}"
BorderThickness="1"
CornerRadius="{StaticResource ControlCornerRadius}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Ellipse
Grid.Column="0"
Width="56"
Height="56">
<Ellipse.Fill>
<ImageBrush ImageSource="/Assets/image/a.jpeg" Stretch="UniformToFill" />
</Ellipse.Fill>
</Ellipse>
<StackPanel Grid.Column="1" Margin="9,0,0,0">
<TextBlock Style="{StaticResource SubtitleTextBlockStyle}" Text="名称" />
<TextBlock
Margin="0,3,0,0"
Style="{StaticResource BodyTextBlockStyle}"
Text="信息 日期" />
</StackPanel>
<FontIcon
Grid.Column="2"
VerticalAlignment="Top"
Glyph="&#xE712;" />
</Grid>
<TextBlock
Margin="16"
Style="{StaticResource BodyTextBlockStyle}"
Text="内容是大概就是这个东西了" />
<StackPanel
Margin="16,0,16,0"
HorizontalAlignment="Right"
FlowDirection="RightToLeft"
Orientation="Horizontal">
<StackPanel.Resources>
<Style TargetType="FontIcon">
<Setter Property="Margin" Value="0,0,26,0" />
</Style>
</StackPanel.Resources>
<FontIcon Glyph="&#xE8E1;" />
<FontIcon Glyph="&#xE72D;" />
</StackPanel>
</StackPanel>
</DataTemplate>
</ResourceDictionary>

View File

@ -1,10 +1,96 @@
using CommunityToolkit.Mvvm.ComponentModel;
using System.Collections.ObjectModel;
using CommunityToolkit.Mvvm.ComponentModel;
using Newtonsoft.Json;
using RustTools.DataList;
using RustTools.muqing;
using Windows.System;
namespace RustTools.ViewModels;
public partial class ConcernViewModel : ObservableRecipient
{
public ObservableCollection<CommunityList.Data> communitylist = new();
public ObservableCollection<MovingInfo.Data> MovingInfoList = new();
private readonly string json = @"
{
""code"": 0,
""message"": ""3"",
""data"": [
{
""account"": ""offical"",
""cover"": ""../user/offical/cover.png"",
""introduce"": null,
""fans"": ""64"",
""follower"": ""5"",
""praise"": ""0"",
""userName"": """",
""headIcon"": ""http://rust.coldmint.top/user/offical/icon.png"",
""email"": ""2923268971@qq.com"",
""permission"": ""2"",
""loginTime"": ""2023-10-21 22:28:18"",
""gender"": ""1"",
""enable"": ""true"",
""dynamicColor"": ""null""
},
{
""account"": ""coldmint"",
""cover"": ""http://rust.coldmint.top/user/coldmint/covers/181d019f-7cb7-9c07-389e-5a78b98eea54.png"",
""introduce"": """",
""fans"": ""141"",
""follower"": ""13"",
""praise"": ""0"",
""userName"": ""?"",
""headIcon"": ""https://rust.coldmint.top/user/coldmint/icons/4006dc55-9101-39cc-7076-34c4b32924d5.png"",
""email"": ""cold_mint@qq.com"",
""permission"": ""1"",
""loginTime"": ""2024-08-02 22:04:48"",
""gender"": ""-1"",
""enable"": ""true"",
""dynamicColor"": ""null""
},
{
""account"": ""muqing"",
""cover"": ""../user/muqing/covers/d4083a79-1e7f-d3bc-5944-ae9bce0d6714.png"",
""introduce"": ""nihao"",
""fans"": ""1"",
""follower"": ""1"",
""praise"": ""0"",
""userName"": """",
""headIcon"": ""../user/muqing/icons/cf0582bb-584c-176f-098b-a9a95af22a44.png"",
""email"": ""2583089389@qq.com"",
""permission"": ""3"",
""loginTime"": ""2024-04-18 14:08:22"",
""gender"": ""1"",
""enable"": ""true"",
""dynamicColor"": ""null""
}
]
}";
public ConcernViewModel()
{
var response = JsonConvert.DeserializeObject<CommunityList>(json);
var a = new CommunityList.Data
{
UserName = "全部",
HeadIcon = "/Assets/tool.png"
};
communitylist.Add(a);
foreach (var item in response.data)
{
//item.UserName
item.HeadIcon= item.HeadIcon.Replace("..", wl.api);
communitylist.Add(item);
communitylist.Add(item);
communitylist.Add(item);
}
MovingInfoList.Add(new MovingInfo.Data("123123"));
MovingInfoList.Add(new MovingInfo.Data("123123"));
MovingInfoList.Add(new MovingInfo.Data("123123"));
MovingInfoList.Add(new MovingInfo.Data("123123"));
MovingInfoList.Add(new MovingInfo.Data("123123"));
MovingInfoList.Add(new MovingInfo.Data("123123"));
MovingInfoList.Add(new MovingInfo.Data("123123"));
}
}

View File

@ -14,7 +14,6 @@ public partial class HomePageViewModel : ObservableRecipient
{
}
public async void random()
{
var modListResponse = JsonConvert.DeserializeObject<ModListResponse>(await ApiFox.mod.random());

View File

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RustTools.ViewModels;
public class MovingInfo
{
public class Data
{
public string name;
public Data(string name) {
this.name = name;
}
}
}

View File

@ -1,15 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Page
x:Class="RustTools.Views.Concern"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:RustTools.Views"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid>
</Grid>
</Page>

View File

@ -1,32 +0,0 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
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 RustTools.ViewModels;
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;
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class Concern : Page
{
public ConcernViewModel ConcernViewModel { get; set; }
public Concern()
{
ConcernViewModel = App.GetService<ConcernViewModel>();
InitializeComponent();
}
}

View File

@ -0,0 +1,48 @@
<?xml version="1.0" encoding="utf-8" ?>
<Page
x:Class="RustTools.Views.ConcernPage"
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:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
SizeChanged="Page_SizeChanged"
mc:Ignorable="d">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition MinWidth="56" MaxWidth="320" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<StackPanel
Margin="0,9,9,0"
Padding="9"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<ItemsView
Name="ListViewA"
Grid.Column="0"
ItemInvoked="ItemsView_ItemInvoked"
ItemTemplate="{StaticResource ConCernItem}"
ItemsSource="{x:Bind ViewModels.communitylist}"
ScrollViewer.HorizontalScrollBarVisibility="Hidden"
ScrollViewer.VerticalScrollBarVisibility="Hidden" />
</StackPanel>
<StackPanel
Grid.Column="1"
Margin="9"
Padding="9"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<ListView
Name="ListViewB"
IsItemClickEnabled="False"
ItemTemplate="{StaticResource MovingInfo}"
ItemsSource="{x:Bind ViewModels.MovingInfoList}"
ScrollViewer.HorizontalScrollBarVisibility="Hidden"
ScrollViewer.VerticalScrollBarVisibility="Hidden"
SelectionMode="None" />
</StackPanel>
</Grid>
</Page>

View File

@ -0,0 +1,59 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
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 RustTools.muqing;
using RustTools.ViewModels;
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;
/// <summary>
/// 动态界面
/// </summary>
public sealed partial class ConcernPage : Page
{
public ConcernViewModel ViewModels { get; set; }
public ConcernPage()
{
ViewModels = App.GetService<ConcernViewModel>();
InitializeComponent();
}
private void ItemsView_ItemInvoked(ItemsView sender, ItemsViewItemInvokedEventArgs args)
{
}
private void Page_SizeChanged(object sender, SizeChangedEventArgs e)
{
var height = ActualHeight; // 确保使用页面的实际高度
// 检查是否为有效的数值
if (!double.IsNaN(height) && !double.IsInfinity(height) && height > 16)
{
ListViewA.Height = height - 16;
ListViewB.Height = height - 16;
}
else
{
ListViewA.Height = 500; // 或者其他适当的默认值
ListViewB.Height = 500; // 或者其他适当的默认值
}
}
}

View File

@ -18,6 +18,9 @@ using RustTools.ViewModels;
// and more about our project templates, see: http://aka.ms/winui-project-info.
namespace RustTools.Views;
/// <summary>
/// 排名界面
/// </summary>
public sealed partial class RankingPage : Page
{
public RankingViewModel ViewModel

View File

@ -43,6 +43,7 @@ public sealed partial class SettingsPage : Page
case "Mica":
BackgroundRadioButtons.SelectedIndex = 3;
break;
default: BackgroundRadioButtons.SelectedIndex = 0; break;
}
BackgroundRadioButtons.SelectionChanged += BackgroundColor_SelectionChanged;
ModFileUrlText.Text = iniHelper.GetValue(IniHelper.CODE.Rust, IniHelper.KEY.ModFileUrl);

View File

@ -29,7 +29,7 @@ public class IniHelper
public const string MapsFileUrl = "MapsFileUrl";
}
private string filePath;
private string filePath = string.Empty;
public IniHelper()
{
@ -58,15 +58,19 @@ public class IniHelper
/// </summary>
/// <param name="filePath"></param>
/// <exception cref="FileNotFoundException"></exception>
public void Load(string filePath)
public void Load(string a)
{
this.filePath = filePath;
if (!File.Exists(filePath))
filePath = a;
if (!File.Exists(a))
{
File.Create(filePath);
File.Create(a);
return;
//throw new FileNotFoundException("The specified file does not exist.", filePath);
}
if (filePath == null || filePath == string.Empty)
{
return;
}
var lines = File.ReadAllLines(filePath);
string? currentSection = null;

View File

@ -41,7 +41,7 @@ class gj
/// <summary>
/// 设置window窗口适配器 主题颜色
/// </summary>
public static void SetBackTheme(WindowEx windowEx)
public static async void SetBackTheme(WindowEx windowEx)
{
var iniHelper = new IniHelper();
iniHelper.Load(IniHelper.FILE.Config);

View File

@ -1,18 +1,18 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using Windows.Storage;
namespace RustTools.muqing;
class wj
{
//存储主要文件的路径
public const string CD = "D:\\抓包";
public static string CD = ApplicationData.Current.LocalFolder.Path;
//缓存路径
public const string Cache = "";
//不知道为什么会保存到这里的路径
//C:\Users\账号\AppData\Local\VirtualStore\Windows\SysWOW64
public const string CachePath= "C:/Users/19669/AppData/Local/VirtualStore/Windows/SysWOW64";
//不知道为什么会保存到这里的路径 废弃了 找到了新的文件夹路径
//public const string CachePath= "C:/Users/账号/AppData/Local/VirtualStore/Windows/SysWOW64";
/// <summary>
/// 存储文件名字的路径