2022-08-17 00:16:39 +00:00
|
|
|
using System;
|
2019-02-15 04:23:51 +00:00
|
|
|
using System.Collections.Generic;
|
2019-02-15 04:18:31 +00:00
|
|
|
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
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
namespace PKHeX.WinForms;
|
|
|
|
|
|
|
|
public partial class BallBrowser : Form
|
2019-02-15 04:18:31 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
public BallBrowser() => InitializeComponent();
|
2019-02-15 04:18:31 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public int BallChoice { get; private set; } = -1;
|
2019-02-15 04:18:31 +00:00
|
|
|
|
2022-08-17 00:16:39 +00:00
|
|
|
public void LoadBalls(PKM pk)
|
|
|
|
{
|
|
|
|
var legal = BallApplicator.GetLegalBalls(pk);
|
|
|
|
LoadBalls(legal, pk.MaxBallID + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void LoadBalls(IEnumerable<Ball> legal, int max)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
2022-08-17 00:16:39 +00:00
|
|
|
Span<bool> flags = stackalloc bool[max];
|
|
|
|
foreach (var ball in legal)
|
|
|
|
flags[(int)ball] = true;
|
|
|
|
|
|
|
|
int countLegal = 0;
|
|
|
|
List<PictureBox> controls = new();
|
|
|
|
var names = GameInfo.BallDataSource;
|
|
|
|
for (int ballID = 1; ballID < flags.Length; ballID++)
|
|
|
|
{
|
|
|
|
var name = GetBallName(ballID, names);
|
|
|
|
var pb = GetBallView(ballID, name, flags[ballID]);
|
|
|
|
if (Main.Settings.EntityEditor.ShowLegalBallsFirst && flags[ballID])
|
|
|
|
controls.Insert(countLegal++, pb);
|
|
|
|
else
|
|
|
|
controls.Add(pb);
|
|
|
|
}
|
|
|
|
|
|
|
|
int countInRow = 0;
|
|
|
|
var container = flp.Controls;
|
|
|
|
foreach (var pb in controls)
|
2019-02-15 04:18:31 +00:00
|
|
|
{
|
2022-08-17 00:16:39 +00:00
|
|
|
container.Add(pb);
|
2022-06-18 18:04:24 +00:00
|
|
|
const int width = 5; // balls wide
|
2022-08-17 00:16:39 +00:00
|
|
|
if (++countInRow != width)
|
|
|
|
continue;
|
|
|
|
flp.SetFlowBreak(pb, true);
|
|
|
|
countInRow = 0;
|
2019-02-15 04:18:31 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2019-02-15 04:18:31 +00:00
|
|
|
|
2022-08-17 00:16:39 +00:00
|
|
|
private static string GetBallName(int ballID, IEnumerable<ComboItem> names)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
2022-08-17 00:16:39 +00:00
|
|
|
foreach (var x in names)
|
|
|
|
{
|
|
|
|
if (x.Value == ballID)
|
|
|
|
return x.Text;
|
|
|
|
}
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(ballID));
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2019-02-15 04:23:51 +00:00
|
|
|
|
2022-08-17 00:16:39 +00:00
|
|
|
private PictureBox GetBallView(int ballID, string name, bool valid)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
2022-08-17 00:16:39 +00:00
|
|
|
var img = SpriteUtil.GetBallSprite(ballID);
|
2022-06-18 18:04:24 +00:00
|
|
|
var pb = new PictureBox
|
2019-02-15 04:18:31 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
Size = img.Size,
|
|
|
|
Image = img,
|
2022-08-17 00:16:39 +00:00
|
|
|
BackgroundImage = valid ? SpriteUtil.Spriter.Set : SpriteUtil.Spriter.Delete,
|
2022-06-18 18:04:24 +00:00
|
|
|
BackgroundImageLayout = ImageLayout.Tile,
|
|
|
|
};
|
2022-08-17 00:16:39 +00:00
|
|
|
|
|
|
|
pb.MouseEnter += (_, _) => Text = name;
|
|
|
|
pb.Click += (_, _) => SelectBall(ballID);
|
2022-06-18 18:04:24 +00:00
|
|
|
return pb;
|
|
|
|
}
|
2019-02-15 04:18:31 +00:00
|
|
|
|
2022-08-17 00:16:39 +00:00
|
|
|
private void SelectBall(int b)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
2022-08-17 00:16:39 +00:00
|
|
|
BallChoice = b;
|
2022-06-18 18:04:24 +00:00
|
|
|
Close();
|
2019-02-15 04:18:31 +00:00
|
|
|
}
|
|
|
|
}
|