mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-14 16:27:21 +00:00
Extract summary object to core
This commit is contained in:
parent
82f305cd36
commit
c7eecf5976
4 changed files with 39 additions and 14 deletions
|
@ -1,19 +1,23 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using PKHeX.Core;
|
||||
|
||||
namespace PKHeX.WinForms
|
||||
namespace PKHeX.Core
|
||||
{
|
||||
public class PKMPreview
|
||||
/// <summary>
|
||||
/// Bindable summary object that can fetch strings that summarize a <see cref="PKM"/>.
|
||||
/// </summary>
|
||||
public class PKMSummary
|
||||
{
|
||||
private readonly PKM pkm;
|
||||
private static readonly IReadOnlyList<string> GenderSymbols = GameInfo.GenderSymbolASCII;
|
||||
|
||||
private readonly GameStrings Strings;
|
||||
private readonly ushort[] Stats;
|
||||
protected readonly PKM pkm; // protected for children generating extra properties
|
||||
|
||||
public string Position => pkm.Identifier;
|
||||
public Image Sprite => pkm.Sprite();
|
||||
public string Nickname => pkm.Nickname;
|
||||
public string Species => Get(Strings.specieslist, pkm.Species);
|
||||
public string Nature => Get(Strings.natures, pkm.Nature);
|
||||
public string Gender => Get(Main.GenderSymbols, pkm.Gender);
|
||||
public string Gender => Get(GenderSymbols, pkm.Gender);
|
||||
public string ESV => pkm.PSV.ToString("0000");
|
||||
public string HP_Type => Get(Strings.types, pkm.HPType + 1);
|
||||
public string Ability => Get(Strings.abilitylist, pkm.Ability);
|
||||
|
@ -107,15 +111,19 @@ namespace PKHeX.WinForms
|
|||
|
||||
#endregion
|
||||
|
||||
private readonly GameStrings Strings;
|
||||
|
||||
public PKMPreview(PKM p, GameStrings strings)
|
||||
protected PKMSummary(PKM p, GameStrings strings)
|
||||
{
|
||||
pkm = p;
|
||||
Strings = strings;
|
||||
Stats = pkm.GetStats(pkm.PersonalInfo);
|
||||
}
|
||||
|
||||
private static string Get(IReadOnlyList<string> arr, int val) => arr?.Count > val && val >= 0 ? arr[val] : null;
|
||||
/// <summary>
|
||||
/// Safely fetches the string from the array.
|
||||
/// </summary>
|
||||
/// <param name="arr">Array of strings</param>
|
||||
/// <param name="val">Index to fetch</param>
|
||||
/// <returns>Null if array is null</returns>
|
||||
private static string Get(IReadOnlyList<string> arr, int val) => (uint)val < arr?.Count ? arr[val] : null;
|
||||
}
|
||||
}
|
|
@ -308,7 +308,7 @@
|
|||
<DesignTime>True</DesignTime>
|
||||
<DependentUpon>Resources.resx</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Subforms\Misc\PKMPreview.cs" />
|
||||
<Compile Include="Subforms\Misc\PKMSummaryImage.cs" />
|
||||
<Compile Include="Subforms\Misc\PropertyComparer.cs" />
|
||||
<Compile Include="Subforms\Save Editors\Gen4\PoffinCase4Editor.cs">
|
||||
<SubType>UserControl</SubType>
|
||||
|
|
17
PKHeX.WinForms/Subforms/Misc/PKMSummaryImage.cs
Normal file
17
PKHeX.WinForms/Subforms/Misc/PKMSummaryImage.cs
Normal file
|
@ -0,0 +1,17 @@
|
|||
using System.Drawing;
|
||||
using PKHeX.Core;
|
||||
|
||||
namespace PKHeX.WinForms
|
||||
{
|
||||
/// <summary>
|
||||
/// Bindable summary object that can fetch sprite and strings that summarize a <see cref="PKM"/>.
|
||||
/// </summary>
|
||||
public class PKMSummaryImage : PKMSummary
|
||||
{
|
||||
public Image Sprite => pkm.Sprite();
|
||||
|
||||
public PKMSummaryImage(PKM p, GameStrings strings) : base(p, strings)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
|
@ -54,12 +54,12 @@ namespace PKHeX.WinForms
|
|||
{
|
||||
SuspendLayout();
|
||||
BoxBar.Step = 1;
|
||||
var PL = new PokemonList<PKMPreview>();
|
||||
var PL = new PokemonList<PKMSummaryImage>();
|
||||
var strings = GameInfo.Strings;
|
||||
foreach (PKM pkm in Data.Where(pkm => pkm.ChecksumValid && pkm.Species != 0))
|
||||
{
|
||||
pkm.Stat_Level = Experience.GetLevel(pkm.EXP, pkm.Species, pkm.AltForm); // recalc Level
|
||||
PL.Add(new PKMPreview(pkm, strings));
|
||||
PL.Add(new PKMSummaryImage(pkm, strings));
|
||||
BoxBar.PerformStep();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue