Files
NebulaLauncher/Nebula.Launcher/ViewModels/Popup/LoadingContextViewModel.cs

90 lines
2.5 KiB
C#
Raw Normal View History

2025-01-08 18:00:06 +03:00
using CommunityToolkit.Mvvm.ComponentModel;
2025-06-23 16:39:30 +03:00
using Nebula.Launcher.Services;
2025-01-08 18:00:06 +03:00
using Nebula.Launcher.Views.Popup;
using Nebula.Shared.Models;
2025-01-14 22:10:16 +03:00
using Nebula.Shared.Services;
2025-07-02 21:32:51 +03:00
using Nebula.Shared.ViewHelper;
2025-01-08 18:00:06 +03:00
2025-01-14 22:10:16 +03:00
namespace Nebula.Launcher.ViewModels.Popup;
2025-01-08 18:00:06 +03:00
[ViewModelRegister(typeof(LoadingContextView), false)]
2025-01-14 22:10:16 +03:00
[ConstructGenerator]
2025-01-08 18:00:06 +03:00
public sealed partial class LoadingContextViewModel : PopupViewModelBase, ILoadingHandler
{
2025-01-14 22:10:16 +03:00
[GenerateProperty] public override PopupMessageService PopupMessageService { get; }
2025-03-12 14:51:47 +03:00
[GenerateProperty] public CancellationService CancellationService { get; }
2025-01-08 18:00:06 +03:00
2025-01-14 22:10:16 +03:00
[ObservableProperty] private int _currJobs;
[ObservableProperty] private int _resolvedJobs;
2025-07-10 15:22:15 +03:00
[ObservableProperty] private string _message = string.Empty;
2025-01-14 22:10:16 +03:00
2025-06-23 16:39:30 +03:00
public string LoadingName { get; set; } = LocalisationService.GetString("popup-loading");
2025-03-14 18:32:03 +03:00
public bool IsCancellable { get; set; } = true;
2025-01-12 15:15:01 +03:00
public override bool IsClosable => false;
2025-01-08 18:00:06 +03:00
public override string Title => LoadingName;
2025-01-14 22:10:16 +03:00
2025-01-08 18:00:06 +03:00
public void SetJobsCount(int count)
{
CurrJobs = count;
}
public int GetJobsCount()
{
return CurrJobs;
}
public void SetResolvedJobsCount(int count)
{
ResolvedJobs = count;
}
public int GetResolvedJobsCount()
{
return ResolvedJobs;
}
2025-01-14 22:10:16 +03:00
2025-07-10 15:22:15 +03:00
public void SetLoadingMessage(string message)
{
Message = message + "\n" + Message;
}
2025-03-12 14:51:47 +03:00
public void Cancel(){
2025-03-14 18:32:03 +03:00
if(!IsCancellable) return;
2025-03-12 14:51:47 +03:00
CancellationService.Cancel();
Dispose();
}
2025-01-14 22:10:16 +03:00
protected override void Initialise()
{
}
protected override void InitialiseInDesignMode()
{
2025-07-10 15:22:15 +03:00
SetJobsCount(5);
SetResolvedJobsCount(2);
string[] debugMessages = {
"Debug: Starting phase 1...",
"Debug: Loading assets...",
"Debug: Connecting to server...",
"Debug: Fetching user data...",
"Debug: Applying configurations...",
"Debug: Starting phase 2...",
"Debug: Rendering UI...",
"Debug: Preparing scene...",
"Debug: Initializing components...",
"Debug: Running diagnostics...",
"Debug: Checking dependencies...",
"Debug: Verifying files...",
"Debug: Cleaning up cache...",
"Debug: Finalizing setup...",
"Debug: Setup complete.",
"Debug: Ready for launch."
};
foreach (string message in debugMessages)
{
SetLoadingMessage(message);
}
2025-01-14 22:10:16 +03:00
}
2025-01-08 18:00:06 +03:00
}