2023-02-22 17:35:59 +01:00
|
|
|
|
using Throw;
|
2023-02-21 19:55:32 +01:00
|
|
|
|
using WebUI.Pages.Dialogs;
|
2023-02-21 15:45:51 +01:00
|
|
|
|
using WebUI.Services;
|
|
|
|
|
|
|
|
|
|
namespace WebUI.Pages;
|
|
|
|
|
|
|
|
|
|
public partial class Option
|
|
|
|
|
{
|
|
|
|
|
[Parameter]
|
|
|
|
|
public long CardId { get; set; }
|
|
|
|
|
|
|
|
|
|
[Inject]
|
|
|
|
|
public required HttpClient Client { get; set; }
|
|
|
|
|
|
|
|
|
|
[Inject]
|
|
|
|
|
public required IDialogService DialogService { get; set; }
|
|
|
|
|
|
|
|
|
|
[Inject]
|
|
|
|
|
public required IDataService DataService { get; set; }
|
2023-02-21 19:55:32 +01:00
|
|
|
|
|
|
|
|
|
private bool isSaving;
|
2023-02-21 15:45:51 +01:00
|
|
|
|
|
|
|
|
|
private readonly List<BreadcrumbItem> breadcrumbs = new()
|
|
|
|
|
{
|
|
|
|
|
new BreadcrumbItem("Cards", href: "/Cards"),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private PlayOptionData? playOptionData;
|
|
|
|
|
|
2023-02-21 19:55:32 +01:00
|
|
|
|
private string? errorMessage;
|
|
|
|
|
|
|
|
|
|
private static readonly DialogOptions OPTIONS = new()
|
|
|
|
|
{
|
|
|
|
|
CloseOnEscapeKey = false,
|
|
|
|
|
DisableBackdropClick = true,
|
|
|
|
|
FullWidth = true,
|
|
|
|
|
MaxWidth = MaxWidth.ExtraExtraLarge
|
|
|
|
|
};
|
2023-02-21 15:45:51 +01:00
|
|
|
|
|
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
|
|
|
{
|
|
|
|
|
await base.OnInitializedAsync();
|
|
|
|
|
breadcrumbs.Add(new BreadcrumbItem($"Card: {CardId}", href:null, disabled:true));
|
|
|
|
|
breadcrumbs.Add(new BreadcrumbItem("Option", href: $"/Cards/Option/{CardId}", disabled: false));
|
|
|
|
|
|
|
|
|
|
var result = await Client.GetFromJsonAsync<ServiceResult<PlayOptionData>>($"api/PlayOption/{CardId}");
|
|
|
|
|
result.ThrowIfNull();
|
|
|
|
|
|
|
|
|
|
if (!result.Succeeded)
|
|
|
|
|
{
|
|
|
|
|
errorMessage = result.Error!.Message;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
playOptionData = result.Data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string GetNavigatorName(uint navigatorId)
|
|
|
|
|
{
|
2023-02-21 19:55:32 +01:00
|
|
|
|
var navigator = DataService.GetNavigatorById(navigatorId);
|
2023-02-21 15:45:51 +01:00
|
|
|
|
|
|
|
|
|
return navigator?.NavigatorName ?? "Navigator id unknown";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string GetAvatarName(uint avatarId)
|
|
|
|
|
{
|
2023-02-21 19:55:32 +01:00
|
|
|
|
var avatar = DataService.GetAvatarById(avatarId);
|
2023-02-21 15:45:51 +01:00
|
|
|
|
|
|
|
|
|
return avatar?.AvatarName ?? "Avatar id unknown";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string GetTitleName(uint titleId)
|
|
|
|
|
{
|
2023-02-21 19:55:32 +01:00
|
|
|
|
var title = DataService.GetTitleById(titleId);
|
2023-02-21 15:45:51 +01:00
|
|
|
|
|
|
|
|
|
return title?.TitleName ?? "Title id unknown";
|
|
|
|
|
}
|
2023-02-21 19:55:32 +01:00
|
|
|
|
|
|
|
|
|
private async Task OpenChangeTitleDialog()
|
|
|
|
|
{
|
|
|
|
|
var parameters = new DialogParameters
|
|
|
|
|
{
|
|
|
|
|
["Data"] = playOptionData
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var dialog = await DialogService.ShowAsync<ChangeTitleDialog>("Change Title", parameters, OPTIONS);
|
|
|
|
|
var result = await dialog.Result;
|
|
|
|
|
if (!result.Canceled)
|
|
|
|
|
{
|
|
|
|
|
StateHasChanged();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task OpenChangeNavigatorDialog()
|
|
|
|
|
{
|
|
|
|
|
var parameters = new DialogParameters
|
|
|
|
|
{
|
|
|
|
|
["Data"] = playOptionData
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var dialog = await DialogService.ShowAsync<ChangeNavigatorDialog>("Change Navigator", parameters, OPTIONS);
|
|
|
|
|
var result = await dialog.Result;
|
|
|
|
|
if (!result.Canceled)
|
|
|
|
|
{
|
|
|
|
|
StateHasChanged();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private async Task OpenChangeAvatarDialog()
|
|
|
|
|
{
|
|
|
|
|
var parameters = new DialogParameters
|
|
|
|
|
{
|
|
|
|
|
["Data"] = playOptionData
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var dialog = await DialogService.ShowAsync<ChangeAvatarDialog>("Change Navigator", parameters, OPTIONS);
|
|
|
|
|
var result = await dialog.Result;
|
|
|
|
|
if (!result.Canceled)
|
|
|
|
|
{
|
|
|
|
|
StateHasChanged();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task SaveOptions()
|
|
|
|
|
{
|
|
|
|
|
isSaving = true;
|
|
|
|
|
var result = await Client.PostAsJsonAsync("api/PlayOption", playOptionData);
|
|
|
|
|
isSaving = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task UnlockMusics()
|
|
|
|
|
{
|
|
|
|
|
await Client.PostAsync($"api/Profiles/UnlockAllMusic/{CardId}", null);
|
|
|
|
|
}
|
2023-02-21 15:45:51 +01:00
|
|
|
|
}
|