diff --git a/src/Starward.Core/GameBiz.cs b/src/Starward.Core/GameBiz.cs index fdf616617..8e68a391e 100644 --- a/src/Starward.Core/GameBiz.cs +++ b/src/Starward.Core/GameBiz.cs @@ -55,17 +55,17 @@ public GameBiz(string? value) public static ReadOnlyCollection AllGameBizs { get; private set; } = new List { bh3_cn, - //bh3_global, - bh3_os, - bh3_jp, - bh3_kr, - bh3_usa, - bh3_asia, - bh3_eur, + bh3_global, + //bh3_os, + //bh3_jp, + //bh3_kr, + //bh3_usa, + //bh3_asia, + //bh3_eur, hk4e_cn, hk4e_global, hk4e_bilibili, - clgm_cn, + //clgm_cn, //clgm_global, hkrpg_cn, hkrpg_global, @@ -102,7 +102,7 @@ public static class GameBizExtension { GameBiz.bh3_cn or GameBiz.bh3_global => true, GameBiz.hk4e_cn or GameBiz.hk4e_global or GameBiz.hk4e_bilibili => true, - GameBiz.clgm_cn or GameBiz.clgm_global => true, + //GameBiz.clgm_cn or GameBiz.clgm_global => true, GameBiz.hkrpg_cn or GameBiz.hkrpg_global or GameBiz.hkrpg_bilibili => true, GameBiz.nap_cn or GameBiz.nap_global or GameBiz.nap_bilibili => true, _ => false, diff --git a/src/Starward.Core/HoYoPlay/GameImage.cs b/src/Starward.Core/HoYoPlay/GameImage.cs index b1ff37feb..13b6d4581 100644 --- a/src/Starward.Core/HoYoPlay/GameImage.cs +++ b/src/Starward.Core/HoYoPlay/GameImage.cs @@ -8,12 +8,18 @@ namespace Starward.Core.HoYoPlay; public class GameImage { + /// + /// 图片链接 + /// [JsonPropertyName("url")] public string Url { get; set; } [JsonPropertyName("hover_url")] public string? HoverUrl { get; set; } + /// + /// 点击图片后打开的链接 + /// [JsonPropertyName("link")] public string Link { get; set; } diff --git a/src/Starward/Features/GameSelector/GameBizIcon.cs b/src/Starward/Features/GameSelector/GameBizIcon.cs new file mode 100644 index 000000000..3a8e340f6 --- /dev/null +++ b/src/Starward/Features/GameSelector/GameBizIcon.cs @@ -0,0 +1,95 @@ +using CommunityToolkit.Mvvm.ComponentModel; +using Starward.Core; +using Starward.Core.HoYoPlay; +using System; + + +namespace Starward.Features.GameSelector; + +public partial class GameBizIcon : ObservableObject, IEquatable +{ + + + public GameId GameId { get; set; } + + public GameBiz GameBiz { get; set; } + + + public string GameIcon { get; set => SetProperty(ref field, value); } + + public string GameName { get; set => SetProperty(ref field, value); } + + public string ServerIcon { get; set => SetProperty(ref field, value); } + + public string ServerName { get; set => SetProperty(ref field, value); } + + public double MaskOpacity { get; set => SetProperty(ref field, value); } = 1.0; + + public bool IsSelected + { + get; + set + { + field = value; + MaskOpacity = value ? 0 : 1; + } + } + + + + public GameBizIcon(GameBiz gameBiz) + { + GameBiz = gameBiz; + GameId = GameId.FromGameBiz(gameBiz)!; + GameIcon = GameBizToIcon(gameBiz); + ServerIcon = GameBizToServerIcon(gameBiz); + GameName = gameBiz.ToGameName(); + ServerName = gameBiz.ToGameServerName(); + } + + + + public GameBizIcon(GameInfo gameInfo) + { + // todo icon 和 name 按照 gamebiz 匹配 _cn / _global + GameId = gameInfo; + GameBiz = gameInfo.GameBiz; + GameIcon = gameInfo.Display.Icon.Url; + ServerIcon = ""; + GameName = gameInfo.Display.Name; + ServerName = ""; + } + + + + private static string GameBizToIcon(GameBiz gameBiz) + { + return gameBiz.ToGame().Value switch + { + GameBiz.bh3 => "ms-appx:///Assets/Image/icon_bh3.jpg", + GameBiz.hk4e => "ms-appx:///Assets/Image/icon_ys.jpg", + GameBiz.hkrpg => "ms-appx:///Assets/Image/icon_sr.jpg", + GameBiz.nap => "ms-appx:///Assets/Image/icon_zzz.jpg", + _ => "ms-appx:///Assets/Image/Transparent.png", + }; + } + + + private static string GameBizToServerIcon(GameBiz gameBiz) + { + return gameBiz.Value switch + { + GameBiz.hk4e_cn or GameBiz.hkrpg_cn or GameBiz.bh3_cn or GameBiz.nap_cn => "ms-appx:///Assets/Image/gameicon_hyperion.png", + GameBiz.hk4e_global or GameBiz.hkrpg_global or GameBiz.bh3_global or GameBiz.nap_global => "ms-appx:///Assets/Image/gameicon_hoyolab.png", + GameBiz.hk4e_bilibili or GameBiz.hkrpg_bilibili or GameBiz.nap_bilibili => "ms-appx:///Assets/Image/gameicon_bilibili.png", + _ => "ms-appx:///Assets/Image/Transparent.png", + }; + } + + + public bool Equals(GameBizIcon? other) + { + return ReferenceEquals(this, other) || GameBiz == other?.GameBiz; + } + +} diff --git a/src/Starward/Features/GameSelector/GameSelector.xaml b/src/Starward/Features/GameSelector/GameSelector.xaml new file mode 100644 index 000000000..c59b849a9 --- /dev/null +++ b/src/Starward/Features/GameSelector/GameSelector.xaml @@ -0,0 +1,223 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Starward/Features/GameSelector/GameSelector.xaml.cs b/src/Starward/Features/GameSelector/GameSelector.xaml.cs new file mode 100644 index 000000000..b5c75d036 --- /dev/null +++ b/src/Starward/Features/GameSelector/GameSelector.xaml.cs @@ -0,0 +1,440 @@ +using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.Input; +using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Controls; +using Starward.Core; +using Starward.Core.HoYoPlay; +using Starward.Features.HoYoPlay; +using Starward.Frameworks; +using Starward.Helpers; +using Starward.Messages; +using Starward.Services.Launcher; +using System; +using System.Collections.ObjectModel; +using System.Linq; +using System.Numerics; +using System.Text; +using Windows.Foundation; + + +namespace Starward.Features.GameSelector; + +[INotifyPropertyChanged] +public sealed partial class GameSelector : UserControl +{ + + private const string IconPin = "\uE718"; + + private const string IconUnpin = "\uE77A"; + + + public event EventHandler<(GameId, bool DoubleTapped)>? CurrentGameChanged; + + + private HoYoPlayService _hoyoplayService = AppService.GetService(); + + + + public GameSelector() + { + this.InitializeComponent(); + InitializeGameSelector(); + } + + + + public GameBiz CurrentGameBiz { get; set; } + + + public GameId? CurrentGameId { get; set; } + + + public ObservableCollection GameBizIcons { get; set => SetProperty(ref field, value); } = new(); + + + public GameBizIcon? CurrentGameBizIcon { get; set => SetProperty(ref field, value); } + + + public bool IsPinned { get; set => SetProperty(ref field, value); } + + + + + public void InitializeGameSelector() + { + GameBizIcons.Clear(); + + // ļȡѡ GameBiz + string? bizs = AppSetting.SelectedGameBizs; + foreach (string str in bizs?.Split(',') ?? []) + { + if (GameBiz.TryParse(str, out GameBiz biz)) + { + // ֪ GameBiz + GameBizIcons.Add(new GameBizIcon(biz)); + } + else if (_hoyoplayService.GetCachedGameInfo(biz) is GameInfo info) + { + // HoYoPlay API ȡδ GameBiz + GameBizIcons.Add(new GameBizIcon(info)); + } + } + + // ѡȡǰϷ + GameBiz lastSelectedGameBiz = AppSetting.CurrentGameBiz; + if (GameBizIcons.FirstOrDefault(x => x.GameBiz == lastSelectedGameBiz) is GameBizIcon icon) + { + CurrentGameBizIcon = icon; + CurrentGameBizIcon.IsSelected = true; + CurrentGameBiz = lastSelectedGameBiz; + } + else if (lastSelectedGameBiz.IsKnown()) + { + CurrentGameBizIcon = new GameBizIcon(lastSelectedGameBiz); + CurrentGameBiz = lastSelectedGameBiz; + } + + CurrentGameId = CurrentGameBizIcon?.GameId; + if (CurrentGameId is not null) + { + CurrentGameChanged?.Invoke(this, (CurrentGameId, false)); + } + + if (AppSetting.IsGameBizSelectorPinned) + { + Pin(); + } + } + + + + [RelayCommand] + public void AutoSearchInstalledGames() + { + try + { + // todo עԶѰװϷ + var service = AppService.GetService(); + var sb = new StringBuilder(); + foreach (GameBiz biz in GameBiz.AllGameBizs) + { + if (service.IsGameExeExists(biz)) + { + sb.Append(biz.ToString()); + sb.Append(','); + } + } + AppSetting.SelectedGameBizs = sb.ToString().TrimEnd(','); + InitializeGameSelector(); + } + catch (Exception ex) + { + + } + } + + + + + #region Game Icon + + + + /// + /// ϷͼǷɼ + /// + public bool GameIconsAreaVisible + { + get => Border_GameIconsArea.Translation == Vector3.Zero; + set + { + if (value) + { + Border_GameIconsArea.Translation = Vector3.Zero; + } + else + { + Border_GameIconsArea.Translation = new Vector3(0, -100, 0); + } + UpdateDragRectangles(); + } + } + + + /// + /// ´ק + /// + public void UpdateDragRectangles() + { + try + { + double x = Border_CurrentGameIcon.ActualWidth; + if (GameIconsAreaVisible) + { + x = Border_CurrentGameIcon.ActualWidth + Border_GameIconsArea.ActualWidth; + } + this.XamlRoot.SetWindowDragRectangles([new Rect(x, 0, 10000, 48)]); + } + catch { } + } + + + + /// + /// 뵽ǰϷͼ + /// + /// + /// + private void Border_CurrentGameIcon_PointerEntered(object sender, Microsoft.UI.Xaml.Input.PointerRoutedEventArgs e) + { + // ʾϷͼ + GameIconsAreaVisible = true; + } + + + + /// + /// ƳǰϷͼ + /// + /// + /// + private void Border_CurrentGameIcon_PointerExited(object sender, Microsoft.UI.Xaml.Input.PointerRoutedEventArgs e) + { + if (FullBackgroundVisible || IsPinned) + { + // ǰϷͼ걻̶ȫʾʱϷͼ + return; + } + if (sender is UIElement ele) + { + var postion = e.GetCurrentPoint(sender as UIElement).Position; + if (postion.X > ele.ActualSize.X - 1 && postion.Y > 0 && postion.Y < ele.ActualSize.Y) + { + // ҲƳʱ뵽Ϸͼ򣬲 + return; + } + } + // ƳϷͼ + GameIconsAreaVisible = false; + } + + + + /// + /// ƳϷͼ + /// + /// + /// + private void Border_GameIconsArea_PointerExited(object sender, Microsoft.UI.Xaml.Input.PointerRoutedEventArgs e) + { + if (FullBackgroundVisible || IsPinned) + { + return; + } + GameIconsAreaVisible = false; + } + + + + /// + /// ûбѡϷͼ + /// + /// + /// + private void Button_GameIcon_Tapped(object sender, Microsoft.UI.Xaml.Input.TappedRoutedEventArgs e) + { + if (sender is Button button && button.DataContext is GameBizIcon icon) + { + if (CurrentGameBizIcon is not null) + { + CurrentGameBizIcon.IsSelected = false; + } + + CurrentGameBizIcon = icon; + CurrentGameBiz = icon.GameBiz; + CurrentGameId = icon.GameId; + icon.IsSelected = true; + HideFullBackground(); + + CurrentGameChanged?.Invoke(this, (icon.GameId, false)); + } + } + + + + /// + /// ˫ûбѡϷͼ + /// + /// + /// + private void Button_GameIcon_DoubleTapped(object sender, Microsoft.UI.Xaml.Input.DoubleTappedRoutedEventArgs e) + { + if (sender is Button button && button.DataContext is GameBizIcon icon) + { + if (CurrentGameBizIcon is not null) + { + CurrentGameBizIcon.IsSelected = false; + } + + CurrentGameBizIcon = icon; + CurrentGameBiz = icon.GameBiz; + CurrentGameId = icon.GameId; + icon.IsSelected = true; + HideFullBackground(); + + CurrentGameChanged?.Invoke(this, (icon.GameId, true)); + } + } + + + /// + /// 뵽Ϸͼ + /// + /// + /// + private void Button_GameIcon_PointerEntered(object sender, Microsoft.UI.Xaml.Input.PointerRoutedEventArgs e) + { + if (sender is Button button && button.DataContext is GameBizIcon icon) + { + if (!icon.IsSelected) + { + icon.MaskOpacity = 0; + } + } + } + + + + /// + /// ƳϷͼ + /// + /// + /// + private void Button_GameIcon_PointerExited(object sender, Microsoft.UI.Xaml.Input.PointerRoutedEventArgs e) + { + if (sender is Button button && button.DataContext is GameBizIcon icon) + { + if (!icon.IsSelected) + { + icon.MaskOpacity = 1; + } + } + } + + + + /// + /// ϷͼС仯 + /// + /// + /// + private void Border_GameIconsArea_SizeChanged(object sender, SizeChangedEventArgs e) + { + UpdateDragRectangles(); + } + + + + + [RelayCommand] + private void Pin() + { + IsPinned = !IsPinned; + if (IsPinned) + { + FontIcon_Pin.Glyph = IconUnpin; + GameIconsAreaVisible = true; + } + else + { + FontIcon_Pin.Glyph = IconPin; + // ڹ̶ʱǰϷȡ̶Ͻǵͼ겻ı + var temp = CurrentGameBizIcon; + CurrentGameBizIcon = null; + CurrentGameBizIcon = temp; + if (!FullBackgroundVisible) + { + GameIconsAreaVisible = false; + } + } + AppSetting.IsGameBizSelectorPinned = IsPinned; + } + + + + + #endregion + + + + + + + #region Full Background ɫ͸ + + + + public bool FullBackgroundVisible => Border_FullBackground.Opacity > 0; + + + [RelayCommand] + private void ShowFullBackground() + { + Border_FullBackground.Opacity = 1; + Border_FullBackground.IsHitTestVisible = true; + GameIconsAreaVisible = true; + } + + + private void HideFullBackground() + { + Border_FullBackground.Opacity = 0; + Border_FullBackground.IsHitTestVisible = false; + if (!IsPinned) + { + GameIconsAreaVisible = false; + } + } + + + private void Border_FullBackground_Tapped(object sender, Microsoft.UI.Xaml.Input.TappedRoutedEventArgs e) + { + var position = e.GetPosition(sender as UIElement); + if (position.X <= Border_CurrentGameIcon.ActualWidth && position.Y <= Border_CurrentGameIcon.ActualHeight) + { + Border_FullBackground.Opacity = 0; + Border_FullBackground.IsHitTestVisible = false; + } + else + { + HideFullBackground(); + } + } + + + + #endregion + + + + + + + public void OnLanguageChanged(object? sender, LanguageChangedMessage message) + { + if (message.Completed) + { + this.Bindings.Update(); + } + } + + + + + + + + + +} + diff --git a/src/Starward/Features/HoYoPlay/HoYoPlayService.cs b/src/Starward/Features/HoYoPlay/HoYoPlayService.cs index d489447a2..3d09aac0f 100644 --- a/src/Starward/Features/HoYoPlay/HoYoPlayService.cs +++ b/src/Starward/Features/HoYoPlay/HoYoPlayService.cs @@ -1,6 +1,7 @@ using Microsoft.Extensions.Logging; using Starward.Core; using Starward.Core.HoYoPlay; +using Starward.Frameworks; using System; using System.Collections.Concurrent; using System.Collections.Generic; @@ -8,6 +9,7 @@ using System.IO; using System.Linq; using System.Net.Http; +using System.Text.Json; using System.Threading.Tasks; namespace Starward.Features.HoYoPlay; @@ -37,6 +39,7 @@ public HoYoPlayService(ILogger logger, HoYoPlayClient client, H Interval = TimeSpan.FromMinutes(10).TotalMilliseconds, }; _timer.Elapsed += async (_, _) => await PrepareDataAsync(); + LoadCachedGameInfo(); } @@ -58,6 +61,40 @@ public HoYoPlayService(ILogger logger, HoYoPlayClient client, H + private void LoadCachedGameInfo() + { + try + { + string? json = AppSetting.CachedGameInfo; + if (!string.IsNullOrWhiteSpace(json)) + { + var infos = JsonSerializer.Deserialize>(json); + if (infos is not null) + { + foreach (var item in infos) + { + _gameInfo[item] = item; + } + } + } + } + catch { } + } + + + private void CacheGameInfo() + { + try + { + var infos = _gameInfo.Values.ToList(); + string json = JsonSerializer.Serialize(infos); + AppSetting.CachedGameInfo = json; + } + catch { } + } + + + public void ClearCache() { _gameInfo.Clear(); @@ -80,6 +117,7 @@ public async Task PrepareDataAsync() tasks.Add(PrepareDataForServerAsync(LauncherId.GlobalOfficial, lang)); tasks.Add(PrepareDataForBilibiliServerAsync(lang)); await Task.WhenAll(tasks); + CacheGameInfo(); await PrepareImagesAsync(); } catch (Exception ex) @@ -256,6 +294,13 @@ public async Task GetGameInfoAsync(GameId gameId) + public GameInfo? GetCachedGameInfo(GameBiz gameBiz) + { + return _gameInfo.Values.FirstOrDefault(x => x.GameBiz == gameBiz); + } + + + public async Task GetGameBackgroundAsync(GameId gameId) { if (!_gameBackground.TryGetValue(gameId, out GameBackgroundInfo? background)) diff --git a/src/Starward/Features/ViewHost/MainView.xaml b/src/Starward/Features/ViewHost/MainView.xaml index be20ed3c3..4fe07f41e 100644 --- a/src/Starward/Features/ViewHost/MainView.xaml +++ b/src/Starward/Features/ViewHost/MainView.xaml @@ -3,15 +3,155 @@ 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.ViewHost" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:sfg="using:Starward.Features.GameSelector" mc:Ignorable="d"> + + + + + + + + + + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Starward/Features/ViewHost/MainView.xaml.cs b/src/Starward/Features/ViewHost/MainView.xaml.cs index b2d0b2d96..3d27fa0e4 100644 --- a/src/Starward/Features/ViewHost/MainView.xaml.cs +++ b/src/Starward/Features/ViewHost/MainView.xaml.cs @@ -1,12 +1,44 @@ +using CommunityToolkit.Mvvm.ComponentModel; using Microsoft.UI.Xaml.Controls; +using Starward.Core; +using Starward.Core.HoYoPlay; namespace Starward.Features.ViewHost; +[INotifyPropertyChanged] public sealed partial class MainView : UserControl { + + + + public GameId CurrentGameId { get; private set; } + + + public GameBiz CurrentGameBiz { get; private set; } + + + + public MainView() { this.InitializeComponent(); + this.Loaded += MainView_Loaded; + } + + + + + + private void MainView_Loaded(object sender, Microsoft.UI.Xaml.RoutedEventArgs e) + { + } + + + + + + + } diff --git a/src/Starward/Features/ViewHost/MainWindow.xaml.cs b/src/Starward/Features/ViewHost/MainWindow.xaml.cs index d80e2bb74..fee50793f 100644 --- a/src/Starward/Features/ViewHost/MainWindow.xaml.cs +++ b/src/Starward/Features/ViewHost/MainWindow.xaml.cs @@ -22,21 +22,15 @@ public sealed partial class MainWindow : WindowEx public static new MainWindow Current { get; private set; } + private bool _mainViewLoaded; + public MainWindow() { Current = this; this.InitializeComponent(); InitializeMainWindow(); - if (string.IsNullOrWhiteSpace(AppSetting.UserDataFolder)) - { - MainContentHost.Content = new WelcomeView(); - } - else - { - MainContentHost.Content = new MainView(); - App.Current.EnsureSystemTray(); - } + LoadContentView(); } @@ -48,6 +42,7 @@ private void InitializeMainWindow() AppWindow.TitleBar.IconShowOptions = IconShowOptions.ShowIconAndSystemMenu; AppWindow.TitleBar.PreferredHeightOption = TitleBarHeightOption.Tall; AppWindow.Closing += AppWindow_Closing; + Content.KeyDown += Content_KeyDown; CenterInScreen(1200, 676); AdaptTitleBarButtonColorToActuallTheme(); SetDragRectangles(new RectInt32(0, 0, 100000, (int)(48 * UIScale))); @@ -61,11 +56,28 @@ private void InitializeMainWindow() } + + private void LoadContentView() + { + if (string.IsNullOrWhiteSpace(AppSetting.UserDataFolder)) + { + MainContentHost.Content = new WelcomeView(); + } + else + { + MainContentHost.Content = new MainView(); + App.Current.EnsureSystemTray(); + _mainViewLoaded = true; + } + } + + + private async void AppWindow_Closing(AppWindow sender, AppWindowClosingEventArgs args) { try { - if (string.IsNullOrWhiteSpace(AppSetting.UserDataFolder)) + if (!_mainViewLoaded) { App.Current.Exit(); return; @@ -103,6 +115,20 @@ private async void AppWindow_Closing(AppWindow sender, AppWindowClosingEventArgs } + + private void Content_KeyDown(object sender, Microsoft.UI.Xaml.Input.KeyRoutedEventArgs e) + { + if (_mainViewLoaded) + { + if (e.Key is Windows.System.VirtualKey.Escape) + { + Hide(); + } + } + } + + + protected override nint WindowSubclassProc(HWND hWnd, uint uMsg, nint wParam, nint lParam, nuint uIdSubclass, nint dwRefData) { if (uMsg == (uint)User32.WindowMessage.WM_SYSCOMMAND) diff --git a/src/Starward/AppService.cs b/src/Starward/Frameworks/AppService.cs similarity index 92% rename from src/Starward/AppService.cs rename to src/Starward/Frameworks/AppService.cs index 04d730f09..0c6b8d28f 100644 --- a/src/Starward/AppService.cs +++ b/src/Starward/Frameworks/AppService.cs @@ -2,13 +2,15 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Serilog; +using Starward.Core.HoYoPlay; using Starward.Features.Database; +using Starward.Features.HoYoPlay; using System; using System.IO; using System.Net; using System.Net.Http; -namespace Starward; +namespace Starward.Frameworks; public static class AppService { @@ -50,6 +52,9 @@ private static void BuildServiceProvider() return client; }); + sc.AddSingleton(); + sc.AddSingleton(); + _serviceProvider = sc.BuildServiceProvider(); } } diff --git a/src/Starward/AppSetting.cs b/src/Starward/Frameworks/AppSetting.cs similarity index 96% rename from src/Starward/AppSetting.cs rename to src/Starward/Frameworks/AppSetting.cs index a4e2252ae..db77160d5 100644 --- a/src/Starward/AppSetting.cs +++ b/src/Starward/Frameworks/AppSetting.cs @@ -13,7 +13,7 @@ using System.Runtime.CompilerServices; using System.Text.RegularExpressions; -namespace Starward; +namespace Starward.Frameworks; public static class AppSetting { @@ -44,8 +44,8 @@ static AppSetting() if (File.Exists(iniPath)) { string text = File.ReadAllText(iniPath); - string lang = Regex.Match(text, @"Language=(.+)").Groups[1].Value; - string folder = Regex.Match(text, @"UserDataFolder=(.+)").Groups[1].Value; + string lang = Regex.Match(text, @"Language=(.+)").Groups[1].Value.Trim(); + string folder = Regex.Match(text, @"UserDataFolder=(.+)").Groups[1].Value.Trim(); if (!string.IsNullOrWhiteSpace(lang)) { try @@ -99,16 +99,6 @@ static AppSetting() #region Static Setting - /// - /// 主窗口关闭选项,隐藏/退出 - /// - public static MainWindowCloseOption CloseWindowOption - { - get => GetValue(); - set => SetValue(value); - } - - public static bool EnablePreviewRelease { @@ -207,6 +197,16 @@ public static bool ExitWhenClosing } + /// + /// 主窗口关闭选项,隐藏/退出 + /// + public static MainWindowCloseOption CloseWindowOption + { + get => GetValue(); + set => SetValue(value); + } + + public static bool UseSystemThemeColor { get => GetValue(); @@ -274,6 +274,9 @@ public static string? LastAppVersion } + /// + /// 当前选择的游戏区服 + /// public static GameBiz CurrentGameBiz { get => GetValue(); @@ -288,6 +291,9 @@ public static string? SelectedGameBizs } + /// + /// 固定待选择的游戏区服图标 + /// public static bool IsGameBizSelectorPinned { get => GetValue(); @@ -310,6 +316,16 @@ public static int SpeedLimitKBPerSecond + /// + /// 缓存的游戏信息 + /// + public static string? CachedGameInfo + { + get => GetValue(); + set => SetValue(value); + } + + #endregion diff --git a/src/Starward/Helpers/SystemUIHelper.cs b/src/Starward/Helpers/SystemUIHelper.cs new file mode 100644 index 000000000..1d426bef6 --- /dev/null +++ b/src/Starward/Helpers/SystemUIHelper.cs @@ -0,0 +1,39 @@ +using Vanara.PInvoke; + +namespace Starward.Helpers; + +public static class SystemUIHelper +{ + + + /// + /// 辅助功能 - 视觉效果 - 透明效果 + /// + public static bool TransparencyEffectEnabled + { + get + { + User32.SystemParametersInfo(User32.SPI.SPI_GETDISABLEOVERLAPPEDCONTENT, out bool enabled); + return enabled; + } + set => User32.SystemParametersInfo(User32.SPI.SPI_SETDISABLEOVERLAPPEDCONTENT, value); + } + + + + /// + /// 辅助功能 - 视觉效果 - 动画效果 + /// + public static bool AnimationEffectEnabled + { + get + { + User32.SystemParametersInfo(User32.SPI.SPI_GETCLIENTAREAANIMATION, out bool enabled); + return enabled; + } + set => User32.SystemParametersInfo(User32.SPI.SPI_SETCLIENTAREAANIMATION, value); + } + + + +} diff --git a/src/Starward/Helpers/XamlRootExtension.cs b/src/Starward/Helpers/XamlRootExtension.cs new file mode 100644 index 000000000..0de91094c --- /dev/null +++ b/src/Starward/Helpers/XamlRootExtension.cs @@ -0,0 +1,48 @@ +using Microsoft.UI; +using Microsoft.UI.Windowing; +using Microsoft.UI.Xaml; +using System.Linq; +using Vanara.PInvoke; +using Windows.Foundation; +using Windows.Graphics; + +namespace Starward.Helpers; + +internal static class XamlRootExtension +{ + + + + public static void SetWindowDragRectangles(this XamlRoot xamlRoot, params RectInt32[] rects) + { + WindowId id = xamlRoot.ContentIslandEnvironment.AppWindowId; + AppWindow appWindow = AppWindow.GetFromWindowId(id); + appWindow.TitleBar.SetDragRectangles(rects); + } + + + + public static void SetWindowDragRectangles(this XamlRoot xamlRoot, params Rect[] rects) + { + if (xamlRoot is null) + { + return; + } + WindowId id = xamlRoot.ContentIslandEnvironment.AppWindowId; + AppWindow appWindow = AppWindow.GetFromWindowId(id); + double scale = User32.GetDpiForWindow((nint)id.Value) / 96d; + var value = rects.Select(rect => RectToRectInt32(rect, scale)).ToArray(); + appWindow.TitleBar.SetDragRectangles(value); + } + + + + private static RectInt32 RectToRectInt32(Rect rect, double scale = 1) + { + return new RectInt32((int)(rect.X * scale), (int)(rect.Y * scale), (int)(rect.Width * scale), (int)(rect.Height * scale)); + } + + + + +} diff --git a/src/Starward/Pages/ImageViewPage.xaml.cs b/src/Starward/Pages/ImageViewPage.xaml.cs index e6022c6ac..bd807284c 100644 --- a/src/Starward/Pages/ImageViewPage.xaml.cs +++ b/src/Starward/Pages/ImageViewPage.xaml.cs @@ -84,7 +84,7 @@ protected override void OnUnloaded() - private void ImageViewPage_KeyDown(object? sender, MainWindow.KeyDownEventArgs e) + private void ImageViewPage_KeyDown(object? sender, MyWindows.MainWindow.KeyDownEventArgs e) { try { diff --git a/src/Starward/Pages/MainPage.xaml.cs b/src/Starward/Pages/MainPage.xaml.cs index d6b092734..52f8bb60a 100644 --- a/src/Starward/Pages/MainPage.xaml.cs +++ b/src/Starward/Pages/MainPage.xaml.cs @@ -664,7 +664,7 @@ public void NavigateTo(Type? page, object? param = null, NavigationTransitionInf - private void MainPage_KeyDown(object? sender, MainWindow.KeyDownEventArgs e) + private void MainPage_KeyDown(object? sender, MyWindows.MainWindow.KeyDownEventArgs e) { try { diff --git a/src/Starward/Pages/Setting/SettingPage.xaml.cs b/src/Starward/Pages/Setting/SettingPage.xaml.cs index dacba07cc..8dd439d4a 100644 --- a/src/Starward/Pages/Setting/SettingPage.xaml.cs +++ b/src/Starward/Pages/Setting/SettingPage.xaml.cs @@ -42,7 +42,7 @@ protected override void OnUnloaded() } - private void SettingPage_KeyDown(object? sender, MainWindow.KeyDownEventArgs e) + private void SettingPage_KeyDown(object? sender, MyWindows.MainWindow.KeyDownEventArgs e) { try { diff --git a/src/Starward/Program.cs b/src/Starward/Program.cs index 83d4546e8..9a21aa5c8 100644 --- a/src/Starward/Program.cs +++ b/src/Starward/Program.cs @@ -16,10 +16,9 @@ namespace Starward; /// public static class Program { - [global::System.Runtime.InteropServices.DllImport("Microsoft.ui.xaml.dll")] - private static extern void XamlCheckProcessRequirements(); - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.UI.Xaml.Markup.Compiler", " 1.0.0.0")] + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.UI.Xaml.Markup.Compiler", " 3.0.0.2411")] //[global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.STAThreadAttribute] static void Main(string[] args) @@ -71,8 +70,6 @@ static void Main(string[] args) } - XamlCheckProcessRequirements(); - global::WinRT.ComWrappersSupport.InitializeComWrappers(); global::Microsoft.UI.Xaml.Application.Start((p) => { @@ -81,6 +78,8 @@ static void Main(string[] args) new App(); }); } + + } #endif diff --git a/src/Starward/Starward.csproj b/src/Starward/Starward.csproj index f0a6ce788..4081faa8e 100644 --- a/src/Starward/Starward.csproj +++ b/src/Starward/Starward.csproj @@ -44,7 +44,7 @@ - +