- add: Service think
This commit is contained in:
@@ -36,8 +36,8 @@ public partial class MainViewModel : ViewModelBase
|
||||
|
||||
private readonly List<ListItemTemplate> _templates =
|
||||
[
|
||||
new ListItemTemplate(typeof(AccountInfoViewModel), "HomeRegular", "Account"),
|
||||
new ListItemTemplate(typeof(ServerListViewModel), "List", "Servers")
|
||||
new ListItemTemplate(typeof(AccountInfoViewModel), "Account", "Account"),
|
||||
new ListItemTemplate(typeof(ServerListViewModel), "HomeRegular", "Servers")
|
||||
];
|
||||
|
||||
[ObservableProperty]
|
||||
@@ -51,12 +51,10 @@ public partial class MainViewModel : ViewModelBase
|
||||
|
||||
partial void OnSelectedListItemChanged(ListItemTemplate? value)
|
||||
{
|
||||
Console.WriteLine("FUCKED " + value?.ModelType);
|
||||
if (value is null) return;
|
||||
|
||||
if(!TryGetViewModel(value.ModelType, out var vmb))
|
||||
{
|
||||
Console.WriteLine("FUCKCCC");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,13 +1,46 @@
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using Nebula.Launcher.Models;
|
||||
using Nebula.Launcher.Services;
|
||||
using Nebula.Launcher.ViewHelper;
|
||||
using Nebula.Launcher.Views.Pages;
|
||||
|
||||
namespace Nebula.Launcher.ViewModels;
|
||||
|
||||
[ViewRegister(typeof(ServerListView))]
|
||||
public class ServerListViewModel : ViewModelBase
|
||||
public partial class ServerListViewModel : ViewModelBase
|
||||
{
|
||||
public ServerListViewModel(IServiceProvider serviceProvider) : base(serviceProvider)
|
||||
public ObservableCollection<ServerInfo> ServerInfos { get; }
|
||||
|
||||
[ObservableProperty]
|
||||
private ServerInfo? _selectedListItem;
|
||||
|
||||
public ServerListViewModel()
|
||||
{
|
||||
ServerInfos = new ObservableCollection<ServerInfo>();
|
||||
}
|
||||
public ServerListViewModel(IServiceProvider serviceProvider, HubService hubService) : base(serviceProvider)
|
||||
{
|
||||
ServerInfos = new ObservableCollection<ServerInfo>();
|
||||
hubService.HubServerChangedEventArgs += HubServerChangedEventArgs;
|
||||
}
|
||||
|
||||
private void HubServerChangedEventArgs(HubServerChangedEventArgs obj)
|
||||
{
|
||||
if (obj.Action == HubServerChangeAction.Add)
|
||||
{
|
||||
foreach (var info in obj.Items)
|
||||
{
|
||||
ServerInfos.Add(info);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var info in obj.Items)
|
||||
{
|
||||
ServerInfos.Remove(info);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,8 +24,6 @@ public abstract class ViewModelBase : ObservableObject
|
||||
var vm = Design.IsDesignMode
|
||||
? Activator.CreateInstance(type)
|
||||
: _serviceProvider.GetService(type);
|
||||
|
||||
Console.WriteLine(vm?.ToString());
|
||||
|
||||
if (vm is not ViewModelBase vmb) return false;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user