Skip to content
代码片段 群组 项目
未验证 提交 eb6cfa78 编辑于 作者: WithLithum's avatar WithLithum
浏览文件

:sparkles: 游玩页面

上级 841f3694
No related branches found
No related tags found
无相关合并请求
显示
296 个添加5 个删除
namespace NexusKrop.Mir.Models.PlaySession;
using Microsoft.UI.Xaml.Data;
using NexusKrop.Mir.Resources;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
public class PlaySessionConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
if (targetType != typeof(string)
|| value is not PlaySessionMethod method)
{
return null;
}
return method switch
{
PlaySessionMethod.NeteaseLanGame => AppResources.MethodNeteaseLanGame,
PlaySessionMethod.NeteaseNetworkGame => AppResources.MethodNeteaseServer,
PlaySessionMethod.NeteaseRentalServer => AppResources.MethodNeteaseRental,
PlaySessionMethod.Realms => AppResources.MethodRealms,
PlaySessionMethod.Server => AppResources.MethodServer,
PlaySessionMethod.Essential => AppResources.MethodEssential,
_ => null,
};
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
throw new NotImplementedException();
}
}
namespace NexusKrop.Mir.Models.PlaySession;
public class PlaySessionData
{
public string FriendlyName { get; set; }
public PlaySessionMethod SessionMethod { get; set; }
public string Address { get; set; }
public string Owner { get; set; }
}
namespace NexusKrop.Mir.Models.PlaySession;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
public enum PlaySessionMethod
{
NeteaseLanGame,
NeteaseNetworkGame,
NeteaseRentalServer,
Server,
Realms,
Essential
}
......@@ -5,4 +5,4 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
public record struct ProductInfo(string HomePageData, string NewsPageData);
public record struct ProductInfo(string HomePageData, string NewsPageData, string PlayPageData);
......@@ -62,6 +62,7 @@
</Page>
</ItemGroup>
<ItemGroup>
<Folder Include="Controls\" />
<Folder Include="Models\Collections\" />
</ItemGroup>
<ItemGroup>
......
......@@ -69,8 +69,8 @@ public sealed partial class NewsPage : Page
}
catch (Exception ex)
{
var dialog = new MessageDialog(ex.Message, "Error");
await dialog.ShowAsync();
Debug.WriteLine(ex);
return;
}
Progress.IsActive = false;
......
......@@ -6,12 +6,71 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:NexusKrop.Mir.Pages"
xmlns:sessions="using:NexusKrop.Mir.Models.PlaySession"
xmlns:network="using:NexusKrop.Mir.Util.Network"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
Loaded="Page_Loaded">
<Page.Resources>
<sessions:PlaySessionConverter x:Key="Converter"/>
<DataTemplate x:Key="SessionPlayTemplate" x:DataType="sessions:PlaySessionData">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<TextBlock Text="{x:Bind FriendlyName}" FontWeight="Bold" x:Phase="1" Margin="0,5,0,5" Grid.Row="0"/>
<StackPanel Grid.Row="1" Orientation="Horizontal" VerticalAlignment="Center">
<SymbolIcon Symbol="Highlight" VerticalAlignment="Center">
<SymbolIcon.RenderTransform>
<CompositeTransform ScaleX="0.85" ScaleY="0.85"/>
</SymbolIcon.RenderTransform>
</SymbolIcon>
<TextBlock Text="{x:Bind SessionMethod, Converter={StaticResource Converter}}" Margin="5, 0, 5, 0" FontSize="12px" VerticalAlignment="Top" />
<SymbolIcon Symbol="Contact" VerticalAlignment="Center">
<SymbolIcon.RenderTransform>
<CompositeTransform ScaleX="0.85" ScaleY="0.85"/>
</SymbolIcon.RenderTransform>
</SymbolIcon>
<TextBlock Text="{x:Bind Owner}" Margin="5, 0, 10, 0" FontSize="12px" VerticalAlignment="Top" />
<SymbolIcon Symbol="Globe" VerticalAlignment="Center">
<SymbolIcon.RenderTransform>
<CompositeTransform ScaleX="0.85" ScaleY="0.85"/>
</SymbolIcon.RenderTransform>
</SymbolIcon>
<TextBlock Text="{x:Bind Address}" Margin="5, 0, 5, 0" FontSize="12px" VerticalAlignment="Top" />
</StackPanel>
</Grid>
</DataTemplate>
</Page.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<CommandBar Name="BarMain"
Grid.Row="0"
DefaultLabelPosition="Right"
HorizontalAlignment="Left">
<AppBarButton Icon="Refresh" Label="Refresh" Name="ButtonRefresh" x:Uid="BarButtonRefresh" Click="ButtonRefresh_Click"/>
</CommandBar>
<ProgressRing IsActive="False" Grid.Row="1" Name="Progress"/>
<ListView Grid.Row="1" SelectionMode="Single"
BorderBrush="Transparent"
ItemTemplate="{StaticResource SessionPlayTemplate}"
ItemsSource="{x:Bind network:NetworkDataService.Instance.PlaySessions}"
SelectionChanged="ListView_SelectionChanged"
Name="ListMain">
<ListView.ContextFlyout>
<MenuFlyout>
<MenuFlyoutItem x:Uid="ItemClipboard" Text="Copy" Icon="Copy" Click="Button_Click" />
</MenuFlyout>
</ListView.ContextFlyout>
</ListView>
</Grid>
</Page>
......@@ -12,21 +12,100 @@ using Microsoft.UI.Xaml.Data;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Navigation;
using NexusKrop.Mir.Models.PlaySession;
using NexusKrop.Mir.Util.Network;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.ApplicationModel.DataTransfer;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.Security.Cryptography.Core;
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class PlayPage : Page
{
private readonly List<PlaySessionData> _playSessions = new()
{
new PlaySessionData() { Address = "284102", SessionMethod = PlaySessionMethod.NeteaseLanGame, Owner = "NexusKrop", FriendlyName = "Test Session" },
new PlaySessionData() { Address = "232412", SessionMethod = PlaySessionMethod.NeteaseLanGame, Owner = "MinecraftSTL", FriendlyName = "Test Session 2" },
};
public PlayPage()
{
this.InitializeComponent();
}
private void ListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (e.AddedItems.Count == 0)
{
return;
}
var flyout = new Flyout()
{
Content = new TextBlock()
{
Text = "Something"
}
};
}
private void Button_Click(object sender, RoutedEventArgs e)
{
if (ListMain.SelectedIndex == -1)
{
Debugger.Break();
return;
}
if (ListMain.SelectedItem is not PlaySessionData data)
{
Debugger.Break();
return;
}
var package = new DataPackage();
package.SetText(data.Address);
Clipboard.SetContent(package);
}
private void SetActivity(bool activity)
{
Progress.IsActive = activity;
if (activity)
{
ListMain.Visibility = Visibility.Collapsed;
}
else
{
ListMain.Visibility = Visibility.Visible;
}
}
private async void Page_Loaded(object sender, RoutedEventArgs e)
{
SetActivity(true);
await NetworkDataService.Instance.InitializeAsync(this);
SetActivity(false);
}
private async void ButtonRefresh_Click(object sender, RoutedEventArgs e)
{
SetActivity(true);
await NetworkDataService.Instance.RefreshAsync(this);
SetActivity(false);
}
}
......@@ -60,6 +60,60 @@ namespace NexusKrop.Mir.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Essential.gg.
/// </summary>
internal static string MethodEssential {
get {
return ResourceManager.GetString("MethodEssential", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to 本地联机(网易).
/// </summary>
internal static string MethodNeteaseLanGame {
get {
return ResourceManager.GetString("MethodNeteaseLanGame", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to 租赁服(网易).
/// </summary>
internal static string MethodNeteaseRental {
get {
return ResourceManager.GetString("MethodNeteaseRental", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to 服务器(网易).
/// </summary>
internal static string MethodNeteaseServer {
get {
return ResourceManager.GetString("MethodNeteaseServer", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to 领域服.
/// </summary>
internal static string MethodRealms {
get {
return ResourceManager.GetString("MethodRealms", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to 服务器.
/// </summary>
internal static string MethodServer {
get {
return ResourceManager.GetString("MethodServer", resourceCulture);
}
}
/// <summary>
/// Looks up a localized resource of type System.Byte[].
/// </summary>
......
......@@ -117,6 +117,24 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="MethodEssential" xml:space="preserve">
<value>Essential.gg</value>
</data>
<data name="MethodNeteaseLanGame" xml:space="preserve">
<value>本地联机(网易)</value>
</data>
<data name="MethodNeteaseRental" xml:space="preserve">
<value>租赁服(网易)</value>
</data>
<data name="MethodNeteaseServer" xml:space="preserve">
<value>服务器(网易)</value>
</data>
<data name="MethodRealms" xml:space="preserve">
<value>领域服</value>
</data>
<data name="MethodServer" xml:space="preserve">
<value>服务器</value>
</data>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="NexusKrop" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>NexusKrop.ico;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
......
{
"HomePageData": "http://localhost:8080/app.json",
"NewsPageData": "http://localhost:8080/test.json"
"NewsPageData": "http://localhost:8080/test.json",
"PlayPageData": "http://localhost:8080/play.json"
}
\ No newline at end of file
......@@ -123,6 +123,9 @@
<data name="ButtonRefresh.Content" xml:space="preserve">
<value>刷新</value>
</data>
<data name="ItemClipboard.Text" xml:space="preserve">
<value>复制</value>
</data>
<data name="ItemHome.Content" xml:space="preserve">
<value>主页</value>
</data>
......
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:NexusKrop.Mir">
</ResourceDictionary>
......@@ -4,6 +4,7 @@ using CommunityToolkit.WinUI;
using Microsoft.UI.Xaml;
using Newtonsoft.Json;
using NexusKrop.Mir.Models;
using NexusKrop.Mir.Models.PlaySession;
using NexusKrop.Mir.Resources;
using System;
using System.Collections.Generic;
......@@ -30,6 +31,7 @@ public class NetworkDataService
public ObservableCollection<ActivityPush> CommunityFeed { get; } = new();
public ObservableCollection<ActivityPush> OfficialFeed { get; } = new();
public ObservableCollection<NewsArticle> NewsArticles { get; } = new();
public ObservableCollection<PlaySessionData> PlaySessions { get; } = new();
internal async Task InitializeAsync(UIElement host)
{
......@@ -44,6 +46,7 @@ public class NetworkDataService
{
var homePage = await GetRemoteDataAsync<AppMetadata>(ProductInfo.HomePageData);
var newsPage = await GetRemoteDataAsync<NewsArticle[]>(ProductInfo.NewsPageData);
var playPage = await GetRemoteDataAsync<PlaySessionData[]>(ProductInfo.PlayPageData);
await host.DispatcherQueue.EnqueueAsync(() =>
{
......@@ -70,6 +73,12 @@ public class NetworkDataService
{
FlipItems.Add(flip);
}
PlaySessions.Clear();
foreach (var session in playPage)
{
PlaySessions.Add(session);
}
});
}
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册