2022-06-18 18:04:24 +00:00
|
|
|
using System;
|
2017-06-18 04:49:14 +00:00
|
|
|
using System.Drawing;
|
|
|
|
using System.Windows.Forms;
|
2019-09-29 16:47:06 +00:00
|
|
|
using PKHeX.Drawing;
|
2017-06-18 04:49:14 +00:00
|
|
|
using PKHeX.WinForms.Properties;
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
namespace PKHeX.WinForms.Controls;
|
|
|
|
|
|
|
|
public partial class ShinyLeaf : UserControl
|
2017-06-18 04:49:14 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
public ShinyLeaf()
|
2017-06-18 04:49:14 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
InitializeComponent();
|
|
|
|
Flags = new[] { CHK_1, CHK_2, CHK_3, CHK_4, CHK_5, CHK_C };
|
|
|
|
}
|
2017-06-18 04:49:14 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private readonly CheckBox[] Flags;
|
2017-06-18 04:49:14 +00:00
|
|
|
|
2022-08-18 06:48:37 +00:00
|
|
|
private const byte CrownAndFiveLeafs = 0b00_1_11111;
|
|
|
|
public void CheckAll(bool all = true) => SetValue(all ? CrownAndFiveLeafs : 0);
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public int GetValue()
|
|
|
|
{
|
|
|
|
int value = 0;
|
|
|
|
for (int i = 0; i < Flags.Length; i++)
|
2019-10-02 01:12:08 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
if (Flags[i].Checked)
|
|
|
|
value |= 1 << i;
|
2019-10-02 01:12:08 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
return value;
|
|
|
|
}
|
2019-10-02 01:12:08 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public void SetValue(int value)
|
|
|
|
{
|
|
|
|
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 not CheckBox c)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Image resource;
|
|
|
|
if (CHK_C == c)
|
2019-10-02 01:12:08 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
resource = Resources.crown;
|
2017-06-18 04:49:14 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
else
|
2017-06-18 04:49:14 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
resource = Resources.leaf;
|
2019-10-02 01:12:08 +00:00
|
|
|
if (!c.Checked)
|
2022-06-18 18:04:24 +00:00
|
|
|
CHK_C.Checked = CHK_C.Enabled = false;
|
2022-08-18 06:48:37 +00:00
|
|
|
else if (HasAllFiveLeafs())
|
2022-06-18 18:04:24 +00:00
|
|
|
CHK_C.Enabled = true;
|
2017-06-18 04:49:14 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
if (!c.Checked)
|
|
|
|
resource = ImageUtil.ChangeOpacity(resource, 0.4);
|
|
|
|
c.Image = resource;
|
2017-06-18 04:49:14 +00:00
|
|
|
}
|
2022-08-18 06:48:37 +00:00
|
|
|
|
|
|
|
private bool HasAllFiveLeafs()
|
|
|
|
{
|
|
|
|
for (int i = 0; i < 5; i++)
|
|
|
|
{
|
|
|
|
if (!Flags[i].Checked)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2017-06-18 04:49:14 +00:00
|
|
|
}
|