2022-06-18 18:04:24 +00:00
|
|
|
using System.Collections.Generic;
|
2019-11-16 01:34:18 +00:00
|
|
|
using System.Diagnostics;
|
2019-10-03 03:04:12 +00:00
|
|
|
using System.Drawing;
|
2021-05-09 19:10:32 +00:00
|
|
|
using System.Linq;
|
2019-10-03 03:04:12 +00:00
|
|
|
using System.Windows.Forms;
|
2021-11-27 23:48:08 +00:00
|
|
|
using PKHeX.Drawing.PokeSprite;
|
2019-10-03 03:04:12 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
namespace PKHeX.WinForms.Controls;
|
|
|
|
|
|
|
|
public partial class PokeGrid : UserControl
|
2019-10-03 03:04:12 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
public PokeGrid()
|
2019-10-03 03:04:12 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
InitializeComponent();
|
|
|
|
}
|
2019-10-03 03:04:12 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public readonly List<PictureBox> Entries = new();
|
|
|
|
public int Slots { get; private set; }
|
2019-10-03 03:04:12 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private int sizeW = 68;
|
|
|
|
private int sizeH = 56;
|
2019-10-03 03:04:12 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public bool InitializeGrid(int width, int height, SpriteBuilder info)
|
|
|
|
{
|
|
|
|
var newCount = width * height;
|
|
|
|
if (Slots == newCount)
|
2019-10-03 03:04:12 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
if (info.Width == sizeW && info.Height == sizeH)
|
|
|
|
return false;
|
|
|
|
}
|
2019-10-03 03:04:12 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
sizeW = info.Width;
|
|
|
|
sizeH = info.Height;
|
|
|
|
Generate(width, height);
|
|
|
|
Slots = newCount;
|
2019-10-03 03:04:12 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
return true;
|
|
|
|
}
|
2019-10-03 03:04:12 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private const int padEdge = 1; // edges
|
|
|
|
private const int border = 1; // between
|
2019-10-03 03:04:12 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void Generate(int width, int height)
|
|
|
|
{
|
|
|
|
SuspendLayout();
|
|
|
|
Controls.Clear();
|
|
|
|
foreach (var c in Entries)
|
|
|
|
c.Dispose();
|
|
|
|
Entries.Clear();
|
2019-10-03 03:04:12 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
int colWidth = sizeW;
|
|
|
|
int rowHeight = sizeH;
|
2019-10-03 03:04:12 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
Location = Location with { X = 0 }; // prevent auto-expanding parent if position changes (centered)
|
|
|
|
for (int row = 0; row < height; row++)
|
|
|
|
{
|
|
|
|
var y = padEdge + (row * (rowHeight + border));
|
|
|
|
for (int column = 0; column < width; column++)
|
2019-10-03 03:04:12 +00:00
|
|
|
{
|
2023-02-05 08:42:37 +00:00
|
|
|
var name = $"Pokémon Grid Row {row:00} Column {column:00}";
|
2022-06-18 18:04:24 +00:00
|
|
|
var x = padEdge + (column * (colWidth + border));
|
2023-02-05 08:42:37 +00:00
|
|
|
var pb = GetControl(sizeW, sizeH, name);
|
2022-06-18 18:04:24 +00:00
|
|
|
pb.Location = new Point(x, y);
|
|
|
|
Entries.Add(pb);
|
2019-10-03 03:04:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
int w = (2 * padEdge) + border + (width * (colWidth + border));
|
|
|
|
int h = (2 * padEdge) + border + (height * (rowHeight + border));
|
|
|
|
Size = new Size(w, h);
|
|
|
|
Controls.AddRange(Entries.Cast<Control>().ToArray());
|
|
|
|
Debug.WriteLine($"{Name} -- Width: {Width}, Height: {Height}");
|
|
|
|
ResumeLayout();
|
2019-10-03 03:04:12 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
|
|
|
|
public void SetBackground(Image img) => BackgroundImage = img;
|
|
|
|
|
2023-02-05 08:42:37 +00:00
|
|
|
public static SelectablePictureBox GetControl(int width, int height, string name) => new()
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
AutoSize = false,
|
|
|
|
SizeMode = PictureBoxSizeMode.CenterImage,
|
|
|
|
BackColor = SlotUtil.GoodDataColor,
|
|
|
|
Width = width + (2 * border),
|
|
|
|
Height = height + (2 * border),
|
|
|
|
Padding = Padding.Empty,
|
|
|
|
Margin = Padding.Empty,
|
|
|
|
BorderStyle = BorderStyle.FixedSingle,
|
2023-02-05 08:42:37 +00:00
|
|
|
AccessibleRole = AccessibleRole.Alert,
|
|
|
|
Name = name,
|
|
|
|
AccessibleName = name,
|
2022-06-18 18:04:24 +00:00
|
|
|
};
|
2019-10-03 03:04:12 +00:00
|
|
|
}
|