Add technical record flag editor & api

This commit is contained in:
Kurt 2019-11-15 23:12:28 -08:00
parent f0dfaa2e50
commit 981ed9a253
8 changed files with 295 additions and 15 deletions

View file

@ -543,6 +543,59 @@ namespace PKHeX.Core
/// <param name="hptype">Desired Hidden Power typing.</param>
public static void SetHiddenPower(this PKM pk, MoveType hptype) => pk.SetHiddenPower((int) hptype);
/// <summary>
/// Sets the Technical Record flags for the <see cref="pk"/>.
/// </summary>
/// <param name="pk">Pokémon to modify.</param>
/// <param name="value">Value to set for the record.</param>
/// <param name="max">Max record to set.</param>
public static void SetRecordFlags(this PKM pk, bool value, int max = 100)
{
if (!(pk is PK8 pk8))
return;
for (int i = 0; i < max; i++)
pk8.SetMoveRecordFlag(i, value);
}
/// <summary>
/// Clears the Technical Record flags for the <see cref="pk"/>.
/// </summary>
/// <param name="pk">Pokémon to modify.</param>
public static void ClearRecordFlags(this PKM pk) => pk.SetRecordFlags(false, 128);
/// <summary>
/// Sets the Technical Record flags for the <see cref="pk"/> based on the current moves.
/// </summary>
/// <param name="pk">Pokémon to modify.</param>
/// <param name="moves">Moves to set flags for (if applicable)</param>
public static void SetRecordFlags(this PKM pk, IReadOnlyList<int> moves)
{
if (!(pk is PK8 pk8))
return;
foreach (var m in moves)
{
var index = Array.FindIndex(Legal.Pouch_TMHM_SWSH, 100, z => z == m) - 100;
if (index >= 0)
pk8.SetMoveRecordFlag(index, true);
}
}
/// <summary>
/// Sets all the Technical Record flags for the <see cref="pk"/>.
/// </summary>
/// <param name="pk">Pokémon to modify.</param>
public static void SetRecordFlags(this PKM pk)
{
if (!(pk is PK8 pk8))
return;
var pi = pk8.PersonalInfo.TMHM;
for (int i = 100; i < pi.Length; i++)
{
if (pi[i])
pk8.SetMoveRecordFlag(i - 100, true);
}
}
/// <summary>
/// Force hatches a PKM by applying the current species name and a valid Met Location from the origin game.
/// </summary>

View file

@ -264,7 +264,7 @@ namespace PKHeX.Core
160, 162,
};
internal static readonly int[] TMHM_SWSH =
public static readonly int[] TMHM_SWSH =
{
// TM
005, 025, 006, 007, 008, 009, 019, 042, 063, 416,

View file

@ -159,6 +159,7 @@
this.Stats = new PKHeX.WinForms.Controls.StatEditor();
this.Contest = new PKHeX.WinForms.Controls.ContestStat();
this.Tab_Attacks = new System.Windows.Forms.TabPage();
this.B_Records = new System.Windows.Forms.Button();
this.PB_WarnMove4 = new System.Windows.Forms.PictureBox();
this.PB_WarnMove3 = new System.Windows.Forms.PictureBox();
this.PB_WarnMove2 = new System.Windows.Forms.PictureBox();
@ -197,6 +198,7 @@
this.TB_EC = new System.Windows.Forms.TextBox();
this.GB_nOT = new System.Windows.Forms.GroupBox();
this.Label_CTGender = new System.Windows.Forms.Label();
this.CB_HTLanguage = new System.Windows.Forms.ComboBox();
this.TB_OTt2 = new System.Windows.Forms.TextBox();
this.Label_PrevOT = new System.Windows.Forms.Label();
this.BTN_RerollEC = new System.Windows.Forms.Button();
@ -221,7 +223,6 @@
this.SpeciesIDTip = new System.Windows.Forms.ToolTip(this.components);
this.NatureTip = new System.Windows.Forms.ToolTip(this.components);
this.Tip3 = new System.Windows.Forms.ToolTip(this.components);
this.CB_HTLanguage = new System.Windows.Forms.ComboBox();
this.tabMain.SuspendLayout();
this.Tab_Main.SuspendLayout();
this.FLP_Main.SuspendLayout();
@ -1847,6 +1848,7 @@
// Tab_Attacks
//
this.Tab_Attacks.AllowDrop = true;
this.Tab_Attacks.Controls.Add(this.B_Records);
this.Tab_Attacks.Controls.Add(this.PB_WarnMove4);
this.Tab_Attacks.Controls.Add(this.PB_WarnMove3);
this.Tab_Attacks.Controls.Add(this.PB_WarnMove2);
@ -1856,11 +1858,26 @@
this.Tab_Attacks.Location = new System.Drawing.Point(4, 22);
this.Tab_Attacks.Name = "Tab_Attacks";
this.Tab_Attacks.Padding = new System.Windows.Forms.Padding(3);
this.Tab_Attacks.Size = new System.Drawing.Size(192, 74);
this.Tab_Attacks.Size = new System.Drawing.Size(272, 539);
this.Tab_Attacks.TabIndex = 3;
this.Tab_Attacks.Text = "Attacks";
this.Tab_Attacks.UseVisualStyleBackColor = true;
//
// B_Records
//
this.B_Records.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.B_Records.AutoSize = true;
this.B_Records.Location = new System.Drawing.Point(73, 284);
this.B_Records.Margin = new System.Windows.Forms.Padding(1);
this.B_Records.Name = "B_Records";
this.B_Records.Size = new System.Drawing.Size(124, 23);
this.B_Records.TabIndex = 8;
this.B_Records.Text = "Technical Records";
this.B_Records.UseVisualStyleBackColor = true;
this.B_Records.Click += new System.EventHandler(this.B_Records_Click);
//
// PB_WarnMove4
//
this.PB_WarnMove4.Image = global::PKHeX.WinForms.Properties.Resources.warn;
@ -2244,7 +2261,7 @@
this.Tab_OTMisc.Location = new System.Drawing.Point(4, 22);
this.Tab_OTMisc.Name = "Tab_OTMisc";
this.Tab_OTMisc.Padding = new System.Windows.Forms.Padding(3);
this.Tab_OTMisc.Size = new System.Drawing.Size(272, 539);
this.Tab_OTMisc.Size = new System.Drawing.Size(192, 74);
this.Tab_OTMisc.TabIndex = 4;
this.Tab_OTMisc.Text = "OT/Misc";
this.Tab_OTMisc.UseVisualStyleBackColor = true;
@ -2369,6 +2386,17 @@
this.Label_CTGender.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.Label_CTGender.Click += new System.EventHandler(this.ClickTRGender);
//
// CB_HTLanguage
//
this.CB_HTLanguage.Anchor = System.Windows.Forms.AnchorStyles.Left;
this.CB_HTLanguage.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.CB_HTLanguage.FormattingEnabled = true;
this.CB_HTLanguage.Location = new System.Drawing.Point(46, 43);
this.CB_HTLanguage.Margin = new System.Windows.Forms.Padding(0);
this.CB_HTLanguage.Name = "CB_HTLanguage";
this.CB_HTLanguage.Size = new System.Drawing.Size(126, 21);
this.CB_HTLanguage.TabIndex = 15;
//
// TB_OTt2
//
this.TB_OTt2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
@ -2610,17 +2638,6 @@
this.Label_EncryptionConstant.Text = "Encryption Constant:";
this.Label_EncryptionConstant.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// CB_HTLanguage
//
this.CB_HTLanguage.Anchor = System.Windows.Forms.AnchorStyles.Left;
this.CB_HTLanguage.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.CB_HTLanguage.FormattingEnabled = true;
this.CB_HTLanguage.Location = new System.Drawing.Point(46, 43);
this.CB_HTLanguage.Margin = new System.Windows.Forms.Padding(0);
this.CB_HTLanguage.Name = "CB_HTLanguage";
this.CB_HTLanguage.Size = new System.Drawing.Size(126, 21);
this.CB_HTLanguage.TabIndex = 15;
//
// PKMEditor
//
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit;
@ -2694,6 +2711,7 @@
this.FLP_TimeOfDay.ResumeLayout(false);
this.Tab_Stats.ResumeLayout(false);
this.Tab_Attacks.ResumeLayout(false);
this.Tab_Attacks.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.PB_WarnMove4)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.PB_WarnMove3)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.PB_WarnMove2)).EndInit();
@ -2925,5 +2943,6 @@
private System.Windows.Forms.ComboBox CB_StatNature;
private System.Windows.Forms.PictureBox PB_Origin;
private System.Windows.Forms.ComboBox CB_HTLanguage;
private System.Windows.Forms.Button B_Records;
}
}

View file

@ -1587,6 +1587,13 @@ namespace PKHeX.WinForms.Controls
TB_Friendship.Text = Entity.CurrentFriendship.ToString();
}
private void B_Records_Click(object sender, EventArgs e)
{
using var form = new TechRecordEditor(Entity);
form.ShowDialog();
UpdateLegality();
}
/// <summary>
/// Refreshes the interface for the current PKM format.
/// </summary>
@ -1614,6 +1621,7 @@ namespace PKHeX.WinForms.Controls
BTN_Medals.Visible = gen >= 6 && gen <= 7 && !pb7;
FLP_Country.Visible = FLP_SubRegion.Visible = FLP_3DSRegion.Visible = gen >= 6 && gen <= 7 && !pb7;
FLP_OriginalNature.Visible = gen >= 8;
B_Records.Visible = gen >= 8;
ToggleInterface(Entity.Format);
}

View file

@ -718,6 +718,8 @@ namespace PKHeX.WinForms
{
if (sav == null || sav.Version == GameVersion.Invalid)
{
// temporary swsh fix for initial release broken saves
// remove any time after November
if (sav is SAV8SWSH z)
{
var shift = z.Game + (GameVersion.SW - GameVersion.SN);

View file

@ -62,6 +62,9 @@
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Update="Subforms\PKM Editors\TechRecordEditor.cs">
<SubType>Form</SubType>
</Compile>
</ItemGroup>
<ItemGroup>

View file

@ -0,0 +1,124 @@
namespace PKHeX.WinForms
{
partial class TechRecordEditor
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(TechRecordEditor));
this.B_Save = new System.Windows.Forms.Button();
this.B_Cancel = new System.Windows.Forms.Button();
this.B_None = new System.Windows.Forms.Button();
this.B_All = new System.Windows.Forms.Button();
this.tipName = new System.Windows.Forms.ToolTip(this.components);
this.CLB_Flags = new System.Windows.Forms.CheckedListBox();
this.SuspendLayout();
//
// B_Save
//
this.B_Save.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.B_Save.Location = new System.Drawing.Point(108, 345);
this.B_Save.Name = "B_Save";
this.B_Save.Size = new System.Drawing.Size(90, 23);
this.B_Save.TabIndex = 1;
this.B_Save.Text = "Save";
this.B_Save.UseVisualStyleBackColor = true;
this.B_Save.Click += new System.EventHandler(this.B_Save_Click);
//
// B_Cancel
//
this.B_Cancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.B_Cancel.Location = new System.Drawing.Point(12, 345);
this.B_Cancel.Name = "B_Cancel";
this.B_Cancel.Size = new System.Drawing.Size(90, 23);
this.B_Cancel.TabIndex = 2;
this.B_Cancel.Text = "Cancel";
this.B_Cancel.UseVisualStyleBackColor = true;
this.B_Cancel.Click += new System.EventHandler(this.B_Cancel_Click);
//
// B_None
//
this.B_None.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.B_None.Location = new System.Drawing.Point(108, 316);
this.B_None.Name = "B_None";
this.B_None.Size = new System.Drawing.Size(90, 23);
this.B_None.TabIndex = 5;
this.B_None.Text = "Remove All";
this.B_None.UseVisualStyleBackColor = true;
this.B_None.Click += new System.EventHandler(this.B_None_Click);
//
// B_All
//
this.B_All.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.B_All.Location = new System.Drawing.Point(12, 316);
this.B_All.Name = "B_All";
this.B_All.Size = new System.Drawing.Size(90, 23);
this.B_All.TabIndex = 4;
this.B_All.Text = "Give All";
this.B_All.UseVisualStyleBackColor = true;
this.B_All.Click += new System.EventHandler(this.B_All_Click);
//
// CLB_Flags
//
this.CLB_Flags.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.CLB_Flags.FormattingEnabled = true;
this.CLB_Flags.Location = new System.Drawing.Point(12, 12);
this.CLB_Flags.Name = "CLB_Flags";
this.CLB_Flags.Size = new System.Drawing.Size(186, 289);
this.CLB_Flags.TabIndex = 6;
//
// TechRecordEditor
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(210, 380);
this.Controls.Add(this.CLB_Flags);
this.Controls.Add(this.B_None);
this.Controls.Add(this.B_All);
this.Controls.Add(this.B_Cancel);
this.Controls.Add(this.B_Save);
this.Icon = Properties.Resources.Icon;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "TechRecordEditor";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "TR Relearn Editor";
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Button B_Save;
private System.Windows.Forms.Button B_Cancel;
private System.Windows.Forms.Button B_None;
private System.Windows.Forms.Button B_All;
private System.Windows.Forms.ToolTip tipName;
private System.Windows.Forms.CheckedListBox CLB_Flags;
}
}

View file

@ -0,0 +1,71 @@
using System;
using System.Linq;
using System.Windows.Forms;
using PKHeX.Core;
namespace PKHeX.WinForms
{
public partial class TechRecordEditor : Form
{
private readonly PK8 pkm;
public TechRecordEditor(PKM pk)
{
pkm = (PK8)pk;
InitializeComponent();
WinFormsUtil.TranslateInterface(this, Main.CurrentLanguage);
PopulateRecords();
LoadRecords();
}
private void PopulateRecords()
{
var trs = Legal.TMHM_SWSH;
var names = GameInfo.Strings.Move;
var lines = trs.Skip(100).Select((z, i) => $"{i:00} - {names[z]}").ToArray();
CLB_Flags.Items.AddRange(lines);
}
private void B_Cancel_Click(object sender, EventArgs e) => Close();
private void B_Save_Click(object sender, EventArgs e)
{
Save();
Close();
}
private void LoadRecords()
{
for (int i = 0; i < 100; i++)
CLB_Flags.SetItemChecked(i, pkm.GetMoveRecordFlag(i));
}
private void Save()
{
for (int i = 0; i < 100; i++)
pkm.SetMoveRecordFlag(i, CLB_Flags.GetItemChecked(i));
}
private void B_All_Click(object sender, EventArgs e)
{
Save();
if (ModifierKeys == Keys.Shift)
pkm.SetRecordFlags(true);
else if (ModifierKeys == Keys.Control)
pkm.SetRecordFlags(pkm.Moves);
else
pkm.SetRecordFlags();
LoadRecords();
Close();
}
private void B_None_Click(object sender, EventArgs e)
{
Save();
pkm.ClearRecordFlags();
LoadRecords();
Close();
}
}
}