2022-06-18 18:04:24 +00:00
|
|
|
using System;
|
2017-05-23 04:55:05 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Drawing;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Windows.Forms;
|
|
|
|
using System.ComponentModel;
|
2022-03-26 22:51:12 +00:00
|
|
|
using System.Runtime.CompilerServices;
|
2023-03-22 01:19:55 +00:00
|
|
|
using System.Text;
|
2022-08-05 23:18:42 +00:00
|
|
|
using PKHeX.Core;
|
|
|
|
using PKHeX.Drawing;
|
2023-04-01 23:52:12 +00:00
|
|
|
using PKHeX.Drawing.Misc;
|
2021-11-27 23:48:08 +00:00
|
|
|
using PKHeX.Drawing.PokeSprite;
|
|
|
|
using PKHeX.Drawing.PokeSprite.Properties;
|
2018-04-06 04:25:18 +00:00
|
|
|
using static PKHeX.Core.MessageStrings;
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
namespace PKHeX.WinForms.Controls;
|
|
|
|
|
|
|
|
public sealed partial class PKMEditor : UserControl, IMainEditor
|
2017-05-23 04:55:05 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
public bool IsInitialized { get; private set; }
|
2023-01-22 04:02:33 +00:00
|
|
|
private readonly ToolTip SpeciesIDTip = new();
|
|
|
|
private readonly ToolTip NatureTip = new();
|
2023-04-01 23:52:12 +00:00
|
|
|
private readonly ToolTip TipPIDInfo = new();
|
|
|
|
private readonly ToolTip AffixedTip = new();
|
2022-06-18 18:04:24 +00:00
|
|
|
|
|
|
|
public PKMEditor()
|
2017-05-23 04:55:05 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
InitializeComponent();
|
|
|
|
|
|
|
|
// Groupbox doesn't show Click event in Designer...
|
|
|
|
GB_OT.Click += ClickGT;
|
|
|
|
GB_nOT.Click += ClickGT;
|
|
|
|
GB_CurrentMoves.Click += ClickMoves;
|
|
|
|
GB_RelearnMoves.Click += ClickMoves;
|
|
|
|
|
|
|
|
var font = FontUtil.GetPKXFont();
|
|
|
|
TB_Nickname.Font = TB_OT.Font = TB_HT.Font = font;
|
|
|
|
|
|
|
|
// Commonly reused Control arrays
|
2023-01-22 04:02:33 +00:00
|
|
|
Moves = new[] { MC_Move1, MC_Move2, MC_Move3, MC_Move4 };
|
2022-06-18 18:04:24 +00:00
|
|
|
Relearn = new[] { CB_RelearnMove1, CB_RelearnMove2, CB_RelearnMove3, CB_RelearnMove4 };
|
|
|
|
Markings = new[] { PB_Mark1, PB_Mark2, PB_Mark3, PB_Mark4, PB_Mark5, PB_Mark6 };
|
|
|
|
|
|
|
|
// Legality Indicators
|
|
|
|
relearnPB = new[] { PB_WarnRelearn1, PB_WarnRelearn2, PB_WarnRelearn3, PB_WarnRelearn4 };
|
|
|
|
|
|
|
|
// Validation of incompletely entered data fields
|
|
|
|
bool Criteria(Control c) => c.BackColor == Draw.InvalidSelection && c is ComboBox { Items.Count: not 0 };
|
|
|
|
ValidatedControls = new ValidationRequiredSet[]
|
|
|
|
{
|
2023-01-22 04:02:33 +00:00
|
|
|
new(Moves, _ => true, z => Criteria(((MoveChoice)z).CB_Move)),
|
2022-06-18 18:04:24 +00:00
|
|
|
new(new[] {CB_Species}, _ => true, Criteria),
|
|
|
|
new(new[] {CB_HeldItem}, pk => pk.Format >= 2, Criteria),
|
|
|
|
new(new[] {CB_Ability, CB_Nature, CB_MetLocation, CB_Ball}, pk => pk.Format >= 3, Criteria),
|
|
|
|
new(new[] {CB_EggLocation}, pk => pk.Format >= 4, Criteria),
|
|
|
|
new(new[] {CB_Country, CB_SubRegion}, pk => pk is PK6 or PK7, Criteria),
|
|
|
|
new(Relearn, pk => pk.Format >= 6, Criteria),
|
|
|
|
new(new[] {CB_StatNature}, pk => pk.Format >= 8, Criteria),
|
|
|
|
new(new[] {CB_AlphaMastered}, pk => pk is PA8, Criteria),
|
|
|
|
};
|
2020-10-18 18:02:39 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
foreach (var c in WinFormsUtil.GetAllControlsOfType<ComboBox>(this))
|
|
|
|
c.KeyDown += WinFormsUtil.RemoveDropCB;
|
2023-01-22 04:02:33 +00:00
|
|
|
foreach (var m in Moves)
|
|
|
|
{
|
|
|
|
m.CB_Move.KeyDown += WinFormsUtil.RemoveDropCB;
|
|
|
|
m.CB_PPUps.KeyDown += WinFormsUtil.RemoveDropCB;
|
|
|
|
m.CB_PPUps.SelectedIndexChanged += (_, _) => m.HealPP(Entity);
|
|
|
|
m.CB_Move.DrawItem += ValidateMovePaint;
|
|
|
|
m.CB_Move.DropDown += ValidateMoveDropDown;
|
|
|
|
m.CB_Move.MeasureItem += MeasureDropDownHeight;
|
|
|
|
m.CB_Move.SelectedIndexChanged += ValidateMove;
|
|
|
|
m.CB_Move.Leave += ValidateComboBox2;
|
|
|
|
m.CB_Move.Validating += ValidateComboBox;
|
|
|
|
}
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
Stats.MainEditor = this;
|
|
|
|
LoadShowdownSet = LoadShowdownSetDefault;
|
|
|
|
TID_Trainer.UpdatedID += Update_ID;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Controls contained in a TabPage are not created until the tab page is shown
|
|
|
|
// Any data bindings in these controls are not activated until the tab page is shown.
|
|
|
|
FlickerInterface();
|
|
|
|
}
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private sealed class ValidationRequiredSet
|
|
|
|
{
|
|
|
|
private readonly Control[] Controls;
|
|
|
|
private readonly Func<PKM, bool> ShouldCheck;
|
|
|
|
private readonly Func<Control, bool> IsInvalidState;
|
2021-07-31 01:05:17 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public Control? IsNotValid(PKM pk)
|
|
|
|
{
|
|
|
|
if (!ShouldCheck(pk))
|
|
|
|
return null;
|
|
|
|
return Array.Find(Controls, z => IsInvalidState(z));
|
|
|
|
}
|
2019-02-10 01:07:44 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public ValidationRequiredSet(Control[] controls, Func<PKM, bool> shouldCheck, Func<Control, bool> state)
|
|
|
|
{
|
|
|
|
Controls = controls;
|
|
|
|
ShouldCheck = shouldCheck;
|
|
|
|
IsInvalidState = state;
|
|
|
|
}
|
|
|
|
}
|
2021-07-31 01:05:17 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public void InitializeBinding()
|
|
|
|
{
|
|
|
|
ComboBox[] cbs =
|
|
|
|
{
|
|
|
|
CB_Nature, CB_StatNature,
|
|
|
|
CB_Country, CB_SubRegion, CB_3DSReg, CB_Language, CB_Ball, CB_HeldItem, CB_Species, DEV_Ability,
|
|
|
|
CB_GroundTile, CB_GameOrigin, CB_BattleVersion, CB_Ability, CB_MetLocation, CB_EggLocation, CB_Language, CB_HTLanguage,
|
|
|
|
CB_AlphaMastered,
|
|
|
|
};
|
2023-01-22 04:02:33 +00:00
|
|
|
foreach (var cb in cbs.Concat(Relearn))
|
2022-06-18 18:04:24 +00:00
|
|
|
cb.InitializeBinding();
|
2017-12-22 06:55:33 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
IsInitialized = true;
|
|
|
|
}
|
2021-07-31 01:05:17 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void UpdateStats()
|
|
|
|
{
|
|
|
|
Stats.UpdateStats();
|
|
|
|
if (Entity is IScaledSizeAbsolute)
|
|
|
|
SizeCP.TryResetStats();
|
|
|
|
}
|
2021-07-31 01:05:17 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void LoadPartyStats(PKM pk) => Stats.LoadPartyStats(pk);
|
2021-07-31 01:05:17 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void SavePartyStats(PKM pk) => Stats.SavePartyStats(pk);
|
2021-07-31 01:05:17 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public PKM CurrentPKM { get => PreparePKM(); set => Entity = value; }
|
|
|
|
public bool ModifyPKM { private get; set; } = true;
|
|
|
|
private bool _hideSecret;
|
2018-12-20 06:10:32 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public bool HideSecretValues
|
|
|
|
{
|
|
|
|
private get => _hideSecret;
|
|
|
|
set
|
2018-12-20 06:10:32 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
_hideSecret = value;
|
|
|
|
var sav = RequestSaveFile;
|
|
|
|
ToggleSecrets(_hideSecret, sav.Generation);
|
2017-05-23 04:55:05 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public DrawConfig Draw { private get; set; } = null!;
|
|
|
|
public bool Unicode { get; set; } = true;
|
|
|
|
private bool _hax;
|
|
|
|
public bool HaX { get => _hax; set => _hax = Stats.HaX = value; }
|
|
|
|
private byte[] LastData = Array.Empty<byte>();
|
|
|
|
|
2023-05-07 02:42:48 +00:00
|
|
|
public PKM Data => Entity;
|
2022-06-18 18:04:24 +00:00
|
|
|
public PKM Entity { get; private set; } = null!;
|
|
|
|
public bool FieldsLoaded { get; private set; }
|
|
|
|
public bool ChangingFields { get; set; }
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Currently loaded met location group that is populating Met and Egg location comboboxes
|
|
|
|
/// </summary>
|
|
|
|
private GameVersion origintrack;
|
|
|
|
|
|
|
|
private EntityContext originFormat = EntityContext.None;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Action to perform when loading a PKM to the editor GUI.
|
|
|
|
/// </summary>
|
|
|
|
private Action GetFieldsfromPKM = null!;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Function that returns a <see cref="PKM"/> from the loaded fields.
|
|
|
|
/// </summary>
|
|
|
|
private Func<PKM> GetPKMfromFields = null!;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Latest legality check result used to show legality indication.
|
|
|
|
/// </summary>
|
|
|
|
private LegalityAnalysis Legality = null!;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// List of legal moves for the latest <see cref="Legality"/>.
|
|
|
|
/// </summary>
|
|
|
|
private readonly LegalMoveSource<ComboItem> LegalMoveSource = new(new LegalMoveComboSource());
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gender Symbols for showing Genders
|
|
|
|
/// </summary>
|
|
|
|
private IReadOnlyList<string> gendersymbols = GameInfo.GenderSymbolUnicode;
|
|
|
|
|
|
|
|
public event EventHandler? LegalityChanged;
|
|
|
|
public event EventHandler? UpdatePreviewSprite;
|
|
|
|
public event EventHandler? RequestShowdownImport;
|
|
|
|
public event EventHandler? RequestShowdownExport;
|
|
|
|
public event ReturnSAVEventHandler SaveFileRequested = null!;
|
|
|
|
public delegate SaveFile ReturnSAVEventHandler(object sender, EventArgs e);
|
|
|
|
|
2023-01-22 04:02:33 +00:00
|
|
|
private readonly PictureBox[] relearnPB;
|
2022-06-18 18:04:24 +00:00
|
|
|
public SaveFile RequestSaveFile => SaveFileRequested.Invoke(this, EventArgs.Empty);
|
|
|
|
public bool PKMIsUnsaved => FieldsLoaded && LastData.Any(b => b != 0) && !LastData.SequenceEqual(CurrentPKM.Data);
|
|
|
|
|
2023-01-22 04:02:33 +00:00
|
|
|
private readonly MoveChoice[] Moves;
|
|
|
|
private readonly ComboBox[] Relearn;
|
2022-06-18 18:04:24 +00:00
|
|
|
private readonly ValidationRequiredSet[] ValidatedControls;
|
|
|
|
private readonly PictureBox[] Markings;
|
|
|
|
|
|
|
|
private bool forceValidation;
|
|
|
|
|
|
|
|
public PKM PreparePKM(bool click = true)
|
|
|
|
{
|
|
|
|
if (click)
|
2018-11-26 23:37:44 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
forceValidation = true;
|
|
|
|
ValidateChildren();
|
|
|
|
forceValidation = false;
|
2018-11-26 23:37:44 +00:00
|
|
|
}
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
var pk = GetPKMfromFields();
|
|
|
|
LastData = pk.Data;
|
|
|
|
return pk.Clone();
|
|
|
|
}
|
2018-12-20 06:10:32 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public bool EditsComplete
|
|
|
|
{
|
|
|
|
get
|
2018-12-20 06:10:32 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
if (ModifierKeys == (Keys.Control | Keys.Shift | Keys.Alt))
|
|
|
|
return true; // Override
|
|
|
|
|
|
|
|
// If any controls are partially filled out, find the first one so we can indicate as such.
|
|
|
|
Control? cb = null;
|
|
|
|
foreach (var type in ValidatedControls)
|
2018-12-20 06:10:32 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
cb = type.IsNotValid(Entity);
|
|
|
|
if (cb is not null)
|
|
|
|
break;
|
2018-12-20 06:10:32 +00:00
|
|
|
}
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (cb != null)
|
2023-01-22 04:02:33 +00:00
|
|
|
Hidden_TC.SelectedTab = WinFormsUtil.FindFirstControlOfType<TabPage>(cb);
|
2022-06-18 18:04:24 +00:00
|
|
|
else if (!Stats.Valid)
|
2023-01-22 04:02:33 +00:00
|
|
|
Hidden_TC.SelectedTab = Hidden_Stats;
|
2022-06-18 18:04:24 +00:00
|
|
|
else if (WinFormsUtil.GetIndex(CB_Species) == 0 && !HaX) // can't set an empty slot...
|
2023-01-22 04:02:33 +00:00
|
|
|
Hidden_TC.SelectedTab = Hidden_Main;
|
2022-06-18 18:04:24 +00:00
|
|
|
else
|
|
|
|
return true;
|
|
|
|
|
|
|
|
System.Media.SystemSounds.Exclamation.Play();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2017-06-19 05:27:40 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public void SetPKMFormatMode(PKM pk)
|
|
|
|
{
|
|
|
|
// Load Extra Byte List
|
|
|
|
SetPKMFormatExtraBytes(pk);
|
|
|
|
(GetFieldsfromPKM, GetPKMfromFields) = GetLoadSet(pk);
|
2023-04-04 21:22:49 +00:00
|
|
|
foreach (var move in Moves)
|
|
|
|
move.SetContext(pk.Context);
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2018-02-27 05:22:35 +00:00
|
|
|
|
2022-08-05 23:18:42 +00:00
|
|
|
private (Action Load, Func<PKM> Set) GetLoadSet(PKM pk) => GetLoadSet(pk.Context);
|
|
|
|
|
|
|
|
private (Action Load, Func<PKM> Set) GetLoadSet(EntityContext context) => context switch
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
2022-08-05 23:18:42 +00:00
|
|
|
EntityContext.Gen1 => (PopulateFieldsPK1, PreparePK1),
|
|
|
|
EntityContext.Gen2 => (PopulateFieldsPK2, PreparePK2),
|
|
|
|
EntityContext.Gen3 => (PopulateFieldsPK3, PreparePK3),
|
|
|
|
EntityContext.Gen4 => (PopulateFieldsPK4, PreparePK4),
|
|
|
|
EntityContext.Gen5 => (PopulateFieldsPK5, PreparePK5),
|
|
|
|
EntityContext.Gen6 => (PopulateFieldsPK6, PreparePK6),
|
|
|
|
EntityContext.Gen7 => (PopulateFieldsPK7, PreparePK7),
|
|
|
|
EntityContext.Gen8 => (PopulateFieldsPK8, PreparePK8),
|
2022-11-25 01:42:17 +00:00
|
|
|
EntityContext.Gen9 => (PopulateFieldsPK9, PreparePK9),
|
2022-08-05 23:18:42 +00:00
|
|
|
|
|
|
|
EntityContext.Gen7b => (PopulateFieldsPB7, PreparePB7),
|
|
|
|
EntityContext.Gen8a => (PopulateFieldsPA8, PreparePA8),
|
|
|
|
EntityContext.Gen8b => (PopulateFieldsPB8, PreparePB8),
|
|
|
|
_ => throw new ArgumentOutOfRangeException(nameof(context), context, null),
|
2022-06-18 18:04:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
private void SetPKMFormatExtraBytes(PKM pk)
|
|
|
|
{
|
|
|
|
var extraBytes = pk.ExtraBytes;
|
2023-03-26 00:55:55 +00:00
|
|
|
FLP_ExtraBytes.Visible = FLP_ExtraBytes.Enabled = extraBytes.Length != 0;
|
2022-06-18 18:04:24 +00:00
|
|
|
CB_ExtraBytes.Items.Clear();
|
|
|
|
foreach (var b in extraBytes)
|
|
|
|
CB_ExtraBytes.Items.Add($"0x{b:X2}");
|
2023-01-22 04:02:33 +00:00
|
|
|
if (FLP_ExtraBytes.Enabled)
|
2022-06-18 18:04:24 +00:00
|
|
|
CB_ExtraBytes.SelectedIndex = 0;
|
|
|
|
}
|
2020-06-20 23:23:03 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public void PopulateFields(PKM pk, bool focus = true, bool skipConversionCheck = false) => LoadFieldsFromPKM(pk, focus, skipConversionCheck);
|
2021-04-10 17:30:10 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void LoadFieldsFromPKM(PKM pk, bool focus = true, bool skipConversionCheck = true)
|
|
|
|
{
|
|
|
|
if (focus)
|
2023-01-22 04:02:33 +00:00
|
|
|
Hidden_Main.Focus();
|
2020-06-20 23:23:03 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (!skipConversionCheck && !EntityConverter.TryMakePKMCompatible(pk, Entity, out var c, out pk))
|
|
|
|
{
|
|
|
|
var msg = c.GetDisplayString(pk, Entity.GetType());
|
|
|
|
WinFormsUtil.Alert(msg);
|
|
|
|
return;
|
|
|
|
}
|
2020-06-20 23:23:03 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
FieldsLoaded = false;
|
2020-06-20 23:23:03 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
Entity = pk.Clone();
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
#if !DEBUG
|
|
|
|
try { GetFieldsfromPKM(); }
|
|
|
|
catch { }
|
|
|
|
#else
|
|
|
|
GetFieldsfromPKM();
|
|
|
|
#endif
|
2020-06-20 23:23:03 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
Stats.UpdateIVs(this, EventArgs.Empty);
|
|
|
|
UpdatePKRSInfected(this, EventArgs.Empty);
|
|
|
|
UpdatePKRSCured(this, EventArgs.Empty);
|
|
|
|
UpdateNatureModification(CB_StatNature, Entity.StatNature);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (HaX)
|
|
|
|
{
|
|
|
|
if (pk.PartyStatsPresent) // stats present
|
|
|
|
Stats.LoadPartyStats(pk);
|
|
|
|
}
|
|
|
|
FieldsLoaded = true;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2023-04-01 23:52:12 +00:00
|
|
|
UpdateAffixed(pk);
|
2022-06-18 18:04:24 +00:00
|
|
|
SetMarkings();
|
|
|
|
UpdateLegality();
|
|
|
|
UpdateSprite();
|
|
|
|
LastData = PreparePKM().Data;
|
|
|
|
}
|
2018-03-11 02:03:09 +00:00
|
|
|
|
2023-01-22 04:02:33 +00:00
|
|
|
public void UpdateLegality(LegalityAnalysis? la = null, UpdateLegalityArgs args = 0)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
if (!FieldsLoaded)
|
|
|
|
return;
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
Legality = la ?? new LegalityAnalysis(Entity, RequestSaveFile.Personal);
|
|
|
|
if (!Legality.Parsed || HaX || Entity.Species == 0)
|
2017-05-23 04:55:05 +00:00
|
|
|
{
|
2023-01-22 04:02:33 +00:00
|
|
|
MC_Move1.HideLegality = MC_Move2.HideLegality = MC_Move3.HideLegality = MC_Move4.HideLegality = true;
|
2022-06-18 18:04:24 +00:00
|
|
|
PB_WarnRelearn1.Visible = PB_WarnRelearn2.Visible = PB_WarnRelearn3.Visible = PB_WarnRelearn4.Visible = false;
|
|
|
|
LegalityChanged?.Invoke(Legality.Valid, EventArgs.Empty);
|
|
|
|
return;
|
|
|
|
}
|
2023-01-22 22:55:35 +00:00
|
|
|
MC_Move1.HideLegality = MC_Move2.HideLegality = MC_Move3.HideLegality = MC_Move4.HideLegality = false;
|
2019-09-03 02:30:58 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Refresh Move Legality
|
|
|
|
var info = Legality.Info;
|
|
|
|
var moves = info.Moves;
|
|
|
|
for (int i = 0; i < 4; i++)
|
2023-01-22 04:02:33 +00:00
|
|
|
Moves[i].UpdateLegality(moves[i], Entity, i);
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (Entity.Format >= 6)
|
2017-05-23 04:55:05 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
var relearn = info.Relearn;
|
|
|
|
for (int i = 0; i < 4; i++)
|
|
|
|
relearnPB[i].Visible = !relearn[i].Valid;
|
|
|
|
}
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2023-01-22 04:02:33 +00:00
|
|
|
if (args.HasFlag(UpdateLegalityArgs.SkipMoveRepopulation))
|
2022-06-18 18:04:24 +00:00
|
|
|
return;
|
|
|
|
// Resort moves
|
|
|
|
FieldsLoaded = false;
|
Refactoring: Move Source (Legality) (#3560)
Rewrites a good amount of legality APIs pertaining to:
* Legal moves that can be learned
* Evolution chains & cross-generation paths
* Memory validation with forgotten moves
In generation 8, there are 3 separate contexts an entity can exist in: SW/SH, BD/SP, and LA. Not every entity can cross between them, and not every entity from generation 7 can exist in generation 8 (Gogoat, etc). By creating class models representing the restrictions to cross each boundary, we are able to better track and validate data.
The old implementation of validating moves was greedy: it would iterate for all generations and evolutions, and build a full list of every move that can be learned, storing it on the heap. Now, we check one game group at a time to see if the entity can learn a move that hasn't yet been validated. End result is an algorithm that requires 0 allocation, and a smaller/quicker search space.
The old implementation of storing move parses was inefficient; for each move that was parsed, a new object is created and adjusted depending on the parse. Now, move parse results are `struct` and store the move parse contiguously in memory. End result is faster parsing and 0 memory allocation.
* `PersonalTable` objects have been improved with new API methods to check if a species+form can exist in the game.
* `IEncounterTemplate` objects have been improved to indicate the `EntityContext` they originate in (similar to `Generation`).
* Some APIs have been extended to accept `Span<T>` instead of Array/IEnumerable
2022-08-03 23:15:27 +00:00
|
|
|
LegalMoveSource.ReloadMoves(Legality);
|
2022-06-18 18:04:24 +00:00
|
|
|
FieldsLoaded = true;
|
|
|
|
LegalityChanged?.Invoke(Legality.Valid, EventArgs.Empty);
|
|
|
|
}
|
2021-07-31 01:05:17 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public void UpdateUnicode(IReadOnlyList<string> symbols)
|
|
|
|
{
|
|
|
|
gendersymbols = symbols;
|
|
|
|
if (!Unicode)
|
|
|
|
{
|
|
|
|
BTN_Shinytize.Text = Draw.ShinyDefault;
|
|
|
|
TB_Nickname.Font = TB_OT.Font = TB_HT.Font = GB_OT.Font;
|
2017-05-23 04:55:05 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
else
|
2017-05-23 04:55:05 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
BTN_Shinytize.Text = Draw.ShinyUnicode;
|
|
|
|
TB_Nickname.Font = TB_OT.Font = TB_HT.Font = FontUtil.GetPKXFont();
|
2018-12-20 06:10:32 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
internal void UpdateSprite()
|
|
|
|
{
|
|
|
|
if (FieldsLoaded && !forceValidation)
|
|
|
|
UpdatePreviewSprite?.Invoke(this, EventArgs.Empty);
|
|
|
|
}
|
|
|
|
|
|
|
|
// General Use Functions //
|
|
|
|
private void SetDetailsOT(ITrainerInfo tr)
|
|
|
|
{
|
|
|
|
if (string.IsNullOrWhiteSpace(tr.OT))
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Get Save Information
|
|
|
|
TB_OT.Text = tr.OT;
|
|
|
|
UC_OTGender.Gender = tr.Gender & 1;
|
|
|
|
TID_Trainer.LoadInfo(tr);
|
2021-11-20 02:23:49 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (tr.Game >= 0)
|
|
|
|
CB_GameOrigin.SelectedValue = tr.Game;
|
|
|
|
|
|
|
|
var lang = tr.Language;
|
|
|
|
if (lang <= 0)
|
|
|
|
lang = (int)LanguageID.English;
|
|
|
|
CB_Language.SelectedValue = lang;
|
|
|
|
if (tr is IRegionOrigin o)
|
2018-12-20 06:10:32 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
CB_3DSReg.SelectedValue = (int)o.ConsoleRegion;
|
|
|
|
CB_Country.SelectedValue = (int)o.Country;
|
|
|
|
CB_SubRegion.SelectedValue = (int)o.Region;
|
2017-05-23 04:55:05 +00:00
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Copy OT trash bytes for sensitive games (Gen1/2)
|
|
|
|
if (tr is SAV1 s1 && Entity is PK1 p1) s1.OT_Trash.CopyTo(p1.OT_Trash);
|
|
|
|
else if (tr is SAV2 s2 && Entity is PK2 p2) s2.OT_Trash.CopyTo(p2.OT_Trash);
|
|
|
|
|
|
|
|
UpdateNickname(this, EventArgs.Empty);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void SetDetailsHT(ITrainerInfo tr)
|
|
|
|
{
|
|
|
|
var trainer = tr.OT;
|
|
|
|
if (trainer.Length == 0)
|
|
|
|
return;
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (!tr.IsOriginalHandler(Entity, false))
|
|
|
|
{
|
|
|
|
TB_HT.Text = trainer;
|
|
|
|
UC_HTGender.Gender = tr.Gender & 1;
|
|
|
|
if (Entity is IHandlerLanguage)
|
|
|
|
CB_HTLanguage.SelectedValue = tr.Language;
|
|
|
|
}
|
|
|
|
else if (TB_HT.Text.Length != 0)
|
2017-05-23 04:55:05 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
if (CB_HTLanguage.SelectedIndex == 0 && Entity is IHandlerLanguage)
|
|
|
|
CB_HTLanguage.SelectedValue = tr.Language;
|
|
|
|
}
|
|
|
|
}
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void SetForms()
|
|
|
|
{
|
2022-08-27 06:43:36 +00:00
|
|
|
var species = Entity.Species;
|
2022-06-18 18:04:24 +00:00
|
|
|
var pi = RequestSaveFile.Personal[species];
|
2023-02-05 19:31:12 +00:00
|
|
|
UC_Gender.AllowClick = pi.IsDualGender;
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
bool hasForms = FormInfo.HasFormSelection(pi, species, Entity.Format);
|
|
|
|
CB_Form.Enabled = CB_Form.Visible = Label_Form.Visible = hasForms;
|
|
|
|
|
|
|
|
if (HaX && Entity.Format >= 4)
|
|
|
|
Label_Form.Visible = true; // show with value entry textbox
|
|
|
|
|
|
|
|
if (!hasForms)
|
|
|
|
{
|
|
|
|
if (HaX)
|
2022-04-09 18:58:52 +00:00
|
|
|
return;
|
2022-06-18 18:04:24 +00:00
|
|
|
Entity.Form = 0;
|
|
|
|
if (CB_Form.Items.Count > 0)
|
|
|
|
CB_Form.SelectedIndex = 0;
|
|
|
|
return;
|
|
|
|
}
|
2017-10-28 21:26:27 +00:00
|
|
|
|
2022-08-23 06:18:53 +00:00
|
|
|
var str = GameInfo.Strings;
|
|
|
|
var forms = FormConverter.GetFormList(species, str.types, str.forms, gendersymbols, Entity.Context);
|
|
|
|
if (forms.Length <= 1) // no choices
|
2022-06-18 18:04:24 +00:00
|
|
|
CB_Form.Enabled = CB_Form.Visible = Label_Form.Visible = false;
|
|
|
|
else
|
2022-08-23 06:18:53 +00:00
|
|
|
CB_Form.DataSource = forms;
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void SetAbilityList()
|
|
|
|
{
|
|
|
|
if (Entity.Format < 3) // no abilities
|
|
|
|
return;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (Entity.Format > 3 && FieldsLoaded) // has forms
|
2022-08-27 06:43:36 +00:00
|
|
|
Entity.Form = (byte)CB_Form.SelectedIndex; // update pk field for form specific abilities
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
int abil = CB_Ability.SelectedIndex;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
bool tmp = FieldsLoaded;
|
|
|
|
FieldsLoaded = false;
|
2023-01-22 04:02:33 +00:00
|
|
|
var items = GameInfo.FilteredSources.GetAbilityList(Entity);
|
|
|
|
CB_Ability.DataSource = items;
|
|
|
|
CB_Ability.SelectedIndex = Math.Clamp(abil, 0, items.Count - 1); // restore original index if available
|
2022-06-18 18:04:24 +00:00
|
|
|
FieldsLoaded = tmp;
|
|
|
|
}
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void UpdateIsShiny()
|
|
|
|
{
|
|
|
|
// Set the Controls
|
|
|
|
var type = ShinyExtensions.GetType(Entity);
|
|
|
|
BTN_Shinytize.Visible = BTN_Shinytize.Enabled = type == Shiny.Never;
|
|
|
|
PB_ShinyStar.Visible = type == Shiny.AlwaysStar;
|
|
|
|
PB_ShinySquare.Visible = type == Shiny.AlwaysSquare;
|
|
|
|
|
|
|
|
// Refresh Markings (for Shiny Star if applicable)
|
|
|
|
SetMarkings();
|
|
|
|
}
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void SetMarkings()
|
|
|
|
{
|
|
|
|
var pba = Markings;
|
|
|
|
var count = Entity.MarkingCount;
|
|
|
|
for (int i = 0; i < pba.Length; i++)
|
|
|
|
pba[i].Image = GetMarkSprite(pba[i], i < count && Entity.GetMarking(i) != 0);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
PB_MarkShiny.Image = GetMarkSprite(PB_MarkShiny, !BTN_Shinytize.Enabled);
|
|
|
|
PB_MarkCured.Image = GetMarkSprite(PB_MarkCured, CHK_Cured.Checked);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2023-04-01 23:52:12 +00:00
|
|
|
PB_Favorite.Image = GetMarkSprite(PB_Favorite, Entity is IFavorite { IsFavorite: true });
|
2022-06-18 18:04:24 +00:00
|
|
|
PB_Origin.Image = GetOriginSprite(Entity);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Colored Markings
|
|
|
|
if (Entity.Format < 7)
|
|
|
|
return;
|
2018-08-02 04:22:49 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
for (int i = 0; i < count; i++)
|
2022-03-26 22:51:12 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
if (!Draw.GetMarkingColor(Entity.GetMarking(i), out Color c))
|
|
|
|
continue;
|
|
|
|
var pb = pba[i];
|
|
|
|
pb.Image = ImageUtil.ChangeAllColorTo(pb.Image, c);
|
2022-03-26 22:51:12 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2022-03-26 22:51:12 +00:00
|
|
|
|
2022-08-05 23:18:42 +00:00
|
|
|
private static Bitmap? GetOriginSprite(PKM pk) => OriginMarkUtil.GetOriginMark(pk) switch
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
2022-08-05 23:18:42 +00:00
|
|
|
OriginMark.Gen6Pentagon => Properties.Resources.gen_6,
|
2023-04-01 23:52:12 +00:00
|
|
|
OriginMark.Gen7Clover => Properties.Resources.gen_7,
|
|
|
|
OriginMark.Gen8Galar => Properties.Resources.gen_8,
|
|
|
|
OriginMark.Gen8Trio => Properties.Resources.gen_bs,
|
|
|
|
OriginMark.Gen8Arc => Properties.Resources.gen_la,
|
|
|
|
OriginMark.Gen9Paldea => Properties.Resources.gen_sv,
|
|
|
|
OriginMark.GameBoy => Properties.Resources.gen_vc,
|
|
|
|
OriginMark.GO => Properties.Resources.gen_go,
|
|
|
|
OriginMark.LetsGo => Properties.Resources.gen_gg,
|
2022-08-05 23:18:42 +00:00
|
|
|
_ => null,
|
|
|
|
};
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private static void SetCountrySubRegion(ComboBox cb, string type)
|
|
|
|
{
|
|
|
|
int oldIndex = cb.SelectedIndex;
|
|
|
|
cb.DataSource = Util.GetCountryRegionList(type, GameInfo.CurrentLanguage);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (oldIndex > 0 && oldIndex < cb.Items.Count)
|
|
|
|
cb.SelectedIndex = oldIndex;
|
|
|
|
}
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Prompted Updates of PKM //
|
|
|
|
private void ClickFriendship(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
var pk = Entity;
|
|
|
|
bool worst = (ModifierKeys == Keys.Control) ^ pk.IsEgg;
|
|
|
|
var current = int.Parse(TB_Friendship.Text);
|
|
|
|
var value = worst
|
|
|
|
? pk.IsEgg ? EggStateLegality.GetMinimumEggHatchCycles(pk) : 0
|
|
|
|
: pk.IsEgg ? EggStateLegality.GetMaximumEggHatchCycles(pk) : current == 255 ? pk.PersonalInfo.BaseFriendship : 255;
|
|
|
|
TB_Friendship.Text = value.ToString();
|
|
|
|
}
|
2018-12-20 06:10:32 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void ClickLevel(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
if (ModifierKeys == Keys.Control && sender is TextBoxBase tb)
|
|
|
|
tb.Text = "100";
|
|
|
|
}
|
2018-02-23 06:42:50 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void ClickGender(object sender, EventArgs e)
|
|
|
|
{
|
2022-12-17 22:04:22 +00:00
|
|
|
var pi = Entity.PersonalInfo;
|
|
|
|
if (!pi.IsDualGender)
|
|
|
|
{
|
|
|
|
var expect = pi.FixedGender();
|
|
|
|
if (UC_Gender.Gender != expect)
|
|
|
|
UC_Gender.Gender = expect;
|
2022-06-18 18:04:24 +00:00
|
|
|
return; // can't toggle
|
2022-12-17 22:04:22 +00:00
|
|
|
}
|
2018-02-23 06:42:50 +00:00
|
|
|
|
2023-02-06 17:05:34 +00:00
|
|
|
var canToggle = UC_Gender.CanToggle();
|
|
|
|
var gender = UC_Gender.Gender;
|
2022-06-18 18:04:24 +00:00
|
|
|
if (!canToggle)
|
2022-12-17 22:04:22 +00:00
|
|
|
gender = UC_Gender.Gender = 0; // fix bad genders
|
2022-06-18 18:04:24 +00:00
|
|
|
if (Entity.Format <= 2)
|
|
|
|
{
|
|
|
|
Stats.SetATKIVGender(gender);
|
|
|
|
UpdateIsShiny();
|
2017-05-23 04:55:05 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
else if (Entity.Format <= 4)
|
2017-05-23 04:55:05 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
Entity.Version = WinFormsUtil.GetIndex(CB_GameOrigin);
|
|
|
|
Entity.Nature = WinFormsUtil.GetIndex(CB_Nature);
|
2022-08-27 06:43:36 +00:00
|
|
|
Entity.Form = (byte)CB_Form.SelectedIndex;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
Entity.SetPIDGender(gender);
|
|
|
|
TB_PID.Text = Entity.PID.ToString("X8");
|
2017-05-23 04:55:05 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
Entity.Gender = gender;
|
2018-07-07 00:37:07 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (EntityGender.GetFromString(CB_Form.Text) < 2) // Gendered Forms
|
|
|
|
CB_Form.SelectedIndex = Math.Min(gender, CB_Form.Items.Count - 1);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
UpdatePreviewSprite?.Invoke(UC_Gender, EventArgs.Empty);
|
|
|
|
}
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void ClickPP(object sender, EventArgs e)
|
|
|
|
{
|
2023-01-22 04:02:33 +00:00
|
|
|
foreach (var cb in Moves)
|
|
|
|
cb.HealPP(Entity);
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void ClickPPUps(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
bool min = (ModifierKeys & Keys.Control) != 0 || !Legal.IsPPUpAvailable(Entity);
|
2022-12-17 21:29:06 +00:00
|
|
|
if (min)
|
|
|
|
{
|
2023-01-22 04:02:33 +00:00
|
|
|
MC_Move1.PPUps = MC_Move2.PPUps = MC_Move3.PPUps = MC_Move4.PPUps = 0;
|
2022-12-17 21:29:06 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-01-22 04:02:33 +00:00
|
|
|
static int GetValue(ushort move) => Legal.IsPPUpAvailable(move) ? 3 : 0;
|
|
|
|
foreach (var cb in Moves)
|
|
|
|
cb.PPUps = GetValue(cb.SelectedMove);
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void ClickMarking(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
int index = Array.IndexOf(Markings, (PictureBox)sender);
|
|
|
|
Entity.ToggleMarking(index);
|
|
|
|
SetMarkings();
|
|
|
|
}
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void ClickFavorite(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
if (Entity is IFavorite pb7)
|
2022-11-25 01:42:17 +00:00
|
|
|
pb7.IsFavorite ^= true;
|
2022-06-18 18:04:24 +00:00
|
|
|
SetMarkings();
|
|
|
|
}
|
2017-10-03 06:13:40 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void ClickOT(object sender, EventArgs e) => SetDetailsOT(SaveFileRequested.Invoke(this, e));
|
|
|
|
private void ClickCT(object sender, EventArgs e) => SetDetailsHT(SaveFileRequested.Invoke(this, e));
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void ClickBall(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
Entity.Ball = WinFormsUtil.GetIndex(CB_Ball);
|
|
|
|
if ((ModifierKeys & Keys.Alt) != 0)
|
|
|
|
{
|
|
|
|
CB_Ball.SelectedValue = (int)Ball.Poke;
|
|
|
|
return;
|
2017-05-23 04:55:05 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
if ((ModifierKeys & Keys.Shift) != 0)
|
2017-05-23 04:55:05 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
CB_Ball.SelectedValue = BallApplicator.ApplyBallLegalByColor(Entity);
|
|
|
|
return;
|
2017-05-23 04:55:05 +00:00
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
using var frm = new BallBrowser();
|
|
|
|
frm.LoadBalls(Entity);
|
|
|
|
frm.ShowDialog();
|
|
|
|
if (frm.BallChoice >= 0)
|
|
|
|
CB_Ball.SelectedValue = frm.BallChoice;
|
|
|
|
}
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void ClickMetLocation(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
if (HaX)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Entity = PreparePKM();
|
2023-01-22 04:02:33 +00:00
|
|
|
UpdateLegality(args: UpdateLegalityArgs.SkipMoveRepopulation);
|
2022-06-18 18:04:24 +00:00
|
|
|
if (Legality.Valid)
|
|
|
|
return;
|
|
|
|
if (!SetSuggestedMetLocation())
|
|
|
|
return;
|
|
|
|
|
|
|
|
Entity = PreparePKM();
|
|
|
|
UpdateLegality();
|
|
|
|
}
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void ClickGT(object? sender, EventArgs e)
|
|
|
|
{
|
|
|
|
if (!GB_nOT.Visible)
|
|
|
|
return;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2023-01-22 04:02:33 +00:00
|
|
|
int handler = 0;
|
2022-06-18 18:04:24 +00:00
|
|
|
if (sender == GB_OT)
|
2023-01-22 04:02:33 +00:00
|
|
|
handler = 0;
|
2022-06-18 18:04:24 +00:00
|
|
|
else if (TB_HT.Text.Length > 0)
|
2023-01-22 04:02:33 +00:00
|
|
|
handler = 1;
|
|
|
|
UpdateHandlerSelected(handler);
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2023-01-22 04:02:33 +00:00
|
|
|
private void ChangeHandlerIndex(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
UpdateHandlerSelected(CB_Handler.SelectedIndex & 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void UpdateHandlerSelected(int handler)
|
|
|
|
{
|
|
|
|
Entity.CurrentHandler = handler;
|
|
|
|
UpadteHandlingTrainerBackground(Entity.CurrentHandler);
|
2022-06-18 18:04:24 +00:00
|
|
|
ReloadToFriendshipTextBox(Entity);
|
|
|
|
}
|
2020-03-17 17:34:23 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void ClickNature(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
if (Entity.Format < 8)
|
|
|
|
return;
|
|
|
|
if (sender == Label_Nature)
|
|
|
|
CB_Nature.SelectedIndex = CB_StatNature.SelectedIndex;
|
|
|
|
else
|
|
|
|
CB_StatNature.SelectedIndex = CB_Nature.SelectedIndex;
|
|
|
|
}
|
2020-03-17 17:34:23 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void ClickMoves(object? sender, EventArgs e)
|
|
|
|
{
|
2023-01-22 04:02:33 +00:00
|
|
|
UpdateLegality(args: UpdateLegalityArgs.SkipMoveRepopulation);
|
2022-06-18 18:04:24 +00:00
|
|
|
if (sender == GB_CurrentMoves)
|
|
|
|
{
|
|
|
|
bool random = ModifierKeys == Keys.Control;
|
|
|
|
if (!SetSuggestedMoves(random))
|
|
|
|
return;
|
2019-11-16 01:34:18 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
else if (sender == GB_RelearnMoves)
|
2017-05-23 04:55:05 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
if (!SetSuggestedRelearnMoves())
|
|
|
|
return;
|
2017-05-23 04:55:05 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
else
|
2017-05-23 04:55:05 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
return;
|
2017-05-23 04:55:05 +00:00
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
UpdateLegality();
|
|
|
|
}
|
|
|
|
|
|
|
|
private bool SetSuggestedMoves(bool random = false, bool silent = false)
|
|
|
|
{
|
2023-03-22 01:19:55 +00:00
|
|
|
Span<ushort> moves = stackalloc ushort[4];
|
|
|
|
Entity.GetMoveSet(moves, random);
|
|
|
|
if (moves[0] == 0)
|
2017-05-23 04:55:05 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
if (!silent)
|
|
|
|
WinFormsUtil.Alert(MsgPKMSuggestionFormat);
|
|
|
|
return false;
|
2017-05-23 04:55:05 +00:00
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2023-03-22 01:19:55 +00:00
|
|
|
Span<ushort> current = stackalloc ushort[4];
|
|
|
|
Entity.GetMoves(current);
|
|
|
|
var same = Entity.IsEgg ? current.SequenceEqual(moves) : IsAllElementsShared(current, moves);
|
|
|
|
if (same)
|
2022-06-18 18:04:24 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!silent)
|
2017-05-23 04:55:05 +00:00
|
|
|
{
|
2023-03-22 01:19:55 +00:00
|
|
|
var msg = GetMoveListPrint(moves, GameInfo.Strings.movelist);
|
2022-06-18 18:04:24 +00:00
|
|
|
if (DialogResult.Yes != WinFormsUtil.Prompt(MessageBoxButtons.YesNo, MsgPKMSuggestionMoves, msg))
|
|
|
|
return false;
|
|
|
|
}
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2023-03-22 01:19:55 +00:00
|
|
|
Entity.SetMoves(moves);
|
2023-07-06 04:14:09 +00:00
|
|
|
if (Entity is ITechRecord tr)
|
|
|
|
{
|
|
|
|
tr.ClearRecordFlags();
|
|
|
|
tr.SetRecordFlags(moves);
|
|
|
|
}
|
2023-03-22 01:19:55 +00:00
|
|
|
Entity.HealPP();
|
2022-06-18 18:04:24 +00:00
|
|
|
FieldsLoaded = false;
|
|
|
|
LoadMoves(Entity);
|
|
|
|
ClickPP(this, EventArgs.Empty);
|
|
|
|
FieldsLoaded = true;
|
|
|
|
return true;
|
|
|
|
}
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2023-03-22 01:19:55 +00:00
|
|
|
private static bool IsAllElementsShared(Span<ushort> seq1, Span<ushort> seq2)
|
|
|
|
{
|
|
|
|
foreach (var entry in seq2)
|
|
|
|
{
|
|
|
|
if (!seq1.Contains(entry))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private bool SetSuggestedRelearnMoves(bool silent = false)
|
|
|
|
{
|
|
|
|
if (Entity.Format < 6)
|
|
|
|
return false;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2023-03-22 01:19:55 +00:00
|
|
|
Span<ushort> m = stackalloc ushort[4];
|
|
|
|
Legality.GetSuggestedRelearnMoves(m);
|
|
|
|
if (Entity.RelearnMove1 == m[0] && Entity.RelearnMove2 == m[1] && Entity.RelearnMove3 == m[2] && Entity.RelearnMove4 == m[3])
|
2022-06-18 18:04:24 +00:00
|
|
|
return false;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (!silent)
|
|
|
|
{
|
2023-03-22 01:19:55 +00:00
|
|
|
var msg = GetMoveListPrint(m, GameInfo.Strings.movelist);
|
2022-06-18 18:04:24 +00:00
|
|
|
if (DialogResult.Yes != WinFormsUtil.Prompt(MessageBoxButtons.YesNo, MsgPKMSuggestionRelearn, msg))
|
|
|
|
return false;
|
2017-05-23 04:55:05 +00:00
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-08-27 06:43:36 +00:00
|
|
|
CB_RelearnMove4.SelectedValue = (int)m[3];
|
|
|
|
CB_RelearnMove3.SelectedValue = (int)m[2];
|
|
|
|
CB_RelearnMove2.SelectedValue = (int)m[1];
|
|
|
|
CB_RelearnMove1.SelectedValue = (int)m[0];
|
2022-06-18 18:04:24 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-03-22 01:19:55 +00:00
|
|
|
private static string GetMoveListPrint(Span<ushort> moves, ReadOnlySpan<string> names)
|
|
|
|
{
|
|
|
|
var sb = new StringBuilder();
|
|
|
|
foreach (var move in moves)
|
|
|
|
{
|
|
|
|
if (move != 0)
|
|
|
|
sb.AppendLine(names[move]);
|
|
|
|
}
|
|
|
|
return sb.ToString();
|
|
|
|
}
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private bool SetSuggestedMetLocation(bool silent = false)
|
|
|
|
{
|
|
|
|
var encounter = EncounterSuggestion.GetSuggestedMetInfo(Entity);
|
|
|
|
if (encounter == null || (Entity.Format >= 3 && encounter.Location < 0))
|
2020-01-04 04:07:56 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
if (!silent)
|
|
|
|
WinFormsUtil.Alert(MsgPKMSuggestionNone);
|
|
|
|
return false;
|
2020-01-04 04:07:56 +00:00
|
|
|
}
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
int level = encounter.LevelMin;
|
|
|
|
int location = encounter.Location;
|
|
|
|
int minlvl = EncounterSuggestion.GetLowestLevel(Entity, encounter.LevelMin);
|
|
|
|
if (minlvl == 0)
|
|
|
|
minlvl = level;
|
|
|
|
|
|
|
|
if (Entity.CurrentLevel >= minlvl && Entity.Met_Level == level && Entity.Met_Location == location)
|
2017-05-23 04:55:05 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
if (!encounter.HasGroundTile(Entity.Format) || WinFormsUtil.GetIndex(CB_GroundTile) == (int)encounter.GetSuggestedGroundTile())
|
|
|
|
return false;
|
2017-05-23 04:55:05 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
if (minlvl < level)
|
|
|
|
minlvl = level;
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (!silent)
|
2017-05-23 04:55:05 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
var suggestions = EntitySuggestionUtil.GetMetLocationSuggestionMessage(Entity, level, location, minlvl);
|
|
|
|
if (suggestions.Count <= 1) // no suggestion
|
|
|
|
return false;
|
|
|
|
|
|
|
|
var msg = string.Join(Environment.NewLine, suggestions);
|
|
|
|
if (WinFormsUtil.Prompt(MessageBoxButtons.YesNo, msg) != DialogResult.Yes)
|
|
|
|
return false;
|
2017-05-23 04:55:05 +00:00
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (Entity.Format >= 3)
|
2018-12-05 02:38:47 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
Entity.Met_Location = location;
|
|
|
|
TB_MetLevel.Text = encounter.GetSuggestedMetLevel(Entity).ToString();
|
|
|
|
CB_MetLocation.SelectedValue = location;
|
|
|
|
|
|
|
|
if (encounter.HasGroundTile(Entity.Format))
|
|
|
|
CB_GroundTile.SelectedValue = (int)encounter.GetSuggestedGroundTile();
|
|
|
|
|
2023-01-22 04:02:33 +00:00
|
|
|
if (Entity is { Gen6: true, WasEgg: true } && ModifyPKM)
|
2022-06-18 18:04:24 +00:00
|
|
|
Entity.SetHatchMemory6();
|
2018-12-05 02:38:47 +00:00
|
|
|
}
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (Entity.CurrentLevel < minlvl)
|
|
|
|
TB_Level.Text = minlvl.ToString();
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
return true;
|
|
|
|
}
|
2018-08-29 04:13:45 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public void UpdateIVsGB(bool skipForm)
|
|
|
|
{
|
|
|
|
if (!FieldsLoaded)
|
|
|
|
return;
|
|
|
|
UC_Gender.Gender = Entity.Gender;
|
|
|
|
if (Entity.Species == (int)Species.Unown && !skipForm)
|
|
|
|
CB_Form.SelectedIndex = Entity.Form;
|
|
|
|
|
|
|
|
UpdateIsShiny();
|
|
|
|
UpdateSprite();
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void UpdateBall(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
PB_Ball.Image = SpriteUtil.GetBallSprite(WinFormsUtil.GetIndex(CB_Ball));
|
|
|
|
}
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void UpdateEXPLevel(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
if (ChangingFields)
|
|
|
|
return;
|
|
|
|
ChangingFields = true;
|
|
|
|
if (sender == TB_EXP)
|
|
|
|
{
|
|
|
|
// Change the Level
|
2023-02-05 19:18:05 +00:00
|
|
|
var expInput = Util.ToUInt32(TB_EXP.Text);
|
|
|
|
var expCalc = expInput;
|
2022-06-18 18:04:24 +00:00
|
|
|
var gr = Entity.PersonalInfo.EXPGrowth;
|
2023-02-05 19:18:05 +00:00
|
|
|
int lvlExp = Experience.GetLevel(expInput, gr);
|
|
|
|
if (lvlExp == 100)
|
|
|
|
expCalc = Experience.GetEXP(100, gr);
|
2022-06-18 18:04:24 +00:00
|
|
|
|
2023-02-05 19:18:05 +00:00
|
|
|
var lvlInput = Math.Max(1, Util.ToInt32(TB_Level.Text));
|
|
|
|
if (lvlInput != lvlExp)
|
|
|
|
TB_Level.Text = lvlExp.ToString();
|
|
|
|
if (expInput != expCalc && !HaX)
|
|
|
|
TB_EXP.Text = expCalc.ToString();
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Change the XP
|
|
|
|
int input = Util.ToInt32(TB_Level.Text);
|
|
|
|
int level = Math.Max(1, Math.Min(input, 100));
|
|
|
|
|
2023-02-05 19:18:05 +00:00
|
|
|
if (input != level && !string.IsNullOrWhiteSpace(TB_Level.Text))
|
2022-06-18 18:04:24 +00:00
|
|
|
TB_Level.Text = level.ToString();
|
|
|
|
TB_EXP.Text = Experience.GetEXP(level, Entity.PersonalInfo.EXPGrowth).ToString();
|
|
|
|
}
|
|
|
|
ChangingFields = false;
|
|
|
|
if (FieldsLoaded) // store values back
|
|
|
|
Entity.EXP = Util.ToUInt32(TB_EXP.Text);
|
|
|
|
UpdateStats();
|
|
|
|
UpdateLegality();
|
|
|
|
}
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void UpdateRandomPID(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
if (Entity.Format < 3)
|
|
|
|
return;
|
|
|
|
if (FieldsLoaded)
|
|
|
|
Entity.PID = Util.GetHexValue(TB_PID.Text);
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (sender == UC_Gender)
|
|
|
|
Entity.SetPIDGender(Entity.Gender);
|
|
|
|
else if (sender == CB_Nature && Entity.Nature != WinFormsUtil.GetIndex(CB_Nature))
|
|
|
|
Entity.SetPIDNature(WinFormsUtil.GetIndex(CB_Nature));
|
|
|
|
else if (sender == BTN_RerollPID)
|
|
|
|
Entity.SetPIDGender(Entity.Gender);
|
|
|
|
else if (sender == CB_Ability && CB_Ability.SelectedIndex != Entity.PIDAbility && Entity.PIDAbility > -1)
|
|
|
|
Entity.SetAbilityIndex(CB_Ability.SelectedIndex);
|
|
|
|
|
|
|
|
TB_PID.Text = Entity.PID.ToString("X8");
|
|
|
|
if (Entity.Format >= 6 && (Entity.Gen3 || Entity.Gen4 || Entity.Gen5))
|
|
|
|
TB_EC.Text = TB_PID.Text;
|
|
|
|
Update_ID(TB_EC, e);
|
|
|
|
}
|
2019-10-02 01:12:08 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void UpdateRandomEC(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
if (Entity.Format < 6)
|
|
|
|
return;
|
2019-10-02 01:12:08 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
Entity.SetRandomEC();
|
|
|
|
TB_EC.Text = Entity.EncryptionConstant.ToString("X8");
|
|
|
|
Update_ID(TB_EC, e);
|
|
|
|
UpdateLegality();
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void Update255_MTB(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
if (sender is not MaskedTextBox tb)
|
|
|
|
return;
|
|
|
|
if (Util.ToInt32(tb.Text) > byte.MaxValue)
|
|
|
|
tb.Text = "255";
|
|
|
|
if (sender == TB_Friendship && int.TryParse(TB_Friendship.Text, out var value))
|
2019-12-04 04:12:13 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
UpdateFromFriendshipTextBox(Entity, value);
|
|
|
|
UpdateStats();
|
2019-12-04 04:12:13 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2019-12-04 04:12:13 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void UpdateFormArgument(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
if (FieldsLoaded && Entity.Species == (int)Species.Alcremie)
|
|
|
|
UpdateSprite();
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void UpdateForm(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
if (FieldsLoaded && sender == CB_Form)
|
2017-06-18 01:37:19 +00:00
|
|
|
{
|
2022-08-27 06:43:36 +00:00
|
|
|
Entity.Form = (byte)CB_Form.SelectedIndex;
|
2022-06-18 18:04:24 +00:00
|
|
|
uint EXP = Experience.GetEXP(Entity.CurrentLevel, Entity.PersonalInfo.EXPGrowth);
|
|
|
|
TB_EXP.Text = EXP.ToString();
|
2017-06-18 01:37:19 +00:00
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
UpdateStats();
|
|
|
|
SetAbilityList();
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Gender Forms
|
|
|
|
if (WinFormsUtil.GetIndex(CB_Species) == (int)Species.Unown && FieldsLoaded)
|
2017-06-30 02:32:29 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
if (Entity.Format == 3)
|
2020-10-08 22:01:23 +00:00
|
|
|
{
|
2022-08-27 19:53:30 +00:00
|
|
|
Entity.SetPIDUnown3((byte)CB_Form.SelectedIndex);
|
2022-06-18 18:04:24 +00:00
|
|
|
TB_PID.Text = Entity.PID.ToString("X8");
|
2017-06-30 02:32:29 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
else if (Entity.Format == 2)
|
2017-06-30 02:32:29 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
int desiredForm = CB_Form.SelectedIndex;
|
|
|
|
while (Entity.Form != desiredForm)
|
|
|
|
{
|
|
|
|
FieldsLoaded = false;
|
|
|
|
Stats.UpdateRandomIVs(sender, EventArgs.Empty);
|
|
|
|
FieldsLoaded = true;
|
|
|
|
}
|
2017-06-30 02:32:29 +00:00
|
|
|
}
|
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
else if (CB_Form.Enabled && EntityGender.GetFromString(CB_Form.Text) < 2)
|
2017-05-23 04:55:05 +00:00
|
|
|
{
|
Refactoring: Move Source (Legality) (#3560)
Rewrites a good amount of legality APIs pertaining to:
* Legal moves that can be learned
* Evolution chains & cross-generation paths
* Memory validation with forgotten moves
In generation 8, there are 3 separate contexts an entity can exist in: SW/SH, BD/SP, and LA. Not every entity can cross between them, and not every entity from generation 7 can exist in generation 8 (Gogoat, etc). By creating class models representing the restrictions to cross each boundary, we are able to better track and validate data.
The old implementation of validating moves was greedy: it would iterate for all generations and evolutions, and build a full list of every move that can be learned, storing it on the heap. Now, we check one game group at a time to see if the entity can learn a move that hasn't yet been validated. End result is an algorithm that requires 0 allocation, and a smaller/quicker search space.
The old implementation of storing move parses was inefficient; for each move that was parsed, a new object is created and adjusted depending on the parse. Now, move parse results are `struct` and store the move parse contiguously in memory. End result is faster parsing and 0 memory allocation.
* `PersonalTable` objects have been improved with new API methods to check if a species+form can exist in the game.
* `IEncounterTemplate` objects have been improved to indicate the `EntityContext` they originate in (similar to `Generation`).
* Some APIs have been extended to accept `Span<T>` instead of Array/IEnumerable
2022-08-03 23:15:27 +00:00
|
|
|
if (CB_Form.Items.Count == 2) // actually M/F; Pumpkaboo forms in German are S,M,L,XL
|
2017-05-23 04:55:05 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
Entity.Gender = CB_Form.SelectedIndex;
|
|
|
|
UC_Gender.Gender = Entity.GetSaneGender();
|
2017-05-23 04:55:05 +00:00
|
|
|
}
|
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
else
|
2017-05-23 04:55:05 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
UC_Gender.Gender = Entity.GetSaneGender();
|
|
|
|
}
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
RefreshFormArguments();
|
|
|
|
if (ChangingFields)
|
|
|
|
return;
|
|
|
|
UpdateSprite();
|
|
|
|
}
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void RefreshFormArguments()
|
|
|
|
{
|
|
|
|
if (Entity is not IFormArgument f)
|
2022-12-17 21:04:37 +00:00
|
|
|
{
|
|
|
|
L_FormArgument.Visible = false;
|
2022-06-18 18:04:24 +00:00
|
|
|
return;
|
2022-12-17 21:04:37 +00:00
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (FieldsLoaded)
|
|
|
|
FA_Form.SaveArgument(f);
|
2022-11-26 22:40:31 +00:00
|
|
|
L_FormArgument.Visible = FA_Form.LoadArgument(f, Entity.Species, Entity.Form, Entity.Format);
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void UpdatePKRSstrain(object sender, EventArgs e)
|
|
|
|
{
|
2023-04-19 07:11:45 +00:00
|
|
|
if (!FieldsLoaded)
|
|
|
|
return;
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Change the PKRS Days to the legal bounds.
|
2023-04-19 07:11:45 +00:00
|
|
|
ChangePKRSstrainDropDownLists(-1, CB_PKRSStrain.SelectedIndex, CB_PKRSDays.SelectedIndex);
|
|
|
|
}
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2023-04-19 07:11:45 +00:00
|
|
|
private void ChangePKRSstrainDropDownLists(int oldStrain, int newStrain, int currentDuration)
|
|
|
|
{
|
|
|
|
if (oldStrain == newStrain)
|
|
|
|
return;
|
|
|
|
|
|
|
|
CB_PKRSDays.Items.Clear();
|
|
|
|
int max = Pokerus.GetMaxDuration(newStrain);
|
2022-06-18 18:04:24 +00:00
|
|
|
for (int day = 0; day <= max; day++)
|
|
|
|
CB_PKRSDays.Items.Add(day.ToString());
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Set the days back if they're legal
|
2023-04-19 07:11:45 +00:00
|
|
|
CB_PKRSDays.SelectedIndex = Math.Min(max, currentDuration);
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void UpdatePKRSdays(object sender, EventArgs e)
|
|
|
|
{
|
2023-04-19 07:11:45 +00:00
|
|
|
if (!FieldsLoaded)
|
|
|
|
return;
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
var days = CB_PKRSDays.SelectedIndex;
|
|
|
|
if (days != 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// If no days are selected
|
|
|
|
var strain = CB_PKRSStrain.SelectedIndex;
|
|
|
|
if (Pokerus.IsSusceptible(strain, days))
|
|
|
|
CHK_Cured.Checked = CHK_Infected.Checked = false; // No Strain = Never Cured / Infected, triggers Strain update
|
|
|
|
else if (Pokerus.IsImmune(strain, days))
|
|
|
|
CHK_Cured.Checked = true; // Any Strain = Cured
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void UpdatePKRSCured(object sender, EventArgs e)
|
|
|
|
{
|
2023-04-19 07:11:45 +00:00
|
|
|
if (!FieldsLoaded)
|
|
|
|
return;
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Cured PokeRus is toggled
|
|
|
|
if (CHK_Cured.Checked)
|
2019-11-29 18:44:52 +00:00
|
|
|
{
|
2023-04-19 07:11:45 +00:00
|
|
|
// If we're cured we have to have a strain infection.
|
|
|
|
if (CB_PKRSStrain.SelectedIndex == 0)
|
|
|
|
CB_PKRSStrain.SelectedIndex = 1;
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Has Had PokeRus
|
|
|
|
Label_PKRSdays.Visible = CB_PKRSDays.Visible = false;
|
|
|
|
CB_PKRSDays.SelectedIndex = 0;
|
2020-12-28 19:51:25 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
Label_PKRS.Visible = CB_PKRSStrain.Visible = true;
|
|
|
|
CHK_Infected.Checked = true;
|
2020-01-04 04:07:56 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
else if (!CHK_Infected.Checked)
|
2020-01-04 04:07:56 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
// Not Infected, Disable the other
|
|
|
|
Label_PKRS.Visible = CB_PKRSStrain.Visible = false;
|
|
|
|
CB_PKRSStrain.SelectedIndex = 0;
|
2017-05-23 04:55:05 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
else
|
2017-05-23 04:55:05 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
// Still Infected for a duration
|
|
|
|
Label_PKRSdays.Visible = CB_PKRSDays.Visible = true;
|
|
|
|
CB_PKRSDays.SelectedValue = 1;
|
2017-05-23 04:55:05 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
// if not cured yet, days > 0
|
|
|
|
if (!CHK_Cured.Checked && CHK_Infected.Checked && CB_PKRSDays.SelectedIndex == 0)
|
|
|
|
CB_PKRSDays.SelectedIndex = 1;
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
SetMarkings();
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void UpdatePKRSInfected(object sender, EventArgs e)
|
|
|
|
{
|
2023-04-19 07:11:45 +00:00
|
|
|
if (!FieldsLoaded)
|
|
|
|
return;
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (CHK_Cured.Checked)
|
2017-05-23 04:55:05 +00:00
|
|
|
{
|
2021-03-14 23:16:55 +00:00
|
|
|
if (!CHK_Infected.Checked)
|
2022-06-18 18:04:24 +00:00
|
|
|
CHK_Cured.Checked = false;
|
|
|
|
return;
|
2017-05-23 04:55:05 +00:00
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
Label_PKRS.Visible = CB_PKRSStrain.Visible = CHK_Infected.Checked;
|
|
|
|
if (!CHK_Infected.Checked)
|
2017-05-23 04:55:05 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
CB_PKRSStrain.SelectedIndex = 0;
|
|
|
|
CB_PKRSDays.SelectedIndex = 0;
|
|
|
|
Label_PKRSdays.Visible = CB_PKRSDays.Visible = false;
|
2017-05-23 04:55:05 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
else if (CB_PKRSStrain.SelectedIndex == 0)
|
2017-05-23 04:55:05 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
CB_PKRSStrain.SelectedIndex = CB_PKRSDays.SelectedIndex = 1;
|
|
|
|
Label_PKRSdays.Visible = CB_PKRSDays.Visible = true;
|
|
|
|
UpdatePKRSCured(sender, e);
|
2017-05-23 04:55:05 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void UpdateCountry(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
int index;
|
|
|
|
if (sender is ComboBox c && (index = WinFormsUtil.GetIndex(c)) > 0)
|
|
|
|
SetCountrySubRegion(CB_SubRegion, $"sr_{index:000}");
|
|
|
|
}
|
2021-01-02 18:35:48 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void UpdateSpecies(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
// Get Species dependent information
|
|
|
|
if (FieldsLoaded)
|
2022-08-27 06:43:36 +00:00
|
|
|
Entity.Species = (ushort)WinFormsUtil.GetIndex(CB_Species);
|
2022-06-18 18:04:24 +00:00
|
|
|
SpeciesIDTip.SetToolTip(CB_Species, Entity.Species.ToString("000"));
|
|
|
|
SetAbilityList();
|
|
|
|
SetForms();
|
|
|
|
UpdateForm(sender, EventArgs.Empty);
|
2018-05-24 23:53:51 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (!FieldsLoaded)
|
|
|
|
return;
|
2021-11-24 21:14:02 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Recalculate EXP for Given Level
|
|
|
|
uint EXP = Experience.GetEXP(Entity.CurrentLevel, Entity.PersonalInfo.EXPGrowth);
|
|
|
|
TB_EXP.Text = EXP.ToString();
|
2018-05-24 23:53:51 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Check for Gender Changes
|
|
|
|
UC_Gender.Gender = Entity.GetSaneGender();
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// If species changes and no nickname, set the new name == speciesName.
|
2023-01-22 04:02:33 +00:00
|
|
|
if (!CHK_NicknamedFlag.Checked)
|
2022-06-18 18:04:24 +00:00
|
|
|
UpdateNickname(sender, e);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
UpdateLegality();
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void UpdateOriginGame(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
GameVersion version = (GameVersion)WinFormsUtil.GetIndex(CB_GameOrigin);
|
2022-12-04 05:00:25 +00:00
|
|
|
if (version is 0 || version.IsValidSavedVersion())
|
2017-05-23 04:55:05 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
CheckMetLocationChange(version, Entity.Context);
|
|
|
|
if (FieldsLoaded)
|
|
|
|
Entity.Version = (int)version;
|
2017-05-23 04:55:05 +00:00
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Visibility logic for Gen 4 ground tile; only show for Gen 4 Pokemon.
|
|
|
|
if (Entity is IGroundTile)
|
2022-01-26 00:45:41 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
bool g4 = Entity.Gen4;
|
|
|
|
CB_GroundTile.Visible = Label_GroundTile.Visible = g4 && Entity.Format < 7;
|
|
|
|
if (!g4)
|
|
|
|
CB_GroundTile.SelectedValue = (int)GroundTileType.None;
|
2022-01-26 00:45:41 +00:00
|
|
|
}
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (!FieldsLoaded)
|
|
|
|
return;
|
2018-02-27 05:22:35 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
PB_Origin.Image = GetOriginSprite(Entity);
|
2023-01-22 04:02:33 +00:00
|
|
|
TID_Trainer.LoadIDValues(Entity, Entity.Format);
|
2022-06-18 18:04:24 +00:00
|
|
|
UpdateLegality();
|
|
|
|
}
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void CheckMetLocationChange(GameVersion version, EntityContext context)
|
|
|
|
{
|
|
|
|
// Does the list of locations need to be changed to another group?
|
|
|
|
var group = GameUtil.GetMetLocationVersionGroup(version);
|
2022-12-04 05:00:25 +00:00
|
|
|
if (group is GameVersion.Invalid)
|
2022-12-06 03:02:43 +00:00
|
|
|
{
|
|
|
|
var sav = RequestSaveFile;
|
|
|
|
group = GameUtil.GetMetLocationVersionGroup(sav.Version);
|
|
|
|
if (group is GameVersion.Invalid || version is GameVersion.Any)
|
|
|
|
version = group = context.GetSingleGameVersion();
|
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
if (group != origintrack || context != originFormat)
|
|
|
|
ReloadMetLocations(version, context);
|
|
|
|
origintrack = group;
|
|
|
|
originFormat = context;
|
|
|
|
}
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void ReloadMetLocations(GameVersion version, EntityContext context)
|
|
|
|
{
|
|
|
|
var metList = GameInfo.GetLocationList(version, context, egg: false);
|
|
|
|
CB_MetLocation.DataSource = new BindingSource(metList, null);
|
|
|
|
CB_MetLocation.DropDownWidth = GetWidth(metList, CB_MetLocation.Font);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
var eggList = GameInfo.GetLocationList(version, context, egg: true);
|
|
|
|
CB_EggLocation.DataSource = new BindingSource(eggList, null);
|
|
|
|
CB_EggLocation.DropDownWidth = GetWidth(eggList, CB_EggLocation.Font);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2022-12-06 03:02:43 +00:00
|
|
|
static int GetWidth(IReadOnlyList<ComboItem> items, Font f) => items.Count == 0 ? throw new ArgumentException("Expected items in array.", nameof(items)) :
|
2022-06-18 18:04:24 +00:00
|
|
|
items.Max(z => TextRenderer.MeasureText(z.Text, f).Width) +
|
|
|
|
SystemInformation.VerticalScrollBarWidth;
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (FieldsLoaded)
|
2017-05-23 04:55:05 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
SetMarkings(); // Set/Remove the Nativity marking when gamegroup changes too
|
|
|
|
int metLoc = EncounterSuggestion.GetSuggestedTransferLocation(Entity);
|
|
|
|
int eggLoc = CHK_AsEgg.Checked
|
|
|
|
? EncounterSuggestion.GetSuggestedEncounterEggLocationEgg(Entity, true)
|
|
|
|
: LocationEdits.GetNoneLocation(Entity);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
CB_MetLocation.SelectedValue = Math.Max(0, metLoc);
|
|
|
|
CB_EggLocation.SelectedValue = eggLoc;
|
2017-05-23 04:55:05 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
else
|
2017-05-23 04:55:05 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
ValidateChildren(); // hacky validation forcing
|
2017-05-23 04:55:05 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void UpdateExtraByteValue(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
if (!FieldsLoaded || CB_ExtraBytes.Items.Count == 0 || sender is not MaskedTextBox mtb)
|
|
|
|
return;
|
|
|
|
// Changed Extra Byte's Value
|
|
|
|
var value = Util.ToInt32(mtb.Text);
|
|
|
|
if (value > byte.MaxValue)
|
2017-05-23 04:55:05 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
mtb.Text = "255";
|
|
|
|
return; // above statement triggers the event again.
|
2017-05-23 04:55:05 +00:00
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
int offset = Convert.ToInt32(CB_ExtraBytes.Text, 16);
|
|
|
|
Entity.Data[offset] = (byte)value;
|
|
|
|
}
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void UpdateExtraByteIndex(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
if (CB_ExtraBytes.Items.Count == 0)
|
|
|
|
return;
|
|
|
|
// Byte changed, need to refresh the Text box for the byte's value.
|
|
|
|
var offset = Convert.ToInt32(CB_ExtraBytes.Text, 16);
|
|
|
|
TB_ExtraByte.Text = Entity.Data[offset].ToString();
|
|
|
|
}
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public void ChangeNature(int newNature)
|
|
|
|
{
|
|
|
|
if (Entity.Format < 3)
|
|
|
|
return;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
var cb = Entity.Format >= 8 ? CB_StatNature : CB_Nature;
|
|
|
|
cb.SelectedValue = newNature;
|
|
|
|
}
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void UpdateNatureModification(ComboBox cb, int nature)
|
|
|
|
{
|
|
|
|
string text = Stats.UpdateNatureModification(nature);
|
|
|
|
NatureTip.SetToolTip(cb, text);
|
|
|
|
}
|
2017-08-06 03:30:33 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void UpdateIsNicknamed(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
if (!FieldsLoaded)
|
|
|
|
return;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
Entity.Nickname = TB_Nickname.Text;
|
2023-01-22 04:02:33 +00:00
|
|
|
if (CHK_NicknamedFlag.Checked)
|
2022-06-18 18:04:24 +00:00
|
|
|
return;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2022-08-27 06:43:36 +00:00
|
|
|
var species = (ushort)WinFormsUtil.GetIndex(CB_Species);
|
2022-06-18 18:04:24 +00:00
|
|
|
if (species < 1 || species > Entity.MaxSpeciesID)
|
|
|
|
return;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (CHK_IsEgg.Checked)
|
|
|
|
species = 0; // get the egg name.
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (SpeciesName.IsNicknamedAnyLanguage(species, TB_Nickname.Text, Entity.Format))
|
2023-01-22 04:02:33 +00:00
|
|
|
CHK_NicknamedFlag.Checked = true;
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void UpdateNickname(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
if (sender == Label_Species)
|
2017-05-23 04:55:05 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
switch (ModifierKeys)
|
2017-05-23 04:55:05 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
case Keys.Control: RequestShowdownImport?.Invoke(sender, e); return;
|
|
|
|
case Keys.Alt: RequestShowdownExport?.Invoke(sender, e); return;
|
|
|
|
default:
|
2017-05-23 04:55:05 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2023-01-22 04:02:33 +00:00
|
|
|
if (CHK_NicknamedFlag.Checked)
|
2022-06-18 18:04:24 +00:00
|
|
|
return;
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Fetch Current Species and set it as Nickname Text
|
2022-08-27 06:43:36 +00:00
|
|
|
var species = (ushort)WinFormsUtil.GetIndex(CB_Species);
|
2022-08-27 19:53:30 +00:00
|
|
|
if (species is 0 || species > Entity.MaxSpeciesID)
|
|
|
|
{
|
|
|
|
TB_Nickname.Text = string.Empty;
|
|
|
|
return;
|
|
|
|
}
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2022-08-27 19:53:30 +00:00
|
|
|
string nick;
|
2022-06-18 18:04:24 +00:00
|
|
|
if (CHK_IsEgg.Checked)
|
2022-08-27 19:53:30 +00:00
|
|
|
{
|
|
|
|
// Get the egg name.
|
|
|
|
int language = WinFormsUtil.GetIndex(CB_Language);
|
|
|
|
nick = SpeciesName.GetEggName(language, Entity.Format);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// If name is that of another language, don't replace the nickname
|
|
|
|
if (sender != CB_Language && !SpeciesName.IsNicknamedAnyLanguage(species, TB_Nickname.Text, Entity.Format))
|
|
|
|
return;
|
|
|
|
int lang = WinFormsUtil.GetIndex(CB_Language);
|
|
|
|
nick = SpeciesName.GetSpeciesNameGeneration(species, lang, Entity.Format);
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-08-27 19:53:30 +00:00
|
|
|
TB_Nickname.Text = nick;
|
2022-06-18 18:04:24 +00:00
|
|
|
if (Entity is GBPKM pk)
|
|
|
|
pk.SetNotNicknamed();
|
|
|
|
}
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void UpdateNicknameClick(object sender, MouseEventArgs e)
|
|
|
|
{
|
|
|
|
if (ModifierKeys != Keys.Control)
|
|
|
|
return;
|
|
|
|
|
2022-11-25 01:42:17 +00:00
|
|
|
// Open Trash/Special Character form
|
|
|
|
// Set the string back to the entity in the right spot, so the span fetch has latest date.
|
|
|
|
Span<byte> trash;
|
|
|
|
TextBox tb = sender as TextBox ?? TB_Nickname;
|
2022-06-18 18:04:24 +00:00
|
|
|
if (tb == TB_Nickname)
|
2020-02-13 02:10:03 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
Entity.Nickname = tb.Text;
|
2022-11-25 01:42:17 +00:00
|
|
|
trash = Entity.Nickname_Trash;
|
2020-02-13 02:10:03 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
else if (tb == TB_OT)
|
2017-05-23 04:55:05 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
Entity.OT_Name = tb.Text;
|
2022-11-25 01:42:17 +00:00
|
|
|
trash = Entity.OT_Trash;
|
2017-05-23 04:55:05 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
else if (tb == TB_HT)
|
2017-05-23 04:55:05 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
Entity.HT_Name = tb.Text;
|
2022-11-25 01:42:17 +00:00
|
|
|
trash = Entity.HT_Trash;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return;
|
2017-05-23 04:55:05 +00:00
|
|
|
}
|
2022-11-25 01:42:17 +00:00
|
|
|
|
|
|
|
var sav = RequestSaveFile;
|
|
|
|
using var d = new TrashEditor(tb, trash, sav);
|
|
|
|
d.ShowDialog();
|
|
|
|
tb.Text = d.FinalString;
|
|
|
|
d.FinalBytes.CopyTo(trash);
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void UpdateNotOT(object sender, EventArgs e)
|
|
|
|
{
|
2023-01-27 05:58:04 +00:00
|
|
|
var text = TB_HT.Text;
|
|
|
|
if (string.IsNullOrWhiteSpace(text))
|
2017-05-23 04:55:05 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
ClickGT(GB_OT, EventArgs.Empty); // Switch CT over to OT.
|
|
|
|
UC_HTGender.Visible = false;
|
|
|
|
UC_HTGender.Gender = 0;
|
|
|
|
ReloadToFriendshipTextBox(Entity);
|
2023-01-27 05:58:04 +00:00
|
|
|
ToggleHandlerVisibility(false);
|
2017-05-23 04:55:05 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
else if (!UC_HTGender.Visible)
|
2017-05-23 04:55:05 +00:00
|
|
|
{
|
2023-01-27 05:58:04 +00:00
|
|
|
ToggleHandlerVisibility(true);
|
2017-05-23 04:55:05 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void UpdateIsEgg(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
// Display hatch counter if it is an egg, Display Friendship if it is not.
|
|
|
|
Label_HatchCounter.Visible = CHK_IsEgg.Checked && Entity.Format > 1;
|
|
|
|
Label_Friendship.Visible = !CHK_IsEgg.Checked && Entity.Format > 1;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (!FieldsLoaded)
|
|
|
|
return;
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (Entity.Format == 3 && CHK_IsEgg.Checked)
|
|
|
|
Entity.OT_Name = TB_OT.Text; // going to be remapped
|
|
|
|
|
|
|
|
Entity.IsEgg = CHK_IsEgg.Checked;
|
|
|
|
if (CHK_IsEgg.Checked)
|
2017-05-23 04:55:05 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
TB_Friendship.Text = EggStateLegality.GetMinimumEggHatchCycles(Entity).ToString();
|
|
|
|
|
|
|
|
// If we are an egg, it won't have a met location.
|
|
|
|
CHK_AsEgg.Checked = true;
|
|
|
|
GB_EggConditions.Enabled = true;
|
2018-07-07 00:37:07 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
CAL_MetDate.Value = new DateTime(2000, 01, 01);
|
|
|
|
|
|
|
|
// if egg wasn't originally obtained by OT => Link Trade, else => None
|
|
|
|
if (Entity.Format >= 4)
|
2017-05-23 04:55:05 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
var sav = SaveFileRequested.Invoke(this, e);
|
2023-01-22 04:02:33 +00:00
|
|
|
bool isTraded = sav.OT != TB_OT.Text || sav.TID16 != Entity.TID16 || sav.SID16 != Entity.SID16;
|
2022-11-25 01:42:17 +00:00
|
|
|
var loc = isTraded
|
|
|
|
? Locations.TradedEggLocation(sav.Generation, sav.Version)
|
|
|
|
: LocationEdits.GetNoneLocation(Entity);
|
2022-06-18 18:04:24 +00:00
|
|
|
CB_MetLocation.SelectedValue = loc;
|
2018-07-07 00:37:07 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
else if (Entity.Format == 3)
|
2018-07-07 00:37:07 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
CB_Language.SelectedValue = Entity.Language; // JPN
|
|
|
|
TB_OT.Text = Entity.OT_Name;
|
2019-11-18 00:00:23 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
|
2023-01-22 04:02:33 +00:00
|
|
|
CHK_NicknamedFlag.Checked = EggStateLegality.IsNicknameFlagSet(Entity);
|
Refactoring: Move Source (Legality) (#3560)
Rewrites a good amount of legality APIs pertaining to:
* Legal moves that can be learned
* Evolution chains & cross-generation paths
* Memory validation with forgotten moves
In generation 8, there are 3 separate contexts an entity can exist in: SW/SH, BD/SP, and LA. Not every entity can cross between them, and not every entity from generation 7 can exist in generation 8 (Gogoat, etc). By creating class models representing the restrictions to cross each boundary, we are able to better track and validate data.
The old implementation of validating moves was greedy: it would iterate for all generations and evolutions, and build a full list of every move that can be learned, storing it on the heap. Now, we check one game group at a time to see if the entity can learn a move that hasn't yet been validated. End result is an algorithm that requires 0 allocation, and a smaller/quicker search space.
The old implementation of storing move parses was inefficient; for each move that was parsed, a new object is created and adjusted depending on the parse. Now, move parse results are `struct` and store the move parse contiguously in memory. End result is faster parsing and 0 memory allocation.
* `PersonalTable` objects have been improved with new API methods to check if a species+form can exist in the game.
* `IEncounterTemplate` objects have been improved to indicate the `EntityContext` they originate in (similar to `Generation`).
* Some APIs have been extended to accept `Span<T>` instead of Array/IEnumerable
2022-08-03 23:15:27 +00:00
|
|
|
TB_Nickname.Text = SpeciesName.GetEggName(WinFormsUtil.GetIndex(CB_Language), Entity.Format);
|
2022-06-18 18:04:24 +00:00
|
|
|
|
|
|
|
// Wipe egg memories
|
|
|
|
if (Entity.Format >= 6 && ModifyPKM)
|
|
|
|
Entity.ClearMemories();
|
2022-12-17 22:42:41 +00:00
|
|
|
|
|
|
|
if (Entity is PK9)
|
|
|
|
CB_GameOrigin.SelectedValue = 0;
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
|
|
|
else // Not Egg
|
|
|
|
{
|
2023-01-22 04:02:33 +00:00
|
|
|
if (!CHK_NicknamedFlag.Checked)
|
2022-06-18 18:04:24 +00:00
|
|
|
UpdateNickname(this, EventArgs.Empty);
|
|
|
|
|
|
|
|
TB_Friendship.Text = Entity.PersonalInfo.BaseFriendship.ToString();
|
|
|
|
|
|
|
|
if (CB_EggLocation.SelectedIndex == 0)
|
2019-11-18 00:00:23 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
CAL_MetDate.Value = DateTime.Now;
|
|
|
|
CAL_EggDate.Value = new DateTime(2000, 01, 01);
|
|
|
|
CHK_AsEgg.Checked = false;
|
|
|
|
GB_EggConditions.Enabled = false;
|
2018-07-07 00:37:07 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
else
|
2018-07-07 00:37:07 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
CAL_MetDate.Value = CAL_EggDate.Value;
|
|
|
|
CB_MetLocation.SelectedValue = EncounterSuggestion.GetSuggestedEggMetLocation(Entity);
|
2017-05-23 04:55:05 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
|
Refactoring: Move Source (Legality) (#3560)
Rewrites a good amount of legality APIs pertaining to:
* Legal moves that can be learned
* Evolution chains & cross-generation paths
* Memory validation with forgotten moves
In generation 8, there are 3 separate contexts an entity can exist in: SW/SH, BD/SP, and LA. Not every entity can cross between them, and not every entity from generation 7 can exist in generation 8 (Gogoat, etc). By creating class models representing the restrictions to cross each boundary, we are able to better track and validate data.
The old implementation of validating moves was greedy: it would iterate for all generations and evolutions, and build a full list of every move that can be learned, storing it on the heap. Now, we check one game group at a time to see if the entity can learn a move that hasn't yet been validated. End result is an algorithm that requires 0 allocation, and a smaller/quicker search space.
The old implementation of storing move parses was inefficient; for each move that was parsed, a new object is created and adjusted depending on the parse. Now, move parse results are `struct` and store the move parse contiguously in memory. End result is faster parsing and 0 memory allocation.
* `PersonalTable` objects have been improved with new API methods to check if a species+form can exist in the game.
* `IEncounterTemplate` objects have been improved to indicate the `EntityContext` they originate in (similar to `Generation`).
* Some APIs have been extended to accept `Span<T>` instead of Array/IEnumerable
2022-08-03 23:15:27 +00:00
|
|
|
var nick = SpeciesName.GetEggName(WinFormsUtil.GetIndex(CB_Language), Entity.Format);
|
|
|
|
if (TB_Nickname.Text == nick)
|
2023-01-22 04:02:33 +00:00
|
|
|
CHK_NicknamedFlag.Checked = false;
|
2017-05-23 04:55:05 +00:00
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
UpdateNickname(this, EventArgs.Empty);
|
|
|
|
UpdateSprite();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void UpdateMetAsEgg(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
GB_EggConditions.Enabled = CHK_AsEgg.Checked;
|
|
|
|
if (CHK_AsEgg.Checked)
|
2017-05-23 04:55:05 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
if (!FieldsLoaded)
|
2017-05-23 04:55:05 +00:00
|
|
|
return;
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
CAL_EggDate.Value = DateTime.Now;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
bool isTradedEgg = Entity.IsEgg && Entity.Version != (int)RequestSaveFile.Version;
|
|
|
|
CB_EggLocation.SelectedValue = EncounterSuggestion.GetSuggestedEncounterEggLocationEgg(Entity, isTradedEgg);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Remove egg met data
|
|
|
|
CHK_IsEgg.Checked = false;
|
|
|
|
CAL_EggDate.Value = new DateTime(2000, 01, 01);
|
|
|
|
CB_EggLocation.SelectedValue = LocationEdits.GetNoneLocation(Entity);
|
|
|
|
|
|
|
|
UpdateLegality();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void UpdateShinyPID(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
var changePID = Entity.Format >= 3 && (ModifierKeys & Keys.Alt) == 0;
|
|
|
|
UpdateShiny(changePID);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void UpdateShiny(bool changePID)
|
|
|
|
{
|
|
|
|
Entity.PID = Util.GetHexValue(TB_PID.Text);
|
|
|
|
Entity.Nature = WinFormsUtil.GetIndex(CB_Nature);
|
|
|
|
Entity.Gender = UC_Gender.Gender;
|
2022-08-27 06:43:36 +00:00
|
|
|
Entity.Form = (byte)CB_Form.SelectedIndex;
|
2022-06-18 18:04:24 +00:00
|
|
|
Entity.Version = WinFormsUtil.GetIndex(CB_GameOrigin);
|
|
|
|
|
|
|
|
if (Entity.Format > 2)
|
|
|
|
{
|
|
|
|
var type = (ModifierKeys & ~Keys.Alt) switch
|
2022-05-03 01:11:31 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
Keys.Shift => Shiny.AlwaysSquare,
|
|
|
|
Keys.Control => Shiny.AlwaysStar,
|
|
|
|
_ => Shiny.Random,
|
|
|
|
};
|
|
|
|
if (changePID)
|
2022-05-03 01:11:31 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
CommonEdits.SetShiny(Entity, type);
|
|
|
|
TB_PID.Text = Entity.PID.ToString("X8");
|
|
|
|
|
|
|
|
int gen = Entity.Generation;
|
|
|
|
bool pre3DS = gen is 3 or 4 or 5;
|
|
|
|
if (pre3DS && Entity.Format >= 6)
|
|
|
|
TB_EC.Text = TB_PID.Text;
|
2022-05-03 01:11:31 +00:00
|
|
|
}
|
|
|
|
else
|
2021-07-31 01:05:17 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
Entity.SetShinySID(type);
|
|
|
|
TID_Trainer.UpdateSID();
|
2021-07-31 01:05:17 +00:00
|
|
|
}
|
2017-05-23 04:55:05 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
else
|
2017-05-23 04:55:05 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
Entity.SetShiny();
|
2022-06-26 06:08:28 +00:00
|
|
|
LoadIVs(Entity);
|
2022-06-18 18:04:24 +00:00
|
|
|
Stats.UpdateIVs(this, EventArgs.Empty);
|
|
|
|
}
|
2019-05-30 04:35:52 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
UpdateIsShiny();
|
|
|
|
UpdatePreviewSprite?.Invoke(this, EventArgs.Empty);
|
|
|
|
UpdateLegality();
|
|
|
|
}
|
2019-05-30 04:35:52 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void UpdateTSV(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
if (Entity.Format <= 2)
|
|
|
|
return;
|
2019-02-10 02:44:21 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
TID_Trainer.UpdateTSV();
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
Entity.PID = Util.GetHexValue(TB_PID.Text);
|
|
|
|
var tip = $"PSV: {Entity.PSV:d4}";
|
|
|
|
if (Entity.IsShiny)
|
|
|
|
tip += $" | Xor = {Entity.ShinyXor}";
|
2023-04-01 23:52:12 +00:00
|
|
|
TipPIDInfo.SetToolTip(TB_PID, tip);
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void Update_ID(object? sender, EventArgs e)
|
|
|
|
{
|
|
|
|
if (!FieldsLoaded)
|
|
|
|
return;
|
|
|
|
// Trim out nonhex characters
|
|
|
|
TB_PID.Text = (Entity.PID = Util.GetHexValue(TB_PID.Text)).ToString("X8");
|
|
|
|
TB_EC.Text = (Entity.EncryptionConstant = Util.GetHexValue(TB_EC.Text)).ToString("X8");
|
2019-02-10 02:44:21 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
UpdateIsShiny();
|
|
|
|
UpdateSprite();
|
|
|
|
Stats.UpdateCharacteristic(); // If the EC is changed, EC%6 (Characteristic) might be changed.
|
|
|
|
if (Entity.Format <= 4)
|
2018-08-02 04:57:15 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
FieldsLoaded = false;
|
|
|
|
Entity.PID = Util.GetHexValue(TB_PID.Text);
|
|
|
|
CB_Nature.SelectedValue = Entity.Nature;
|
|
|
|
UC_Gender.Gender = Entity.Gender;
|
|
|
|
UpdateNatureModification(CB_Nature, Entity.Nature);
|
|
|
|
FieldsLoaded = true;
|
2019-05-30 04:35:52 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2019-05-30 04:35:52 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void Update_ID64(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
if (!FieldsLoaded)
|
|
|
|
return;
|
|
|
|
// Trim out nonhex characters
|
|
|
|
if (sender == TB_HomeTracker && Entity is IHomeTrack home)
|
2019-05-30 04:35:52 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
var value = Util.GetHexValue64(TB_HomeTracker.Text);
|
|
|
|
home.Tracker = value;
|
|
|
|
TB_HomeTracker.Text = value.ToString("X16");
|
2018-08-02 04:57:15 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2018-08-02 04:57:15 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void UpdateShadowID(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
if (!FieldsLoaded)
|
|
|
|
return;
|
|
|
|
FLP_Purification.Visible = NUD_ShadowID.Value > 0;
|
|
|
|
}
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void UpdatePurification(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
if (!FieldsLoaded)
|
|
|
|
return;
|
|
|
|
FieldsLoaded = false;
|
|
|
|
var value = NUD_Purification.Value;
|
|
|
|
CHK_Shadow.Checked = Entity is CK3 ? value != CK3.Purified : value > 0;
|
|
|
|
FieldsLoaded = true;
|
|
|
|
}
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void UpdateShadowCHK(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
if (!FieldsLoaded)
|
|
|
|
return;
|
|
|
|
FieldsLoaded = false;
|
|
|
|
NUD_Purification.Value = CHK_Shadow.Checked ? 1 : Entity is CK3 && NUD_ShadowID.Value != 0 ? CK3.Purified : 0;
|
2022-11-25 01:42:17 +00:00
|
|
|
((IShadowCapture)Entity).Purification = (int)NUD_Purification.Value;
|
2022-06-18 18:04:24 +00:00
|
|
|
UpdatePreviewSprite?.Invoke(this, EventArgs.Empty);
|
|
|
|
FieldsLoaded = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void ValidateComboBox(ComboBox cb)
|
|
|
|
{
|
|
|
|
if (cb.Text.Length == 0 && cb.Items.Count > 0)
|
|
|
|
cb.SelectedIndex = 0;
|
|
|
|
else if (cb.SelectedValue == null)
|
|
|
|
cb.BackColor = Draw.InvalidSelection;
|
|
|
|
else
|
|
|
|
cb.ResetBackColor();
|
|
|
|
}
|
|
|
|
|
2023-01-22 04:02:33 +00:00
|
|
|
private void ValidateComboBox(object? sender, CancelEventArgs e)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
if (sender is not ComboBox cb)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ValidateComboBox(cb);
|
|
|
|
UpdateSprite();
|
|
|
|
}
|
|
|
|
|
2023-01-22 04:02:33 +00:00
|
|
|
private void ValidateComboBox2(object? sender, EventArgs e)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
if (!FieldsLoaded)
|
|
|
|
return;
|
2019-10-20 03:33:37 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
ValidateComboBox(sender, new CancelEventArgs());
|
|
|
|
if (sender == CB_Ability)
|
2019-10-20 03:33:37 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
if (Entity.Format >= 6)
|
|
|
|
TB_AbilityNumber.Text = (1 << CB_Ability.SelectedIndex).ToString();
|
|
|
|
else if (Entity.Format <= 5 && CB_Ability.SelectedIndex < 2) // Format <= 5, not hidden
|
|
|
|
UpdateRandomPID(sender, e);
|
|
|
|
UpdateLegality();
|
2019-10-20 03:33:37 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
else if (sender == CB_Nature)
|
2017-05-23 04:55:05 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
if (Entity.Format <= 4)
|
|
|
|
UpdateRandomPID(sender, e);
|
|
|
|
Entity.Nature = WinFormsUtil.GetIndex(CB_Nature);
|
|
|
|
UpdateNatureModification(CB_Nature, Entity.Nature);
|
|
|
|
Stats.UpdateIVs(sender, EventArgs.Empty); // updating Nature will trigger stats to update as well
|
|
|
|
UpdateLegality();
|
2017-05-23 04:55:05 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
else if (sender == CB_StatNature)
|
2019-11-16 07:12:28 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
Entity.StatNature = WinFormsUtil.GetIndex(CB_StatNature);
|
|
|
|
UpdateNatureModification(CB_StatNature, Entity.StatNature);
|
|
|
|
Stats.UpdateIVs(sender, EventArgs.Empty); // updating Nature will trigger stats to update as well
|
2022-02-05 01:36:51 +00:00
|
|
|
UpdateLegality();
|
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
else if (sender == CB_HeldItem)
|
2022-02-05 01:36:51 +00:00
|
|
|
{
|
2019-11-16 07:12:28 +00:00
|
|
|
UpdateLegality();
|
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
|
|
|
|
2023-01-22 04:02:33 +00:00
|
|
|
private void ValidateMove(object? sender, EventArgs e)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
if (!FieldsLoaded || sender is not ComboBox cb)
|
|
|
|
return;
|
2019-11-16 07:12:28 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
ValidateComboBox(cb);
|
|
|
|
|
|
|
|
// Store value back, repopulate legality.
|
2022-08-27 06:43:36 +00:00
|
|
|
var value = (ushort)WinFormsUtil.GetIndex(cb);
|
2023-01-22 04:02:33 +00:00
|
|
|
int index = Array.FindIndex(Moves, z => z.CB_Move == cb);
|
2022-06-18 18:04:24 +00:00
|
|
|
if (index != -1)
|
2017-05-23 04:55:05 +00:00
|
|
|
{
|
2023-01-22 04:02:33 +00:00
|
|
|
Moves[index].HealPP(Entity);
|
2022-06-18 18:04:24 +00:00
|
|
|
Entity.SetMove(index, value);
|
2017-06-21 00:57:23 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
else if ((index = Array.IndexOf(Relearn, cb)) != -1)
|
2017-06-21 00:57:23 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
Entity.SetRelearnMove(index, value);
|
2017-06-21 00:57:23 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
else if (cb == CB_AlphaMastered && Entity is PA8 pa8)
|
2018-08-20 01:22:07 +00:00
|
|
|
{
|
2022-08-27 06:43:36 +00:00
|
|
|
pa8.AlphaMove = value;
|
2018-08-20 01:22:07 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
else
|
2017-06-21 00:57:23 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
// Shouldn't hit here.
|
|
|
|
throw new InvalidOperationException();
|
|
|
|
}
|
2023-01-22 04:02:33 +00:00
|
|
|
UpdateLegality(args: UpdateLegalityArgs.SkipMoveRepopulation);
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2023-01-22 04:02:33 +00:00
|
|
|
private void ValidateMovePaint(object? sender, DrawItemEventArgs e)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
2023-01-22 04:02:33 +00:00
|
|
|
if (sender is null || e.Index < 0)
|
2022-06-18 18:04:24 +00:00
|
|
|
return;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2023-01-22 04:02:33 +00:00
|
|
|
var cb = (ComboBox)sender;
|
|
|
|
var item = cb.Items[e.Index];
|
|
|
|
var (text, value) = (ComboItem)item;
|
2022-08-27 06:43:36 +00:00
|
|
|
var valid = LegalMoveSource.Info.CanLearn((ushort)value) && !HaX;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
var current = (e.State & DrawItemState.Selected) != 0;
|
|
|
|
var brush = Draw.Brushes.GetBackground(valid, current);
|
|
|
|
var textColor = Draw.GetText(current);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
DrawMoveRectangle(e, brush, text, textColor);
|
|
|
|
}
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private static void DrawMoveRectangle(DrawItemEventArgs e, Brush brush, string text, Color textColor)
|
|
|
|
{
|
|
|
|
var rec = new Rectangle(e.Bounds.X - 1, e.Bounds.Y, e.Bounds.Width + 1, e.Bounds.Height + 0); // 1px left
|
|
|
|
e.Graphics.FillRectangle(brush, rec);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
const TextFormatFlags flags = TextFormatFlags.Left | TextFormatFlags.EndEllipsis | TextFormatFlags.ExpandTabs | TextFormatFlags.SingleLine;
|
|
|
|
TextRenderer.DrawText(e.Graphics, text, e.Font, rec, textColor, flags);
|
|
|
|
}
|
2018-05-12 15:13:39 +00:00
|
|
|
|
2023-01-22 04:02:33 +00:00
|
|
|
private void MeasureDropDownHeight(object? sender, MeasureItemEventArgs e) => e.ItemHeight = CB_RelearnMove1.ItemHeight;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2023-01-22 04:02:33 +00:00
|
|
|
private void ValidateMoveDropDown(object? sender, EventArgs e)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
2023-01-22 04:02:33 +00:00
|
|
|
if (sender is not ComboBox s)
|
|
|
|
return;
|
|
|
|
var index = Array.FindIndex(Moves, z => z.CB_Move == s);
|
2022-06-18 18:04:24 +00:00
|
|
|
|
|
|
|
// Populating the combobox drop-down list is deferred until the dropdown is entered into at least once.
|
|
|
|
// Saves some lag delays when viewing a pk.
|
|
|
|
if (LegalMoveSource.Display.GetIsMoveBoxOrdered(index))
|
|
|
|
return;
|
|
|
|
SetMoveDataSource(s);
|
|
|
|
LegalMoveSource.Display.SetIsMoveBoxOrdered(index, true);
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void SetMoveDataSource(ComboBox c)
|
|
|
|
{
|
2022-08-22 03:45:35 +00:00
|
|
|
FieldsLoaded = false;
|
2022-06-18 18:04:24 +00:00
|
|
|
var index = WinFormsUtil.GetIndex(c);
|
|
|
|
c.DataSource = new BindingSource(LegalMoveSource.Display.DataSource, null);
|
|
|
|
c.SelectedValue = index;
|
2022-08-22 03:45:35 +00:00
|
|
|
FieldsLoaded = true;
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2017-06-19 05:27:40 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void ValidateLocation(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
if (!FieldsLoaded)
|
|
|
|
return;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
ValidateComboBox((ComboBox)sender);
|
|
|
|
Entity.Met_Location = WinFormsUtil.GetIndex(CB_MetLocation);
|
|
|
|
Entity.Egg_Location = WinFormsUtil.GetIndex(CB_EggLocation);
|
|
|
|
UpdateLegality();
|
|
|
|
}
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Secondary Windows for Ribbons/Amie/Memories
|
|
|
|
private void OpenRibbons(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
using var form = new RibbonEditor(Entity);
|
|
|
|
form.ShowDialog();
|
2023-04-01 23:52:12 +00:00
|
|
|
|
|
|
|
UpdateAffixed(Entity);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void UpdateAffixed(PKM pk)
|
|
|
|
{
|
|
|
|
if (pk is IRibbonSetAffixed a)
|
|
|
|
{
|
|
|
|
var affixed = a.AffixedRibbon;
|
|
|
|
if (affixed != -1)
|
|
|
|
{
|
|
|
|
PB_Affixed.Image = RibbonSpriteUtil.GetRibbonSprite((RibbonIndex)affixed);
|
2023-04-02 00:46:10 +00:00
|
|
|
PB_Affixed.Visible = true;
|
2023-04-01 23:52:12 +00:00
|
|
|
// Update the tooltip with the ribbon name.
|
|
|
|
var name = RibbonStrings.GetName($"Ribbon{(RibbonIndex)affixed}");
|
|
|
|
AffixedTip.SetToolTip(PB_Affixed, name);
|
2023-04-02 00:46:10 +00:00
|
|
|
return;
|
2023-04-01 23:52:12 +00:00
|
|
|
}
|
2023-04-02 00:46:10 +00:00
|
|
|
if (pk is IRibbonSetMarks { RibbonMarkCount: not 0 })
|
2023-04-02 00:23:04 +00:00
|
|
|
{
|
2023-04-02 00:46:10 +00:00
|
|
|
PB_Affixed.Image = Properties.Resources.ribbon_affix_none;
|
|
|
|
PB_Affixed.Visible = true;
|
2023-04-02 00:23:04 +00:00
|
|
|
AffixedTip.SetToolTip(PB_Affixed, "Ribbons / Marks available to affix.");
|
2023-04-02 00:46:10 +00:00
|
|
|
return;
|
2023-04-02 00:23:04 +00:00
|
|
|
}
|
2023-04-01 23:52:12 +00:00
|
|
|
}
|
|
|
|
PB_Affixed.Visible = false;
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void OpenMedals(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
using var form = new SuperTrainingEditor(Entity);
|
|
|
|
form.ShowDialog();
|
|
|
|
}
|
2018-11-14 03:25:03 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void OpenHistory(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
// Write back current values
|
|
|
|
Entity.HT_Name = TB_HT.Text;
|
|
|
|
Entity.OT_Name = TB_OT.Text;
|
|
|
|
Entity.IsEgg = CHK_IsEgg.Checked;
|
|
|
|
UpdateFromFriendshipTextBox(Entity, Util.ToInt32(TB_Friendship.Text));
|
|
|
|
using var form = new MemoryAmie(Entity);
|
|
|
|
form.ShowDialog();
|
|
|
|
ReloadToFriendshipTextBox(Entity);
|
|
|
|
}
|
2022-02-18 14:52:30 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void B_Records_Click(object sender, EventArgs e)
|
|
|
|
{
|
2022-11-25 01:42:17 +00:00
|
|
|
if (Entity is not ITechRecord t)
|
2022-06-18 18:04:24 +00:00
|
|
|
return;
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (ModifierKeys == Keys.Shift)
|
2017-05-23 04:55:05 +00:00
|
|
|
{
|
2022-08-27 06:43:36 +00:00
|
|
|
Span<ushort> moves = stackalloc ushort[4];
|
2022-06-26 06:08:28 +00:00
|
|
|
Entity.GetMoves(moves);
|
|
|
|
t.SetRecordFlags(moves);
|
2022-06-18 18:04:24 +00:00
|
|
|
UpdateLegality();
|
|
|
|
return;
|
2017-05-23 04:55:05 +00:00
|
|
|
}
|
2018-05-12 15:13:39 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
using var form = new TechRecordEditor(t, Entity);
|
|
|
|
form.ShowDialog();
|
|
|
|
UpdateLegality();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void B_MoveShop_Click(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
if (Entity is not IMoveShop8Mastery m)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (ModifierKeys == Keys.Shift)
|
2017-05-23 04:55:05 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
m.ClearMoveShopFlags();
|
|
|
|
if (Legality.EncounterMatch is IMasteryInitialMoveShop8 enc)
|
|
|
|
enc.SetInitialMastery(Entity);
|
|
|
|
m.SetMoveShopFlags(Entity);
|
|
|
|
UpdateLegality();
|
|
|
|
return;
|
2017-05-23 04:55:05 +00:00
|
|
|
}
|
2017-12-22 06:55:33 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
using var form = new MoveShopEditor(m, m, Entity);
|
|
|
|
form.ShowDialog();
|
|
|
|
UpdateLegality();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Refreshes the interface for the current PKM format.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="sav">Save File context the editor is editing for</param>
|
|
|
|
/// <param name="pk">Pokémon data to edit</param>
|
|
|
|
public bool ToggleInterface(SaveFile sav, PKM pk)
|
|
|
|
{
|
|
|
|
Entity = sav.GetCompatiblePKM(pk);
|
|
|
|
ToggleInterface(Entity);
|
|
|
|
return FinalizeInterface(sav);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void ToggleInterface(PKM t)
|
|
|
|
{
|
|
|
|
var pb7 = t is PB7;
|
|
|
|
int gen = t.Format;
|
2022-11-25 01:42:17 +00:00
|
|
|
FLP_Purification.Visible = FLP_ShadowID.Visible = t is IShadowCapture;
|
2022-06-18 18:04:24 +00:00
|
|
|
bool sizeCP = gen >= 8 || pb7;
|
2023-02-05 23:00:31 +00:00
|
|
|
SizeCP.Visible = SizeCP.TabStop = sizeCP;
|
2022-06-18 18:04:24 +00:00
|
|
|
if (sizeCP)
|
|
|
|
SizeCP.ToggleVisibility(t);
|
|
|
|
PB_Favorite.Visible = t is IFavorite;
|
|
|
|
PB_BattleVersion.Visible = FLP_BattleVersion.Visible = t is IBattleVersion;
|
|
|
|
BTN_History.Visible = gen >= 6 && !pb7;
|
|
|
|
BTN_Ribbons.Visible = gen >= 3 && !pb7;
|
|
|
|
BTN_Medals.Visible = gen is 6 or 7 && !pb7;
|
|
|
|
FLP_Country.Visible = FLP_SubRegion.Visible = FLP_3DSRegion.Visible = t is IRegionOrigin;
|
|
|
|
FLP_OriginalNature.Visible = gen >= 8;
|
2023-01-22 04:02:33 +00:00
|
|
|
B_RelearnFlags.Visible = t is ITechRecord;
|
2022-06-18 18:04:24 +00:00
|
|
|
B_MoveShop.Visible = t is IMoveShop8Mastery;
|
2023-01-22 04:02:33 +00:00
|
|
|
FLP_HTLanguage.Visible = gen >= 8;
|
2022-06-18 18:04:24 +00:00
|
|
|
L_AlphaMastered.Visible = CB_AlphaMastered.Visible = t is PA8;
|
2022-11-25 01:42:17 +00:00
|
|
|
FLP_ObedienceLevel.Visible = t is IObedienceLevel;
|
2022-06-18 18:04:24 +00:00
|
|
|
Contest.ToggleInterface(Entity, Entity.Context);
|
2022-12-17 21:04:37 +00:00
|
|
|
if (t is not IFormArgument)
|
|
|
|
L_FormArgument.Visible = false;
|
2022-06-18 18:04:24 +00:00
|
|
|
|
|
|
|
ToggleInterface(Entity.Format);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void ToggleSecrets(bool hidden, int gen)
|
|
|
|
{
|
|
|
|
Label_EncryptionConstant.Visible = BTN_RerollEC.Visible = TB_EC.Visible = gen >= 6 && !hidden;
|
|
|
|
BTN_RerollPID.Visible = Label_PID.Visible = TB_PID.Visible = gen >= 3 && !hidden;
|
|
|
|
TB_HomeTracker.Visible = L_HomeTracker.Visible = gen >= 8 && !hidden;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void ToggleInterface(int gen)
|
|
|
|
{
|
|
|
|
ToggleSecrets(HideSecretValues, gen);
|
2023-01-22 04:02:33 +00:00
|
|
|
FLP_Handler.Visible = GB_nOT.Visible = FLP_HT.Visible = GB_RelearnMoves.Visible = gen >= 6;
|
2022-06-18 18:04:24 +00:00
|
|
|
|
|
|
|
PB_Origin.Visible = gen >= 6;
|
|
|
|
FLP_NSparkle.Visible = L_NSparkle.Visible = CHK_NSparkle.Visible = gen == 5;
|
|
|
|
|
|
|
|
CHK_AsEgg.Visible = GB_EggConditions.Visible = PB_Mark5.Visible = PB_Mark6.Visible = gen >= 4;
|
2023-01-22 04:02:33 +00:00
|
|
|
ShinyLeaf.Visible = gen == 4;
|
2022-06-18 18:04:24 +00:00
|
|
|
|
2023-02-05 23:00:31 +00:00
|
|
|
DEV_Ability.Enabled = DEV_Ability.Visible = DEV_Ability.TabStop = gen > 3 && HaX;
|
|
|
|
CB_Ability.Visible = CB_Ability.TabStop = !DEV_Ability.Enabled && gen >= 3;
|
2022-06-18 18:04:24 +00:00
|
|
|
FLP_Nature.Visible = gen >= 3;
|
|
|
|
FLP_Ability.Visible = gen >= 3;
|
2023-01-22 04:02:33 +00:00
|
|
|
FLP_ExtraBytes.Visible = gen >= 3;
|
2023-02-05 23:00:31 +00:00
|
|
|
GB_Markings.Visible = GB_Markings.TabStop = gen >= 3;
|
2022-06-18 18:04:24 +00:00
|
|
|
CB_Form.Enabled = gen >= 3;
|
2023-02-05 23:00:31 +00:00
|
|
|
FA_Form.Visible = FA_Form.TabStop = gen >= 6;
|
2022-06-18 18:04:24 +00:00
|
|
|
|
|
|
|
FLP_Friendship.Visible = FLP_Form.Visible = gen >= 2;
|
|
|
|
FLP_HeldItem.Visible = gen >= 2;
|
2023-02-05 23:00:31 +00:00
|
|
|
CHK_IsEgg.Visible = CHK_IsEgg.TabStop = gen >= 2;
|
2022-06-18 18:04:24 +00:00
|
|
|
FLP_PKRS.Visible = FLP_EggPKRSRight.Visible = gen >= 2;
|
2023-02-05 23:00:31 +00:00
|
|
|
UC_Gender.Visible = UC_OTGender.Visible = UC_OTGender.TabStop = gen >= 2;
|
2022-06-18 18:04:24 +00:00
|
|
|
FLP_CatchRate.Visible = gen == 1;
|
|
|
|
|
|
|
|
// HaX override, needs to be after DEV_Ability enabled assignment.
|
|
|
|
TB_AbilityNumber.Visible = gen >= 6 && DEV_Ability.Enabled;
|
|
|
|
|
|
|
|
// Met Tab
|
|
|
|
FLP_MetDate.Visible = gen >= 4;
|
2022-11-25 01:42:17 +00:00
|
|
|
CHK_Fateful.Visible = FLP_Ball.Visible = FLP_OriginGame.Visible = gen >= 3;
|
2022-06-18 18:04:24 +00:00
|
|
|
FLP_MetLocation.Visible = FLP_MetLevel.Visible = gen >= 2;
|
|
|
|
FLP_GroundTile.Visible = gen is 4 or 5 or 6;
|
|
|
|
FLP_TimeOfDay.Visible = gen == 2;
|
|
|
|
|
|
|
|
Stats.ToggleInterface(Entity, gen);
|
|
|
|
|
|
|
|
CenterSubEditors();
|
|
|
|
}
|
|
|
|
|
|
|
|
private bool FinalizeInterface(SaveFile sav)
|
|
|
|
{
|
|
|
|
FieldsLoaded = false;
|
|
|
|
|
|
|
|
bool TranslationRequired = false;
|
|
|
|
PopulateFilteredDataSources(sav);
|
|
|
|
PopulateFields(Entity);
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Save File Specific Limits
|
2022-11-25 01:42:17 +00:00
|
|
|
TB_OT.MaxLength = Entity.MaxStringLengthOT;
|
|
|
|
TB_HT.MaxLength = Entity.MaxStringLengthOT;
|
|
|
|
TB_Nickname.MaxLength = Entity.MaxStringLengthNickname;
|
2022-06-18 18:04:24 +00:00
|
|
|
|
|
|
|
// Hide Unused Tabs
|
2023-01-22 04:02:33 +00:00
|
|
|
if (Entity.Format == 1 && Hidden_TC.TabPages.Contains(Hidden_Met))
|
|
|
|
{
|
|
|
|
Hidden_TC.TabPages.Remove(Hidden_Met);
|
|
|
|
TC_Editor.TabPages.Remove(Tab_Met);
|
|
|
|
}
|
|
|
|
else if (Entity.Format != 1 && !Hidden_TC.TabPages.Contains(Hidden_Met))
|
|
|
|
{
|
|
|
|
Hidden_TC.TabPages.Insert(1, Hidden_Met);
|
|
|
|
TC_Editor.TabPages.Insert(1, Tab_Met);
|
|
|
|
TranslationRequired = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Entity.Format <= 2 && Hidden_TC.TabPages.Contains(Hidden_Cosmetic))
|
2017-05-23 04:55:05 +00:00
|
|
|
{
|
2023-01-22 04:02:33 +00:00
|
|
|
Hidden_TC.TabPages.Remove(Hidden_Cosmetic);
|
|
|
|
TC_Editor.TabPages.Remove(Tab_Cosmetic);
|
2017-05-23 04:55:05 +00:00
|
|
|
}
|
2023-01-22 04:02:33 +00:00
|
|
|
else if (Entity.Format > 2 && !Hidden_TC.TabPages.Contains(Hidden_Cosmetic))
|
2020-06-19 23:51:15 +00:00
|
|
|
{
|
2023-01-22 04:02:33 +00:00
|
|
|
Hidden_TC.TabPages.Insert(4, Hidden_Cosmetic);
|
|
|
|
TC_Editor.TabPages.Insert(4, Tab_Cosmetic);
|
2022-06-18 18:04:24 +00:00
|
|
|
TranslationRequired = true;
|
2020-06-20 23:23:03 +00:00
|
|
|
}
|
2020-06-19 23:51:15 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (!HaX && sav is SAV7b)
|
2020-06-20 23:23:03 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
FLP_HeldItem.Visible = false;
|
|
|
|
FLP_Country.Visible = false;
|
|
|
|
FLP_SubRegion.Visible = false;
|
|
|
|
FLP_3DSRegion.Visible = false;
|
2020-06-19 23:51:15 +00:00
|
|
|
}
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (!HaX && sav is SAV8LA)
|
2020-07-25 16:58:21 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
FLP_HeldItem.Visible = false;
|
2020-07-25 16:58:21 +00:00
|
|
|
}
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// pk2 save files do not have an Origin Game stored. Prompt the met location list to update.
|
|
|
|
if (Entity.Format == 2)
|
|
|
|
CheckMetLocationChange(GameVersion.C, Entity.Context);
|
|
|
|
return TranslationRequired;
|
|
|
|
}
|
2017-06-19 05:27:40 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void CenterSubEditors()
|
|
|
|
{
|
|
|
|
// Recenter PKM SubEditors
|
2023-01-22 04:02:33 +00:00
|
|
|
var firstTabArea = Hidden_Main; // first is always initialized
|
2022-06-18 18:04:24 +00:00
|
|
|
FLP_PKMEditors.HorizontallyCenter(firstTabArea);
|
|
|
|
FLP_MoveFlags.HorizontallyCenter(firstTabArea);
|
2023-02-02 00:55:38 +00:00
|
|
|
Stats.CenterSubEditors();
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public void EnableDragDrop(DragEventHandler enter, DragEventHandler drop)
|
|
|
|
{
|
|
|
|
AllowDrop = true;
|
|
|
|
DragDrop += drop;
|
2023-01-22 04:02:33 +00:00
|
|
|
foreach (var tab in Hidden_TC.TabPages.OfType<TabPage>())
|
2017-06-19 05:27:40 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
tab.AllowDrop = true;
|
|
|
|
tab.DragEnter += enter;
|
|
|
|
tab.DragDrop += drop;
|
2017-06-19 05:27:40 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2017-06-19 05:27:40 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// ReSharper disable once FieldCanBeMadeReadOnly.Global
|
|
|
|
public Action<IBattleTemplate> LoadShowdownSet;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void LoadShowdownSetDefault(IBattleTemplate Set)
|
|
|
|
{
|
|
|
|
var pk = PreparePKM();
|
|
|
|
pk.ApplySetDetails(Set);
|
|
|
|
PopulateFields(pk);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void CB_BattleVersion_SelectedValueChanged(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
if (Entity is not IBattleVersion b)
|
|
|
|
return;
|
|
|
|
var value = (byte)WinFormsUtil.GetIndex(CB_BattleVersion);
|
2022-11-25 01:42:17 +00:00
|
|
|
if (FieldsLoaded)
|
|
|
|
b.BattleVersion = value;
|
2022-06-18 18:04:24 +00:00
|
|
|
PB_BattleVersion.Image = GetMarkSprite(PB_BattleVersion, value != 0);
|
|
|
|
}
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private static Image GetMarkSprite(PictureBox p, bool opaque, double trans = 0.175)
|
|
|
|
{
|
|
|
|
var sprite = p.InitialImage;
|
|
|
|
return opaque ? sprite : ImageUtil.ChangeOpacity(sprite, trans);
|
|
|
|
}
|
2018-02-27 05:22:35 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void ClickVersionMarking(object sender, EventArgs e)
|
|
|
|
{
|
2023-01-22 04:02:33 +00:00
|
|
|
TC_Editor.SelectedTab = Tab_Met;
|
2022-06-18 18:04:24 +00:00
|
|
|
if (sender == PB_BattleVersion)
|
|
|
|
CB_BattleVersion.DroppedDown = true;
|
|
|
|
else
|
|
|
|
CB_GameOrigin.DroppedDown = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void ChangeLanguage(ITrainerInfo sav)
|
|
|
|
{
|
|
|
|
// Force an update to the met locations
|
|
|
|
origintrack = GameVersion.Invalid;
|
|
|
|
|
|
|
|
InitializeLanguage(sav);
|
|
|
|
CenterSubEditors();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void FlickerInterface()
|
|
|
|
{
|
2023-01-22 04:02:33 +00:00
|
|
|
TC_Editor.SelectedTab = Tab_Met; // parent tab of CB_GameOrigin
|
|
|
|
TC_Editor.SelectedTab = Tab_Main; // first tab
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
|
|
|
|
2022-11-25 01:42:17 +00:00
|
|
|
private void L_Obedience_Click(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
if (Entity is not IObedienceLevel l)
|
|
|
|
return;
|
|
|
|
var met = Util.ToInt32(TB_MetLevel.Text);
|
|
|
|
var suggest = l.GetSuggestedObedienceLevel(Entity, met);
|
|
|
|
var current = Util.ToInt32(TB_ObedienceLevel.Text);
|
|
|
|
if (suggest != current)
|
|
|
|
TB_ObedienceLevel.Text = suggest.ToString();
|
|
|
|
}
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void InitializeLanguage(ITrainerInfo sav)
|
|
|
|
{
|
|
|
|
var source = GameInfo.FilteredSources;
|
|
|
|
// Set the various ComboBox DataSources up with their allowed entries
|
|
|
|
SetCountrySubRegion(CB_Country, "countries");
|
|
|
|
CB_3DSReg.DataSource = source.ConsoleRegions;
|
|
|
|
|
|
|
|
CB_GroundTile.DataSource = new BindingSource(source.G4GroundTiles, null);
|
|
|
|
CB_Nature.DataSource = new BindingSource(source.Natures, null);
|
|
|
|
CB_StatNature.DataSource = new BindingSource(source.Natures, null);
|
|
|
|
|
|
|
|
// Sub editors
|
|
|
|
Stats.InitializeDataSources();
|
|
|
|
|
|
|
|
PopulateFilteredDataSources(sav, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void SetIfDifferentCount(IReadOnlyCollection<ComboItem> update, ComboBox exist, bool force = false)
|
|
|
|
{
|
|
|
|
if (!force && exist.DataSource is BindingSource b && b.Count == update.Count)
|
|
|
|
return;
|
|
|
|
exist.DataSource = new BindingSource(update, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void PopulateFilteredDataSources(ITrainerInfo sav, bool force = false)
|
|
|
|
{
|
|
|
|
var source = GameInfo.FilteredSources;
|
|
|
|
SetIfDifferentCount(source.Languages, CB_Language, force);
|
2020-12-31 23:10:37 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (sav.Generation >= 2)
|
2020-12-31 23:10:37 +00:00
|
|
|
{
|
2023-04-01 23:52:12 +00:00
|
|
|
var game = (GameVersion)sav.Game;
|
2022-06-18 18:04:24 +00:00
|
|
|
if (game <= 0)
|
|
|
|
game = Entity.Context.GetSingleGameVersion();
|
|
|
|
CheckMetLocationChange(game, sav.Context);
|
|
|
|
SetIfDifferentCount(source.Items, CB_HeldItem, force);
|
2017-05-23 04:55:05 +00:00
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (sav.Generation >= 3)
|
2017-05-23 04:55:05 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
SetIfDifferentCount(source.Balls, CB_Ball, force);
|
|
|
|
SetIfDifferentCount(source.Games, CB_GameOrigin, force);
|
|
|
|
}
|
2019-11-16 01:34:18 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (sav.Generation >= 4)
|
|
|
|
SetIfDifferentCount(source.Abilities, DEV_Ability, force);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (sav.Generation >= 8)
|
|
|
|
{
|
|
|
|
var lang = source.Languages;
|
2023-04-01 23:52:12 +00:00
|
|
|
var langWith0 = new List<ComboItem>(1 + lang.Count) { GameInfo.Sources.Empty };
|
2022-06-18 18:04:24 +00:00
|
|
|
langWith0.AddRange(lang);
|
|
|
|
SetIfDifferentCount(langWith0, CB_HTLanguage, force);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
var game = source.Games;
|
2022-11-25 01:42:17 +00:00
|
|
|
SetIfDifferentCount(game, CB_BattleVersion, force);
|
2017-05-23 04:55:05 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
SetIfDifferentCount(source.Species, CB_Species, force);
|
|
|
|
|
|
|
|
// Set the Move ComboBoxes too..
|
|
|
|
LegalMoveSource.ChangeMoveSource(source.Moves);
|
2023-01-22 04:02:33 +00:00
|
|
|
foreach (var cb in Relearn)
|
2022-06-18 18:04:24 +00:00
|
|
|
SetIfDifferentCount(source.Moves, cb, force);
|
2023-01-22 04:02:33 +00:00
|
|
|
foreach (var cb in Moves)
|
|
|
|
SetIfDifferentCount(source.Moves, cb.CB_Move, force);
|
2022-06-18 18:04:24 +00:00
|
|
|
if (sav is SAV8LA)
|
|
|
|
SetIfDifferentCount(source.Moves, CB_AlphaMastered, force);
|
2017-05-23 04:55:05 +00:00
|
|
|
}
|
2023-01-22 04:02:33 +00:00
|
|
|
|
2023-01-25 04:10:08 +00:00
|
|
|
private void ChangeSelectedTabIndex(object? sender, EventArgs e)
|
|
|
|
{
|
|
|
|
// flip to the tabless control's tab
|
|
|
|
Hidden_TC.SelectedIndex = TC_Editor.SelectedIndex;
|
|
|
|
// reset focus back to the vertical tab selection rather than the inaccessible tab
|
|
|
|
TC_Editor.Focus();
|
|
|
|
}
|
|
|
|
|
2023-01-22 04:02:33 +00:00
|
|
|
private void CHK_Nicknamed_Click(object? sender, EventArgs e) => CHK_NicknamedFlag.Checked ^= true;
|
|
|
|
|
|
|
|
private void PB_MarkShiny_Click(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
if (Entity.Format <= 2)
|
|
|
|
{
|
|
|
|
TC_Editor.SelectedTab = Tab_Stats;
|
|
|
|
Stats.Focus();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
TC_Editor.SelectedTab = Tab_Main;
|
|
|
|
TB_PID.Focus();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void PB_MarkCured_Click(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
// Toggle Pokérus cured state.
|
|
|
|
if (!CHK_Cured.Checked)
|
|
|
|
{
|
|
|
|
CHK_Infected.Checked = true;
|
|
|
|
if (CB_PKRSDays.SelectedIndex != 0)
|
|
|
|
CB_PKRSDays.SelectedIndex = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CHK_Cured.Checked = false;
|
|
|
|
}
|
|
|
|
TC_Editor.SelectedTab = Tab_Main;
|
|
|
|
CB_PKRSStrain.DroppedDown = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static class MoveDisplay
|
|
|
|
{
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
|
|
public static Bitmap? GetMoveImage(bool isIllegal, PKM pk, int index)
|
|
|
|
{
|
|
|
|
if (isIllegal)
|
|
|
|
return Resources.warn;
|
|
|
|
|
|
|
|
var dummied = MoveInfo.GetDummiedMovesHashSet(pk.Context);
|
|
|
|
if (dummied?.Contains(pk.GetMove(index)) == true)
|
|
|
|
return Resources.hint;
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
2017-05-23 04:55:05 +00:00
|
|
|
}
|