PKHeX/PKHeX.WinForms/Controls/PKM Editor/BallBrowser.cs
Kurt 94baab1c45
Split off image generation to separate project (#2395)
With the approaching games, PKM sprites are a different size from the 3DS era (as already hinted by LGPE, which has 56x68). It'll be a little easier to manage with this portion of the library walled off from the rest of the codebase.

Eventually the net46 target will use fody or something to merge in these extra dependency dll's automatically to not disturb the usual exe/dll experience.
2019-09-29 09:47:06 -07:00

60 lines
1.9 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using PKHeX.Core;
using PKHeX.Drawing;
using PKHeX.WinForms.Properties;
namespace PKHeX.WinForms
{
public partial class BallBrowser : Form
{
public BallBrowser() => InitializeComponent();
public int BallChoice { get; private set; } = -1;
public void LoadBalls(Ball[] poss, ICollection<Ball> legal, IReadOnlyList<ComboItem> names)
{
for (int i = 0; i < poss.Length; i++)
{
var pb = GetBallView(poss[i], legal, names);
flp.Controls.Add(pb);
const int width = 5; // balls wide
if (i % width == width - 1)
flp.SetFlowBreak(pb, true);
}
}
public void LoadBalls(PKM pkm)
{
var legal = BallRandomizer.GetLegalBalls(pkm).ToArray();
var poss = ((Ball[])Enum.GetValues(typeof(Ball))).Skip(1)
.TakeWhile(z => (int)z <= pkm.MaxBallID).ToArray();
var names = GameInfo.BallDataSource;
LoadBalls(poss, legal, names);
}
private PictureBox GetBallView(Ball b, ICollection<Ball> legal, IReadOnlyList<ComboItem> names)
{
var img = SpriteUtil.GetBallSprite((int)b);
var pb = new PictureBox
{
Size = img.Size,
Image = img,
BackgroundImage = legal.Contains(b) ? Resources.slotSet : Resources.slotDel,
BackgroundImageLayout = ImageLayout.Tile
};
pb.MouseEnter += (_, __) => Text = names.First(z => z.Value == (int)b).Text;
pb.Click += (_, __) => SelectBall(b);
return pb;
}
private void SelectBall(Ball b)
{
BallChoice = (int)b;
Close();
}
}
}