PKHeX/PKHeX.WinForms/Controls/PKM Editor/ShinyLeaf.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

65 lines
1.9 KiB
C#

using System;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using PKHeX.Drawing;
using PKHeX.WinForms.Properties;
namespace PKHeX.WinForms.Controls
{
public partial class ShinyLeaf : UserControl
{
public ShinyLeaf()
{
InitializeComponent();
Flags = new[] {CHK_1, CHK_2, CHK_3, CHK_4, CHK_5, CHK_C};
greyLeaf = ImageUtil.ChangeOpacity(ImageUtil.ToGrayscale(CHK_1.Image), 0.4);
greyCrown = ImageUtil.ChangeOpacity(ImageUtil.ToGrayscale(CHK_C.Image), 0.4);
foreach (var chk in Flags)
UpdateFlagState(chk, null);
}
private readonly CheckBox[] Flags;
private readonly Bitmap greyLeaf, greyCrown;
public void CheckAll(bool all = true) => Value = all ? 0b00111111 : 0;
public int Value
{
get
{
int value = 0;
for (int i = 0; i < Flags.Length; i++)
{
if (Flags[i].Checked)
value |= 1 << i;
}
return value;
}
set
{
for (int i = 0; i < Flags.Length; i++)
Flags[i].Checked = (value >> i & 1) == 1;
}
}
private void UpdateFlagState(object sender, EventArgs e)
{
if (!(sender is CheckBox c))
return;
if (CHK_C == c)
{
c.Image = c.Checked ? Resources.crown : greyCrown;
}
else
{
if (!c.Checked)
CHK_C.Checked = CHK_C.Enabled = false;
else if (Flags.Take(5).All(z => z.Checked))
CHK_C.Enabled = true;
c.Image = c.Checked ? Resources.leaf : greyLeaf;
}
}
}
}