2016-07-16 23:13:33 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
namespace PKHeX
|
|
|
|
|
{
|
|
|
|
|
public partial class SuperTrainingEditor : Form
|
|
|
|
|
{
|
|
|
|
|
public SuperTrainingEditor()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
int vertScrollWidth = SystemInformation.VerticalScrollBarWidth;
|
|
|
|
|
TLP_SuperTrain.Padding = TLP_DistSuperTrain.Padding = new Padding(0, 0, vertScrollWidth, 0);
|
2016-07-17 02:59:53 +00:00
|
|
|
|
|
|
|
|
|
// Updating a Control display with autosized elements on every row addition is cpu intensive. Disable layout updates while populating.
|
|
|
|
|
TLP_SuperTrain.SuspendLayout();
|
|
|
|
|
TLP_DistSuperTrain.SuspendLayout();
|
2016-07-16 23:13:33 +00:00
|
|
|
|
populateRegimens("SuperTrain", TLP_SuperTrain, reglist);
|
|
|
|
|
populateRegimens("DistSuperTrain", TLP_DistSuperTrain, distlist);
|
2016-07-17 18:38:19 +00:00
|
|
|
|
Util.TranslateInterface(this, Main.curlanguage);
|
2016-07-17 02:59:53 +00:00
|
|
|
|
TLP_SuperTrain.ResumeLayout();
|
|
|
|
|
TLP_DistSuperTrain.ResumeLayout();
|
2016-07-16 23:13:33 +00:00
|
|
|
|
|
|
|
|
|
CB_Bag.Items.Clear();
|
|
|
|
|
CB_Bag.Items.Add("---");
|
|
|
|
|
for (int i = 1; i < Main.trainingbags.Length - 1; i++)
|
|
|
|
|
CB_Bag.Items.Add(Main.trainingbags[i]);
|
|
|
|
|
|
|
|
|
|
if (pkm is PK6)
|
|
|
|
|
{
|
2016-07-17 17:06:52 +00:00
|
|
|
|
PK6 pk6 = (PK6) pkm;
|
2016-07-17 02:59:53 +00:00
|
|
|
|
CHK_Secret.Checked = pk6.SecretSuperTraining;
|
|
|
|
|
if (!CHK_Secret.Checked) // force update to disable checkboxes
|
|
|
|
|
CHK_Secret_CheckedChanged(null, null);
|
2016-07-16 23:13:33 +00:00
|
|
|
|
CB_Bag.SelectedIndex = pk6.TrainingBag;
|
|
|
|
|
NUD_BagHits.Value = pk6.TrainingBagHits;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
CB_Bag.Visible = NUD_BagHits.Visible = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private readonly List<RegimenInfo> reglist = new List<RegimenInfo>();
|
|
|
|
|
private readonly List<RegimenInfo> distlist = new List<RegimenInfo>();
|
|
|
|
|
private readonly PKM pkm = Main.pkm.Clone();
|
|
|
|
|
private const string PrefixLabel = "L_";
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void populateRegimens(string Type, TableLayoutPanel TLP, List<RegimenInfo> list)
|
|
|
|
|
{
|
|
|
|
|
// Get a list of all Regimen Attregutes in the PKM
|
|
|
|
|
var RegimenNames = ReflectUtil.getPropertiesStartWithPrefix(pkm.GetType(), Type);
|
|
|
|
|
list.AddRange(from RegimenName in RegimenNames
|
|
|
|
|
let RegimenValue = ReflectUtil.GetValue(pkm, RegimenName)
|
|
|
|
|
where RegimenValue is bool
|
|
|
|
|
select new RegimenInfo(RegimenName, (bool) RegimenValue));
|
2016-07-17 00:52:07 +00:00
|
|
|
|
TLP.ColumnCount = 1;
|
2016-07-16 23:13:33 +00:00
|
|
|
|
TLP.RowCount = 0;
|
|
|
|
|
|
|
|
|
|
// Add Regimens
|
|
|
|
|
foreach (var reg in list)
|
2016-07-17 00:52:07 +00:00
|
|
|
|
addRegimenChoice(reg, TLP);
|
2016-07-16 23:13:33 +00:00
|
|
|
|
|
|
|
|
|
// Force auto-size
|
|
|
|
|
foreach (RowStyle style in TLP.RowStyles)
|
|
|
|
|
style.SizeType = SizeType.AutoSize;
|
|
|
|
|
foreach (ColumnStyle style in TLP.ColumnStyles)
|
|
|
|
|
style.SizeType = SizeType.AutoSize;
|
|
|
|
|
}
|
2016-07-17 00:52:07 +00:00
|
|
|
|
private void addRegimenChoice(RegimenInfo reg, TableLayoutPanel TLP)
|
2016-07-16 23:13:33 +00:00
|
|
|
|
{
|
|
|
|
|
// Get row we add to
|
2016-07-17 00:52:07 +00:00
|
|
|
|
int row = TLP.RowCount;
|
|
|
|
|
TLP.RowCount++;
|
2016-07-16 23:13:33 +00:00
|
|
|
|
|
|
|
|
|
var chk = new CheckBox
|
|
|
|
|
{
|
2016-07-17 00:52:07 +00:00
|
|
|
|
Anchor = AnchorStyles.Left,
|
2016-07-16 23:13:33 +00:00
|
|
|
|
Name = PrefixCHK + reg.Name,
|
2016-07-17 00:52:07 +00:00
|
|
|
|
Margin = new Padding(2),
|
|
|
|
|
Text = reg.Name,
|
2016-07-16 23:13:33 +00:00
|
|
|
|
AutoSize = true,
|
|
|
|
|
Padding = Padding.Empty,
|
|
|
|
|
};
|
|
|
|
|
chk.CheckedChanged += (sender, e) => { reg.CompletedRegimen = chk.Checked; };
|
|
|
|
|
chk.Checked = reg.CompletedRegimen;
|
2016-07-17 00:52:07 +00:00
|
|
|
|
TLP.Controls.Add(chk, 0, row);
|
2016-07-16 23:13:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void save()
|
|
|
|
|
{
|
|
|
|
|
foreach (var reg in reglist)
|
|
|
|
|
ReflectUtil.SetValue(pkm, reg.Name, reg.CompletedRegimen);
|
|
|
|
|
foreach (var reg in distlist)
|
|
|
|
|
ReflectUtil.SetValue(pkm, reg.Name, reg.CompletedRegimen);
|
|
|
|
|
|
2016-07-17 02:59:53 +00:00
|
|
|
|
if (pkm is PK6)
|
2016-07-16 23:13:33 +00:00
|
|
|
|
{
|
2016-07-17 17:06:52 +00:00
|
|
|
|
PK6 pk6 = (PK6) pkm;
|
2016-07-17 02:59:53 +00:00
|
|
|
|
pk6.SecretSuperTraining = CHK_Secret.Checked;
|
|
|
|
|
pk6.TrainingBag = CB_Bag.SelectedIndex;
|
|
|
|
|
pk6.TrainingBagHits = (int)NUD_BagHits.Value;
|
2016-07-16 23:13:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Main.pkm = pkm;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private class RegimenInfo
|
|
|
|
|
{
|
|
|
|
|
public readonly string Name;
|
|
|
|
|
public bool CompletedRegimen;
|
|
|
|
|
public RegimenInfo(string name, bool completedRegimen)
|
|
|
|
|
{
|
|
|
|
|
Name = name;
|
|
|
|
|
CompletedRegimen = completedRegimen;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void B_All_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
CHK_Secret.Checked = true;
|
|
|
|
|
foreach (var c in TLP_SuperTrain.Controls.OfType<CheckBox>())
|
|
|
|
|
c.Checked = true;
|
|
|
|
|
foreach (var c in TLP_DistSuperTrain.Controls.OfType<CheckBox>())
|
|
|
|
|
c.Checked = true;
|
|
|
|
|
}
|
|
|
|
|
private void B_None_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
CHK_Secret.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)
|
|
|
|
|
{
|
2016-07-17 16:32:34 +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
|
|
|
|
{
|
|
|
|
|
c.Enabled = CHK_Secret.Checked;
|
|
|
|
|
if (!CHK_Secret.Checked)
|
|
|
|
|
c.Checked = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|