diff --git a/.idea/.idea.Nebula/.idea/avalonia.xml b/.idea/.idea.Nebula/.idea/avalonia.xml index 206214a..e750fea 100644 --- a/.idea/.idea.Nebula/.idea/avalonia.xml +++ b/.idea/.idea.Nebula/.idea/avalonia.xml @@ -23,6 +23,7 @@ + diff --git a/Nebula.Launcher/App.axaml.cs b/Nebula.Launcher/App.axaml.cs index 286a19d..ef122a8 100644 --- a/Nebula.Launcher/App.axaml.cs +++ b/Nebula.Launcher/App.axaml.cs @@ -1,6 +1,7 @@ using System; using System.Linq; using Avalonia; +using Avalonia.Controls; using Avalonia.Controls.ApplicationLifetimes; using Avalonia.Data.Core.Plugins; using Avalonia.Markup.Xaml; @@ -12,8 +13,6 @@ namespace Nebula.Launcher; public class App : Application { - private IServiceProvider _serviceProvider = null!; - public override void Initialize() { AvaloniaXamlLoader.Load(this); @@ -21,23 +20,40 @@ public class App : Application public override void OnFrameworkInitializationCompleted() { - var services = new ServiceCollection(); - services.AddAvaloniaServices(); - services.AddServices(); - services.AddViews(); - - _serviceProvider = services.BuildServiceProvider(); - - switch (ApplicationLifetime) + if (Design.IsDesignMode) { - case IClassicDesktopStyleApplicationLifetime desktop: - DisableAvaloniaDataAnnotationValidation(); - desktop.MainWindow = _serviceProvider.GetService(); - break; - case ISingleViewApplicationLifetime singleViewPlatform: - singleViewPlatform.MainView = _serviceProvider.GetRequiredService(); - break; + switch (ApplicationLifetime) + { + case IClassicDesktopStyleApplicationLifetime desktop: + DisableAvaloniaDataAnnotationValidation(); + desktop.MainWindow = new MainWindow(); + break; + case ISingleViewApplicationLifetime singleViewPlatform: + singleViewPlatform.MainView = new MainView(); + break; + } } + else + { + var services = new ServiceCollection(); + services.AddAvaloniaServices(); + services.AddServices(); + services.AddViews(); + + var serviceProvider = services.BuildServiceProvider(); + + switch (ApplicationLifetime) + { + case IClassicDesktopStyleApplicationLifetime desktop: + DisableAvaloniaDataAnnotationValidation(); + desktop.MainWindow = serviceProvider.GetService(); + break; + case ISingleViewApplicationLifetime singleViewPlatform: + singleViewPlatform.MainView = serviceProvider.GetRequiredService(); + break; + } + } + base.OnFrameworkInitializationCompleted(); } diff --git a/Nebula.Launcher/ViewModels/Pages/ServerListViewModel.cs b/Nebula.Launcher/ViewModels/Pages/ServerListViewModel.cs index 9a46f31..f4c4efa 100644 --- a/Nebula.Launcher/ViewModels/Pages/ServerListViewModel.cs +++ b/Nebula.Launcher/ViewModels/Pages/ServerListViewModel.cs @@ -28,6 +28,10 @@ public partial class ServerListViewModel : ViewModelBase { ServerInfos.Add(CreateServerView(new ServerHubInfo("ss14://localhost", new ServerStatus("Nebula", "TestCraft", ["16+", "RU"], "super", 12, 55, 1, false, DateTime.Now, 20), []))); + ServerInfos.Add(CreateServerView(new ServerHubInfo("ss14://localhost", + new ServerStatus("Nebula", "TestCraft", ["16+", "RU"], "super", 12, 55, 1, false, DateTime.Now, 20), []))); + ServerInfos.Add(CreateServerView(new ServerHubInfo("ss14://localhost", + new ServerStatus("Nebula", "TestCraft", ["16+", "RU"], "super", 12, 55, 1, false, DateTime.Now, 20), []))); } //real think diff --git a/Nebula.Launcher/ViewModels/ServerEntryModelView.cs b/Nebula.Launcher/ViewModels/ServerEntryModelView.cs index f82a416..0df9c3e 100644 --- a/Nebula.Launcher/ViewModels/ServerEntryModelView.cs +++ b/Nebula.Launcher/ViewModels/ServerEntryModelView.cs @@ -7,12 +7,13 @@ using System.Threading.Tasks; using Avalonia.Media; using Nebula.Launcher.Services; using Nebula.Launcher.ViewModels.Popup; +using Nebula.Launcher.Views; using Nebula.Shared.Models; using Nebula.Shared.Services; namespace Nebula.Launcher.ViewModels; -[ViewModelRegister(isSingleton: false)] +[ViewModelRegister(typeof(ServerEntryView), isSingleton: false)] [ConstructGenerator] public partial class ServerEntryModelView : ViewModelBase { @@ -44,7 +45,7 @@ public partial class ServerEntryModelView : ViewModelBase protected override void InitialiseInDesignMode() { - CurrLog = ViewHelperService.GetViewModel(); + } protected override void Initialise() diff --git a/Nebula.Launcher/Views/Pages/AccountInfoView.axaml.cs b/Nebula.Launcher/Views/Pages/AccountInfoView.axaml.cs index fdbfd2a..6696dd6 100644 --- a/Nebula.Launcher/Views/Pages/AccountInfoView.axaml.cs +++ b/Nebula.Launcher/Views/Pages/AccountInfoView.axaml.cs @@ -3,8 +3,6 @@ using AccountInfoViewModel = Nebula.Launcher.ViewModels.Pages.AccountInfoViewMod namespace Nebula.Launcher.Views.Pages; -public interface ITab; - public partial class AccountInfoView : UserControl { public AccountInfoView() diff --git a/Nebula.Launcher/Views/Pages/ServerListView.axaml b/Nebula.Launcher/Views/Pages/ServerListView.axaml index 6472d7a..9331142 100644 --- a/Nebula.Launcher/Views/Pages/ServerListView.axaml +++ b/Nebula.Launcher/Views/Pages/ServerListView.axaml @@ -5,10 +5,8 @@ x:Class="Nebula.Launcher.Views.Pages.ServerListView" x:DataType="pages:ServerListViewModel" xmlns="https://github.com/avaloniaui" - xmlns:asyncImageLoader="clr-namespace:AsyncImageLoader;assembly=AsyncImageLoader.Avalonia" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - xmlns:viewModels="clr-namespace:Nebula.Launcher.ViewModels" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:pages="clr-namespace:Nebula.Launcher.ViewModels.Pages"> @@ -25,144 +23,6 @@ Background="#00000000" ItemsSource="{Binding ServerInfos}" Padding="0"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Nebula.Launcher/Views/ServerEntryView.axaml b/Nebula.Launcher/Views/ServerEntryView.axaml new file mode 100644 index 0000000..0896003 --- /dev/null +++ b/Nebula.Launcher/Views/ServerEntryView.axaml @@ -0,0 +1,148 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Nebula.Launcher/Views/ServerEntryView.axaml.cs b/Nebula.Launcher/Views/ServerEntryView.axaml.cs new file mode 100644 index 0000000..f1bf5ca --- /dev/null +++ b/Nebula.Launcher/Views/ServerEntryView.axaml.cs @@ -0,0 +1,19 @@ +using Avalonia; +using Avalonia.Controls; +using Avalonia.Markup.Xaml; +using Nebula.Launcher.ViewModels; + +namespace Nebula.Launcher.Views; + +public partial class ServerEntryView : UserControl +{ + public ServerEntryView() + { + InitializeComponent(); + } + + public ServerEntryView(ServerEntryModelView modelView) : this() + { + DataContext = modelView; + } +} \ No newline at end of file diff --git a/Nebula.SourceGenerators/DependencyAutoGenerator.cs b/Nebula.SourceGenerators/DependencyAutoGenerator.cs index fbc7315..5a9e367 100644 --- a/Nebula.SourceGenerators/DependencyAutoGenerator.cs +++ b/Nebula.SourceGenerators/DependencyAutoGenerator.cs @@ -39,32 +39,28 @@ public class DependencyAutoGenerator : IIncrementalGenerator var namespaceName = classSymbol.ContainingNamespace.ToDisplayString(); var className = classDeclarationSyntax.Identifier.Text; - var defaultConstruct = $@"public {className}(){{}}"; + var defaultConstruct = $@"public {className}(){{ + InitialiseInDesignMode(); + }}"; var propertiesGenerated = GetProperties(classSymbol).ToList(); var constr = propertiesGenerated.Select(a => $"{a.Type.ToDisplayString()} g{a.Name}"); var body = propertiesGenerated.Select(a => $"this.{a.Name} = g{a.Name};"); - if (!constr.Any()) defaultConstruct = ""; + //if (!constr.Any()) defaultConstruct = ""; var code = $@"// - -using System; -using System.Collections.Generic; - namespace {namespaceName}; partial class {className} {{ - {defaultConstruct} public {className}( {string.Join(",\n\t\t", constr)} ) : base(){{ {string.Join("\n\t\t", body)} - if (Avalonia.Controls.Design.IsDesignMode) InitialiseInDesignMode(); - else Initialise(); + Initialise(); }} }} ";