-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change avatar/navigator/title select method
Add the function to change player name
- Loading branch information
Showing
19 changed files
with
610 additions
and
241 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
@using SharedProject.common | ||
@using System.Text.RegularExpressions | ||
@inject HttpClient Client | ||
@inject ILogger<ChangePlayerNameDialog> Logger | ||
|
||
<MudDialog> | ||
<TitleContent> | ||
<MudText Typo="Typo.h6"> | ||
Change Player Name | ||
</MudText> | ||
</TitleContent> | ||
<DialogContent> | ||
<MudForm @bind-IsValid="IsValid"> | ||
<MudTextField Value="@Data.CardId" Label="CardId" ReadOnly="true"/> | ||
<MudTextField @bind-Value="Data.PlayerName" | ||
Immediate="true" | ||
Counter="SharedConstants.MAX_PLAYER_NAME_LENGTH" | ||
MaxLength="SharedConstants.MAX_PLAYER_NAME_LENGTH" | ||
Validation="ValidatePlayerName"/> | ||
</MudForm> | ||
</DialogContent> | ||
<DialogActions> | ||
<MudButton OnClick="Cancel">Cancel</MudButton> | ||
<MudButton Color="Color.Primary" OnClick="Submit" Disabled="@(!IsValid)">Confirm</MudButton> | ||
</DialogActions> | ||
</MudDialog> | ||
|
||
@code { | ||
|
||
[CascadingParameter] | ||
MudDialogInstance MudDialog { get; set; } = null!; | ||
|
||
[Parameter] | ||
public SharedProject.models.User Data { get; set; } = null!; | ||
|
||
private string originalName = string.Empty; | ||
|
||
private bool IsValid { get; set; } | ||
|
||
protected override void OnInitialized() | ||
{ | ||
base.OnInitialized(); | ||
originalName = new string(Data.PlayerName); | ||
} | ||
|
||
async Task Submit() | ||
{ | ||
Logger.LogInformation("Data is {cardId}, {name}", Data.CardId, Data.PlayerName); | ||
var response = await Client.PostAsJsonAsync("api/Users/SetPlayerName", Data); | ||
var result = await response.Content.ReadFromJsonAsync<bool>(); | ||
Logger.LogInformation("SetPlayerName result is {result}", result); | ||
MudDialog.Close(DialogResult.Ok(result)); | ||
} | ||
|
||
void Cancel() | ||
{ | ||
Data.PlayerName = originalName; | ||
MudDialog.Cancel(); | ||
} | ||
|
||
private static string? ValidatePlayerName(string playerName) | ||
{ | ||
const string pattern = @"^[a-zA-Z0-9!?,./\-+:<>_\\@*#&=() ]{1,8}$"; | ||
|
||
return playerName.Length switch | ||
{ | ||
0 => "Player name cannot be empty!", | ||
> 8 => "Player name cannot be longer than 8 characters!", | ||
_ => !Regex.IsMatch(playerName, pattern) ? "Player name contains invalid character!" : null | ||
}; | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.