2024-12-21 13:11:30 +03:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Collections.ObjectModel;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
|
|
|
using CommunityToolkit.Mvvm.Input;
|
2024-12-27 19:15:33 +03:00
|
|
|
using JetBrains.Annotations;
|
2024-12-21 13:11:30 +03:00
|
|
|
using Nebula.Launcher.Models;
|
2024-12-27 08:22:17 +03:00
|
|
|
using Nebula.Launcher.Services;
|
2024-12-21 15:15:04 +03:00
|
|
|
using Nebula.Launcher.ViewHelper;
|
|
|
|
|
using Nebula.Launcher.Views;
|
2024-12-21 13:11:30 +03:00
|
|
|
|
|
|
|
|
namespace Nebula.Launcher.ViewModels;
|
|
|
|
|
|
2024-12-21 15:15:04 +03:00
|
|
|
[ViewRegister(typeof(MainView))]
|
2024-12-21 13:11:30 +03:00
|
|
|
public partial class MainViewModel : ViewModelBase
|
|
|
|
|
{
|
2024-12-21 15:15:04 +03:00
|
|
|
public MainViewModel()
|
|
|
|
|
{
|
|
|
|
|
TryGetViewModel(typeof(AccountInfoViewModel), out var model);
|
|
|
|
|
_currentPage = model!;
|
2024-12-26 18:54:37 +03:00
|
|
|
|
2024-12-21 15:15:04 +03:00
|
|
|
Items = new ObservableCollection<ListItemTemplate>(_templates);
|
|
|
|
|
|
|
|
|
|
SelectedListItem = Items.First(vm => vm.ModelType == typeof(AccountInfoViewModel));
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-27 19:15:33 +03:00
|
|
|
[UsedImplicitly]
|
2024-12-27 08:22:17 +03:00
|
|
|
public MainViewModel(AccountInfoViewModel accountInfoViewModel, PopupMessageService popupMessageService,
|
2024-12-26 18:54:37 +03:00
|
|
|
IServiceProvider serviceProvider): base(serviceProvider)
|
2024-12-21 13:11:30 +03:00
|
|
|
{
|
|
|
|
|
_currentPage = accountInfoViewModel;
|
2024-12-27 08:22:17 +03:00
|
|
|
_popupMessageService = popupMessageService;
|
2024-12-21 13:11:30 +03:00
|
|
|
Items = new ObservableCollection<ListItemTemplate>(_templates);
|
|
|
|
|
|
2024-12-27 08:22:17 +03:00
|
|
|
_popupMessageService.OnPopupRequired += OnPopupRequired;
|
2024-12-26 18:54:37 +03:00
|
|
|
|
2024-12-27 08:22:17 +03:00
|
|
|
SelectedListItem = Items.First(vm => vm.ModelType == typeof(AccountInfoViewModel));
|
2024-12-26 18:54:37 +03:00
|
|
|
}
|
|
|
|
|
|
2024-12-27 08:22:17 +03:00
|
|
|
private readonly Queue<PopupViewModelBase> _viewQueue = new();
|
|
|
|
|
|
2024-12-21 13:11:30 +03:00
|
|
|
private readonly List<ListItemTemplate> _templates =
|
|
|
|
|
[
|
2024-12-22 16:38:47 +03:00
|
|
|
new ListItemTemplate(typeof(AccountInfoViewModel), "Account", "Account"),
|
|
|
|
|
new ListItemTemplate(typeof(ServerListViewModel), "HomeRegular", "Servers")
|
2024-12-21 13:11:30 +03:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
[ObservableProperty]
|
|
|
|
|
private bool _isPaneOpen;
|
|
|
|
|
|
|
|
|
|
[ObservableProperty]
|
|
|
|
|
private ViewModelBase _currentPage;
|
|
|
|
|
|
2024-12-27 08:22:17 +03:00
|
|
|
private readonly PopupMessageService _popupMessageService;
|
|
|
|
|
|
2024-12-26 18:54:37 +03:00
|
|
|
[ObservableProperty] private bool _isEnabled = true;
|
|
|
|
|
[ObservableProperty] private bool _popup;
|
2024-12-27 08:22:17 +03:00
|
|
|
|
|
|
|
|
[ObservableProperty]
|
|
|
|
|
private PopupViewModelBase? _currentPopup;
|
|
|
|
|
[ObservableProperty]
|
|
|
|
|
private string _currentTitle = "Default";
|
2024-12-26 18:54:37 +03:00
|
|
|
|
2024-12-21 13:11:30 +03:00
|
|
|
[ObservableProperty]
|
|
|
|
|
private ListItemTemplate? _selectedListItem;
|
|
|
|
|
|
|
|
|
|
partial void OnSelectedListItemChanged(ListItemTemplate? value)
|
|
|
|
|
{
|
|
|
|
|
if (value is null) return;
|
|
|
|
|
|
2024-12-21 15:15:04 +03:00
|
|
|
if(!TryGetViewModel(value.ModelType, out var vmb))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-21 13:11:30 +03:00
|
|
|
CurrentPage = vmb;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ObservableCollection<ListItemTemplate> Items { get; }
|
2024-12-27 08:22:17 +03:00
|
|
|
|
|
|
|
|
public void PopupMessage(PopupViewModelBase viewModelBase)
|
|
|
|
|
{
|
|
|
|
|
if (CurrentPopup == null)
|
|
|
|
|
{
|
|
|
|
|
CurrentPopup = viewModelBase;
|
|
|
|
|
CurrentTitle = viewModelBase.Title;
|
|
|
|
|
OnOpenRequired();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_viewQueue.Enqueue(viewModelBase);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnCloseRequired()
|
|
|
|
|
{
|
|
|
|
|
IsEnabled = true;
|
|
|
|
|
Popup = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnOpenRequired()
|
|
|
|
|
{
|
|
|
|
|
IsEnabled = false;
|
|
|
|
|
Popup = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnPopupRequired(PopupViewModelBase? viewModelBase)
|
|
|
|
|
{
|
|
|
|
|
if (viewModelBase is null)
|
|
|
|
|
{
|
|
|
|
|
ClosePopup();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
PopupMessage(viewModelBase);
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-12-21 13:11:30 +03:00
|
|
|
|
|
|
|
|
[RelayCommand]
|
|
|
|
|
private void TriggerPane()
|
|
|
|
|
{
|
|
|
|
|
IsPaneOpen = !IsPaneOpen;
|
|
|
|
|
}
|
2024-12-27 08:22:17 +03:00
|
|
|
|
|
|
|
|
[RelayCommand]
|
|
|
|
|
public void ClosePopup()
|
|
|
|
|
{
|
|
|
|
|
if (!_viewQueue.TryDequeue(out var viewModelBase))
|
|
|
|
|
OnCloseRequired();
|
|
|
|
|
else
|
|
|
|
|
CurrentTitle = viewModelBase.Title;
|
|
|
|
|
|
|
|
|
|
CurrentPopup = viewModelBase;
|
|
|
|
|
}
|
2024-12-21 13:11:30 +03:00
|
|
|
}
|
|
|
|
|
|