2019-02-15 04:23:51 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2019-02-15 04:18:31 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
using PKHeX.Core;
|
2021-11-27 23:48:08 +00:00
|
|
|
|
using PKHeX.Drawing.PokeSprite;
|
2019-02-15 04:18:31 +00:00
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-15 04:23:51 +00:00
|
|
|
|
public void LoadBalls(PKM pkm)
|
|
|
|
|
{
|
2020-01-26 00:47:44 +00:00
|
|
|
|
var legal = BallApplicator.GetLegalBalls(pkm).ToArray();
|
2019-02-15 04:23:51 +00:00
|
|
|
|
var poss = ((Ball[])Enum.GetValues(typeof(Ball))).Skip(1)
|
|
|
|
|
.TakeWhile(z => (int)z <= pkm.MaxBallID).ToArray();
|
|
|
|
|
var names = GameInfo.BallDataSource;
|
|
|
|
|
LoadBalls(poss, legal, names);
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-15 04:18:31 +00:00
|
|
|
|
private PictureBox GetBallView(Ball b, ICollection<Ball> legal, IReadOnlyList<ComboItem> names)
|
|
|
|
|
{
|
2019-02-15 08:50:23 +00:00
|
|
|
|
var img = SpriteUtil.GetBallSprite((int)b);
|
2019-02-15 04:18:31 +00:00
|
|
|
|
var pb = new PictureBox
|
|
|
|
|
{
|
|
|
|
|
Size = img.Size,
|
|
|
|
|
Image = img,
|
2019-11-16 01:34:18 +00:00
|
|
|
|
BackgroundImage = legal.Contains(b) ? SpriteUtil.Spriter.Set : SpriteUtil.Spriter.Delete,
|
2021-08-20 20:49:20 +00:00
|
|
|
|
BackgroundImageLayout = ImageLayout.Tile,
|
2019-02-15 04:18:31 +00:00
|
|
|
|
};
|
2022-04-27 02:48:09 +00:00
|
|
|
|
pb.MouseEnter += (_, _) => Text = names.First(z => z.Value == (int)b).Text;
|
|
|
|
|
pb.Click += (_, _) => SelectBall(b);
|
2019-02-15 04:18:31 +00:00
|
|
|
|
return pb;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SelectBall(Ball b)
|
|
|
|
|
{
|
|
|
|
|
BallChoice = (int)b;
|
|
|
|
|
Close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|