Style & function extracting

This commit is contained in:
Kurt 2018-07-29 16:39:15 -07:00
parent 0de335d52b
commit 3fd21db51e
8 changed files with 176 additions and 101 deletions

View file

@ -115,5 +115,16 @@ namespace PKHeX.Core
message = null;
return true;
}
public static bool CanRecieveGift(this SaveFile SAV, MysteryGift gift)
{
if (gift.Species > SAV.MaxSpeciesID)
return false;
if (gift.Moves.Any(move => move > SAV.MaxMoveID))
return false;
if (gift.HeldItem > SAV.MaxItemID)
return false;
return true;
}
}
}

View file

@ -0,0 +1,60 @@
using System.Collections.Generic;
namespace PKHeX.Core
{
public sealed class RibbonInfo
{
public readonly string Name;
public bool HasRibbon { get; set; }
public int RibbonCount { get; set; }
private RibbonInfo(string name, bool hasRibbon)
{
Name = name;
HasRibbon = hasRibbon;
RibbonCount = -1;
}
private RibbonInfo(string name, int count)
{
Name = name;
HasRibbon = false;
RibbonCount = count;
}
public int MaxCount
{
get
{
if (RibbonCount < 0)
return -1;
switch (Name)
{
case nameof(IRibbonSetCommon6.RibbonCountMemoryContest):
return 40;
case nameof(IRibbonSetCommon6.RibbonCountMemoryBattle):
return 8;
default:
return 4; // g3 contest ribbons
}
}
}
public static IReadOnlyList<RibbonInfo> GetRibbonInfo(PKM pkm)
{
// Get a list of all Ribbon Attributes in the PKM
var riblist = new List<RibbonInfo>();
var names = ReflectUtil.GetPropertiesStartWithPrefix(pkm.GetType(), "Ribbon");
foreach (var name in names)
{
object RibbonValue = ReflectUtil.GetValue(pkm, name);
if (RibbonValue is int x)
riblist.Add(new RibbonInfo(name, x));
if (RibbonValue is bool b)
riblist.Add(new RibbonInfo(name, b));
}
return riblist;
}
}
}

View file

@ -4,7 +4,6 @@ namespace PKHeX.Core
{
public sealed class InventoryPouch4 : InventoryPouch
{
public InventoryPouch4(InventoryType type, ushort[] legal, int maxcount, int offset)
: base(type, legal, maxcount, offset)
{

View file

@ -13,6 +13,7 @@ namespace PKHeX.WinForms
public partial class BatchEditor : Form
{
private readonly SaveFile SAV;
public BatchEditor(PKM pk, SaveFile sav)
{
InitializeComponent();
@ -38,7 +39,6 @@ namespace PKHeX.WinForms
private int currentFormat = -1;
// GUI Methods
private void B_Open_Click(object sender, EventArgs e)
{
if (!B_Go.Enabled) return;
@ -49,15 +49,18 @@ namespace PKHeX.WinForms
TB_Folder.Text = fbd.SelectedPath;
TB_Folder.Visible = true;
}
private void B_SAV_Click(object sender, EventArgs e)
{
TB_Folder.Text = "";
TB_Folder.Visible = false;
}
private void B_Go_Click(object sender, EventArgs e)
{
RunBackgroundWorker();
}
private void B_Add_Click(object sender, EventArgs e)
{
if (CB_Property.SelectedIndex < 0)
@ -70,6 +73,7 @@ namespace PKHeX.WinForms
RTB_Instructions.AppendText(s);
}
private void CB_Format_SelectedIndexChanged(object sender, EventArgs e)
{
if (currentFormat == CB_Format.SelectedIndex)
@ -81,6 +85,7 @@ namespace PKHeX.WinForms
CB_Property.SelectedIndex = 0;
currentFormat = format;
}
private void CB_Property_SelectedIndexChanged(object sender, EventArgs e)
{
L_PropType.Text = BatchEditing.GetPropertyType(CB_Property.Text, CB_Format.SelectedIndex);
@ -95,11 +100,13 @@ namespace PKHeX.WinForms
L_PropType.ForeColor = Color.Red;
}
}
private static void TabMain_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
e.Effect = DragDropEffects.Copy;
}
private void TabMain_DragDrop(object sender, DragEventArgs e)
{
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
@ -113,6 +120,7 @@ namespace PKHeX.WinForms
}
private BackgroundWorker b;
private void RunBackgroundWorker()
{
if (RTB_Instructions.Lines.Any(line => line.Length == 0))
@ -155,6 +163,7 @@ namespace PKHeX.WinForms
}
RunBatchEdit(sets, TB_Folder.Text, destPath);
}
private void RunBatchEdit(StringInstructionSet[] sets, string source, string destination)
{
editor = new Core.BatchEditor();
@ -186,6 +195,7 @@ namespace PKHeX.WinForms
foreach (var set in sets)
ProcessFolder(files, set.Filters, set.Instructions, destination);
}
private void RunBatchEditSaveFile(IList<StringInstructionSet> sets, bool boxes = false, bool party = false)
{
IList<PKM> data;
@ -211,15 +221,18 @@ namespace PKHeX.WinForms
else
mi.Invoke();
}
private void SetProgressBar(int i)
{
if (PB_Show.InvokeRequired)
PB_Show.Invoke((MethodInvoker)(() => PB_Show.Value = i));
else { PB_Show.Value = i; }
else
PB_Show.Value = i;
}
// Mass Editing
private Core.BatchEditor editor = new Core.BatchEditor();
private void ProcessSAV(IList<PKM> data, IList<StringInstruction> Filters, IList<StringInstruction> Instructions)
{
for (int i = 0; i < data.Count; i++)
@ -228,6 +241,7 @@ namespace PKHeX.WinForms
b.ReportProgress(i);
}
}
private void ProcessFolder(IReadOnlyList<string> files, IList<StringInstruction> Filters, IList<StringInstruction> Instructions, string destPath)
{
for (int i = 0; i < files.Count; i++)

View file

@ -7,6 +7,7 @@ namespace PKHeX.WinForms
public partial class MemoryAmie : Form
{
private readonly TextMarkup TextArgs;
public MemoryAmie(PKM pk)
{
InitializeComponent();
@ -111,13 +112,17 @@ namespace PKHeX.WinForms
GB_M_CT.Text = $"{TextArgs.NeverLeft} {TextArgs.OT} - {TextArgs.Disabled}"; // Never Left : OT : Disabled
}
else
{
GB_M_CT.Text = $"{TextArgs.MemoriesWith} {pkm.HT_Name}";
}
}
RTB_OT.Visible = CB_OTQual.Enabled = CB_OTMemory.Enabled = CB_OTFeel.Enabled = CB_OTVar.Enabled = enable;
M_OT_Affection.Enabled = true;
}
else
{
GB_M_OT.Text = GB_M_CT.Text = $"N/A: {GameInfo.Strings.eggname}";
}
init = true;
@ -125,6 +130,7 @@ namespace PKHeX.WinForms
RTB_CT.Text = GetMemoryString(CB_CTMemory, CB_CTVar, CB_CTQual, CB_CTFeel, pkm.HT_Name);
RTB_OT.Text = GetMemoryString(CB_OTMemory, CB_OTVar, CB_OTQual, CB_OTFeel, pkm.OT_Name);
}
private void SaveFields()
{
// Save Region & Country Data
@ -168,6 +174,7 @@ namespace PKHeX.WinForms
SaveFields();
Close();
}
private void B_Cancel_Click(object sender, EventArgs e)
{
Close();
@ -195,6 +202,7 @@ namespace PKHeX.WinForms
CB_OTFeel.Items.Add(q);
}
}
private void UpdateMemoryDisplay(object sender)
{
int memory = WinFormsUtil.GetIndex((ComboBox) sender);
@ -215,6 +223,7 @@ namespace PKHeX.WinForms
LOTV.Visible = CB_OTVar.Visible = CB_OTVar.Enabled = argvals.Count > 1;
}
}
private string GetMemoryString(ComboBox m, Control arg, Control q, Control f, string tr)
{
string result;
@ -272,6 +281,7 @@ namespace PKHeX.WinForms
mta[index].SelectedValue = 0;
}
}
private void ChangeCountryText(object sender, EventArgs e)
{
if (!(sender is ComboBox cb) || !string.IsNullOrWhiteSpace(cb.Text))

View file

@ -12,6 +12,7 @@ namespace PKHeX.WinForms
public RibbonEditor(PKM pk)
{
pkm = pk;
riblist = RibbonInfo.GetRibbonInfo(pkm);
InitializeComponent();
int vertScrollWidth = SystemInformation.VerticalScrollBarWidth;
TLP_Ribbons.Padding = FLP_Ribbons.Padding = new Padding(0, 0, vertScrollWidth, 0);
@ -25,36 +26,25 @@ namespace PKHeX.WinForms
TLP_Ribbons.ResumeLayout();
}
private readonly List<RibbonInfo> riblist = new List<RibbonInfo>();
private readonly IReadOnlyList<RibbonInfo> riblist;
private readonly PKM pkm;
private readonly ToolTip tipName = new ToolTip();
private const string PrefixNUD = "NUD_";
private const string PrefixLabel = "L_";
private const string PrefixCHK = "CHK_";
private const string PrefixPB = "PB_";
private void B_Cancel_Click(object sender, EventArgs e)
{
Close();
}
private void B_Cancel_Click(object sender, EventArgs e) => Close();
private void B_Save_Click(object sender, EventArgs e)
{
Save();
Close();
}
private readonly ToolTip tipName = new ToolTip();
private void PopulateRibbons()
{
// Get a list of all Ribbon Attributes in the PKM
var RibbonNames = ReflectUtil.GetPropertiesStartWithPrefix(pkm.GetType(), "Ribbon");
foreach (var RibbonName in RibbonNames)
{
object RibbonValue = ReflectUtil.GetValue(pkm, RibbonName);
if (RibbonValue is int x)
riblist.Add(new RibbonInfo(RibbonName, x));
if (RibbonValue is bool b)
riblist.Add(new RibbonInfo(RibbonName, b));
}
TLP_Ribbons.ColumnCount = 2;
TLP_Ribbons.RowCount = 0;
@ -70,10 +60,11 @@ namespace PKHeX.WinForms
foreach (ColumnStyle style in TLP_Ribbons.ColumnStyles)
style.SizeType = SizeType.AutoSize;
}
private void AddRibbonSprite(RibbonInfo rib)
{
var name = rib.Name;
PictureBox pb = new PictureBox { AutoSize = false, Size = new Size(40,40), BackgroundImageLayout = ImageLayout.Center, Visible = false, Name = PrefixPB + name };
var pb = new PictureBox { AutoSize = false, Size = new Size(40,40), BackgroundImageLayout = ImageLayout.Center, Visible = false, Name = PrefixPB + name };
var img = SpriteUtil.GetRibbonSprite(name);
if (img != null)
pb.BackgroundImage = (Bitmap)img;
@ -84,6 +75,7 @@ namespace PKHeX.WinForms
pb.MouseEnter += (s, e) => tipName.SetToolTip(pb, display);
FLP_Ribbons.Controls.Add(pb);
}
private void AddRibbonChoice(RibbonInfo rib)
{
// Get row we add to
@ -106,6 +98,7 @@ namespace PKHeX.WinForms
else // boolean ribbon
AddRibbonCheckBox(rib, row, label);
}
private void AddRibbonNumericUpDown(RibbonInfo rib, int row)
{
var nud = new NumericUpDown
@ -117,45 +110,18 @@ namespace PKHeX.WinForms
Increment = 1,
Padding = Padding.Empty,
Margin = Padding.Empty,
Maximum = rib.MaxCount,
};
if (rib.Name.Contains("MemoryContest"))
nud.Maximum = 40;
else if (rib.Name.Contains("MemoryBattle"))
nud.Maximum = 8;
else nud.Maximum = 4; // g3 contest ribbons
nud.ValueChanged += (sender, e) =>
{
rib.RibbonCount = (int) nud.Value;
FLP_Ribbons.Controls[PrefixPB + rib.Name].Visible = rib.RibbonCount > 0;
if (nud.Maximum == 4)
{
string n = rib.Name.Replace("Count", "");
switch ((int) nud.Value)
{
case 2:
n += "Super";
break;
case 3:
n += "Hyper";
break;
case 4:
n += "Master";
break;
}
FLP_Ribbons.Controls[PrefixPB + rib.Name].BackgroundImage =
(Bitmap) Properties.Resources.ResourceManager.GetObject(n.ToLower());
}
else if (nud.Maximum == nud.Value)
FLP_Ribbons.Controls[PrefixPB + rib.Name].BackgroundImage =
(Bitmap) Properties.Resources.ResourceManager.GetObject(rib.Name.ToLower() + "2");
else
FLP_Ribbons.Controls[PrefixPB + rib.Name].BackgroundImage =
(Bitmap) Properties.Resources.ResourceManager.GetObject(rib.Name.ToLower());
FLP_Ribbons.Controls[PrefixPB + rib.Name].Visible = (rib.RibbonCount = (int)nud.Value) > 0;
FLP_Ribbons.Controls[PrefixPB + rib.Name].BackgroundImage = SpriteUtil.GetRibbonSprite(rib.Name, (int)nud.Maximum, (int)nud.Value);
};
nud.Value = rib.RibbonCount > nud.Maximum ? nud.Maximum : rib.RibbonCount;
TLP_Ribbons.Controls.Add(nud, 0, row);
}
private void AddRibbonCheckBox(RibbonInfo rib, int row, Control label)
{
var chk = new CheckBox
@ -183,25 +149,6 @@ namespace PKHeX.WinForms
ReflectUtil.SetValue(pkm, rib.Name, rib.RibbonCount < 0 ? rib.HasRibbon : (object) rib.RibbonCount);
}
private sealed class RibbonInfo
{
internal readonly string Name;
internal bool HasRibbon { get; set; }
internal int RibbonCount { get; set; }
internal RibbonInfo(string name, bool hasRibbon)
{
Name = name;
HasRibbon = hasRibbon;
RibbonCount = -1;
}
internal RibbonInfo(string name, int count)
{
Name = name;
HasRibbon = false;
RibbonCount = count;
}
}
private void B_All_Click(object sender, EventArgs e)
{
foreach (var c in TLP_Ribbons.Controls.OfType<CheckBox>())
@ -209,6 +156,7 @@ namespace PKHeX.WinForms
foreach (var n in TLP_Ribbons.Controls.OfType<NumericUpDown>())
n.Value = n.Maximum;
}
private void B_None_Click(object sender, EventArgs e)
{
foreach (var c in TLP_Ribbons.Controls.OfType<CheckBox>())

View file

@ -1,10 +1,10 @@
using System;
using PKHeX.Core;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Windows.Forms;
using PKHeX.Core;
using static PKHeX.Core.MessageStrings;
namespace PKHeX.WinForms
@ -13,6 +13,7 @@ namespace PKHeX.WinForms
{
private readonly SaveFile Origin;
private readonly SaveFile SAV;
public SAV_Wondercard(SaveFile sav, MysteryGift g = null)
{
InitializeComponent();
@ -58,7 +59,7 @@ namespace PKHeX.WinForms
ViewGiftData(g);
}
private MysteryGiftAlbum mga;
private readonly MysteryGiftAlbum mga;
private MysteryGift mg;
private readonly PictureBox[] pba;
@ -68,6 +69,7 @@ namespace PKHeX.WinForms
for (int i = 0; i < mga.Gifts.Length; i++)
pba[i].BackgroundImage = index == i ? bg : null;
}
private void SetGiftBoxes()
{
for (int i = 0; i < mga.Gifts.Length; i++)
@ -76,6 +78,7 @@ namespace PKHeX.WinForms
pba[i].Image = m.Sprite();
}
}
private void ViewGiftData(MysteryGift g)
{
try
@ -94,16 +97,20 @@ namespace PKHeX.WinForms
RTB.Clear();
}
}
private void GetReceivedFlags()
{
LB_Received.Items.Clear();
for (int i = 1; i < mga.Flags.Length; i++)
{
if (mga.Flags[i])
LB_Received.Items.Add(i.ToString("0000"));
}
if (LB_Received.Items.Count > 0)
LB_Received.SelectedIndex = 0;
}
private void SetCardID(int cardID)
{
if (cardID <= 0 || cardID >= 0x100 * 8) return;
@ -129,6 +136,7 @@ namespace PKHeX.WinForms
}
ViewGiftData(g);
}
private void B_Output_Click(object sender, EventArgs e)
{
WinFormsUtil.SaveMGDialog(mg);
@ -155,6 +163,7 @@ namespace PKHeX.WinForms
SetBackground(index, Properties.Resources.slotView);
ViewGiftData(mga.Gifts[index]);
}
private void ClickSet(object sender, EventArgs e)
{
if (!mg.IsCardCompatible(SAV, out var msg))
@ -172,7 +181,9 @@ namespace PKHeX.WinForms
index = lastUnfilled;
if (mg is PCD pcd && mga.Gifts[index] is PGT)
{
mg = pcd.Gift;
}
else if (mg.Type != mga.Gifts[index].Type)
{
WinFormsUtil.Alert(MsgMysteryGiftSlotFail, $"{mg.Type} != {mga.Gifts[index].Type}");
@ -183,6 +194,7 @@ namespace PKHeX.WinForms
SetGiftBoxes();
SetCardID(mg.CardID);
}
private void ClickDelete(object sender, EventArgs e)
{
sender = WinFormsUtil.GetUnderlyingControl(sender);
@ -216,6 +228,7 @@ namespace PKHeX.WinForms
{
Close();
}
private void B_Save_Click(object sender, EventArgs e)
{
// Make sure all of the Received Flags are flipped!
@ -246,6 +259,7 @@ namespace PKHeX.WinForms
{
if (e.Data.GetDataPresent(DataFormats.FileDrop)) e.Effect = DragDropEffects.Copy;
}
private void Main_DragDrop(object sender, DragEventArgs e)
{
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
@ -256,19 +270,18 @@ namespace PKHeX.WinForms
if (files.Length == 1 && !Directory.Exists(files[0]))
{
string path = files[0]; // open first D&D
long len = new FileInfo(path).Length;
if (len > 0x1000) // arbitrary
if (!MysteryGift.IsMysteryGift(new FileInfo(path).Length)) // arbitrary
{
WinFormsUtil.Alert(MsgMysteryGiftInvalid, path);
return;
}
MysteryGift g = MysteryGift.GetMysteryGift(File.ReadAllBytes(path), Path.GetExtension(path));
if (g == null)
var gift = MysteryGift.GetMysteryGift(File.ReadAllBytes(path), Path.GetExtension(path));
if (gift == null)
{
WinFormsUtil.Error(MsgMysteryGiftInvalid, path);
return;
}
ViewGiftData(g);
ViewGiftData(gift);
return;
}
SetGiftBoxes();
@ -287,6 +300,7 @@ namespace PKHeX.WinForms
}
ExportQRFromView();
}
private void ExportQRFromView()
{
if (mg.Data.All(z => z == 0))
@ -309,6 +323,7 @@ namespace PKHeX.WinForms
new QR(qr, PB_Preview.Image, null, desc + Environment.NewLine + "PKHeX Wonder Card @ ProjectPokemon.org").ShowDialog();
}
private void ImportQRToView(string url)
{
byte[] data = QR.GetQRData(url);
@ -322,23 +337,12 @@ namespace PKHeX.WinForms
if (mga.Gifts.All(card => card.Data.Length != data.Length))
WinFormsUtil.Alert(MsgMysteryGiftQRTypeLength, string.Format(MsgQRDecodeSize, $"0x{data.Length:X}"));
else if (types.All(type => type != giftType))
WinFormsUtil.Alert(MsgMysteryGiftTypeIncompatible,
$"{MsgMysteryGiftQRRecieved} {gift.Type}{Environment.NewLine}{MsgMysteryGiftTypeUnexpected} {string.Join(", ", types)}");
else if (!CanRecieveGift(SAV, gift))
WinFormsUtil.Alert(MsgMysteryGiftTypeIncompatible, $"{MsgMysteryGiftQRRecieved} {gift.Type}{Environment.NewLine}{MsgMysteryGiftTypeUnexpected} {string.Join(", ", types)}");
else if (!SAV.CanRecieveGift(gift))
WinFormsUtil.Alert(MsgMysteryGiftTypeDetails);
else
ViewGiftData(gift);
}
private static bool CanRecieveGift(SaveFile SAV, MysteryGift gift)
{
if (gift.Species > SAV.MaxSpeciesID)
return false;
if (gift.Moves.Any(move => move > SAV.MaxMoveID))
return false;
if (gift.HeldItem > SAV.MaxItemID)
return false;
return true;
}
private void BoxSlot_MouseDown(object sender, MouseEventArgs e)
{
@ -348,7 +352,7 @@ namespace PKHeX.WinForms
case Keys.Shift: ClickSet(sender, e); return;
case Keys.Alt: ClickDelete(sender, e); return;
}
PictureBox pb = sender as PictureBox;
var pb = sender as PictureBox;
if (pb?.Image == null)
return;
@ -359,15 +363,12 @@ namespace PKHeX.WinForms
// Create Temp File to Drag
Cursor.Current = Cursors.Hand;
// Prepare Data
MysteryGift card = mga.Gifts[index];
string filename = Util.CleanFileName($"{card.CardID:0000} - {card.CardTitle}.{card.Extension}");
// Make File
string newfile = Path.Combine(Path.GetTempPath(), Util.CleanFileName(filename));
var gift = mga.Gifts[index];
string newfile = Path.Combine(Path.GetTempPath(), Util.CleanFileName(gift.FileName));
try
{
File.WriteAllBytes(newfile, card.Data);
File.WriteAllBytes(newfile, gift.Data);
DoDragDrop(new DataObject(DataFormats.FileDrop, new[] { newfile }), DragDropEffects.Move);
}
catch (Exception x)
@ -375,6 +376,7 @@ namespace PKHeX.WinForms
File.Delete(newfile);
wc_slot = -1;
}
private void BoxSlot_DragDrop(object sender, DragEventArgs e)
{
int index = Array.IndexOf(pba, sender);
@ -390,14 +392,16 @@ namespace PKHeX.WinForms
if (files.Length < 1)
return;
if (PCD.Size < (int)new FileInfo(files[0]).Length)
if (!MysteryGift.IsMysteryGift(new FileInfo(files[0]).Length))
{ WinFormsUtil.Alert(MsgFileUnsupported, files[0]); return; }
byte[] data = File.ReadAllBytes(files[0]);
MysteryGift gift = MysteryGift.GetMysteryGift(data, new FileInfo(files[0]).Extension);
if (gift is PCD pcd && mga.Gifts[index] is PGT)
{
gift = pcd.Gift;
}
else if (gift.Type != mga.Gifts[index].Type)
{
WinFormsUtil.Alert(MsgMysteryGiftSlotFail, $"{gift.Type} != {mga.Gifts[index].Type}");
@ -450,6 +454,7 @@ namespace PKHeX.WinForms
SetBackground(index, Properties.Resources.slotView);
SetGiftBoxes();
}
private static void BoxSlot_DragEnter(object sender, DragEventArgs e)
{
if (e.AllowedEffect == (DragDropEffects.Copy | DragDropEffects.Link)) // external file
@ -457,6 +462,7 @@ namespace PKHeX.WinForms
else if (e.Data != null) // within
e.Effect = DragDropEffects.Move;
}
private int wc_slot = -1;
// UI Generation
@ -498,14 +504,15 @@ namespace PKHeX.WinForms
FLP_Gifts.Controls.Add(f3);
return pb;
}
private List<PictureBox> PopulateViewGiftsG567()
{
List<PictureBox> pb = new List<PictureBox>();
var pb = new List<PictureBox>();
for (int i = 0; i < mga.Gifts.Length / 6; i++)
{
var flp = GetFlowLayoutPanel();
flp.Controls.Add(GetLabel($"{i * 6 + 1}-{i * 6 + 6}"));
flp.Controls.Add(GetLabel($"{(i * 6) + 1}-{(i * 6) + 6}"));
for (int j = 0; j < 6; j++)
{
var p = GetPictureBox();
@ -516,6 +523,7 @@ namespace PKHeX.WinForms
}
return pb;
}
private static FlowLayoutPanel GetFlowLayoutPanel()
{
return new FlowLayoutPanel
@ -526,6 +534,7 @@ namespace PKHeX.WinForms
Margin = new Padding(0),
};
}
private static Label GetLabel(string text)
{
return new Label
@ -538,6 +547,7 @@ namespace PKHeX.WinForms
Margin = new Padding(0),
};
}
private static PictureBox GetPictureBox()
{
return new PictureBox

View file

@ -24,6 +24,29 @@ namespace PKHeX.WinForms
return Resources.ResourceManager.GetObject(name.Replace("CountG3", "G3").ToLower()) as Image;
}
public static Image GetRibbonSprite(string name, int max, int value)
{
var resource = GetRibbonSpriteName(name, max, value);
return (Bitmap)Resources.ResourceManager.GetObject(resource);
}
private static string GetRibbonSpriteName(string name, int max, int value)
{
if (max != 4) // Memory
return name.ToLower() + (max == value ? "2" : "");
// Count ribbons
string n = name.Replace("Count", "");
switch (value)
{
case 2: return (n + "Super").ToLower();
case 3: return (n + "Hyper").ToLower();
case 4: return (n + "Master").ToLower();
default:
return n.ToLower();
}
}
public static Image GetTypeSprite(int type, int generation = PKX.Generation)
{
if (generation <= 2)