2018-11-14 03:24:08 +00:00
|
|
|
|
using System;
|
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;
|
|
|
|
|
|
|
|
|
|
namespace PKHeX.WinForms.Controls
|
|
|
|
|
{
|
|
|
|
|
public partial class SizeCP : UserControl
|
|
|
|
|
{
|
2020-10-18 18:02:39 +00:00
|
|
|
|
private IScaledSize? ss;
|
2022-02-05 01:36:51 +00:00
|
|
|
|
private IScaledSizeValue? sv;
|
|
|
|
|
private ICombatPower? pkm;
|
2018-11-14 03:24:08 +00:00
|
|
|
|
private bool Loading;
|
2019-02-04 04:28:03 +00:00
|
|
|
|
|
2018-11-27 03:06:51 +00:00
|
|
|
|
public SizeCP()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
Initialized = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private readonly bool Initialized;
|
2019-11-16 01:34:18 +00:00
|
|
|
|
private static readonly string[] SizeClass = Enum.GetNames(typeof(PokeSize));
|
2018-11-14 03:24:08 +00:00
|
|
|
|
|
|
|
|
|
public void LoadPKM(PKM pk)
|
|
|
|
|
{
|
2022-02-05 01:36:51 +00:00
|
|
|
|
pkm = pk as ICombatPower;
|
2019-11-16 01:34:18 +00:00
|
|
|
|
ss = pk as IScaledSize;
|
2022-02-05 01:36:51 +00:00
|
|
|
|
sv = pk as IScaledSizeValue;
|
2019-11-16 01:34:18 +00:00
|
|
|
|
if (ss == null)
|
2018-11-14 03:24:08 +00:00
|
|
|
|
return;
|
2018-11-18 03:57:53 +00:00
|
|
|
|
TryResetStats();
|
|
|
|
|
}
|
2018-11-14 03:24:08 +00:00
|
|
|
|
|
2018-11-18 03:57:53 +00:00
|
|
|
|
public void TryResetStats()
|
|
|
|
|
{
|
2019-11-16 01:34:18 +00:00
|
|
|
|
if (!Initialized)
|
2018-11-27 03:06:51 +00:00
|
|
|
|
return;
|
2019-11-16 01:34:18 +00:00
|
|
|
|
|
2022-02-05 01:36:51 +00:00
|
|
|
|
if (CHK_Auto.Checked)
|
|
|
|
|
ResetCalculatedStats();
|
2018-11-26 23:42:40 +00:00
|
|
|
|
LoadStoredValues();
|
2018-11-14 03:24:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-02-05 01:36:51 +00:00
|
|
|
|
private void ResetCalculatedStats()
|
|
|
|
|
{
|
|
|
|
|
sv?.ResetHeight();
|
|
|
|
|
sv?.ResetWeight();
|
|
|
|
|
pkm?.ResetCP();
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-14 03:24:08 +00:00
|
|
|
|
private void LoadStoredValues()
|
|
|
|
|
{
|
|
|
|
|
Loading = true;
|
2019-11-16 01:34:18 +00:00
|
|
|
|
if (ss != null)
|
|
|
|
|
{
|
|
|
|
|
NUD_HeightScalar.Value = ss.HeightScalar;
|
|
|
|
|
NUD_WeightScalar.Value = ss.WeightScalar;
|
|
|
|
|
}
|
2022-02-05 01:36:51 +00:00
|
|
|
|
if (sv != null)
|
|
|
|
|
{
|
|
|
|
|
TB_HeightAbs.Text = sv.HeightAbsolute.ToString(CultureInfo.InvariantCulture);
|
|
|
|
|
TB_WeightAbs.Text = sv.WeightAbsolute.ToString(CultureInfo.InvariantCulture);
|
|
|
|
|
}
|
2019-11-16 01:34:18 +00:00
|
|
|
|
if (pkm != null)
|
|
|
|
|
{
|
|
|
|
|
MT_CP.Text = Math.Min(65535, pkm.Stat_CP).ToString();
|
|
|
|
|
}
|
2018-11-14 03:24:08 +00:00
|
|
|
|
Loading = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateFlagState(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (!CHK_Auto.Checked)
|
|
|
|
|
return;
|
|
|
|
|
|
2022-02-05 01:36:51 +00:00
|
|
|
|
ResetCalculatedStats();
|
2018-11-14 03:24:08 +00:00
|
|
|
|
LoadStoredValues();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void MT_CP_TextChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
2022-02-05 01:36:51 +00:00
|
|
|
|
if (pkm != null && int.TryParse(MT_CP.Text, out var cp))
|
2018-11-19 00:24:37 +00:00
|
|
|
|
pkm.Stat_CP = Math.Min(65535, cp);
|
2018-11-14 03:24:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void NUD_HeightScalar_ValueChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
2020-10-18 18:02:39 +00:00
|
|
|
|
if (ss != null)
|
|
|
|
|
{
|
|
|
|
|
ss.HeightScalar = (byte) NUD_HeightScalar.Value;
|
|
|
|
|
L_SizeH.Text = SizeClass[(int)PokeSizeUtil.GetSizeRating(ss.HeightScalar)];
|
|
|
|
|
}
|
2018-12-14 05:10:38 +00:00
|
|
|
|
|
2022-02-05 01:36:51 +00:00
|
|
|
|
if (!CHK_Auto.Checked || Loading || sv == null)
|
2018-11-14 03:24:08 +00:00
|
|
|
|
return;
|
2022-02-05 01:36:51 +00:00
|
|
|
|
sv.ResetHeight();
|
|
|
|
|
TB_HeightAbs.Text = sv.HeightAbsolute.ToString(CultureInfo.InvariantCulture);
|
2018-11-14 03:24:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void NUD_WeightScalar_ValueChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
2020-10-18 18:02:39 +00:00
|
|
|
|
if (ss != null)
|
|
|
|
|
{
|
|
|
|
|
ss.WeightScalar = (byte) NUD_WeightScalar.Value;
|
|
|
|
|
L_SizeW.Text = SizeClass[(int)PokeSizeUtil.GetSizeRating(ss.WeightScalar)];
|
|
|
|
|
}
|
2018-12-14 05:10:38 +00:00
|
|
|
|
|
2022-02-05 01:36:51 +00:00
|
|
|
|
if (!CHK_Auto.Checked || Loading || sv == null)
|
2018-11-14 03:24:08 +00:00
|
|
|
|
return;
|
2022-02-05 01:36:51 +00:00
|
|
|
|
sv.ResetWeight();
|
|
|
|
|
TB_WeightAbs.Text = sv.WeightAbsolute.ToString(CultureInfo.InvariantCulture);
|
2018-11-14 03:24:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void TB_HeightAbs_TextChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
2022-02-05 01:36:51 +00:00
|
|
|
|
if (sv == null)
|
2020-10-18 18:02:39 +00:00
|
|
|
|
return;
|
2018-11-14 03:24:08 +00:00
|
|
|
|
if (CHK_Auto.Checked)
|
2022-02-05 01:36:51 +00:00
|
|
|
|
sv.ResetHeight();
|
2018-11-14 03:24:08 +00:00
|
|
|
|
else if (float.TryParse(TB_HeightAbs.Text, out var result))
|
2022-02-05 01:36:51 +00:00
|
|
|
|
sv.HeightAbsolute = result;
|
2018-11-14 03:24:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void TB_WeightAbs_TextChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
2022-02-05 01:36:51 +00:00
|
|
|
|
if (sv == null)
|
2020-10-18 18:02:39 +00:00
|
|
|
|
return;
|
2018-11-14 03:24:08 +00:00
|
|
|
|
if (CHK_Auto.Checked)
|
2022-02-05 01:36:51 +00:00
|
|
|
|
sv.ResetWeight();
|
2018-11-14 03:24:08 +00:00
|
|
|
|
else if (float.TryParse(TB_WeightAbs.Text, out var result))
|
2022-02-05 01:36:51 +00:00
|
|
|
|
sv.WeightAbsolute = result;
|
2018-11-14 03:24:08 +00:00
|
|
|
|
}
|
2019-11-16 01:34:18 +00:00
|
|
|
|
|
|
|
|
|
public void ToggleVisibility(PKM pk)
|
|
|
|
|
{
|
2022-02-05 01:36:51 +00:00
|
|
|
|
bool isCP = pk is PB7;
|
|
|
|
|
bool isAbsolute = pk is IScaledSizeValue;
|
|
|
|
|
MT_CP.Visible = L_CP.Visible = isCP;
|
|
|
|
|
TB_HeightAbs.Visible = TB_WeightAbs.Visible = isAbsolute;
|
|
|
|
|
FLP_CP.Visible = isCP || isAbsolute; // Auto checkbox
|
2019-11-16 01:34:18 +00:00
|
|
|
|
}
|
2021-11-25 03:32:12 +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
|
|
|
|
}
|
|
|
|
|
}
|