Skip to content

Commit

Permalink
Add common gender display RenderFragments
Browse files Browse the repository at this point in the history
  • Loading branch information
codemonkey85 committed Sep 16, 2023
1 parent 2c83a20 commit ab11602
Show file tree
Hide file tree
Showing 21 changed files with 140 additions and 62 deletions.
2 changes: 0 additions & 2 deletions Pkmds.Rcl/AppState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,4 @@ public SaveFile? SaveFile
public int? SelectedPartySlotNumber { get; set; }

public bool ShowProgressIndicator { get; set; }

public string FileDisplayName { get; set; } = string.Empty;
}
72 changes: 72 additions & 0 deletions Pkmds.Rcl/Components/BasePkmdsComponent.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
@code {
public static RenderFragment TypeSummary(byte type1, byte type2) =>
@<MudStack Row="@true"
Class="my-2"
AlignItems="@AlignItems.Center">
<MudText>
Type:
</MudText>
<MudImage Src="@SpriteHelper.GetTypeWideSpriteFileName(type1)"
Alt="@GameInfo.Strings.Types[type1]"
title="@GameInfo.Strings.Types[type1]"
ObjectFit="@ObjectFit.Contain"
ObjectPosition="@ObjectPosition.Center" />
@if (type1 != type2)
{
<MudImage Src="@SpriteHelper.GetTypeWideSpriteFileName(type2)"
Alt="@GameInfo.Strings.Types[type2]"
title="@GameInfo.Strings.Types[type2]"
ObjectFit="@ObjectFit.Contain"
ObjectPosition="@ObjectPosition.Center" />
}
</MudStack>;

public static RenderFragment TeraTypeSummary(byte type) =>
@<MudStack Row="@true"
Class="my-2"
AlignItems="@AlignItems.Center">
<MudText>
Tera Type:
</MudText>
<MudImage Src="@SpriteHelper.GetTypeGemSpriteFileName(type)"
Alt="@GameInfo.Strings.Types[type]"
title="@GameInfo.Strings.Types[type]"
ObjectFit="@ObjectFit.Contain"
ObjectPosition="@ObjectPosition.Center"
Width="30" />
</MudStack>;

public static RenderFragment GenderDisplayIcon(int gender)
{
var icon = gender switch
{
0 => Icons.Material.Filled.Male,
1 => Icons.Material.Filled.Female,
_ => string.Empty,
};
var color = gender switch
{
0 => Colors.Blue.Default,
1 => Colors.Red.Default,
_ => string.Empty,
};
return @<MudIcon Icon="@icon" Style="@($"color: {color};")" />;
}

public static RenderFragment GenderDisplayAscii(int gender)
{
var color = gender switch
{
0 => Colors.Blue.Default,
1 => Colors.Red.Default,
_ => string.Empty,
};
return @<MudText Style="@($"color: { color}; ")">@GameInfo.GenderSymbolASCII[gender]</MudText>;
}

public static RenderFragment GenderDisplay(int gender) =>
@<MudStack Row="@true">
@GenderDisplayIcon(gender)
@GenderDisplayAscii(gender)
</MudStack>;
}
4 changes: 3 additions & 1 deletion Pkmds.Rcl/Components/BoxComponent.razor
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
@if (BoxEdit is not null)
@inherits BasePkmdsComponent

@if (BoxEdit is not null)
{
<div>
<MudText Typo="Typo.h5">
Expand Down
4 changes: 3 additions & 1 deletion Pkmds.Rcl/Components/BoxGrid.razor
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
@if (BoxEdit is not null)
@inherits BasePkmdsComponent

@if (BoxEdit is not null)
{
<MudGrid Spacing="1"
Justify="@Justify.Center"
Expand Down
4 changes: 3 additions & 1 deletion Pkmds.Rcl/Components/BoxSlotComponent.razor
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<MudPaper Elevation="3"
@inherits BasePkmdsComponent

<MudPaper Elevation="3"
@onclick="SetSelectedPokemon"
Width="68px"
Height="68px"
Expand Down
4 changes: 3 additions & 1 deletion Pkmds.Rcl/Components/EditForms/PokemonEditForm.razor
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
@if (Pokemon is not null &&
@inherits BasePkmdsComponent

@if (Pokemon is not null &&
AppState.SaveFile?.Context is EntityContext saveFileEntityContext &&
saveFileEntityContext is not
EntityContext.None or
Expand Down
4 changes: 3 additions & 1 deletion Pkmds.Rcl/Components/EditForms/Tabs/CosmeticTab.razor
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
@if (Pokemon is not null &&
@inherits BasePkmdsComponent

@if (Pokemon is not null &&
AppState.SaveFile?.Context is EntityContext saveFileEntityContext &&
saveFileEntityContext is not
EntityContext.None or
Expand Down
43 changes: 3 additions & 40 deletions Pkmds.Rcl/Components/EditForms/Tabs/MainTab.razor
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
@if (Pokemon is not null &&
@inherits BasePkmdsComponent

@if (Pokemon is not null &&
AppState.SaveFile?.Context is EntityContext saveFileEntityContext &&
saveFileEntityContext is not
EntityContext.None or
Expand Down Expand Up @@ -200,42 +202,3 @@ EntityContext.MaxInvalid &&

</MudStack>
}

@code {
private static RenderFragment TypeSummary(byte type1, byte type2) =>
@<MudStack Row="@true"
Class="my-2"
AlignItems="@AlignItems.Center">
<MudText>
Type:
</MudText>
<MudImage Src="@SpriteHelper.GetTypeWideSpriteFileName(type1)"
Alt="@GameInfo.Strings.Types[type1]"
title="@GameInfo.Strings.Types[type1]"
ObjectFit="@ObjectFit.Contain"
ObjectPosition="@ObjectPosition.Center" />
@if (type1 != type2)
{
<MudImage Src="@SpriteHelper.GetTypeWideSpriteFileName(type2)"
Alt="@GameInfo.Strings.Types[type2]"
title="@GameInfo.Strings.Types[type2]"
ObjectFit="@ObjectFit.Contain"
ObjectPosition="@ObjectPosition.Center" />
}
</MudStack>;

private static RenderFragment TeraTypeSummary(byte type) =>
@<MudStack Row="@true"
Class="my-2"
AlignItems="@AlignItems.Center">
<MudText>
Tera Type:
</MudText>
<MudImage Src="@SpriteHelper.GetTypeGemSpriteFileName(type)"
Alt="@GameInfo.Strings.Types[type]"
title="@GameInfo.Strings.Types[type]"
ObjectFit="@ObjectFit.Contain"
ObjectPosition="@ObjectPosition.Center"
Width="30" />
</MudStack>;
}
4 changes: 3 additions & 1 deletion Pkmds.Rcl/Components/EditForms/Tabs/MetTab.razor
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
@if (Pokemon is not null &&
@inherits BasePkmdsComponent

@if (Pokemon is not null &&
AppState.SaveFile?.Context is EntityContext saveFileEntityContext &&
saveFileEntityContext is not
EntityContext.None or
Expand Down
4 changes: 3 additions & 1 deletion Pkmds.Rcl/Components/EditForms/Tabs/MovesTab.razor
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
@if (Pokemon is not null &&
@inherits BasePkmdsComponent

@if (Pokemon is not null &&
AppState.SaveFile?.Context is EntityContext saveFileEntityContext &&
saveFileEntityContext is not
EntityContext.None or
Expand Down
4 changes: 3 additions & 1 deletion Pkmds.Rcl/Components/EditForms/Tabs/OtMiscTab.razor
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
@if (Pokemon is not null &&
@inherits BasePkmdsComponent

@if (Pokemon is not null &&
AppState.SaveFile?.Context is EntityContext saveFileEntityContext &&
saveFileEntityContext is not
EntityContext.None or
Expand Down
4 changes: 3 additions & 1 deletion Pkmds.Rcl/Components/EditForms/Tabs/StatsTab.razor
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
@if (Pokemon is not null &&
@inherits BasePkmdsComponent

@if (Pokemon is not null &&
AppState.SaveFile?.Context is EntityContext saveFileEntityContext &&
saveFileEntityContext is not
EntityContext.None or
Expand Down
4 changes: 3 additions & 1 deletion Pkmds.Rcl/Components/FeatureNotImplemented.razor
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<MudText>
@inherits BasePkmdsComponent

<MudText>
Feature not implemented.
</MudText>
4 changes: 3 additions & 1 deletion Pkmds.Rcl/Components/FileUploadDialog.razor
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<MudDialog>
@inherits BasePkmdsComponent

<MudDialog>
<DialogContent>
<MudFileUpload T="IBrowserFile"
FilesChanged="HandleFile">
Expand Down
4 changes: 3 additions & 1 deletion Pkmds.Rcl/Components/PartyGrid.razor
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
@if (AppState.SaveFile is not null)
@inherits BasePkmdsComponent

@if (AppState.SaveFile is not null)
{
<div class="party-grid">
<MudGrid Spacing="1"
Expand Down
4 changes: 3 additions & 1 deletion Pkmds.Rcl/Components/PartySlotComponent.razor
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<MudPaper Elevation="3"
@inherits BasePkmdsComponent

<MudPaper Elevation="3"
@onclick="SetSelectedPokemon"
Width="68px"
Height="68px"
Expand Down
4 changes: 3 additions & 1 deletion Pkmds.Rcl/Components/PokemonStorageComponent.razor
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
@if (AppState.SaveFile is not null)
@inherits BasePkmdsComponent

@if (AppState.SaveFile is not null)
{
<PartyGrid />

Expand Down
8 changes: 5 additions & 3 deletions Pkmds.Rcl/Components/SaveFileComponent.razor
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
@if (AppState.SaveFile is null)
@inherits BasePkmdsComponent

@if (AppState.SaveFile is null)
{
@if (AppState.ShowProgressIndicator)
{
Expand All @@ -18,11 +20,11 @@
else
{
<PageTitle>
PKMDS Save Editor - @AppState.FileDisplayName
PKMDS Save Editor - <SaveFileNameDisplay />
</PageTitle>

<MudText Typo="Typo.h5">
@AppState.FileDisplayName
<SaveFileNameDisplay />
</MudText>

<MudGrid Spacing="1"
Expand Down
18 changes: 18 additions & 0 deletions Pkmds.Rcl/Components/SaveFileNameDisplay.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
@inherits BasePkmdsComponent

@if (AppState.SaveFile is { Gender: 0 or 1 } saveFile)
{
var gender = saveFile.Gender;
@Display(saveFile, gender)
}

@code {
private static RenderFragment Display(SaveFile saveFile, int gender) =>
@<MudStack Row="@true" Spacing="1">
<span>@saveFile.OT </span>
@GenderDisplayIcon(gender)
<span>(@saveFile.DisplayTID</span>
<span>, @saveFile.Version</span>
<span>, @saveFile.PlayTimeString)</span>
</MudStack>;
}
2 changes: 0 additions & 2 deletions Pkmds.Rcl/IAppState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ public interface IAppState

bool ShowProgressIndicator { get; set; }

string FileDisplayName { get; set; }

static string? AppVersion => Assembly.GetAssembly(typeof(App))?.GetName().Version?.ToString();

static string? PkhexVersion => Assembly.GetAssembly(typeof(PKM))?.GetName().Version?.ToString();
Expand Down
1 change: 0 additions & 1 deletion Pkmds.Rcl/Shared/MainLayout.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ private async Task LoadSaveFileAsync()
return;
}

AppState.FileDisplayName = $"{AppState.SaveFile.OT} ({AppState.SaveFile.DisplayTID}, {AppState.SaveFile.Version}, {AppState.SaveFile.PlayTimeString})";
RefreshService.Refresh();
}

Expand Down

0 comments on commit ab11602

Please sign in to comment.