-
Notifications
You must be signed in to change notification settings - Fork 166
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
3,643 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<sf:WindowEx x:Class="Starward.Features.Gacha.CloudGameGachaWindow" | ||
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:lang="using:Starward.Language" | ||
xmlns:local="using:Starward.Features.Gacha" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:sf="using:Starward.Frameworks" | ||
mc:Ignorable="d"> | ||
|
||
<Grid x:Name="RootGrid" | ||
Padding="0,32,0,0" | ||
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" | ||
Loaded="RootGrid_Loaded"> | ||
<Grid.RowDefinitions> | ||
<RowDefinition Height="Auto" /> | ||
<RowDefinition /> | ||
</Grid.RowDefinitions> | ||
<Grid.ColumnDefinitions> | ||
<ColumnDefinition /> | ||
<ColumnDefinition Width="Auto" /> | ||
</Grid.ColumnDefinitions> | ||
|
||
<TextBlock x:Name="TextBlock_Info" | ||
Margin="12,0,12,0" | ||
VerticalAlignment="Center" | ||
Foreground="{ThemeResource TextFillColorSecondaryBrush}" | ||
Text="{x:Bind lang:Lang.CloudGameGachaWindow_OpenTheGachaRecordsPageInGameAndThenClickTheButtonOnTheRight}" | ||
TextWrapping="Wrap" /> | ||
<TextBlock x:Name="TextBlock_Error" | ||
Margin="12,0,12,0" | ||
VerticalAlignment="Center" | ||
Foreground="{ThemeResource SystemFillColorCriticalBrush}" | ||
TextWrapping="Wrap" | ||
Visibility="Collapsed" /> | ||
<Button Grid.Column="1" | ||
Click="Button_Click" | ||
Content="获取抽卡记录" /> | ||
|
||
<WebView2 x:Name="webview" | ||
Grid.Row="1" | ||
Grid.ColumnSpan="2" /> | ||
|
||
</Grid> | ||
|
||
</sf:WindowEx> |
127 changes: 127 additions & 0 deletions
127
src/Starward/Features/Gacha/CloudGameGachaWindow.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
using CommunityToolkit.Mvvm.Messaging; | ||
using Microsoft.UI.Xaml; | ||
using Starward.Core; | ||
using Starward.Frameworks; | ||
using System; | ||
using System.Text.Json.Nodes; | ||
using System.Web; | ||
|
||
|
||
namespace Starward.Features.Gacha; | ||
|
||
public sealed partial class CloudGameGachaWindow : WindowEx | ||
{ | ||
|
||
|
||
private const string SPAN_WEB_PREFIX_YS_CN = "https://webstatic.mihoyo.com/hk4e/event/e20190909gacha-v3/index.html"; | ||
|
||
private const string SPAN_WEB_PREFIX_SR_CN = "https://webstatic.mihoyo.com/hkrpg/event/e20211215gacha-v2/index.html"; | ||
|
||
|
||
|
||
public GameBiz GameBiz { get; set; } | ||
|
||
|
||
|
||
|
||
public CloudGameGachaWindow() | ||
{ | ||
this.InitializeComponent(); | ||
AppWindow.TitleBar.ExtendsContentIntoTitleBar = true; | ||
if (ShouldSystemUseDarkMode()) | ||
{ | ||
RootGrid.RequestedTheme = ElementTheme.Dark; | ||
} | ||
else | ||
{ | ||
RootGrid.RequestedTheme = ElementTheme.Light; | ||
} | ||
AdaptTitleBarButtonColorToActuallTheme(); | ||
} | ||
|
||
|
||
|
||
private void RootGrid_Loaded(object sender, RoutedEventArgs e) | ||
{ | ||
try | ||
{ | ||
// todo WinAppSDK 升级到 1.5 后,为云游戏的网页缓存设置单独的文件夹 | ||
if (GameBiz.ToGame() == GameBiz.hk4e) | ||
{ | ||
webview.Source = new Uri("https://ys.mihoyo.com/cloud/"); | ||
} | ||
if (GameBiz.ToGame() == GameBiz.hkrpg) | ||
{ | ||
webview.Source = new Uri("https://sr.mihoyo.com/cloud/"); | ||
} | ||
} | ||
catch (Exception) | ||
{ | ||
|
||
} | ||
|
||
} | ||
|
||
|
||
|
||
|
||
|
||
private async void Button_Click(object sender, RoutedEventArgs e) | ||
{ | ||
try | ||
{ | ||
await webview.EnsureCoreWebView2Async(); | ||
string result = await webview.CoreWebView2.ExecuteScriptAsync("document.documentElement.outerHTML"); | ||
string? html = JsonNode.Parse(result)?.ToString(); | ||
if (!string.IsNullOrWhiteSpace(html)) | ||
{ | ||
string? url = GetMatchUrl(GameBiz, html); | ||
if (!string.IsNullOrWhiteSpace(url)) | ||
{ | ||
url = HttpUtility.HtmlDecode(url); | ||
WeakReferenceMessenger.Default.Send(new UpdateGachaLogMessage(GameBiz, url)); | ||
TextBlock_Info.Visibility = Visibility.Visible; | ||
TextBlock_Error.Visibility = Visibility.Collapsed; | ||
return; | ||
} | ||
} | ||
TextBlock_Info.Visibility = Visibility.Collapsed; | ||
TextBlock_Error.Visibility = Visibility.Visible; | ||
TextBlock_Error.Text = Lang.GachaLogPage_CannotFindURL; | ||
} | ||
catch (Exception ex) | ||
{ | ||
TextBlock_Info.Visibility = Visibility.Collapsed; | ||
TextBlock_Error.Visibility = Visibility.Visible; | ||
TextBlock_Error.Text = ex.Message; | ||
} | ||
} | ||
|
||
|
||
|
||
|
||
private static string? GetMatchUrl(GameBiz gameBiz, string html) | ||
{ | ||
string? prefix = gameBiz.ToGame().Value switch | ||
{ | ||
GameBiz.hk4e => SPAN_WEB_PREFIX_YS_CN, | ||
GameBiz.hkrpg => SPAN_WEB_PREFIX_SR_CN, | ||
_ => null | ||
}; | ||
if (prefix is not null) | ||
{ | ||
ReadOnlySpan<char> span = html.AsSpan(); | ||
int index = span.LastIndexOf(prefix); | ||
if (index >= 0) | ||
{ | ||
var length = span[index..].IndexOfAny("\""); | ||
return new(span.Slice(index, length)); | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using Starward.Core.Gacha; | ||
using Starward.Frameworks; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace Starward.Features.Gacha; | ||
|
||
internal class GachaLogExportFile<T> where T : GachaLogItem | ||
{ | ||
|
||
|
||
public GachaLogExportFile(int uid, List<T> list) | ||
{ | ||
var time = DateTimeOffset.Now; | ||
Info = new WarpRecordExportInfo | ||
{ | ||
Uid = uid.ToString(), | ||
ExportTime = time.ToString("yyyy-MM-dd HH:mm:ss"), | ||
ExportTimestamp = time.ToUnixTimeSeconds().ToString(), | ||
Count = list.Count.ToString(), | ||
}; | ||
List = list; | ||
} | ||
|
||
|
||
|
||
public class WarpRecordExportInfo | ||
{ | ||
[JsonPropertyName("uid")] | ||
public string Uid { get; set; } | ||
|
||
[JsonPropertyName("export_time")] | ||
public string ExportTime { get; set; } | ||
|
||
[JsonPropertyName("export_timestamp")] | ||
public string ExportTimestamp { get; set; } | ||
|
||
[JsonPropertyName("export_app")] | ||
public string ExportApp { get; set; } = "Starward"; | ||
|
||
[JsonPropertyName("export_app_version")] | ||
public string ExportAppVersion { get; set; } = AppSetting.AppVersion ?? ""; | ||
|
||
[JsonPropertyName("count")] | ||
public string Count { get; set; } | ||
} | ||
|
||
|
||
[JsonPropertyName("info")] | ||
public WarpRecordExportInfo Info { get; set; } | ||
|
||
|
||
[JsonPropertyName("list")] | ||
public List<T> List { get; set; } | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
| ||
using CommunityToolkit.Mvvm.ComponentModel; | ||
using Starward.Core.Gacha; | ||
using Starward.Core.Gacha.Genshin; | ||
using Starward.Core.Gacha.StarRail; | ||
using Starward.Core.Gacha.ZZZ; | ||
|
||
namespace Starward.Features.Gacha; | ||
|
||
[INotifyPropertyChanged] | ||
public partial class GachaLogItemEx : GachaLogItem | ||
{ | ||
|
||
/// <summary> | ||
/// 不要删除,导出 Excel 时有用 | ||
/// </summary> | ||
public string IdText => Id.ToString(); | ||
|
||
public int Index { get; set; } | ||
|
||
public int Pity { get; set; } | ||
|
||
public string Icon { get; set; } | ||
|
||
public double Progress => (double)Pity / ((GachaType is GenshinGachaType.WeaponEventWish or StarRailGachaType.LightConeEventWarp or ZZZGachaType.WEngineChannel) ? 80 : 90) * 100; | ||
|
||
|
||
private bool _IsPointerIn; | ||
public bool IsPointerIn | ||
{ | ||
get => _IsPointerIn; | ||
set => SetProperty(ref _IsPointerIn, value); | ||
} | ||
|
||
|
||
public int ItemCount { get; set; } | ||
|
||
|
||
} |
Oops, something went wrong.