2025-06-22 22:11:27 +03:00
|
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
2025-06-23 16:39:30 +03:00
|
|
|
using Nebula.Launcher.Services;
|
2025-06-22 22:11:27 +03:00
|
|
|
using Nebula.Launcher.Views.Popup;
|
|
|
|
|
using Nebula.Shared.Services;
|
2025-07-02 21:32:51 +03:00
|
|
|
using Nebula.Shared.ViewHelper;
|
2025-06-22 22:11:27 +03:00
|
|
|
|
|
|
|
|
namespace Nebula.Launcher.ViewModels.Popup;
|
|
|
|
|
|
|
|
|
|
[ViewModelRegister(typeof(EditServerNameView), false)]
|
|
|
|
|
[ConstructGenerator]
|
|
|
|
|
public sealed partial class EditServerNameViewModel : PopupViewModelBase
|
|
|
|
|
{
|
|
|
|
|
[GenerateProperty] public override PopupMessageService PopupMessageService { get; }
|
|
|
|
|
[GenerateProperty] public ConfigurationService ConfigurationService { get; }
|
2025-12-06 23:25:25 +03:00
|
|
|
public override string Title => LocalizationService.GetString("popup-edit-name");
|
2025-06-22 22:11:27 +03:00
|
|
|
public override bool IsClosable => true;
|
|
|
|
|
|
|
|
|
|
[ObservableProperty] private string _ipInput;
|
|
|
|
|
[ObservableProperty] private string _nameInput;
|
|
|
|
|
|
|
|
|
|
public void OnEnter()
|
|
|
|
|
{
|
|
|
|
|
if(string.IsNullOrWhiteSpace(IpInput))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(NameInput))
|
|
|
|
|
{
|
2025-06-28 14:05:19 +03:00
|
|
|
OnClear();
|
2025-06-22 22:11:27 +03:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AddServerName();
|
|
|
|
|
Dispose();
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-28 14:05:19 +03:00
|
|
|
public void OnClear()
|
|
|
|
|
{
|
|
|
|
|
RemoveServerName();
|
|
|
|
|
Dispose();
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-22 22:11:27 +03:00
|
|
|
private void AddServerName()
|
|
|
|
|
{
|
|
|
|
|
var currentNames = ConfigurationService.GetConfigValue(LauncherConVar.ServerCustomNames)!;
|
|
|
|
|
currentNames.Add(IpInput, NameInput);
|
|
|
|
|
ConfigurationService.SetConfigValue(LauncherConVar.ServerCustomNames, currentNames);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void RemoveServerName()
|
|
|
|
|
{
|
|
|
|
|
var currentNames = ConfigurationService.GetConfigValue(LauncherConVar.ServerCustomNames)!;
|
|
|
|
|
currentNames.Remove(IpInput);
|
|
|
|
|
ConfigurationService.SetConfigValue(LauncherConVar.ServerCustomNames, currentNames);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void InitialiseInDesignMode()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Initialise()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|