- add: Content manipulation think

This commit is contained in:
2024-12-27 19:15:33 +03:00
parent acad001528
commit bdb8915932
25 changed files with 1275 additions and 248 deletions

View File

@@ -19,6 +19,7 @@ public partial class AccountInfoViewModel : ViewModelBase
private readonly AuthService _authService;
public ObservableCollection<AuthLoginPasswordModel> Accounts { get; } = new();
public ObservableCollection<string> AuthUrls { get; } = new();
[ObservableProperty]
private string _currentLogin = String.Empty;
@@ -29,9 +30,15 @@ public partial class AccountInfoViewModel : ViewModelBase
[ObservableProperty]
private string _currentAuthServer = String.Empty;
public ObservableCollection<string> AuthUrls { get; } = new();
[ObservableProperty] private bool _authUrlConfigExpand;
[ObservableProperty] private bool _pageEnabled = true;
[ObservableProperty] private int _authViewSpan = 1;
[ObservableProperty] private bool _authMenuExpand;
private bool _isProfilesEmpty;
[ObservableProperty] private bool _isLogged;
private AuthLoginPassword CurrentAlp
{
@@ -64,12 +71,9 @@ public partial class AccountInfoViewModel : ViewModelBase
ReadAuthConfig();
}
public void AuthByALP(AuthLoginPassword authLoginPassword)
public void AuthByAlp(AuthLoginPassword authLoginPassword)
{
CurrentLogin = authLoginPassword.Login;
CurrentPassword = authLoginPassword.Password;
CurrentAuthServer = authLoginPassword.AuthServer;
CurrentAlp = authLoginPassword;
DoAuth();
}
@@ -80,19 +84,41 @@ public partial class AccountInfoViewModel : ViewModelBase
if(await _authService.Auth(CurrentAlp))
{
_popupMessageService.ClosePopup();
_popupMessageService.PopupInfo("Hello, " + _authService.SelectedAuth!.Username);
_popupMessageService.PopupInfo("Hello, " + _authService.SelectedAuth!.AuthLoginPassword.Login);
IsLogged = true;
_configurationService.SetConfigValue(CurrentConVar.AuthCurrent, CurrentAlp);
}
else
{
_popupMessageService.ClosePopup();
_popupMessageService.PopupInfo("Well, shit is happened");
Logout();
_popupMessageService.PopupInfo("Well, shit is happened: " + _authService.Reason);
}
}
public void Logout()
{
IsLogged = false;
CurrentAlp = new AuthLoginPassword("", "", "");
_authService.SelectedAuth = null;
}
private void UpdateAuthMenu()
{
if (AuthMenuExpand || _isProfilesEmpty)
{
AuthViewSpan = 2;
}
else
{
AuthViewSpan = 1;
}
}
private void AddAccount(AuthLoginPassword authLoginPassword)
{
var onDelete = new DelegateCommand<AuthLoginPasswordModel>(a => Accounts.Remove(a));
var onSelect = new DelegateCommand<AuthLoginPasswordModel>(AuthByALP);
var onDelete = new DelegateCommand<AuthLoginPasswordModel>(OnDeleteProfile);
var onSelect = new DelegateCommand<AuthLoginPasswordModel>(AuthByAlp);
var alpm = new AuthLoginPasswordModel(
authLoginPassword.Login,
@@ -110,12 +136,17 @@ public partial class AccountInfoViewModel : ViewModelBase
private void ReadAuthConfig()
{
foreach (var profile in
_configurationService.GetConfigValue<AuthLoginPassword[]>(CurrentConVar.AuthProfiles)!)
_configurationService.GetConfigValue(CurrentConVar.AuthProfiles)!)
{
AddAccount(profile);
}
var currProfile = _configurationService.GetConfigValue<AuthLoginPassword>(CurrentConVar.AuthProfiles);
if (Accounts.Count == 0)
{
UpdateAuthMenu();
}
var currProfile = _configurationService.GetConfigValue(CurrentConVar.AuthCurrent);
if (currProfile != null)
{
@@ -124,7 +155,7 @@ public partial class AccountInfoViewModel : ViewModelBase
}
AuthUrls.Clear();
var authUrls = _configurationService.GetConfigValue<string[]>(CurrentConVar.AuthServers)!;
var authUrls = _configurationService.GetConfigValue(CurrentConVar.AuthServers)!;
foreach (var url in authUrls)
{
AuthUrls.Add(url);
@@ -132,10 +163,39 @@ public partial class AccountInfoViewModel : ViewModelBase
}
[RelayCommand]
public void OnSaveProfile()
private void OnSaveProfile()
{
AddAccount(CurrentAlp);
_configurationService.SetConfigValue(CurrentConVar.AuthProfiles, Accounts.Select(a => (AuthLoginPassword) a).ToArray());
_isProfilesEmpty = Accounts.Count == 0;
UpdateAuthMenu();
DirtyProfile();
}
private void OnDeleteProfile(AuthLoginPasswordModel account)
{
Accounts.Remove(account);
_isProfilesEmpty = Accounts.Count == 0;
UpdateAuthMenu();
DirtyProfile();
}
[RelayCommand]
private void OnExpandAuthUrl()
{
AuthUrlConfigExpand = !AuthUrlConfigExpand;
}
[RelayCommand]
private void OnExpandAuthView()
{
AuthMenuExpand = !AuthMenuExpand;
UpdateAuthMenu();
}
private void DirtyProfile()
{
_configurationService.SetConfigValue(CurrentConVar.AuthProfiles,
Accounts.Select(a => (AuthLoginPassword) a).ToArray());
}
public string AuthItemSelect

View File

@@ -2,17 +2,13 @@ using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using Avalonia.Controls;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.DependencyInjection;
using CommunityToolkit.Mvvm.Input;
using CommunityToolkit.Mvvm.Messaging;
using Microsoft.Extensions.DependencyInjection;
using JetBrains.Annotations;
using Nebula.Launcher.Models;
using Nebula.Launcher.Services;
using Nebula.Launcher.ViewHelper;
using Nebula.Launcher.Views;
using Nebula.Launcher.Views.Pages;
namespace Nebula.Launcher.ViewModels;
@@ -29,6 +25,7 @@ public partial class MainViewModel : ViewModelBase
SelectedListItem = Items.First(vm => vm.ModelType == typeof(AccountInfoViewModel));
}
[UsedImplicitly]
public MainViewModel(AccountInfoViewModel accountInfoViewModel, PopupMessageService popupMessageService,
IServiceProvider serviceProvider): base(serviceProvider)
{

View File

@@ -0,0 +1,33 @@
using System;
using CommunityToolkit.Mvvm.ComponentModel;
using Microsoft.Extensions.DependencyInjection;
using Nebula.Launcher.Models;
using Nebula.Launcher.Services;
namespace Nebula.Launcher.ViewModels;
public partial class ServerEntryModelView : ViewModelBase
{
private readonly IServiceProvider _serviceProvider;
private readonly RunnerService _runnerService;
private readonly PopupMessageService _popupMessageService;
private readonly RestService _restService;
public ServerHubInfo ServerHubInfo { get; }
public ServerEntryModelView(IServiceProvider serviceProvider, ServerHubInfo serverHubInfo) : base(serviceProvider)
{
_serviceProvider = serviceProvider;
_runnerService = serviceProvider.GetService<RunnerService>()!;
_popupMessageService = serviceProvider.GetService<PopupMessageService>()!;
_restService = serviceProvider.GetService<RestService>()!;
ServerHubInfo = serverHubInfo;
}
public async void OnConnectRequired()
{
_popupMessageService.PopupInfo("Running server: " + ServerHubInfo.StatusData.Name);
await _runnerService.RunGame(ServerHubInfo.Address);
}
}

View File

@@ -13,26 +13,26 @@ namespace Nebula.Launcher.ViewModels;
[ViewRegister(typeof(ServerListView))]
public partial class ServerListViewModel : ViewModelBase
{
public ObservableCollection<ServerHubInfo> ServerInfos { get; } = new();
private readonly IServiceProvider _serviceProvider;
private readonly HubService _hubService;
public ObservableCollection<ServerEntryModelView> ServerInfos { get; } = new();
public Action? OnSearchChange;
[ObservableProperty] private string _searchText;
[ObservableProperty]
private ServerHubInfo? _selectedListItem;
private List<ServerHubInfo> UnsortedServers { get; } = new List<ServerHubInfo>();
private List<ServerHubInfo> UnsortedServers { get; } = new();
//Design think
public ServerListViewModel()
{
ServerInfos.Add(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
public ServerListViewModel(IServiceProvider serviceProvider, HubService hubService) : base(serviceProvider)
{
_serviceProvider = serviceProvider;
_hubService = hubService;
hubService.HubServerChangedEventArgs += HubServerChangedEventArgs;
OnSearchChange += OnChangeSearch;
}
@@ -51,13 +51,17 @@ public partial class ServerListViewModel : ViewModelBase
UnsortedServers.Add(info);
}
}
else
if(obj.Action == HubServerChangeAction.Remove)
{
foreach (var info in obj.Items)
{
UnsortedServers.Remove(info);
}
}
if(obj.Action == HubServerChangeAction.Clear)
{
UnsortedServers.Clear();
}
SortServers();
}
@@ -68,7 +72,7 @@ public partial class ServerListViewModel : ViewModelBase
UnsortedServers.Sort(new ServerComparer());
foreach (var server in UnsortedServers.Where(CheckServerThink))
{
ServerInfos.Add(server);
ServerInfos.Add(CreateServerView(server));
}
}
@@ -77,6 +81,21 @@ public partial class ServerListViewModel : ViewModelBase
if (string.IsNullOrEmpty(SearchText)) return true;
return hubInfo.StatusData.Name.ToLower().Contains(SearchText.ToLower());
}
private ServerEntryModelView CreateServerView(ServerHubInfo serverHubInfo)
{
return new ServerEntryModelView(_serviceProvider, serverHubInfo);
}
public void FilterRequired()
{
}
public void UpdateRequired()
{
_hubService.UpdateHub();
}
}
public class ServerComparer : IComparer<ServerHubInfo>