mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-23 04:23:12 +00:00
Set TR flags for all evos, indicate yellow
This commit is contained in:
parent
2e0a2ed7eb
commit
0876c8044a
5 changed files with 92 additions and 21 deletions
|
@ -13,7 +13,7 @@ public static class TechnicalRecordApplicator
|
|||
/// <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 ITechRecord pk, bool value, int max)
|
||||
public static void SetRecordFlagsAll(this ITechRecord pk, bool value, int max)
|
||||
{
|
||||
for (int i = 0; i < max; i++)
|
||||
pk.SetMoveRecordFlag(i, value);
|
||||
|
@ -23,7 +23,7 @@ public static class TechnicalRecordApplicator
|
|||
/// Clears the Technical Record flags for the <see cref="pk"/>.
|
||||
/// </summary>
|
||||
/// <param name="pk">Pokémon to modify.</param>
|
||||
public static void ClearRecordFlags(this ITechRecord pk) => pk.SetRecordFlags(false, pk.Permit.RecordCountTotal);
|
||||
public static void ClearRecordFlags(this ITechRecord pk) => pk.SetRecordFlagsAll(false, pk.Permit.RecordCountTotal);
|
||||
|
||||
/// <summary>
|
||||
/// Sets the Technical Record flags for the <see cref="pk"/> based on the current moves.
|
||||
|
@ -33,6 +33,12 @@ public static class TechnicalRecordApplicator
|
|||
public static void SetRecordFlags(this ITechRecord pk, ReadOnlySpan<ushort> moves)
|
||||
{
|
||||
var permit = pk.Permit;
|
||||
SetRecordFlags(pk, moves, permit);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="SetRecordFlags(ITechRecord, ReadOnlySpan{ushort})"/>
|
||||
public static void SetRecordFlags(ITechRecord pk, ReadOnlySpan<ushort> moves, IPermitRecord permit)
|
||||
{
|
||||
var moveIDs = permit.RecordPermitIndexes;
|
||||
|
||||
foreach (var m in moves)
|
||||
|
@ -49,13 +55,72 @@ public static class TechnicalRecordApplicator
|
|||
/// Sets all the Technical Record flags for the <see cref="pk"/> if they are permitted to be learned in-game.
|
||||
/// </summary>
|
||||
/// <param name="pk">Pokémon to modify.</param>
|
||||
public static void SetRecordFlags(this ITechRecord pk)
|
||||
public static void SetRecordFlagsAll(this ITechRecord pk)
|
||||
{
|
||||
var permit = pk.Permit;
|
||||
SetRecordFlagsAll(pk, permit);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="SetRecordFlagsAll(PKHeX.Core.ITechRecord)"/>"/>
|
||||
public static void SetRecordFlagsAll(ITechRecord pk, IPermitRecord permit)
|
||||
{
|
||||
for (int i = 0; i < permit.RecordCountUsed; i++)
|
||||
{
|
||||
if (permit.IsRecordPermitted(i))
|
||||
pk.SetMoveRecordFlag(i);
|
||||
}
|
||||
}
|
||||
|
||||
private static void SetRecordFlags<TTable, TInfo>(this ITechRecord pk, ReadOnlySpan<ushort> moves, ReadOnlySpan<EvoCriteria> evos, TTable pt)
|
||||
where TTable : IPersonalTable<TInfo> where TInfo : IPersonalInfo, IPermitRecord
|
||||
{
|
||||
foreach (var evo in evos)
|
||||
SetRecordFlags(pk, moves, pt[evo.Species, evo.Form]);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="SetRecordFlagsAll(ITechRecord)"/>
|
||||
private static void SetRecordFlagsAll<TTable, TInfo>(this ITechRecord pk, ReadOnlySpan<EvoCriteria> evos, TTable pt)
|
||||
where TTable : IPersonalTable<TInfo> where TInfo : IPersonalInfo, IPermitRecord
|
||||
{
|
||||
foreach (var evo in evos)
|
||||
SetRecordFlagsAll(pk, pt[evo.Species, evo.Form]);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IPermitRecord.IsRecordPermitted"/>
|
||||
private static bool IsRecordPermitted<TTable, TInfo>(ReadOnlySpan<EvoCriteria> evos, TTable pt, int index)
|
||||
where TTable : IPersonalTable<TInfo> where TInfo : IPersonalInfo, IPermitRecord
|
||||
{
|
||||
foreach (var evo in evos)
|
||||
{
|
||||
if (pt[evo.Species, evo.Form].IsRecordPermitted(index))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="SetRecordFlags(ITechRecord, ReadOnlySpan{ushort})"/>
|
||||
public static void SetRecordFlags(this ITechRecord pk, ReadOnlySpan<ushort> moves, ReadOnlySpan<EvoCriteria> evos)
|
||||
{
|
||||
if (pk is PK9 pk9)
|
||||
SetRecordFlags<PersonalTable9SV, PersonalInfo9SV>(pk9, moves, evos, PersonalTable.SV);
|
||||
else if (pk is PK8 pk8)
|
||||
SetRecordFlags<PersonalTable8SWSH, PersonalInfo8SWSH>(pk8, moves, evos, PersonalTable.SWSH);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="SetRecordFlagsAll(ITechRecord)"/>
|
||||
public static void SetRecordFlagsAll(this ITechRecord pk, ReadOnlySpan<EvoCriteria> evos)
|
||||
{
|
||||
if (pk is PK9 pk9)
|
||||
SetRecordFlagsAll<PersonalTable9SV, PersonalInfo9SV>(pk9, evos, PersonalTable.SV);
|
||||
else if (pk is PK8 pk8)
|
||||
SetRecordFlagsAll<PersonalTable8SWSH, PersonalInfo8SWSH>(pk8, evos, PersonalTable.SWSH);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IPermitRecord.IsRecordPermitted"/>
|
||||
public static bool IsRecordPermitted(this ITechRecord pk, ReadOnlySpan<EvoCriteria> evos, int index) => pk switch
|
||||
{
|
||||
PK9 => IsRecordPermitted<PersonalTable9SV, PersonalInfo9SV>(evos, PersonalTable.SV, index),
|
||||
PK8 => IsRecordPermitted<PersonalTable8SWSH, PersonalInfo8SWSH>(evos, PersonalTable.SWSH, index),
|
||||
_ => false,
|
||||
};
|
||||
}
|
||||
|
|
|
@ -31,13 +31,13 @@ internal static class BatchModifications
|
|||
t.ClearRecordFlags();
|
||||
if (IsAll(propValue))
|
||||
{
|
||||
t.SetRecordFlags(); // all
|
||||
t.SetRecordFlagsAll(info.Legality.Info.EvoChainsAllGens.Get(pk.Context)); // all
|
||||
}
|
||||
else if (!IsNone(propValue))
|
||||
{
|
||||
Span<ushort> moves = stackalloc ushort[4];
|
||||
pk.GetMoves(moves);
|
||||
t.SetRecordFlags(moves); // whatever fit the current moves
|
||||
t.SetRecordFlags(moves, info.Legality.Info.EvoChainsAllGens.Get(pk.Context)); // whatever fit the current moves
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -236,11 +236,6 @@ public static class CommonEdits
|
|||
tera.SetTeraType(type);
|
||||
}
|
||||
|
||||
if (pk is ITechRecord t)
|
||||
{
|
||||
t.ClearRecordFlags();
|
||||
t.SetRecordFlags(Set.Moves);
|
||||
}
|
||||
if (pk is IMoveShop8Mastery s)
|
||||
s.SetMoveShopFlags(Set.Moves, pk);
|
||||
|
||||
|
@ -248,6 +243,11 @@ public static class CommonEdits
|
|||
pk.Nature = pk.StatNature;
|
||||
|
||||
var legal = new LegalityAnalysis(pk);
|
||||
if (pk is ITechRecord t)
|
||||
{
|
||||
t.ClearRecordFlags();
|
||||
t.SetRecordFlags(Set.Moves, legal.Info.EvoChainsAllGens.Get(pk.Context));
|
||||
}
|
||||
if (legal.Parsed && !MoveResult.AllValid(legal.Info.Relearn))
|
||||
pk.SetRelearnMoves(legal);
|
||||
pk.ResetPartyStats();
|
||||
|
|
|
@ -768,7 +768,8 @@ public sealed partial class PKMEditor : UserControl, IMainEditor
|
|||
if (Entity is ITechRecord tr)
|
||||
{
|
||||
tr.ClearRecordFlags();
|
||||
tr.SetRecordFlags(moves);
|
||||
var la = new LegalityAnalysis(Entity);
|
||||
tr.SetRecordFlags(moves, la.Info.EvoChainsAllGens.Get(Entity.Context));
|
||||
}
|
||||
Entity.HealPP();
|
||||
FieldsLoaded = false;
|
||||
|
@ -1855,7 +1856,8 @@ public sealed partial class PKMEditor : UserControl, IMainEditor
|
|||
{
|
||||
Span<ushort> moves = stackalloc ushort[4];
|
||||
Entity.GetMoves(moves);
|
||||
t.SetRecordFlags(moves);
|
||||
var la = new LegalityAnalysis(Entity);
|
||||
t.SetRecordFlags(moves, la.Info.EvoChainsAllGens.Get(Entity.Context));
|
||||
UpdateLegality();
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ public partial class TechRecordEditor : Form
|
|||
{
|
||||
private readonly ITechRecord Record;
|
||||
private readonly PKM Entity;
|
||||
private readonly LegalityAnalysis Legality;
|
||||
|
||||
private const int ColumnHasFlag = 0;
|
||||
private const int ColumnIndex = 1;
|
||||
|
@ -22,6 +23,7 @@ public partial class TechRecordEditor : Form
|
|||
{
|
||||
Record = techRecord;
|
||||
Entity = pk;
|
||||
Legality = new LegalityAnalysis(pk);
|
||||
InitializeComponent();
|
||||
WinFormsUtil.TranslateInterface(this, Main.CurrentLanguage);
|
||||
PopulateRecords(pk.Context);
|
||||
|
@ -34,22 +36,21 @@ public partial class TechRecordEditor : Form
|
|||
var indexes = Record.Permit.RecordPermitIndexes;
|
||||
// Add the records to the datagrid.
|
||||
dgv.Rows.Add(indexes.Length);
|
||||
var evos = Legality.Info.EvoChainsAllGens.Get(context);
|
||||
for (int i = 0; i < indexes.Length; i++)
|
||||
{
|
||||
var move = indexes[i];
|
||||
var type = MoveInfo.GetType(move, context);
|
||||
var isValid = Record.Permit.IsRecordPermitted(i);
|
||||
var row = dgv.Rows[i];
|
||||
var cell = row.Cells[ColumnHasFlag];
|
||||
if (isValid)
|
||||
{
|
||||
var cell = row.Cells[ColumnHasFlag];
|
||||
cell.Style.BackColor = cell.Style.SelectionBackColor = Color.LightGreen;
|
||||
}
|
||||
else if (Record.IsRecordPermitted(evos, i))
|
||||
cell.Style.BackColor = cell.Style.SelectionBackColor = Color.Yellow;
|
||||
else
|
||||
{
|
||||
var cell = row.Cells[ColumnHasFlag];
|
||||
cell.Style.SelectionBackColor = Color.Red;
|
||||
}
|
||||
|
||||
row.Cells[ColumnIndex].Value = i.ToString("000");
|
||||
row.Cells[ColumnTypeIcon].Value = TypeSpriteUtil.GetTypeSpriteIcon(type);
|
||||
row.Cells[ColumnType].Value = type.ToString("00") + (isValid ? 0 : 1) + names[move]; // type -> valid -> name sorting
|
||||
|
@ -92,19 +93,22 @@ public partial class TechRecordEditor : Form
|
|||
if (ModifierKeys == Keys.Shift)
|
||||
{
|
||||
Record.ClearRecordFlags();
|
||||
Record.SetRecordFlags(true, Record.Permit.RecordCountUsed);
|
||||
Record.SetRecordFlagsAll(true, Record.Permit.RecordCountUsed);
|
||||
}
|
||||
else if (ModifierKeys == Keys.Control)
|
||||
{
|
||||
Save();
|
||||
Span<ushort> moves = stackalloc ushort[4];
|
||||
Entity.GetMoves(moves);
|
||||
Record.SetRecordFlags(moves);
|
||||
var la = new LegalityAnalysis(Entity);
|
||||
Record.SetRecordFlags(moves, la.Info.EvoChainsAllGens.Get(Entity.Context));
|
||||
}
|
||||
else
|
||||
{
|
||||
Record.ClearRecordFlags();
|
||||
Record.SetRecordFlags();
|
||||
Record.SetRecordFlagsAll();
|
||||
var la = new LegalityAnalysis(Entity);
|
||||
Record.SetRecordFlagsAll(la.Info.EvoChainsAllGens.Get(Entity.Context));
|
||||
}
|
||||
Close();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue