2022-10-17 01:36:33 +00:00
|
|
|
using System;
|
2022-11-25 01:42:17 +00:00
|
|
|
using System.Drawing;
|
2021-05-29 22:31:47 +00:00
|
|
|
using System.Globalization;
|
2018-11-14 03:24:08 +00:00
|
|
|
using System.Windows.Forms;
|
|
|
|
using PKHeX.Core;
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
namespace PKHeX.WinForms.Controls;
|
2018-11-14 03:24:08 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public partial class SizeCP : UserControl
|
|
|
|
{
|
|
|
|
private IScaledSize? ss;
|
2022-11-25 01:42:17 +00:00
|
|
|
private IScaledSize3? scale;
|
2022-06-18 18:04:24 +00:00
|
|
|
private IScaledSizeValue? sv;
|
|
|
|
private ICombatPower? pk;
|
|
|
|
private bool Loading;
|
2018-11-14 03:24:08 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public SizeCP()
|
|
|
|
{
|
|
|
|
InitializeComponent();
|
|
|
|
Initialized = true;
|
|
|
|
}
|
2019-11-16 01:34:18 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private readonly bool Initialized;
|
|
|
|
private static readonly string[] SizeClass = Enum.GetNames(typeof(PokeSize));
|
2022-11-25 01:42:17 +00:00
|
|
|
private static readonly string[] SizeClassDetailed = Enum.GetNames(typeof(PokeSizeDetailed));
|
2018-11-14 03:24:08 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public void LoadPKM(PKM entity)
|
|
|
|
{
|
|
|
|
pk = entity as ICombatPower;
|
|
|
|
ss = entity as IScaledSize;
|
|
|
|
sv = entity as IScaledSizeValue;
|
2022-11-25 01:42:17 +00:00
|
|
|
scale = entity as IScaledSize3;
|
2022-06-18 18:04:24 +00:00
|
|
|
if (ss == null)
|
|
|
|
return;
|
|
|
|
TryResetStats();
|
|
|
|
}
|
2022-02-05 01:36:51 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public void TryResetStats()
|
|
|
|
{
|
|
|
|
if (!Initialized)
|
|
|
|
return;
|
2022-02-09 02:56:11 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (CHK_Auto.Checked)
|
|
|
|
ResetCalculatedStats();
|
|
|
|
LoadStoredValues();
|
|
|
|
}
|
2018-11-14 03:24:08 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void ResetCalculatedStats()
|
|
|
|
{
|
|
|
|
sv?.ResetHeight();
|
|
|
|
sv?.ResetWeight();
|
|
|
|
pk?.ResetCP();
|
|
|
|
}
|
2018-11-14 03:24:08 +00:00
|
|
|
|
2022-10-17 01:36:33 +00:00
|
|
|
private static string GetString(float value) => value.ToString("R", CultureInfo.InvariantCulture);
|
2018-11-14 03:24:08 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void LoadStoredValues()
|
|
|
|
{
|
|
|
|
Loading = true;
|
|
|
|
if (ss != null)
|
2018-11-14 03:24:08 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
if (NUD_HeightScalar.Focused || NUD_WeightScalar.Focused)
|
|
|
|
CHK_Auto.Focus();
|
|
|
|
NUD_HeightScalar.Value = ss.HeightScalar;
|
|
|
|
NUD_WeightScalar.Value = ss.WeightScalar;
|
2018-11-14 03:24:08 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
if (sv != null)
|
2018-11-14 03:24:08 +00:00
|
|
|
{
|
2022-02-09 02:56:11 +00:00
|
|
|
TB_HeightAbs.Text = GetString(sv.HeightAbsolute);
|
|
|
|
TB_WeightAbs.Text = GetString(sv.WeightAbsolute);
|
2018-11-14 03:24:08 +00:00
|
|
|
}
|
2022-11-25 01:42:17 +00:00
|
|
|
if (scale != null)
|
|
|
|
{
|
|
|
|
NUD_Scale.Value = scale.Scale;
|
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
if (pk != null)
|
2018-11-14 03:24:08 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
MT_CP.Text = Math.Min(65535, pk.Stat_CP).ToString();
|
2018-11-14 03:24:08 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
Loading = false;
|
|
|
|
}
|
2018-11-14 03:24:08 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void UpdateFlagState(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
if (!CHK_Auto.Checked)
|
|
|
|
return;
|
2018-11-14 03:24:08 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
ResetCalculatedStats();
|
|
|
|
LoadStoredValues();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void MT_CP_TextChanged(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
if (pk != null && int.TryParse(MT_CP.Text, out var cp))
|
|
|
|
pk.Stat_CP = Math.Min(65535, cp);
|
|
|
|
}
|
2019-11-16 01:34:18 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void NUD_HeightScalar_ValueChanged(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
if (ss != null)
|
2019-11-16 01:34:18 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
if (!Loading)
|
2022-11-25 01:42:17 +00:00
|
|
|
{
|
2023-04-22 03:47:04 +00:00
|
|
|
ss.HeightScalar = (byte)NUD_HeightScalar.Value;
|
2022-11-25 01:42:17 +00:00
|
|
|
if (ss is PA8) // Height copied to Scale
|
|
|
|
NUD_Scale.Value = ss.HeightScalar;
|
|
|
|
}
|
|
|
|
var label = L_SizeH;
|
|
|
|
var value = ss.HeightScalar;
|
|
|
|
label.Text = SizeClass[(int)PokeSizeUtil.GetSizeRating(value)];
|
|
|
|
if (value is 255 && scale is PA8) // Alpha or (unlikely, user error?)
|
|
|
|
label.ForeColor = Color.Red;
|
|
|
|
else
|
|
|
|
label.ResetForeColor();
|
2019-11-16 01:34:18 +00:00
|
|
|
}
|
2021-11-25 03:32:12 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (!CHK_Auto.Checked || Loading || sv == null)
|
|
|
|
return;
|
|
|
|
sv.ResetHeight();
|
|
|
|
sv.ResetWeight();
|
|
|
|
TB_HeightAbs.Text = GetString(sv.HeightAbsolute);
|
|
|
|
TB_WeightAbs.Text = GetString(sv.WeightAbsolute);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void NUD_WeightScalar_ValueChanged(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
if (ss != null)
|
2021-11-25 03:32:12 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
if (!Loading)
|
2023-04-22 03:47:04 +00:00
|
|
|
ss.WeightScalar = (byte)NUD_WeightScalar.Value;
|
2022-11-25 01:42:17 +00:00
|
|
|
var label = L_SizeW;
|
|
|
|
var value = ss.WeightScalar;
|
|
|
|
label.Text = SizeClass[(int)PokeSizeUtil.GetSizeRating(value)];
|
|
|
|
if (value is 255 && scale is PA8) // Alpha or (unlikely, user error?)
|
|
|
|
label.ForeColor = Color.Red;
|
|
|
|
else
|
|
|
|
label.ResetForeColor();
|
2021-11-25 03:32:12 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
|
|
|
|
if (!CHK_Auto.Checked || Loading || sv == null)
|
|
|
|
return;
|
|
|
|
sv.ResetWeight();
|
|
|
|
TB_WeightAbs.Text = GetString(sv.WeightAbsolute);
|
|
|
|
}
|
|
|
|
|
2022-11-25 01:42:17 +00:00
|
|
|
private void NUD_Scale_ValueChanged(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
if (scale != null)
|
|
|
|
{
|
|
|
|
if (!Loading)
|
|
|
|
{
|
|
|
|
scale.Scale = (byte)NUD_Scale.Value;
|
|
|
|
if (scale is PA8) // Height copied to Scale
|
|
|
|
NUD_HeightScalar.Value = scale.Scale;
|
|
|
|
}
|
|
|
|
|
|
|
|
var label = L_SizeS;
|
|
|
|
var value = scale.Scale;
|
|
|
|
label.Text = SizeClassDetailed[(int)PokeSizeDetailedUtil.GetSizeRating(value)];
|
|
|
|
if (value is 0 or 255) // Tiny or Jumbo Mark possible.
|
|
|
|
label.ForeColor = Color.Red;
|
|
|
|
else
|
|
|
|
label.ResetForeColor();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void TB_HeightAbs_TextChanged(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
if (sv == null || Loading)
|
|
|
|
return;
|
|
|
|
if (CHK_Auto.Checked)
|
|
|
|
sv.ResetHeight();
|
|
|
|
else if (float.TryParse(TB_HeightAbs.Text, out var result))
|
|
|
|
sv.HeightAbsolute = result;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void TB_WeightAbs_TextChanged(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
if (sv == null || Loading)
|
|
|
|
return;
|
|
|
|
if (CHK_Auto.Checked)
|
|
|
|
sv.ResetWeight();
|
|
|
|
else if (float.TryParse(TB_WeightAbs.Text, out var result))
|
|
|
|
sv.WeightAbsolute = result;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void ToggleVisibility(PKM entity)
|
|
|
|
{
|
|
|
|
bool isCP = entity is ICombatPower;
|
|
|
|
bool isAbsolute = entity is IScaledSizeValue;
|
2022-11-25 01:42:17 +00:00
|
|
|
bool isScale3 = entity is IScaledSize3;
|
2022-06-18 18:04:24 +00:00
|
|
|
MT_CP.Visible = L_CP.Visible = isCP;
|
|
|
|
TB_HeightAbs.Visible = TB_WeightAbs.Visible = isAbsolute;
|
2022-11-25 01:42:17 +00:00
|
|
|
L_Scale.Visible = FLP_Scale3.Visible = isScale3;
|
2023-01-25 04:10:08 +00:00
|
|
|
FLP_CP.Visible = isCP || isAbsolute; // Auto checkbox
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void ClickScalarEntry(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
if (sender is not NumericUpDown nud || ModifierKeys != Keys.Control)
|
|
|
|
return;
|
|
|
|
nud.Value = PokeSizeUtil.GetRandomScalar();
|
2018-11-14 03:24:08 +00:00
|
|
|
}
|
|
|
|
}
|