Change to table for built in titles
This commit is contained in:
parent
e6eb83af2c
commit
a5f3cef90e
104
TaikoWebUI/Pages/Dialogs/ChooseTitleDialog.razor
Normal file
104
TaikoWebUI/Pages/Dialogs/ChooseTitleDialog.razor
Normal file
@ -0,0 +1,104 @@
|
|||||||
|
@using TaikoWebUI.Shared.Models
|
||||||
|
@using System.Collections.Immutable
|
||||||
|
@inject IGameDataService GameDataService
|
||||||
|
|
||||||
|
<MudDialog>
|
||||||
|
<DialogContent>
|
||||||
|
@*<MudDataGrid T="Title" Items="@GameDataService.GetTitles()"
|
||||||
|
@bind-SelectedItem="@selectedTitle" Filterable="false"
|
||||||
|
QuickFilter="@Filter">
|
||||||
|
<ToolBarContent>
|
||||||
|
<MudText Typo="Typo.h6">Built in titles</MudText>
|
||||||
|
<MudSpacer/>
|
||||||
|
<MudTextField @bind-Value="searchString" Placeholder="Search" Adornment="Adornment.Start" Immediate="true"
|
||||||
|
AdornmentIcon="@Icons.Material.Filled.Search" IconSize="Size.Medium" Class="mt-0">
|
||||||
|
</MudTextField>
|
||||||
|
</ToolBarContent>
|
||||||
|
<Columns>
|
||||||
|
<SelectColumn T="Title" ShowInFooter="false" ShowInHeader="false"/>
|
||||||
|
<Column T="Title" Field="@nameof(Title.TitleId)" Title="Id"/>
|
||||||
|
<Column T="Title" Field="@nameof(Title.TitleName)" Title="Name"/>
|
||||||
|
</Columns>
|
||||||
|
<PagerContent>
|
||||||
|
<MudDataGridPager T="Title"/>
|
||||||
|
</PagerContent>
|
||||||
|
</MudDataGrid>*@
|
||||||
|
<MudTable Items="@titles" Filter="@Filter" @bind-SelectedItem="@selectedTitle">
|
||||||
|
<ToolBarContent>
|
||||||
|
<MudText Typo="Typo.h6">Built in titles</MudText>
|
||||||
|
<MudSpacer/>
|
||||||
|
<MudTextField @bind-Value="searchString" Placeholder="Search" Adornment="Adornment.Start" Immediate="true"
|
||||||
|
AdornmentIcon="@Icons.Material.Filled.Search" IconSize="Size.Medium" Class="mt-0">
|
||||||
|
</MudTextField>
|
||||||
|
</ToolBarContent>
|
||||||
|
<HeaderContent>
|
||||||
|
<MudTh>
|
||||||
|
<MudTableSortLabel SortBy="@(new Func<Title, object>(x => x.TitleId))">
|
||||||
|
Id
|
||||||
|
</MudTableSortLabel>
|
||||||
|
</MudTh>
|
||||||
|
<MudTh>
|
||||||
|
<MudTableSortLabel SortBy="@(new Func<Title, object>(x => x.TitleName))">
|
||||||
|
Name
|
||||||
|
</MudTableSortLabel>
|
||||||
|
</MudTh>
|
||||||
|
</HeaderContent>
|
||||||
|
<RowTemplate>
|
||||||
|
<MudTd DataLabel="Id">@context.TitleId</MudTd>
|
||||||
|
<MudTd DataLabel="Name">@context.TitleName</MudTd>
|
||||||
|
</RowTemplate>
|
||||||
|
<PagerContent>
|
||||||
|
<MudTablePager PageSizeOptions="new []{10}"/>
|
||||||
|
</PagerContent>
|
||||||
|
</MudTable>
|
||||||
|
<MudText>Selected Title: @selectedTitle?.TitleName</MudText>
|
||||||
|
</DialogContent>
|
||||||
|
<DialogActions>
|
||||||
|
<MudButton OnClick="Cancel">Cancel</MudButton>
|
||||||
|
<MudButton Color="Color.Primary" OnClick="Submit">Ok</MudButton>
|
||||||
|
</DialogActions>
|
||||||
|
</MudDialog>
|
||||||
|
|
||||||
|
@code {
|
||||||
|
|
||||||
|
[CascadingParameter]
|
||||||
|
MudDialogInstance MudDialog { get; set; } = null!;
|
||||||
|
|
||||||
|
[Parameter]
|
||||||
|
public UserSetting UserSetting { get; set; } = new();
|
||||||
|
|
||||||
|
private IEnumerable<Title> titles = new List<Title>();
|
||||||
|
|
||||||
|
private Title? selectedTitle;
|
||||||
|
|
||||||
|
private string searchString = string.Empty;
|
||||||
|
|
||||||
|
protected override void OnInitialized()
|
||||||
|
{
|
||||||
|
base.OnInitialized();
|
||||||
|
var titleSet = GameDataService.GetTitles();
|
||||||
|
titles = titleSet.ToImmutableList().Sort((title, title1) => title.TitleId.CompareTo(title1.TitleId));
|
||||||
|
titleSet.TryGetValue(new Title
|
||||||
|
{
|
||||||
|
TitleName = UserSetting.Title
|
||||||
|
}, out selectedTitle);
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool Filter(Title title)
|
||||||
|
{
|
||||||
|
return string.IsNullOrEmpty(searchString) ||
|
||||||
|
title.TitleName.Contains(searchString, StringComparison.InvariantCultureIgnoreCase);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Submit()
|
||||||
|
{
|
||||||
|
if (selectedTitle is not null)
|
||||||
|
{
|
||||||
|
UserSetting.Title = selectedTitle.TitleName;
|
||||||
|
}
|
||||||
|
MudDialog.Close(DialogResult.Ok(true));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Cancel() => MudDialog.Cancel();
|
||||||
|
|
||||||
|
}
|
@ -1,6 +1,7 @@
|
|||||||
@page "/Cards/{baid:int}/Profile"
|
@page "/Cards/{baid:int}/Profile"
|
||||||
@inject HttpClient Client
|
@inject HttpClient Client
|
||||||
@inject IGameDataService GameDataService
|
@inject IGameDataService GameDataService
|
||||||
|
@inject IDialogService DialogService
|
||||||
|
|
||||||
<MudBreadcrumbs Items="breadcrumbs" Class="px-0"></MudBreadcrumbs>
|
<MudBreadcrumbs Items="breadcrumbs" Class="px-0"></MudBreadcrumbs>
|
||||||
|
|
||||||
@ -22,7 +23,9 @@
|
|||||||
<MudGrid>
|
<MudGrid>
|
||||||
<MudItem xs="12" md="8">
|
<MudItem xs="12" md="8">
|
||||||
<MudTextField @bind-Value="@response.Title" Label="Title"/>
|
<MudTextField @bind-Value="@response.Title" Label="Title"/>
|
||||||
<MudButton></MudButton>
|
<MudButton Color="Color.Primary" OnClick="@((e)=>OpenChooseTitleDialog())">
|
||||||
|
Choose a built in title
|
||||||
|
</MudButton>
|
||||||
</MudItem>
|
</MudItem>
|
||||||
<MudItem xs="12" md="4">
|
<MudItem xs="12" md="4">
|
||||||
<MudSelect @bind-Value="@response.TitlePlateId" Label="Title Plate">
|
<MudSelect @bind-Value="@response.TitlePlateId" Label="Title Plate">
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
namespace TaikoWebUI.Pages;
|
using TaikoWebUI.Pages.Dialogs;
|
||||||
|
|
||||||
|
namespace TaikoWebUI.Pages;
|
||||||
|
|
||||||
public partial class Profile
|
public partial class Profile
|
||||||
{
|
{
|
||||||
@ -8,8 +10,6 @@ public partial class Profile
|
|||||||
private UserSetting? response;
|
private UserSetting? response;
|
||||||
|
|
||||||
private bool isSavingOptions;
|
private bool isSavingOptions;
|
||||||
|
|
||||||
private bool enterTextDirectly;
|
|
||||||
|
|
||||||
private static readonly string[] CostumeColors =
|
private static readonly string[] CostumeColors =
|
||||||
{
|
{
|
||||||
@ -71,12 +71,25 @@ public partial class Profile
|
|||||||
await Client.PostAsJsonAsync($"api/UserSettings/{Baid}", response);
|
await Client.PostAsJsonAsync($"api/UserSettings/{Baid}", response);
|
||||||
isSavingOptions = false;
|
isSavingOptions = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<IEnumerable<string>> SearchForTitle(string value)
|
|
||||||
{
|
|
||||||
await Task.Delay(1);
|
|
||||||
var titles = GameDataService.GetTitles();
|
|
||||||
|
|
||||||
return string.IsNullOrWhiteSpace(value) ? titles : titles.Where(x => x.Contains(value, StringComparison.OrdinalIgnoreCase));
|
private async Task OpenChooseTitleDialog()
|
||||||
|
{
|
||||||
|
var options = new DialogOptions
|
||||||
|
{
|
||||||
|
// CloseButton = false,
|
||||||
|
CloseOnEscapeKey = false,
|
||||||
|
DisableBackdropClick = true,
|
||||||
|
FullScreen = true
|
||||||
|
};
|
||||||
|
var parameters = new DialogParameters
|
||||||
|
{
|
||||||
|
["UserSetting"] = response
|
||||||
|
};
|
||||||
|
var dialog = DialogService.Show<ChooseTitleDialog>("Choose a built in dialog", parameters, options);
|
||||||
|
var result = await dialog.Result;
|
||||||
|
if (!result.Cancelled)
|
||||||
|
{
|
||||||
|
StateHasChanged();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -18,7 +18,7 @@ public class GameDataService : IGameDataService
|
|||||||
|
|
||||||
private ImmutableDictionary<uint, DanData> danMap = ImmutableDictionary<uint, DanData>.Empty;
|
private ImmutableDictionary<uint, DanData> danMap = ImmutableDictionary<uint, DanData>.Empty;
|
||||||
|
|
||||||
private ImmutableHashSet<string> titles = ImmutableHashSet<string>.Empty;
|
private ImmutableHashSet<Title> titles = ImmutableHashSet<Title>.Empty;
|
||||||
|
|
||||||
public GameDataService(HttpClient client)
|
public GameDataService(HttpClient client)
|
||||||
{
|
{
|
||||||
@ -117,21 +117,24 @@ public class GameDataService : IGameDataService
|
|||||||
return index < puchiTitles.Length ? puchiTitles[index] : string.Empty;
|
return index < puchiTitles.Length ? puchiTitles[index] : string.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<string> GetTitles()
|
public ImmutableHashSet<Title> GetTitles()
|
||||||
{
|
{
|
||||||
return titles.ToArray();
|
return titles;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void InitializeTitles(ImmutableDictionary<string, WordListEntry> dict)
|
private void InitializeTitles(ImmutableDictionary<string, WordListEntry> dict)
|
||||||
{
|
{
|
||||||
var set = ImmutableHashSet.CreateBuilder<string>();
|
var set = ImmutableHashSet.CreateBuilder<Title>();
|
||||||
for (var i = 1; i < Constants.PLAYER_TITLE_MAX; i++)
|
for (var i = 1; i < Constants.PLAYER_TITLE_MAX; i++)
|
||||||
{
|
{
|
||||||
var key = $"syougou_{i}";
|
var key = $"syougou_{i}";
|
||||||
|
|
||||||
var titleWordlistItem = dict.GetValueOrDefault(key, new WordListEntry());
|
var titleWordlistItem = dict.GetValueOrDefault(key, new WordListEntry());
|
||||||
|
|
||||||
set.Add(titleWordlistItem.JapaneseText);
|
set.Add(new Title{
|
||||||
|
TitleName = titleWordlistItem.JapaneseText,
|
||||||
|
TitleId = i
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
titles = set.ToImmutable();
|
titles = set.ToImmutable();
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
namespace TaikoWebUI.Services;
|
using System.Collections.Immutable;
|
||||||
|
using TaikoWebUI.Shared.Models;
|
||||||
|
|
||||||
|
namespace TaikoWebUI.Services;
|
||||||
|
|
||||||
public interface IGameDataService
|
public interface IGameDataService
|
||||||
{
|
{
|
||||||
@ -22,5 +25,5 @@ public interface IGameDataService
|
|||||||
public string GetFaceTitle(uint index);
|
public string GetFaceTitle(uint index);
|
||||||
public string GetPuchiTitle(uint index);
|
public string GetPuchiTitle(uint index);
|
||||||
|
|
||||||
public IEnumerable<string> GetTitles();
|
public ImmutableHashSet<Title> GetTitles();
|
||||||
}
|
}
|
23
TaikoWebUI/Shared/Models/Title.cs
Normal file
23
TaikoWebUI/Shared/Models/Title.cs
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
namespace TaikoWebUI.Shared.Models;
|
||||||
|
|
||||||
|
public class Title
|
||||||
|
{
|
||||||
|
public int TitleId { get; set; }
|
||||||
|
|
||||||
|
public string TitleName { get; init; } = string.Empty;
|
||||||
|
|
||||||
|
public override bool Equals(object? obj)
|
||||||
|
{
|
||||||
|
if (obj is Title title)
|
||||||
|
{
|
||||||
|
return title.TitleName.Equals(TitleName);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override int GetHashCode()
|
||||||
|
{
|
||||||
|
return TitleName.GetHashCode();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user