2016-07-16 23:13:33 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Windows.Forms;
|
2017-01-08 07:54:09 +00:00
|
|
|
|
using PKHeX.Core;
|
2016-07-16 23:13:33 +00:00
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
|
namespace PKHeX.WinForms;
|
|
|
|
|
|
|
|
|
|
public partial class SuperTrainingEditor : Form
|
2016-07-16 23:13:33 +00:00
|
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
|
public SuperTrainingEditor(PKM pk)
|
2016-07-16 23:13:33 +00:00
|
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
|
Entity = (ISuperTrain)pk;
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
WinFormsUtil.TranslateInterface(this, Main.CurrentLanguage);
|
|
|
|
|
int vertScrollWidth = SystemInformation.VerticalScrollBarWidth;
|
|
|
|
|
TLP_SuperTrain.Padding = TLP_DistSuperTrain.Padding = new Padding(0, 0, vertScrollWidth, 0);
|
|
|
|
|
|
|
|
|
|
// Updating a Control display with auto-sized elements on every row addition is cpu intensive. Disable layout updates while populating.
|
|
|
|
|
TLP_SuperTrain.SuspendLayout();
|
|
|
|
|
TLP_DistSuperTrain.SuspendLayout();
|
|
|
|
|
TLP_SuperTrain.Scroll += WinFormsUtil.PanelScroll;
|
|
|
|
|
TLP_DistSuperTrain.Scroll += WinFormsUtil.PanelScroll;
|
|
|
|
|
PopulateRegimens("SuperTrain", TLP_SuperTrain, reglist);
|
|
|
|
|
PopulateRegimens("DistSuperTrain", TLP_DistSuperTrain, distlist);
|
|
|
|
|
WinFormsUtil.TranslateInterface(this, Main.CurrentLanguage);
|
|
|
|
|
TLP_SuperTrain.ResumeLayout();
|
|
|
|
|
TLP_DistSuperTrain.ResumeLayout();
|
|
|
|
|
|
|
|
|
|
CHK_SecretUnlocked.Checked = Entity.SecretSuperTrainingUnlocked;
|
|
|
|
|
CHK_SecretComplete.Checked = Entity.SecretSuperTrainingComplete;
|
|
|
|
|
|
|
|
|
|
if (pk is PK6 pk6)
|
2016-07-16 23:13:33 +00:00
|
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
|
CB_Bag.Items.Clear();
|
|
|
|
|
CB_Bag.Items.Add("---");
|
|
|
|
|
for (int i = 1; i < GameInfo.Strings.trainingbags.Length - 1; i++)
|
|
|
|
|
CB_Bag.Items.Add(GameInfo.Strings.trainingbags[i]);
|
2016-07-16 23:13:33 +00:00
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
|
CB_Bag.SelectedIndex = pk6.TrainingBag;
|
|
|
|
|
NUD_BagHits.Value = pk6.TrainingBagHits;
|
2018-08-04 17:06:06 +00:00
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
|
if (!CHK_SecretUnlocked.Checked) // force update to disable checkboxes
|
|
|
|
|
CHK_Secret_CheckedChanged(this, EventArgs.Empty);
|
|
|
|
|
}
|
|
|
|
|
else
|
2016-07-16 23:13:33 +00:00
|
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
|
L_Bag.Visible = CB_Bag.Visible = L_Hits.Visible = NUD_BagHits.Visible = false;
|
|
|
|
|
CHK_SecretUnlocked.Visible = CHK_SecretComplete.Visible = false;
|
2016-07-16 23:13:33 +00:00
|
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private readonly List<RegimenInfo> reglist = new();
|
|
|
|
|
private readonly List<RegimenInfo> distlist = new();
|
|
|
|
|
private readonly ISuperTrain Entity;
|
|
|
|
|
private const string PrefixCHK = "CHK_";
|
|
|
|
|
|
|
|
|
|
private void B_Cancel_Click(object sender, EventArgs e) => Close();
|
|
|
|
|
|
|
|
|
|
private void B_Save_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Save();
|
|
|
|
|
Close();
|
|
|
|
|
}
|
2016-07-16 23:13:33 +00:00
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
|
private void PopulateRegimens(string propertyPrefix, TableLayoutPanel TLP, List<RegimenInfo> list)
|
|
|
|
|
{
|
|
|
|
|
// Get a list of all Regimen Attregutes in the PKM
|
|
|
|
|
list.AddRange(GetBooleanRegimenNames(Entity, propertyPrefix));
|
|
|
|
|
TLP.ColumnCount = 1;
|
|
|
|
|
TLP.RowCount = 0;
|
|
|
|
|
|
|
|
|
|
// Add Regimens
|
|
|
|
|
foreach (var reg in list)
|
|
|
|
|
AddRegimenChoice(reg, TLP);
|
|
|
|
|
|
|
|
|
|
// Force auto-size
|
|
|
|
|
foreach (var style in TLP.RowStyles.OfType<RowStyle>())
|
|
|
|
|
style.SizeType = SizeType.AutoSize;
|
|
|
|
|
foreach (var style in TLP.ColumnStyles.OfType<ColumnStyle>())
|
|
|
|
|
style.SizeType = SizeType.AutoSize;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static IEnumerable<RegimenInfo> GetBooleanRegimenNames(ISuperTrain pk, string propertyPrefix)
|
|
|
|
|
{
|
|
|
|
|
var names = ReflectUtil.GetPropertiesStartWithPrefix(pk.GetType(), propertyPrefix);
|
|
|
|
|
foreach (var name in names)
|
2016-07-16 23:13:33 +00:00
|
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
|
var value = ReflectUtil.GetValue(pk, name);
|
|
|
|
|
if (value is bool state)
|
|
|
|
|
yield return new RegimenInfo(name, state);
|
2016-07-16 23:13:33 +00:00
|
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
|
}
|
2018-08-04 17:06:06 +00:00
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
|
private static void AddRegimenChoice(RegimenInfo reg, TableLayoutPanel TLP)
|
|
|
|
|
{
|
|
|
|
|
// Get row we add to
|
|
|
|
|
int row = TLP.RowCount;
|
|
|
|
|
TLP.RowCount++;
|
|
|
|
|
|
|
|
|
|
var chk = new CheckBox
|
2020-09-03 21:28:51 +00:00
|
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
|
Anchor = AnchorStyles.Left,
|
|
|
|
|
Name = PrefixCHK + reg.Name,
|
|
|
|
|
Margin = new Padding(2),
|
|
|
|
|
Text = reg.Name,
|
|
|
|
|
AutoSize = true,
|
|
|
|
|
Padding = Padding.Empty,
|
|
|
|
|
};
|
|
|
|
|
chk.CheckedChanged += (sender, e) => reg.CompletedRegimen = chk.Checked;
|
|
|
|
|
chk.Checked = reg.CompletedRegimen;
|
|
|
|
|
TLP.Controls.Add(chk, 0, row);
|
|
|
|
|
}
|
2020-09-03 21:28:51 +00:00
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
|
private void Save()
|
|
|
|
|
{
|
|
|
|
|
foreach (var reg in reglist)
|
|
|
|
|
ReflectUtil.SetValue(Entity, reg.Name, reg.CompletedRegimen);
|
|
|
|
|
foreach (var reg in distlist)
|
|
|
|
|
ReflectUtil.SetValue(Entity, reg.Name, reg.CompletedRegimen);
|
|
|
|
|
|
|
|
|
|
if (Entity is PK6 pk6)
|
2016-07-16 23:13:33 +00:00
|
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
|
pk6.SecretSuperTrainingUnlocked = CHK_SecretUnlocked.Checked;
|
|
|
|
|
pk6.SecretSuperTrainingComplete = CHK_SecretComplete.Checked;
|
|
|
|
|
pk6.TrainingBag = CB_Bag.SelectedIndex;
|
|
|
|
|
pk6.TrainingBagHits = (int)NUD_BagHits.Value;
|
2016-07-16 23:13:33 +00:00
|
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
|
else // clear flags if manually cleared
|
2016-07-16 23:13:33 +00:00
|
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
|
Entity.SecretSuperTrainingUnlocked &= CHK_SecretUnlocked.Checked;
|
|
|
|
|
Entity.SecretSuperTrainingComplete &= CHK_SecretComplete.Checked;
|
2016-07-16 23:13:33 +00:00
|
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
|
}
|
2018-05-12 15:13:39 +00:00
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
|
private sealed class RegimenInfo
|
|
|
|
|
{
|
|
|
|
|
public readonly string Name;
|
|
|
|
|
public bool CompletedRegimen;
|
|
|
|
|
|
|
|
|
|
internal RegimenInfo(string name, bool completedRegimen)
|
2016-07-16 23:13:33 +00:00
|
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
|
Name = name;
|
|
|
|
|
CompletedRegimen = completedRegimen;
|
2016-07-16 23:13:33 +00:00
|
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
|
}
|
2016-07-16 23:13:33 +00:00
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
|
private void B_All_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (CHK_SecretUnlocked.Checked) // only give dist if Secret is Unlocked (None -> All -> All*)
|
2016-07-16 23:13:33 +00:00
|
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
|
foreach (var c in TLP_DistSuperTrain.Controls.OfType<CheckBox>())
|
2016-07-16 23:13:33 +00:00
|
|
|
|
c.Checked = true;
|
|
|
|
|
}
|
2018-08-04 17:06:06 +00:00
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
|
if (Entity is PK6)
|
2016-07-16 23:13:33 +00:00
|
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
|
CHK_SecretUnlocked.Checked = true;
|
|
|
|
|
CHK_SecretComplete.Checked = true;
|
2016-07-16 23:13:33 +00:00
|
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
|
foreach (var c in TLP_SuperTrain.Controls.OfType<CheckBox>())
|
|
|
|
|
c.Checked = true;
|
|
|
|
|
}
|
2018-08-04 17:06:06 +00:00
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
|
private void B_None_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
CHK_SecretUnlocked.Checked = false;
|
|
|
|
|
CHK_SecretComplete.Checked = false;
|
|
|
|
|
foreach (var c in TLP_SuperTrain.Controls.OfType<CheckBox>())
|
|
|
|
|
c.Checked = false;
|
|
|
|
|
foreach (var c in TLP_DistSuperTrain.Controls.OfType<CheckBox>())
|
|
|
|
|
c.Checked = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CHK_Secret_CheckedChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (Entity is not PK6)
|
|
|
|
|
return;
|
|
|
|
|
CHK_SecretComplete.Checked &= CHK_SecretUnlocked.Checked;
|
|
|
|
|
CHK_SecretComplete.Enabled = CHK_SecretUnlocked.Checked;
|
2023-04-22 03:47:04 +00:00
|
|
|
|
foreach (var c in TLP_SuperTrain.Controls.OfType<CheckBox>().Where(chk => Convert.ToInt16(chk.Name[14] + "") >= 4))
|
2016-07-16 23:13:33 +00:00
|
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
|
c.Enabled = CHK_SecretUnlocked.Checked;
|
|
|
|
|
if (!CHK_SecretUnlocked.Checked)
|
|
|
|
|
c.Checked = false;
|
2016-07-16 23:13:33 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|