diff --git a/src/LipUI/App.xaml.cs b/src/LipUI/App.xaml.cs index 46e8e00..815b78b 100644 --- a/src/LipUI/App.xaml.cs +++ b/src/LipUI/App.xaml.cs @@ -1,5 +1,5 @@ -using Microsoft.UI.Xaml; -using System.IO; +using LipUI.Models; +using Microsoft.UI.Xaml; // To learn more about WinUI, the WinUI project structure, // and more about our project templates, see: http://aka.ms/winui-project-info. @@ -17,6 +17,13 @@ public partial class App : Application public App() { InitializeComponent(); + + Current.RequestedTheme = Main.Config.PersonalizationSettings.ColorTheme switch + { + ElementTheme.Dark => ApplicationTheme.Dark, + ElementTheme.Light => ApplicationTheme.Light, + ElementTheme.Default or _ => Current.RequestedTheme + }; } /// diff --git a/src/LipUI/Language/en-US/Resources.resw b/src/LipUI/Language/en-US/Resources.resw new file mode 100644 index 0000000..8d51dc1 --- /dev/null +++ b/src/LipUI/Language/en-US/Resources.resw @@ -0,0 +1,231 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Search + + + Agree + + + Disagree + + + No description + + + No server selected + + + Error + + + Information + + + Warning + + + Unknown Lip path! + + + Cancel + + + Install + + + Installation completed! + + + Install Lip + + + LipUI + + + Uninstall + + + Update + + + Allowlist + + + Modules + + + Server properties + + + Home + + + Local packages + + + Lip index + + + Pack Tooth package + + + Unknown server path! + + + Save successful! + + + Saving… + + + README.md not found + + + Select server + + + Cancel + + + Confirm + + + Description + + + Name + + + Version + + + Working directory + + + Server path already exists! + + + Start server + + + Install + + \ No newline at end of file diff --git a/src/LipUI/LipUI.csproj b/src/LipUI/LipUI.csproj index 0628e1e..2178fd7 100644 --- a/src/LipUI/LipUI.csproj +++ b/src/LipUI/LipUI.csproj @@ -9,8 +9,8 @@ 10.0.17763.0 LipUI app.manifest - x86;x64;ARM64 - win10-x86;win10-x64;win10-arm64 + x64 + win10-x64 win10-$(Platform).pubxml true true @@ -25,7 +25,7 @@ True Never 0 - zh-CN + en-US @@ -35,26 +35,24 @@ - - - - - - - - - - + + + + + + + + + + - - - - - - - - - + + + + + + + @@ -72,6 +70,7 @@ + @@ -109,61 +108,49 @@ - - MSBuild:Compile + + MSBuild:Compile + Designer - - - - MSBuild:Compile + + MSBuild:Compile - - - + MSBuild:Compile - + MSBuild:Compile - - $(DefaultXamlRuntime) - Designer - - + MSBuild:Compile - + MSBuild:Compile - + MSBuild:Compile - + MSBuild:Compile - + MSBuild:Compile - - MSBuild:Compile - - - - + MSBuild:Compile @@ -173,39 +160,41 @@ - + MSBuild:Compile - + MSBuild:Compile - + MSBuild:Compile - + MSBuild:Compile - + MSBuild:Compile - + MSBuild:Compile - - MSBuild:Compile - + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + diff --git a/src/LipUI/MainWindow.xaml.cs b/src/LipUI/MainWindow.xaml.cs index dd2afb3..1c80e11 100644 --- a/src/LipUI/MainWindow.xaml.cs +++ b/src/LipUI/MainWindow.xaml.cs @@ -1,15 +1,17 @@ using LipUI.Models; -using LipUI.Pages; -using Microsoft.UI.Composition; -using Microsoft.UI.Composition.SystemBackdrops; +using LipUI.Pages.Home; +using LipUI.Pages.Index; +using LipUI.Pages.LocalPackage; +using LipUI.Pages.Settings; +using LipUI.Pages.ToothPack; using Microsoft.UI.Dispatching; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; -using Microsoft.UI.Xaml.Media; using Microsoft.UI.Xaml.Media.Animation; using Microsoft.UI.Xaml.Navigation; using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Runtime.InteropServices; using System.Threading; @@ -23,20 +25,11 @@ namespace LipUI; -internal static class NavigationViewHelper -{ - public static DependencyObject GetChild(this DependencyObject obj, int index) - => VisualTreeHelper.GetChild(obj, index); -} - /// /// An empty window that can be used on its own or navigated to within a Frame. /// -public sealed partial class MainWindow : Window +internal sealed partial class MainWindow : Window { - WindowsSystemDispatcherQueueHelper? m_wsdqHelper; // See below for implementation. - DesktopAcrylicController? m_backdropController; - SystemBackdropConfiguration? m_configurationSource; private readonly int MinWidth = 800; private readonly int MinHeight = 450; @@ -45,18 +38,16 @@ public MainWindow() { InitializeComponent(); - SubClassing(); - - TrySetSystemBackdrop(); - ExtendsContentIntoTitleBar = true; SetTitleBar(AppTitleBar); + SubClassing(); + //TrySetSystemBackdrop(); AppWindow.Resize(new(1600, 900)); - Closed += MainWindow_Closed; - Services.MainWindow = this; + + PersonalizationSettingsView.Initialize(); } private async void MainWindow_Closed(object sender, WindowEventArgs args) @@ -80,7 +71,7 @@ private void SubClassing() newWndProc = new(NewWindowProc); // Here we use the NativeMethods class 👇 - oldWndProc = NativeMethods.SetWindowLong(hwnd, PInvoke.User32.WindowLongIndexFlags.GWL_WNDPROC, newWndProc); + oldWndProc = NativeMethods.SetWindowLong(hwnd, WindowLongIndexFlags.GWL_WNDPROC, newWndProc); if (oldWndProc == nint.Zero) { int error = Marshal.GetLastWin32Error(); @@ -144,82 +135,13 @@ internal interface IWindowNative } } - bool TrySetSystemBackdrop() - { - if (DesktopAcrylicController.IsSupported()) - { - m_wsdqHelper = new WindowsSystemDispatcherQueueHelper(); - m_wsdqHelper.EnsureWindowsSystemDispatcherQueueController(); - - // Create the policy object. - m_configurationSource = new SystemBackdropConfiguration(); - //Activated += WindowActivated; - Closed += WindowClosed; - ((FrameworkElement)Content).ActualThemeChanged += WindowThemeChanged; - - // Initial configuration state. - m_configurationSource.IsInputActive = true; - SetConfigurationSourceTheme(); - - m_backdropController = new DesktopAcrylicController() - { - TintOpacity = 0.2f, - LuminosityOpacity = 0.2f - }; - - // Enable the system backdrop. - // Note: Be sure to have "using WinRT;" to support the Window.As<...>() call. - m_backdropController.AddSystemBackdropTarget(this.As()); - m_backdropController.SetSystemBackdropConfiguration(m_configurationSource); - return true; // succeeded - } - - return false; // Mica is not supported on this system - } - - private void WindowActivated(object sender, WindowActivatedEventArgs args) - { - //m_configurationSource!.IsInputActive = args.WindowActivationState != WindowActivationState.Deactivated; - } - - private void WindowClosed(object sender, WindowEventArgs args) - { - // Make sure any Mica/Acrylic controller is disposed - // so it doesn't try to use this closed window. - if (m_backdropController != null) - { - m_backdropController.Dispose(); - m_backdropController = null; - } - //Activated -= WindowActivated; - m_configurationSource = null; - } - - private void WindowThemeChanged(FrameworkElement sender, object args) - { - if (m_configurationSource != null) - { - SetConfigurationSourceTheme(); - } - } - - private void SetConfigurationSourceTheme() - { - switch (((FrameworkElement)this.Content).ActualTheme) - { - case ElementTheme.Dark: m_configurationSource!.Theme = SystemBackdropTheme.Dark; break; - case ElementTheme.Light: m_configurationSource!.Theme = SystemBackdropTheme.Light; break; - case ElementTheme.Default: m_configurationSource!.Theme = SystemBackdropTheme.Default; break; - } - } - private record NavigationPages(string HomePage, string IndexPage, string PackToothPage, string LocalPackagePage, string SettingsPage); private readonly NavigationPages NavigationPage = new( typeof(HomePage).FullName!, typeof(IndexPage).FullName!, - typeof(PackToothPage).FullName!, + typeof(ToothPackPage).FullName!, typeof(LocalPackagePage).FullName!, typeof(SettingsPage).FullName!); @@ -227,7 +149,7 @@ private record NavigationPages(string HomePage, string IndexPage, string PackToo { typeof(HomePage), typeof(IndexPage), - typeof(PackToothPage), + typeof(ToothPackPage), typeof(LocalPackagePage), typeof(SettingsPage) }; @@ -239,6 +161,34 @@ private void ContentFrame_NavigationFailed(object sender, NavigationFailedEventA throw new Exception("Failed to load Page " + e.SourcePageType.FullName); } + private void NavView_Loading(FrameworkElement sender, object args) + { + sender.Resources["NavigationViewContentBackground"] + = PersonalizationSettingsView.MyRes.ApplicationNavigationViewContentBackground; + sender.Resources["NavigationViewContentGridBorderBrush"] + = PersonalizationSettingsView.MyRes.ApplicationNavigationViewContentBorder; + + PersonalizationSettingsView.MyRes.PropertyChanged += (object? _sender, PropertyChangedEventArgs e) => + { + switch (e.PropertyName) + { + case nameof(GlobalResources.ApplicationNavigationViewContentBackground): + sender.Resources["NavigationViewContentBackground"] + = PersonalizationSettingsView.MyRes.ApplicationNavigationViewContentBackground; + break; + + case nameof(GlobalResources.ApplicationNavigationViewContentBorder): + sender.Resources["NavigationViewContentGridBorderBrush"] + = PersonalizationSettingsView.MyRes.ApplicationNavigationViewContentBorder; + break; + + case nameof(GlobalResources.ApplicationBackground): + RootBorder.Background = PersonalizationSettingsView.MyRes.ApplicationBackground; + break; + } + }; + } + private void NavView_Loaded(object sender, RoutedEventArgs e) { // You can also add items in code. @@ -413,38 +363,10 @@ void task(object? sender, object e) mre.Dispose(); }); } -} - -class WindowsSystemDispatcherQueueHelper -{ - [StructLayout(LayoutKind.Sequential)] - struct DispatcherQueueOptions - { - internal int dwSize; - internal int threadType; - internal int apartmentType; - } - [DllImport("CoreMessaging.dll")] - private static extern int CreateDispatcherQueueController([In] DispatcherQueueOptions options, [In, Out, MarshalAs(UnmanagedType.IUnknown)] ref object dispatcherQueueController); + //public SolidColorBrush NavViewContentBackground => MyNavigationViewContentBackgroundBrush; - object? m_dispatcherQueueController = null; - public void EnsureWindowsSystemDispatcherQueueController() - { - if (Windows.System.DispatcherQueue.GetForCurrentThread() != null) - { - // one already exists, so we'll just use it. - return; - } + //public SolidColorBrush NavViewContentGridBorder => MyNavigationViewContentGridBorderBrush; - if (m_dispatcherQueueController == null) - { - DispatcherQueueOptions options; - options.dwSize = Marshal.SizeOf(typeof(DispatcherQueueOptions)); - options.threadType = 2; // DQTYPE_THREAD_CURRENT - options.apartmentType = 2; // DQTAT_COM_STA - - CreateDispatcherQueueController(options, ref m_dispatcherQueueController!); - } - } + public Grid RootGrid => MainWondowRootGrid; } diff --git a/src/LipUI/Models/Config.cs b/src/LipUI/Models/Config.cs index ac6ccbd..a58e1d3 100644 --- a/src/LipUI/Models/Config.cs +++ b/src/LipUI/Models/Config.cs @@ -1,4 +1,9 @@ -using System.Collections.Generic; +using CommunityToolkit.WinUI.Helpers; +using LipUI.Pages.Settings; +using Microsoft.UI; +using Microsoft.UI.Xaml; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.IO; using System.Text.Json.Serialization; @@ -28,43 +33,97 @@ internal static class DefaultSettings internal class Config { - - [JsonPropertyName("settings")] - public Setting Settings { get; set; } - - [JsonPropertyName("servers")] - public List ServerInstances { get; set; } - - [JsonPropertyName("selected_server")] -#nullable enable - public ServerInstance? SelectedServer { get; set; } -#nullable disable - - public class Setting + public class GeneralSetting { [JsonPropertyName("lip_path")] - public string LipPath { get; set; } + public string LipPath { get; set; } = string.Empty; [JsonPropertyName("lip_index_api")] - public string LipIndexApiKey { get; set; } + public string LipIndexApiKey { get; set; } = string.Empty; [JsonPropertyName("github_api")] - public string GithubApiKey { get; set; } + public string GithubApiKey { get; set; } = string.Empty; } + public class PersonalizationSetting + { + + [JsonPropertyName("color_theme")] + public ElementTheme ColorTheme { get; set; } = ElementTheme.Default; + + [JsonPropertyName("backdrop_type")] + public PersonalizationSettingsView.BackdropControllerType BackdropType { get; set; } = PersonalizationSettingsView.BackdropControllerType.None; + + [JsonPropertyName("backdrop_luminosity")] + public double? BackdropLuminosity { get; set; } = 20; + + [JsonPropertyName("background_color")] + public string? BackgroundColor { get; set; } + + [JsonPropertyName("navigation_view_content_background_color")] + public string? NavigationViewContentBackgroundColor { get; set; } + + [JsonPropertyName("navigation_view_content_border_color")] + public string? NavigationViewContentBorderColor { get; set; } + + [JsonPropertyName("background_secondary_color")] + public string? BackgroundSecondaryColor { get; set; } + + [JsonPropertyName("enable_image_background")] + public bool EnableImageBackground { get; set; } + + [JsonPropertyName("background_image_path")] + public string? BackgroundImagePath { get; set; } + + [JsonPropertyName("reload_colors")] + public bool ResetColors { get; set; } + } + + + [JsonPropertyName("general_settings")] + public GeneralSetting GeneralSettings { get; set; } + + [JsonPropertyName("personalization_settings")] + public PersonalizationSetting PersonalizationSettings { get; set; } + + [JsonPropertyName("servers")] + public List ServerInstances { get; set; } + + [JsonPropertyName("selected_server")] + public ServerInstance? SelectedServer { get; set; } + public Config() { ServerInstances = new(); - ResetSettings(Main.WorkingDirectory); + ResetGeneralSettings(Main.WorkingDirectory); + ResetPersonalizationSettings(); } - public void ResetSettings(string workingDir) + [MemberNotNull(nameof(GeneralSettings))] + public void ResetGeneralSettings(string workingDir) { - Settings = new() + GeneralSettings = new() { LipPath = Path.Combine(workingDir, DefaultSettings.LipExecutableFileName), LipIndexApiKey = DefaultSettings.LipIndexApiKey, GithubApiKey = DefaultSettings.GitHubApiKey, }; } + + [MemberNotNull(nameof(PersonalizationSettings))] + public void ResetPersonalizationSettings() + { + PersonalizationSettings = new() + { + BackdropType = PersonalizationSettingsView.BackdropControllerType.None, + BackdropLuminosity = 0, + BackgroundColor = Colors.Transparent.ToHex(), + NavigationViewContentBackgroundColor = Colors.Transparent.ToHex(), + NavigationViewContentBorderColor = Colors.Transparent.ToHex(), + BackgroundSecondaryColor = Colors.Transparent.ToHex(), + EnableImageBackground = false, + BackgroundImagePath = null, + ResetColors = true + }; + } } diff --git a/src/LipUI/Models/GlobalResources.cs b/src/LipUI/Models/GlobalIcons.cs similarity index 91% rename from src/LipUI/Models/GlobalResources.cs rename to src/LipUI/Models/GlobalIcons.cs index c4329ad..3e10f5d 100644 --- a/src/LipUI/Models/GlobalResources.cs +++ b/src/LipUI/Models/GlobalIcons.cs @@ -4,7 +4,7 @@ namespace LipUI.Models; -internal static class GlobalResources +internal static class GlobalIcons { public static readonly BitmapImage GrassBlock = Services.CreateImageFromBytes(Images.grass_block); public static readonly BitmapImage Netherrack = Services.CreateImageFromBytes(Images.netherrack); diff --git a/src/LipUI/Models/ILipUIModules.cs b/src/LipUI/Models/ILipUIModules.cs index 85d2016..3322df0 100644 --- a/src/LipUI/Models/ILipUIModules.cs +++ b/src/LipUI/Models/ILipUIModules.cs @@ -1,12 +1,7 @@ -using LipUI.VIews; +using LipUI.Pages.Home.Modules; using Microsoft.UI.Xaml; -using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Media; using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace LipUI.Models; @@ -23,6 +18,10 @@ public interface ILipUIModulesNonGeneric public void OnIconInitialze(ModuleIcon icon) { } public void OnExit() { } + + public void OnEnable() { } + + public void OnDisable() { } } public interface ILipUIModules : ILipUIModulesNonGeneric diff --git a/src/LipUI/Models/Main.cs b/src/LipUI/Models/Main.cs index 2f1f4b2..51b58df 100644 --- a/src/LipUI/Models/Main.cs +++ b/src/LipUI/Models/Main.cs @@ -1,5 +1,5 @@ using LipUI.Models.Lip; -using LipUI.VIews; +using LipUI.Pages.LipExecutionPanel; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; using System; @@ -21,6 +21,8 @@ internal static class Main public static string WorkingDirectory { get; private set; } + public static bool ColorsFirstInitSign = false; + [MemberNotNull(nameof(Config), nameof(WorkingDirectory))] private static void Initialize() @@ -55,6 +57,7 @@ private static void InitializeConfig() else { Config = new Config(); + Config.PersonalizationSettings.ResetColors = true; } } @@ -71,26 +74,34 @@ private static void InitializeConfig() return new LipConsole(path!, server.WorkingDirectory); } + + private static readonly object _lock = new(); public static async ValueTask SaveConfigAsync() { - var path = Path.Combine(WorkingDirectory, DefaultSettings.ConfigFileName); - if (File.Exists(path)) File.Delete(path); + await Task.Run(() => + { + lock (_lock) + { + var path = Path.Combine(WorkingDirectory, DefaultSettings.ConfigFileName); + if (File.Exists(path)) File.Delete(path); - using var file = File.Create(path); - using var writer = new StreamWriter(file); + using var file = File.Create(path); + using var writer = new StreamWriter(file); - await writer.WriteAsync(JsonSerializer.Serialize(Config, new JsonSerializerOptions() - { - WriteIndented = true, - Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping - })); + writer.Write(JsonSerializer.Serialize(Config, new JsonSerializerOptions() + { + WriteIndented = true, + Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping + })); + } + }); } public static async ValueTask<(bool, string)> TryGetLipConsolePathAsync(XamlRoot xamlRoot) { - if (File.Exists(Config.Settings.LipPath)) - return (true, Config.Settings.LipPath); + if (File.Exists(Config.GeneralSettings.LipPath)) + return (true, Config.GeneralSettings.LipPath); else { var dialog = new ContentDialog() @@ -102,8 +113,8 @@ public static async ValueTask SaveConfigAsync() await dialog.ShowAsync(); - return File.Exists(Config.Settings.LipPath) ? - (true, Config.Settings.LipPath) : + return File.Exists(Config.GeneralSettings.LipPath) ? + (true, Config.GeneralSettings.LipPath) : (false, string.Empty); } } diff --git a/src/LipUI/Models/ServerIcon.cs b/src/LipUI/Models/ServerIcon.cs index c0b9fd3..d81d799 100644 --- a/src/LipUI/Models/ServerIcon.cs +++ b/src/LipUI/Models/ServerIcon.cs @@ -26,9 +26,9 @@ public static async ValueTask GetIcon(string? version, string? icon switch (type) { - case IconType.Empty: return GlobalResources.Glass; - case IconType.Preview: return GlobalResources.Netherrack; - case IconType.Default: return GlobalResources.GrassBlock; + case IconType.Empty: return GlobalIcons.Glass; + case IconType.Preview: return GlobalIcons.Netherrack; + case IconType.Default: return GlobalIcons.GrassBlock; case IconType.Custom: { if (File.Exists(iconPath)) diff --git a/src/LipUI/Package.appxmanifest b/src/LipUI/Package.appxmanifest index 5e90c80..5005f52 100644 --- a/src/LipUI/Package.appxmanifest +++ b/src/LipUI/Package.appxmanifest @@ -26,7 +26,8 @@ - + + diff --git a/src/LipUI/Pages/HomePage.xaml b/src/LipUI/Pages/Home/HomePage.xaml similarity index 96% rename from src/LipUI/Pages/HomePage.xaml rename to src/LipUI/Pages/Home/HomePage.xaml index 3764df1..e1b0c4c 100644 --- a/src/LipUI/Pages/HomePage.xaml +++ b/src/LipUI/Pages/Home/HomePage.xaml @@ -1,10 +1,11 @@ + Background="{x:Bind settings:PersonalizationSettingsView.MyRes.ApplicationBackgroundSecondary}"> - + diff --git a/src/LipUI/Pages/HomePage.xaml.cs b/src/LipUI/Pages/Home/HomePage.xaml.cs similarity index 93% rename from src/LipUI/Pages/HomePage.xaml.cs rename to src/LipUI/Pages/Home/HomePage.xaml.cs index 6d6287a..f98a67f 100644 --- a/src/LipUI/Pages/HomePage.xaml.cs +++ b/src/LipUI/Pages/Home/HomePage.xaml.cs @@ -1,6 +1,6 @@ using LipUI.Models; -using LipUI.Pages.HomePageModules; -using LipUI.VIews; +using LipUI.Pages.Home.Modules; +using LipUI.Pages.ServerSelection; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Input; @@ -8,13 +8,11 @@ using System; using System.Diagnostics; using System.IO; -using System.Threading.Tasks; -using Windows.ApplicationModel.Resources; // To learn more about WinUI, the WinUI project structure, // and more about our project templates, see: http://aka.ms/winui-project-info. -namespace LipUI.Pages; +namespace LipUI.Pages.Home; /// /// An empty page that can be used on its own or navigated to within a Frame. @@ -33,11 +31,11 @@ private async void RefreshIcon() { ServerInstance? instance = Main.Config.SelectedServer; ServerIconImage.Source = await ServerIcon.GetIcon(instance); - ServerDesc.Text = + ServerDesc.Text = instance is null ? "home$nullServerPath".GetLocalized() : string.IsNullOrWhiteSpace(instance.Description) ? - "home$emptyDesc".GetLocalized() : + "home$emptyDesc".GetLocalized() : instance.Description; } diff --git a/src/LipUI/Pages/HomePageModules/AllowListViewerPage.xaml b/src/LipUI/Pages/Home/Modules/AllowListViewerPage.xaml similarity index 76% rename from src/LipUI/Pages/HomePageModules/AllowListViewerPage.xaml rename to src/LipUI/Pages/Home/Modules/AllowListViewerPage.xaml index cd524f1..846fc89 100644 --- a/src/LipUI/Pages/HomePageModules/AllowListViewerPage.xaml +++ b/src/LipUI/Pages/Home/Modules/AllowListViewerPage.xaml @@ -1,9 +1,9 @@ diff --git a/src/LipUI/Pages/HomePageModules/AllowListViewerPage.xaml.cs b/src/LipUI/Pages/Home/Modules/AllowListViewerPage.xaml.cs similarity index 74% rename from src/LipUI/Pages/HomePageModules/AllowListViewerPage.xaml.cs rename to src/LipUI/Pages/Home/Modules/AllowListViewerPage.xaml.cs index 2ba6d98..3ce4924 100644 --- a/src/LipUI/Pages/HomePageModules/AllowListViewerPage.xaml.cs +++ b/src/LipUI/Pages/Home/Modules/AllowListViewerPage.xaml.cs @@ -2,23 +2,13 @@ using Microsoft.UI; 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 System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Runtime.InteropServices.WindowsRuntime; -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 LipUI.Pages.HomePageModules; +namespace LipUI.Pages.Home.Modules; [LipUIModule] internal class AllowListViewerPage_Module : ILipUIModules diff --git a/src/LipUI/Pages/HomePageModules/BdsPropertiesEditorPage.xaml b/src/LipUI/Pages/Home/Modules/BdsPropertiesEditorPage.xaml similarity index 92% rename from src/LipUI/Pages/HomePageModules/BdsPropertiesEditorPage.xaml rename to src/LipUI/Pages/Home/Modules/BdsPropertiesEditorPage.xaml index 57506ec..be1135f 100644 --- a/src/LipUI/Pages/HomePageModules/BdsPropertiesEditorPage.xaml +++ b/src/LipUI/Pages/Home/Modules/BdsPropertiesEditorPage.xaml @@ -1,6 +1,6 @@ - @@ -28,7 +28,7 @@ - + @@ -63,7 +62,7 @@ private async void Page_Loaded(object sender, RoutedEventArgs e) if (Server is null) { await Task.Delay(500); - await ShowInfoBarAsync("propertiesEditor$nullServerPath".GetLocalized(), null, InfoBarSeverity.Error); + await ShowInfoBarAsync("propertiesEditor$nullServerPath".GetLocalized(), severity: InfoBarSeverity.Error); Frame.TryGoBack(); return; }; @@ -78,10 +77,8 @@ private async ValueTask SaveAsync() { await ShowInfoBarAsync( "propertiesEditor$saving".GetLocalized(), - null, - InfoBarSeverity.Informational, - default, - new ProgressBar() + severity: InfoBarSeverity.Informational, + barContent: new ProgressBar() { IsIndeterminate = true }); @@ -106,7 +103,7 @@ await ShowInfoBarAsync( } await Task.Delay(500); - await ShowInfoBarAsync("propertiesEditor$saveCompleted".GetLocalized(), null, InfoBarSeverity.Success); + await ShowInfoBarAsync("propertiesEditor$saveCompleted".GetLocalized(), severity: InfoBarSeverity.Success); } catch (Exception ex) { @@ -125,7 +122,7 @@ private async void LoadPropertiesAndCreateUI() } catch (Exception ex) { - await ShowInfoBarAsync(ex, default, null); + await ShowInfoBarAsync(ex); Frame.TryGoBack(); return; } diff --git a/src/LipUI/VIews/ModuleIcon.xaml b/src/LipUI/Pages/Home/Modules/ModuleIcon.xaml similarity index 91% rename from src/LipUI/VIews/ModuleIcon.xaml rename to src/LipUI/Pages/Home/Modules/ModuleIcon.xaml index 59eb753..219fe66 100644 --- a/src/LipUI/VIews/ModuleIcon.xaml +++ b/src/LipUI/Pages/Home/Modules/ModuleIcon.xaml @@ -1,9 +1,9 @@ Modules { get; private set; } = new(); + internal static Dictionary Modules { get; private set; } = new(); public Type? PageType { get; private set; } diff --git a/src/LipUI/Pages/HomePageModules/ModulesPage.xaml b/src/LipUI/Pages/Home/Modules/ModulesPage.xaml similarity index 92% rename from src/LipUI/Pages/HomePageModules/ModulesPage.xaml rename to src/LipUI/Pages/Home/Modules/ModulesPage.xaml index 61e83fa..e7f84b8 100644 --- a/src/LipUI/Pages/HomePageModules/ModulesPage.xaml +++ b/src/LipUI/Pages/Home/Modules/ModulesPage.xaml @@ -1,6 +1,6 @@ { diff --git a/src/LipUI/Pages/IndexPage.xaml b/src/LipUI/Pages/Index/IndexPage.xaml similarity index 93% rename from src/LipUI/Pages/IndexPage.xaml rename to src/LipUI/Pages/Index/IndexPage.xaml index 97df746..fb0ac66 100644 --- a/src/LipUI/Pages/IndexPage.xaml +++ b/src/LipUI/Pages/Index/IndexPage.xaml @@ -1,9 +1,9 @@ - + x:Name="TeethScrollView"> - + /// An empty page that can be used on its own or navigated to within a Frame. @@ -33,12 +31,12 @@ private void ReloadLipIndex(IEnumerable? items = null) { DispatcherQueue.TryEnqueue(async () => { - TeethScrollViewer.Content = new ProgressRing(); + TeethScrollView.Content = new ProgressRing(); ToothListView.Items.Clear(); if (items is null) { - lipIndex = await RequestLipIndexAsync(Main.Config.Settings.LipIndexApiKey); + lipIndex = await RequestLipIndexAsync(Main.Config.GeneralSettings.LipIndexApiKey); items = lipIndex.Data.Items; } @@ -47,7 +45,7 @@ private void ReloadLipIndex(IEnumerable? items = null) { ToothListView.Items.Add(new LipIndexToothView(item, handler)); } - TeethScrollViewer.Content = ToothListView; + TeethScrollView.Content = ToothListView; }); } diff --git a/src/LipUI/VIews/LipIndexToothView.xaml b/src/LipUI/Pages/Index/LipIndexToothView.xaml similarity index 95% rename from src/LipUI/VIews/LipIndexToothView.xaml rename to src/LipUI/Pages/Index/LipIndexToothView.xaml index a90d5ed..a7c1d8a 100644 --- a/src/LipUI/VIews/LipIndexToothView.xaml +++ b/src/LipUI/Pages/Index/LipIndexToothView.xaml @@ -1,9 +1,9 @@ diff --git a/src/LipUI/VIews/LipIndexToothView.xaml.cs b/src/LipUI/Pages/Index/LipIndexToothView.xaml.cs similarity index 95% rename from src/LipUI/VIews/LipIndexToothView.xaml.cs rename to src/LipUI/Pages/Index/LipIndexToothView.xaml.cs index d71865b..8c0533d 100644 --- a/src/LipUI/VIews/LipIndexToothView.xaml.cs +++ b/src/LipUI/Pages/Index/LipIndexToothView.xaml.cs @@ -1,4 +1,3 @@ -using LipUI.Protocol; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; using System; @@ -7,7 +6,7 @@ // To learn more about WinUI, the WinUI project structure, // and more about our project templates, see: http://aka.ms/winui-project-info. -namespace LipUI.VIews; +namespace LipUI.Pages.Index; public sealed partial class LipIndexToothView : UserControl { diff --git a/src/LipUI/VIews/EulaAcceptView.xaml b/src/LipUI/Pages/LipExecutionPanel/EulaAcceptView.xaml similarity index 100% rename from src/LipUI/VIews/EulaAcceptView.xaml rename to src/LipUI/Pages/LipExecutionPanel/EulaAcceptView.xaml diff --git a/src/LipUI/VIews/EulaAcceptView.xaml.cs b/src/LipUI/Pages/LipExecutionPanel/EulaAcceptView.xaml.cs similarity index 100% rename from src/LipUI/VIews/EulaAcceptView.xaml.cs rename to src/LipUI/Pages/LipExecutionPanel/EulaAcceptView.xaml.cs diff --git a/src/LipUI/Pages/LipExecutionPanelPage.xaml b/src/LipUI/Pages/LipExecutionPanel/LipExecutionPanelPage.xaml similarity index 97% rename from src/LipUI/Pages/LipExecutionPanelPage.xaml rename to src/LipUI/Pages/LipExecutionPanel/LipExecutionPanelPage.xaml index 79eb952..33c9de2 100644 --- a/src/LipUI/Pages/LipExecutionPanelPage.xaml +++ b/src/LipUI/Pages/LipExecutionPanel/LipExecutionPanelPage.xaml @@ -1,9 +1,9 @@ /// An empty page that can be used on its own or navigated to within a Frame. diff --git a/src/LipUI/VIews/LipInstallerView.xaml b/src/LipUI/Pages/LipExecutionPanel/LipInstallerView.xaml similarity index 93% rename from src/LipUI/VIews/LipInstallerView.xaml rename to src/LipUI/Pages/LipExecutionPanel/LipInstallerView.xaml index c80638b..55ee636 100644 --- a/src/LipUI/VIews/LipInstallerView.xaml +++ b/src/LipUI/Pages/LipExecutionPanel/LipInstallerView.xaml @@ -1,9 +1,9 @@ DownloadLipPortable(InstallerInfo info) { response = await client.GetAsync(info.AssetUrl, HttpCompletionOption.ResponseHeadersRead); } - catch + catch (Exception ex) { + await Services.ShowInfoBarAsync(ex, severity: InfoBarSeverity.Warning); response = await client.GetAsync($"https://github.moeyy.xyz/{info.AssetUrl}"); } @@ -184,6 +185,6 @@ private static void UnzipAndCopyLipEXE(byte[] bytes) using var stream = new MemoryStream(bytes); using var zip = new ZipArchive(stream, ZipArchiveMode.Read); ZipArchiveEntry entry = zip.Entries.First(x => Path.GetFileName(x.Name) == "lip.exe"); - entry.ExtractToFile(Main.Config.Settings.LipPath, true); + entry.ExtractToFile(Main.Config.GeneralSettings.LipPath, true); } } diff --git a/src/LipUI/Pages/LocalPackagePage.xaml b/src/LipUI/Pages/LocalPackage/LocalPackagePage.xaml similarity index 92% rename from src/LipUI/Pages/LocalPackagePage.xaml rename to src/LipUI/Pages/LocalPackage/LocalPackagePage.xaml index acc29cc..1e1b284 100644 --- a/src/LipUI/Pages/LocalPackagePage.xaml +++ b/src/LipUI/Pages/LocalPackage/LocalPackagePage.xaml @@ -1,9 +1,9 @@ - + x:Name="TeethScrollView"> - + /// An empty page that can be used on its own or navigated to within a Frame. @@ -32,14 +31,14 @@ private void ReloadPackage(IEnumerable? items = null) { DispatcherQueue.TryEnqueue(async () => { - TeethScrollViewer.Content = new ProgressRing(); + TeethScrollView.Content = new ProgressRing(); ToothListView.Items.Clear(); var lip = await Main.CreateLipConsole(XamlRoot); if (lip is null) { - ((ProgressRing)TeethScrollViewer.Content).IsActive = false; + ((ProgressRing)TeethScrollView.Content).IsActive = false; return; } @@ -70,7 +69,7 @@ private void ReloadPackage(IEnumerable? items = null) } RefreshUpgradableTeeth(); } - TeethScrollViewer.Content = ToothListView; + TeethScrollView.Content = ToothListView; }); } diff --git a/src/LipUI/VIews/LocalToothView.xaml b/src/LipUI/Pages/LocalPackage/LocalToothView.xaml similarity index 96% rename from src/LipUI/VIews/LocalToothView.xaml rename to src/LipUI/Pages/LocalPackage/LocalToothView.xaml index 0c86b16..79a7725 100644 --- a/src/LipUI/VIews/LocalToothView.xaml +++ b/src/LipUI/Pages/LocalPackage/LocalToothView.xaml @@ -1,9 +1,9 @@ diff --git a/src/LipUI/VIews/LocalToothView.xaml.cs b/src/LipUI/Pages/LocalPackage/LocalToothView.xaml.cs similarity index 95% rename from src/LipUI/VIews/LocalToothView.xaml.cs rename to src/LipUI/Pages/LocalPackage/LocalToothView.xaml.cs index d685959..ca11809 100644 --- a/src/LipUI/VIews/LocalToothView.xaml.cs +++ b/src/LipUI/Pages/LocalPackage/LocalToothView.xaml.cs @@ -1,4 +1,4 @@ -using LipUI.Pages; +using LipUI.Pages.LipExecutionPanel; using LipUI.Protocol; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; @@ -6,7 +6,7 @@ // To learn more about WinUI, the WinUI project structure, // and more about our project templates, see: http://aka.ms/winui-project-info. -namespace LipUI.VIews; +namespace LipUI.Pages.LocalPackage; internal sealed partial class LocalToothView : UserControl { diff --git a/src/LipUI/Pages/PackToothPage.xaml.cs b/src/LipUI/Pages/PackToothPage.xaml.cs deleted file mode 100644 index db588d4..0000000 --- a/src/LipUI/Pages/PackToothPage.xaml.cs +++ /dev/null @@ -1,17 +0,0 @@ -using Microsoft.UI.Xaml.Controls; - -// To learn more about WinUI, the WinUI project structure, -// and more about our project templates, see: http://aka.ms/winui-project-info. - -namespace LipUI.Pages; - -/// -/// An empty page that can be used on its own or navigated to within a Frame. -/// -public sealed partial class PackToothPage : Page -{ - public PackToothPage() - { - this.InitializeComponent(); - } -} diff --git a/src/LipUI/VIews/ServerInstanceEditView.xaml b/src/LipUI/Pages/ServerSelection/ServerInstanceEditView.xaml similarity index 93% rename from src/LipUI/VIews/ServerInstanceEditView.xaml rename to src/LipUI/Pages/ServerSelection/ServerInstanceEditView.xaml index e7d20ef..257a9f0 100644 --- a/src/LipUI/VIews/ServerInstanceEditView.xaml +++ b/src/LipUI/Pages/ServerSelection/ServerInstanceEditView.xaml @@ -1,9 +1,9 @@ diff --git a/src/LipUI/Pages/ServerSelection/ServerInstanceView.xaml.cs b/src/LipUI/Pages/ServerSelection/ServerInstanceView.xaml.cs new file mode 100644 index 0000000..058216b --- /dev/null +++ b/src/LipUI/Pages/ServerSelection/ServerInstanceView.xaml.cs @@ -0,0 +1,39 @@ +using LipUI.Models; +using Microsoft.UI.Xaml.Controls; +using Microsoft.UI.Xaml.Media; +using Microsoft.UI.Xaml.Media.Animation; +using System; + +// To learn more about WinUI, the WinUI project structure, +// and more about our project templates, see: http://aka.ms/winui-project-info. + +namespace LipUI.Pages.ServerSelection; + +internal sealed partial class ServerInstanceView : UserControl +{ + public ServerInstance ServerInstance { get; private set; } + + public void SetIconImageSource(ImageSource source) + => Image.Source = source; + + public ServerInstanceView(ServerInstance instance) + { + InitializeComponent(); + ServerInstance = instance; + + RefreshUI(); + + DispatcherQueue.TryEnqueue(async () => + { + Image.Source = await ServerIcon.GetIcon(instance); + }); + } + + public void RefreshUI() + { + Text.Text = $"{ServerInstance.Name}{Environment.NewLine}{ServerInstance.Description}{Environment.NewLine}{ServerInstance.Version}"; + } + + public Storyboard SelectStoryboard => _selectStoryboard; + public Storyboard UnselectStoryboard => _unselectStoryboard; +} diff --git a/src/LipUI/Pages/ServerSelectionPage.xaml b/src/LipUI/Pages/ServerSelection/ServerSelectionPage.xaml similarity index 84% rename from src/LipUI/Pages/ServerSelectionPage.xaml rename to src/LipUI/Pages/ServerSelection/ServerSelectionPage.xaml index fad8064..687a13a 100644 --- a/src/LipUI/Pages/ServerSelectionPage.xaml +++ b/src/LipUI/Pages/ServerSelection/ServerSelectionPage.xaml @@ -1,9 +1,9 @@ @@ -12,12 +12,12 @@ - - - - - - + + + + + + @@ -31,11 +31,11 @@ - + x:Name="ServerScrollView" + Loaded="ServerScrollView_Loaded"> - + /// An empty page that can be used on its own or navigated to within a Frame. @@ -76,7 +75,7 @@ private void InitButtons() } - private void ServerScrollViewer_Loaded(object sender, RoutedEventArgs e) + private void ServerScrollView_Loaded(object sender, RoutedEventArgs e) { var progressRing = new ProgressRing() { @@ -85,7 +84,7 @@ private void ServerScrollViewer_Loaded(object sender, RoutedEventArgs e) Maximum = Main.Config.ServerInstances.Count, IsActive = true }; - ServerScrollViewer.Content = progressRing; + ServerScrollView.Content = progressRing; DispatcherQueue.TryEnqueue(async () => { @@ -97,7 +96,7 @@ private void ServerScrollViewer_Loaded(object sender, RoutedEventArgs e) progressRing.Value = i; } - ServerScrollViewer.Content = ServerGridView; + ServerScrollView.Content = ServerGridView; }); } diff --git a/src/LipUI/Pages/Settings/GeneralSettingsView.xaml b/src/LipUI/Pages/Settings/GeneralSettingsView.xaml new file mode 100644 index 0000000..20908e4 --- /dev/null +++ b/src/LipUI/Pages/Settings/GeneralSettingsView.xaml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/LipUI/Pages/Settings/GeneralSettingsView.xaml.cs b/src/LipUI/Pages/Settings/GeneralSettingsView.xaml.cs new file mode 100644 index 0000000..0941fc0 --- /dev/null +++ b/src/LipUI/Pages/Settings/GeneralSettingsView.xaml.cs @@ -0,0 +1,14 @@ +using Microsoft.UI.Xaml.Controls; + +// To learn more about WinUI, the WinUI project structure, +// and more about our project templates, see: http://aka.ms/winui-project-info. + +namespace LipUI.Pages.Settings; + +internal sealed partial class GeneralSettingsView : UserControl +{ + public GeneralSettingsView() + { + InitializeComponent(); + } +} diff --git a/src/LipUI/Pages/Settings/PersonalizationSettingsView.xaml b/src/LipUI/Pages/Settings/PersonalizationSettingsView.xaml new file mode 100644 index 0000000..38f39e9 --- /dev/null +++ b/src/LipUI/Pages/Settings/PersonalizationSettingsView.xaml @@ -0,0 +1,288 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - diff --git a/src/LipUI/VIews/ToothVersionView.xaml.cs b/src/LipUI/VIews/ToothVersionView.xaml.cs deleted file mode 100644 index e070ef1..0000000 --- a/src/LipUI/VIews/ToothVersionView.xaml.cs +++ /dev/null @@ -1,23 +0,0 @@ -using LipUI.Protocol; -using Microsoft.UI.Xaml.Controls; -using System; - -// To learn more about WinUI, the WinUI project structure, -// and more about our project templates, see: http://aka.ms/winui-project-info. - -namespace LipUI.VIews; - -public sealed partial class ToothVersionView : UserControl -{ - public ToothVersionView(in LipTooth.LipToothData.LipToothVersion version) - { - this.InitializeComponent(); - - Version.Text = version.Version; - ReleaseTime.Text - = DateTimeOffset - .FromUnixTimeSeconds(version.ReleaseTime) - .LocalDateTime - .ToString(); - } -}