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"
|
||||
@inject HttpClient Client
|
||||
@inject IGameDataService GameDataService
|
||||
@inject IDialogService DialogService
|
||||
|
||||
<MudBreadcrumbs Items="breadcrumbs" Class="px-0"></MudBreadcrumbs>
|
||||
|
||||
@ -22,7 +23,9 @@
|
||||
<MudGrid>
|
||||
<MudItem xs="12" md="8">
|
||||
<MudTextField @bind-Value="@response.Title" Label="Title"/>
|
||||
<MudButton></MudButton>
|
||||
<MudButton Color="Color.Primary" OnClick="@((e)=>OpenChooseTitleDialog())">
|
||||
Choose a built in title
|
||||
</MudButton>
|
||||
</MudItem>
|
||||
<MudItem xs="12" md="4">
|
||||
<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
|
||||
{
|
||||
@ -9,8 +11,6 @@ public partial class Profile
|
||||
|
||||
private bool isSavingOptions;
|
||||
|
||||
private bool enterTextDirectly;
|
||||
|
||||
private static readonly string[] CostumeColors =
|
||||
{
|
||||
"#F84828", "#68C0C0", "#DC1500", "#F8F0E0", "#009687", "#00BF87",
|
||||
@ -72,11 +72,24 @@ public partial class Profile
|
||||
isSavingOptions = false;
|
||||
}
|
||||
|
||||
private async Task<IEnumerable<string>> SearchForTitle(string value)
|
||||
private async Task OpenChooseTitleDialog()
|
||||
{
|
||||
await Task.Delay(1);
|
||||
var titles = GameDataService.GetTitles();
|
||||
|
||||
return string.IsNullOrWhiteSpace(value) ? titles : titles.Where(x => x.Contains(value, StringComparison.OrdinalIgnoreCase));
|
||||
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 ImmutableHashSet<string> titles = ImmutableHashSet<string>.Empty;
|
||||
private ImmutableHashSet<Title> titles = ImmutableHashSet<Title>.Empty;
|
||||
|
||||
public GameDataService(HttpClient client)
|
||||
{
|
||||
@ -117,21 +117,24 @@ public class GameDataService : IGameDataService
|
||||
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)
|
||||
{
|
||||
var set = ImmutableHashSet.CreateBuilder<string>();
|
||||
var set = ImmutableHashSet.CreateBuilder<Title>();
|
||||
for (var i = 1; i < Constants.PLAYER_TITLE_MAX; i++)
|
||||
{
|
||||
var key = $"syougou_{i}";
|
||||
|
||||
var titleWordlistItem = dict.GetValueOrDefault(key, new WordListEntry());
|
||||
|
||||
set.Add(titleWordlistItem.JapaneseText);
|
||||
set.Add(new Title{
|
||||
TitleName = titleWordlistItem.JapaneseText,
|
||||
TitleId = i
|
||||
});
|
||||
}
|
||||
|
||||
titles = set.ToImmutable();
|
||||
|
@ -1,4 +1,7 @@
|
||||
namespace TaikoWebUI.Services;
|
||||
using System.Collections.Immutable;
|
||||
using TaikoWebUI.Shared.Models;
|
||||
|
||||
namespace TaikoWebUI.Services;
|
||||
|
||||
public interface IGameDataService
|
||||
{
|
||||
@ -22,5 +25,5 @@ public interface IGameDataService
|
||||
public string GetFaceTitle(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