2016-07-16 16:13:33 -07:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Windows.Forms;
|
2017-01-07 23:54:09 -08:00
|
|
|
|
using PKHeX.Core;
|
2016-07-16 16:13:33 -07:00
|
|
|
|
|
2017-01-07 23:54:09 -08:00
|
|
|
|
namespace PKHeX.WinForms
|
2016-07-16 16:13:33 -07:00
|
|
|
|
{
|
|
|
|
|
public partial class SuperTrainingEditor : Form
|
|
|
|
|
{
|
2017-05-22 21:55:05 -07:00
|
|
|
|
public SuperTrainingEditor(PKM pk)
|
2016-07-16 16:13:33 -07:00
|
|
|
|
{
|
2019-09-20 20:55:36 -07:00
|
|
|
|
pkm = (ISuperTrain)pk;
|
2016-07-16 16:13:33 -07:00
|
|
|
|
InitializeComponent();
|
2018-04-02 20:36:13 -07:00
|
|
|
|
WinFormsUtil.TranslateInterface(this, Main.CurrentLanguage);
|
2016-07-16 16:13:33 -07:00
|
|
|
|
int vertScrollWidth = SystemInformation.VerticalScrollBarWidth;
|
|
|
|
|
TLP_SuperTrain.Padding = TLP_DistSuperTrain.Padding = new Padding(0, 0, vertScrollWidth, 0);
|
2016-07-16 19:59:53 -07: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();
|
2017-01-07 23:54:09 -08:00
|
|
|
|
TLP_SuperTrain.Scroll += WinFormsUtil.PanelScroll;
|
|
|
|
|
TLP_DistSuperTrain.Scroll += WinFormsUtil.PanelScroll;
|
2017-06-17 18:37:19 -07:00
|
|
|
|
PopulateRegimens("SuperTrain", TLP_SuperTrain, reglist);
|
|
|
|
|
PopulateRegimens("DistSuperTrain", TLP_DistSuperTrain, distlist);
|
2016-07-16 19:59:53 -07:00
|
|
|
|
TLP_SuperTrain.ResumeLayout();
|
|
|
|
|
TLP_DistSuperTrain.ResumeLayout();
|
2018-05-12 08:13:39 -07:00
|
|
|
|
|
2017-01-02 22:18:23 -08:00
|
|
|
|
CHK_SecretUnlocked.Checked = pkm.SecretSuperTrainingUnlocked;
|
|
|
|
|
CHK_SecretComplete.Checked = pkm.SecretSuperTrainingComplete;
|
|
|
|
|
|
2018-05-12 18:11:47 -07:00
|
|
|
|
if (pkm is PK6 pk6)
|
2016-07-16 16:13:33 -07:00
|
|
|
|
{
|
2016-11-08 08:43:57 -08:00
|
|
|
|
CB_Bag.Items.Clear();
|
|
|
|
|
CB_Bag.Items.Add("---");
|
2017-01-07 23:54:09 -08:00
|
|
|
|
for (int i = 1; i < GameInfo.Strings.trainingbags.Length - 1; i++)
|
|
|
|
|
CB_Bag.Items.Add(GameInfo.Strings.trainingbags[i]);
|
2016-11-08 08:43:57 -08:00
|
|
|
|
|
2016-07-16 16:13:33 -07:00
|
|
|
|
CB_Bag.SelectedIndex = pk6.TrainingBag;
|
|
|
|
|
NUD_BagHits.Value = pk6.TrainingBagHits;
|
2017-01-26 08:45:23 -08:00
|
|
|
|
|
|
|
|
|
if (!CHK_SecretUnlocked.Checked) // force update to disable checkboxes
|
2019-02-02 10:19:41 -08:00
|
|
|
|
CHK_Secret_CheckedChanged(null, EventArgs.Empty);
|
2016-07-16 16:13:33 -07:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2016-11-08 08:43:57 -08:00
|
|
|
|
L_Bag.Visible = CB_Bag.Visible = L_Hits.Visible = NUD_BagHits.Visible = false;
|
2017-01-26 08:45:23 -08:00
|
|
|
|
CHK_SecretUnlocked.Visible = CHK_SecretComplete.Visible = false;
|
2016-07-16 16:13:33 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private readonly List<RegimenInfo> reglist = new List<RegimenInfo>();
|
|
|
|
|
private readonly List<RegimenInfo> distlist = new List<RegimenInfo>();
|
2019-09-20 20:55:36 -07:00
|
|
|
|
private readonly ISuperTrain pkm;
|
2016-07-16 16:13:33 -07:00
|
|
|
|
private const string PrefixCHK = "CHK_";
|
|
|
|
|
|
2018-08-04 10:06:06 -07:00
|
|
|
|
private void B_Cancel_Click(object sender, EventArgs e) => Close();
|
|
|
|
|
|
2016-07-16 16:13:33 -07:00
|
|
|
|
private void B_Save_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2017-06-17 18:37:19 -07:00
|
|
|
|
Save();
|
2016-07-16 16:13:33 -07:00
|
|
|
|
Close();
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-17 18:37:19 -07:00
|
|
|
|
private void PopulateRegimens(string Type, TableLayoutPanel TLP, List<RegimenInfo> list)
|
2016-07-16 16:13:33 -07:00
|
|
|
|
{
|
|
|
|
|
// Get a list of all Regimen Attregutes in the PKM
|
2018-05-17 22:43:07 -07:00
|
|
|
|
var RegimenNames = ReflectUtil.GetPropertiesStartWithPrefix(pkm.GetType(), Type);
|
2016-07-16 16:13:33 -07:00
|
|
|
|
list.AddRange(from RegimenName in RegimenNames
|
|
|
|
|
let RegimenValue = ReflectUtil.GetValue(pkm, RegimenName)
|
|
|
|
|
where RegimenValue is bool
|
|
|
|
|
select new RegimenInfo(RegimenName, (bool) RegimenValue));
|
2016-07-16 17:52:07 -07:00
|
|
|
|
TLP.ColumnCount = 1;
|
2016-07-16 16:13:33 -07:00
|
|
|
|
TLP.RowCount = 0;
|
2018-05-12 08:13:39 -07:00
|
|
|
|
|
2016-07-16 16:13:33 -07:00
|
|
|
|
// Add Regimens
|
|
|
|
|
foreach (var reg in list)
|
2017-06-17 18:37:19 -07:00
|
|
|
|
AddRegimenChoice(reg, TLP);
|
2016-07-16 16:13:33 -07:00
|
|
|
|
|
|
|
|
|
// Force auto-size
|
|
|
|
|
foreach (RowStyle style in TLP.RowStyles)
|
|
|
|
|
style.SizeType = SizeType.AutoSize;
|
|
|
|
|
foreach (ColumnStyle style in TLP.ColumnStyles)
|
|
|
|
|
style.SizeType = SizeType.AutoSize;
|
|
|
|
|
}
|
2018-08-04 10:06:06 -07:00
|
|
|
|
|
2017-06-17 18:37:19 -07:00
|
|
|
|
private static void AddRegimenChoice(RegimenInfo reg, TableLayoutPanel TLP)
|
2016-07-16 16:13:33 -07:00
|
|
|
|
{
|
|
|
|
|
// Get row we add to
|
2016-07-16 17:52:07 -07:00
|
|
|
|
int row = TLP.RowCount;
|
|
|
|
|
TLP.RowCount++;
|
2016-07-16 16:13:33 -07:00
|
|
|
|
|
|
|
|
|
var chk = new CheckBox
|
|
|
|
|
{
|
2016-07-16 17:52:07 -07:00
|
|
|
|
Anchor = AnchorStyles.Left,
|
2016-07-16 16:13:33 -07:00
|
|
|
|
Name = PrefixCHK + reg.Name,
|
2016-07-16 17:52:07 -07:00
|
|
|
|
Margin = new Padding(2),
|
|
|
|
|
Text = reg.Name,
|
2016-07-16 16:13:33 -07:00
|
|
|
|
AutoSize = true,
|
|
|
|
|
Padding = Padding.Empty,
|
|
|
|
|
};
|
2017-07-05 23:05:49 -07:00
|
|
|
|
chk.CheckedChanged += (sender, e) => reg.CompletedRegimen = chk.Checked;
|
2016-07-16 16:13:33 -07:00
|
|
|
|
chk.Checked = reg.CompletedRegimen;
|
2016-07-16 17:52:07 -07:00
|
|
|
|
TLP.Controls.Add(chk, 0, row);
|
2016-07-16 16:13:33 -07:00
|
|
|
|
}
|
|
|
|
|
|
2017-06-17 18:37:19 -07:00
|
|
|
|
private void Save()
|
2016-07-16 16:13:33 -07:00
|
|
|
|
{
|
|
|
|
|
foreach (var reg in reglist)
|
|
|
|
|
ReflectUtil.SetValue(pkm, reg.Name, reg.CompletedRegimen);
|
|
|
|
|
foreach (var reg in distlist)
|
|
|
|
|
ReflectUtil.SetValue(pkm, reg.Name, reg.CompletedRegimen);
|
|
|
|
|
|
2017-06-17 18:37:19 -07:00
|
|
|
|
if (pkm is PK6 pk6)
|
2016-07-16 16:13:33 -07:00
|
|
|
|
{
|
2016-08-29 21:52:55 -07:00
|
|
|
|
pk6.SecretSuperTrainingUnlocked = CHK_SecretUnlocked.Checked;
|
|
|
|
|
pk6.SecretSuperTrainingComplete = CHK_SecretComplete.Checked;
|
2016-07-16 19:59:53 -07:00
|
|
|
|
pk6.TrainingBag = CB_Bag.SelectedIndex;
|
|
|
|
|
pk6.TrainingBagHits = (int)NUD_BagHits.Value;
|
2016-07-16 16:13:33 -07:00
|
|
|
|
}
|
2017-01-28 10:50:36 -08:00
|
|
|
|
else // clear flags if manually cleared
|
|
|
|
|
{
|
|
|
|
|
pkm.SecretSuperTrainingUnlocked &= CHK_SecretUnlocked.Checked;
|
|
|
|
|
pkm.SecretSuperTrainingComplete &= CHK_SecretComplete.Checked;
|
|
|
|
|
}
|
2016-07-16 16:13:33 -07:00
|
|
|
|
}
|
2018-05-12 08:13:39 -07:00
|
|
|
|
|
2017-06-17 18:37:19 -07:00
|
|
|
|
private sealed class RegimenInfo
|
2016-07-16 16:13:33 -07:00
|
|
|
|
{
|
|
|
|
|
public readonly string Name;
|
|
|
|
|
public bool CompletedRegimen;
|
2018-08-04 10:06:06 -07:00
|
|
|
|
|
2017-06-17 18:37:19 -07:00
|
|
|
|
internal RegimenInfo(string name, bool completedRegimen)
|
2016-07-16 16:13:33 -07:00
|
|
|
|
{
|
|
|
|
|
Name = name;
|
|
|
|
|
CompletedRegimen = completedRegimen;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void B_All_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2016-09-02 09:54:17 -07:00
|
|
|
|
if (CHK_SecretUnlocked.Checked) // only give dist if Secret is Unlocked (None -> All -> All*)
|
2018-08-04 10:06:06 -07:00
|
|
|
|
{
|
2016-09-02 09:54:17 -07:00
|
|
|
|
foreach (var c in TLP_DistSuperTrain.Controls.OfType<CheckBox>())
|
|
|
|
|
c.Checked = true;
|
2018-08-04 10:06:06 -07:00
|
|
|
|
}
|
2017-01-26 08:45:23 -08:00
|
|
|
|
|
|
|
|
|
if (pkm is PK6)
|
|
|
|
|
{
|
|
|
|
|
CHK_SecretUnlocked.Checked = true;
|
|
|
|
|
CHK_SecretComplete.Checked = true;
|
|
|
|
|
}
|
2016-07-16 16:13:33 -07:00
|
|
|
|
foreach (var c in TLP_SuperTrain.Controls.OfType<CheckBox>())
|
|
|
|
|
c.Checked = true;
|
|
|
|
|
}
|
2018-08-04 10:06:06 -07:00
|
|
|
|
|
2016-07-16 16:13:33 -07:00
|
|
|
|
private void B_None_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2017-01-28 10:50:36 -08:00
|
|
|
|
CHK_SecretUnlocked.Checked = false;
|
|
|
|
|
CHK_SecretComplete.Checked = false;
|
2016-07-16 16:13:33 -07:00
|
|
|
|
foreach (var c in TLP_SuperTrain.Controls.OfType<CheckBox>())
|
|
|
|
|
c.Checked = false;
|
|
|
|
|
foreach (var c in TLP_DistSuperTrain.Controls.OfType<CheckBox>())
|
|
|
|
|
c.Checked = false;
|
|
|
|
|
}
|
2018-08-04 10:06:06 -07:00
|
|
|
|
|
2016-07-16 16:13:33 -07:00
|
|
|
|
private void CHK_Secret_CheckedChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
2017-01-26 08:45:23 -08:00
|
|
|
|
if (!(pkm is PK6))
|
|
|
|
|
return;
|
2016-08-29 21:52:55 -07:00
|
|
|
|
CHK_SecretComplete.Checked &= CHK_SecretUnlocked.Checked;
|
|
|
|
|
CHK_SecretComplete.Enabled = CHK_SecretUnlocked.Checked;
|
2016-07-17 09:32:34 -07:00
|
|
|
|
foreach (var c in TLP_SuperTrain.Controls.OfType<CheckBox>().Where(chk => Convert.ToInt16(chk.Name[14]+"") >= 4))
|
2016-07-16 16:13:33 -07:00
|
|
|
|
{
|
2016-08-29 21:52:55 -07:00
|
|
|
|
c.Enabled = CHK_SecretUnlocked.Checked;
|
|
|
|
|
if (!CHK_SecretUnlocked.Checked)
|
2016-07-16 16:13:33 -07:00
|
|
|
|
c.Checked = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|