PKHeX/PKHeX.WinForms/Controls/PKM Editor/ShinyLeaf.cs
Kurt da6f880c16 Add Shiny Leaf editing
Closes #1236
pk4/bk4 only, obviously

side note, using static events is no-no, designer auto-removed them.
just manually reapply (as well to others that used it)
2017-06-17 21:49:14 -07:00

58 lines
1.8 KiB
C#

using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Windows.Forms;
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 (!c.Checked)
CHK_C.Checked = CHK_C.Enabled = false;
else if (Flags.Take(5).All(z => z.Checked) && CHK_C != c)
CHK_C.Enabled = true;
if (CHK_C == c)
c.Image = c.Checked ? Resources.crown : greyCrown;
else
c.Image = c.Checked ? Resources.leaf : greyLeaf;
}
}
}