From e9cc769bc929bb9494c1fff2a469ad27e0ef0ced Mon Sep 17 00:00:00 2001 From: Visne <39844191+Visne@users.noreply.github.com> Date: Wed, 13 Dec 2023 21:16:37 +0100 Subject: [PATCH] Upgrade to Avalonia 11 (#110) Co-authored-by: Pieter-Jan Briers --- Directory.Packages.props | 11 ++++++----- SS14.Launcher/App.xaml | 3 +-- SS14.Launcher/App.xaml.cs | 4 +--- SS14.Launcher/IconsLoader.cs | 4 +--- SS14.Launcher/SS14.Launcher.csproj | 5 +++-- SS14.Launcher/Theme/Theme.xaml | 10 +++++----- SS14.Launcher/Theme/ThemeDropDown.xaml | 3 +-- SS14.Launcher/Theme/ThemeTabControl.xaml | 4 +--- SS14.Launcher/Theme/ThemeTabItem.xaml | 2 +- SS14.Launcher/ViewLocator.cs | 7 +++++-- .../ViewModels/AccountDropDownViewModel.cs | 12 +++++++++--- SS14.Launcher/ViewModels/ConnectingViewModel.cs | 4 ++++ .../MainWindowTabs/ServerEntryViewModel.cs | 2 -- SS14.Launcher/Views/AccountDropDown.xaml | 2 +- SS14.Launcher/Views/AddFavoriteDialog.xaml.cs | 9 +-------- SS14.Launcher/Views/ConnectingOverlay.xaml | 6 +++++- SS14.Launcher/Views/ConnectingOverlay.xaml.cs | 4 +++- SS14.Launcher/Views/DropDown.cs | 12 ++++++------ SS14.Launcher/Views/HubSettingsDialog.xaml | 4 ++-- SS14.Launcher/Views/HubSettingsDialog.xaml.cs | 4 ---- .../Views/Login/AuthErrorsOverlayView.xaml | 4 ++-- .../Views/Login/AuthErrorsOverlayView.xaml.cs | 6 ++++-- .../Views/Login/ForgotPasswordView.xaml.cs | 4 +--- SS14.Launcher/Views/Login/LoginView.xaml.cs | 7 ++----- SS14.Launcher/Views/Login/RegisterView.xaml.cs | 10 ++++------ .../Views/Login/ResendConfirmationView.xaml.cs | 4 +--- SS14.Launcher/Views/MainWindow.xaml | 2 +- SS14.Launcher/Views/MainWindow.xaml.cs | 17 +++++------------ .../Views/MainWindowTabs/HomePageView.xaml | 2 +- .../Views/MainWindowTabs/NewsTabView.xaml | 2 +- .../Views/MainWindowTabs/OptionsTabView.xaml.cs | 3 +-- .../Views/MainWindowTabs/ServerEntryView.xaml | 5 ++--- .../MainWindowTabs/ServerListFiltersView.xaml | 10 +++++----- .../Views/MainWindowTabs/ServerListTabView.xaml | 2 +- 34 files changed, 87 insertions(+), 103 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index 6c64058b..c000ba42 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -7,13 +7,15 @@ + - - - - + + + + + @@ -24,7 +26,6 @@ - diff --git a/SS14.Launcher/App.xaml b/SS14.Launcher/App.xaml index 8b450210..03893c3c 100644 --- a/SS14.Launcher/App.xaml +++ b/SS14.Launcher/App.xaml @@ -7,8 +7,7 @@ - - + diff --git a/SS14.Launcher/App.xaml.cs b/SS14.Launcher/App.xaml.cs index 9f4e6557..b3fc5db7 100644 --- a/SS14.Launcher/App.xaml.cs +++ b/SS14.Launcher/App.xaml.cs @@ -48,11 +48,9 @@ public override void Initialize() private void LoadBaseAssets() { - var loader = AvaloniaLocator.Current.GetService()!; - foreach (var (name, (path, type)) in AssetDefs) { - using var dataStream = loader.Open(new Uri($"avares://SS14.Launcher/Assets/{path}")); + using var dataStream = AssetLoader.Open(new Uri($"avares://SS14.Launcher/Assets/{path}")); var asset = LoadAsset(type, dataStream); diff --git a/SS14.Launcher/IconsLoader.cs b/SS14.Launcher/IconsLoader.cs index fae39c0b..3dfeecb4 100644 --- a/SS14.Launcher/IconsLoader.cs +++ b/SS14.Launcher/IconsLoader.cs @@ -18,11 +18,9 @@ private static readonly (string path, string resource)[] Icons = public static void Load(App app) { - var loader = AvaloniaLocator.Current.GetService()!; - foreach (var (path, resource) in Icons) { - using var file = loader.Open(new Uri($"avares://SS14.Launcher/Assets/{path}")); + using var file = AssetLoader.Open(new Uri($"avares://SS14.Launcher/Assets/{path}")); var bitmap = new Bitmap(file); app.Resources.Add(resource, bitmap); } diff --git a/SS14.Launcher/SS14.Launcher.csproj b/SS14.Launcher/SS14.Launcher.csproj index 6e5578c7..a0d5f1c4 100644 --- a/SS14.Launcher/SS14.Launcher.csproj +++ b/SS14.Launcher/SS14.Launcher.csproj @@ -23,7 +23,7 @@ Designer - + ServerFilterView.xaml @@ -34,6 +34,7 @@ + @@ -45,13 +46,13 @@ - + diff --git a/SS14.Launcher/Theme/Theme.xaml b/SS14.Launcher/Theme/Theme.xaml index b54b612d..88479248 100644 --- a/SS14.Launcher/Theme/Theme.xaml +++ b/SS14.Launcher/Theme/Theme.xaml @@ -45,19 +45,19 @@ - - - - - diff --git a/SS14.Launcher/Theme/ThemeDropDown.xaml b/SS14.Launcher/Theme/ThemeDropDown.xaml index 551f3370..21e03301 100644 --- a/SS14.Launcher/Theme/ThemeDropDown.xaml +++ b/SS14.Launcher/Theme/ThemeDropDown.xaml @@ -26,8 +26,7 @@ MinWidth="{Binding Bounds.Width, RelativeSource={RelativeSource TemplatedParent}}" Name="PART_Popup" PlacementTarget="{TemplateBinding}" - IsOpen="{TemplateBinding IsDropDownOpen,Mode=TwoWay}" - StaysOpen="False"> + IsOpen="{TemplateBinding IsDropDownOpen,Mode=TwoWay}"> diff --git a/SS14.Launcher/Theme/ThemeTabControl.xaml b/SS14.Launcher/Theme/ThemeTabControl.xaml index 96bd01df..512f502f 100644 --- a/SS14.Launcher/Theme/ThemeTabControl.xaml +++ b/SS14.Launcher/Theme/ThemeTabControl.xaml @@ -21,9 +21,7 @@ Taken & modified from Avalonia's git repo. Background="{DynamicResource ThemeStripeBackBrush}"> + ItemsPanel="{TemplateBinding ItemsPanel}"/> - diff --git a/SS14.Launcher/ViewLocator.cs b/SS14.Launcher/ViewLocator.cs index 1406daa3..ec150e2d 100644 --- a/SS14.Launcher/ViewLocator.cs +++ b/SS14.Launcher/ViewLocator.cs @@ -12,8 +12,11 @@ public class ViewLocator : IDataTemplate { public bool SupportsRecycling => false; - public IControl Build(object data) + public Control? Build(object? data) { + if (data == null) + return null; + var name = data.GetType().FullName!.Replace("ViewModel", "View"); var type = Type.GetType(name); @@ -27,7 +30,7 @@ public IControl Build(object data) } } - public bool Match(object data) + public bool Match(object? data) { return data is IViewModelBase; } diff --git a/SS14.Launcher/ViewModels/AccountDropDownViewModel.cs b/SS14.Launcher/ViewModels/AccountDropDownViewModel.cs index 82897d5c..545d48bb 100644 --- a/SS14.Launcher/ViewModels/AccountDropDownViewModel.cs +++ b/SS14.Launcher/ViewModels/AccountDropDownViewModel.cs @@ -5,6 +5,7 @@ using JetBrains.Annotations; using ReactiveUI; using ReactiveUI.Fody.Helpers; +using Serilog; using Splat; using SS14.Launcher.Api; using SS14.Launcher.Models.Data; @@ -87,11 +88,16 @@ public async void LogoutPressed() } [UsedImplicitly] - public void AccountButtonPressed(LoggedInAccount account) + public void AccountButtonPressed(object account) { - IsDropDownOpen = false; + if (account is not LoggedInAccount loggedInAccount) + { + Log.Warning($"Tried to switch account but parameter was not of type {nameof(LoggedInAccount)}"); + return; + } - _mainVm.TrySwitchToAccount(account); + IsDropDownOpen = false; + _mainVm.TrySwitchToAccount(loggedInAccount); } public void AddAccountPressed() diff --git a/SS14.Launcher/ViewModels/ConnectingViewModel.cs b/SS14.Launcher/ViewModels/ConnectingViewModel.cs index f85f7619..1f1e9caf 100644 --- a/SS14.Launcher/ViewModels/ConnectingViewModel.cs +++ b/SS14.Launcher/ViewModels/ConnectingViewModel.cs @@ -28,6 +28,8 @@ public class ConnectingViewModel : ViewModelBase _connectorStatus == Connector.ConnectionStatus.ClientExited && _connector.ClientExitedBadly; + public static event Action? StartedConnecting; + public ConnectingViewModel(Connector connector, MainWindowViewModel windowVm, string? givenReason) { _updater = Locator.Current.GetRequiredService(); @@ -186,6 +188,7 @@ public static void StartConnect(MainWindowViewModel windowVm, string address, st var vm = new ConnectingViewModel(connector, windowVm, givenReason); windowVm.ConnectingVM = vm; vm.Start(address); + StartedConnecting?.Invoke(); } public static void StartContentBundle(MainWindowViewModel windowVm, string fileName) @@ -194,6 +197,7 @@ public static void StartContentBundle(MainWindowViewModel windowVm, string fileN var vm = new ConnectingViewModel(connector, windowVm, null); windowVm.ConnectingVM = vm; vm.StartContentBundle(fileName); + StartedConnecting?.Invoke(); } private void Start(string address) diff --git a/SS14.Launcher/ViewModels/MainWindowTabs/ServerEntryViewModel.cs b/SS14.Launcher/ViewModels/MainWindowTabs/ServerEntryViewModel.cs index f1a49c25..eb125512 100644 --- a/SS14.Launcher/ViewModels/MainWindowTabs/ServerEntryViewModel.cs +++ b/SS14.Launcher/ViewModels/MainWindowTabs/ServerEntryViewModel.cs @@ -1,6 +1,5 @@ using System; using System.ComponentModel; -using Avalonia.Input; using Microsoft.Toolkit.Mvvm.ComponentModel; using Microsoft.Toolkit.Mvvm.Messaging; using SS14.Launcher.Models.Data; @@ -50,7 +49,6 @@ public ServerEntryViewModel( public void ConnectPressed() { - FocusManager.Instance?.Focus(null); ConnectingViewModel.StartConnect(_windowVm, Address); } diff --git a/SS14.Launcher/Views/AccountDropDown.xaml b/SS14.Launcher/Views/AccountDropDown.xaml index 812e9fca..b08fd708 100644 --- a/SS14.Launcher/Views/AccountDropDown.xaml +++ b/SS14.Launcher/Views/AccountDropDown.xaml @@ -23,7 +23,7 @@ - +