Enhance Text trash editor

#4222
SuggestAppend species dropdown
Indicate trash-to-be-applied when hovering on button
Fix ClickOT in pkmEditor applying English on Japanese Gen3 saves
This commit is contained in:
Kurt 2024-03-20 09:44:20 -05:00
parent 95eb008125
commit f7900ed8b4
4 changed files with 31 additions and 12 deletions

View file

@ -40,6 +40,7 @@ public abstract class SAV3 : SaveFile, ILangDeviantSave, IEventFlag37, IBoxDetai
public readonly byte[] Storage = new byte[9 * SIZE_SECTOR_USED]; // [0x83D0] public readonly byte[] Storage = new byte[9 * SIZE_SECTOR_USED]; // [0x83D0]
private readonly int ActiveSlot; private readonly int ActiveSlot;
public sealed override int Language { get => Japanese ? (int)LanguageID.Japanese : (int)LanguageID.English; set { } }
protected SAV3(bool japanese) => Japanese = japanese; protected SAV3(bool japanese) => Japanese = japanese;
@ -314,13 +315,15 @@ public abstract class SAV3 : SaveFile, ILangDeviantSave, IEventFlag37, IBoxDetai
public abstract uint SecurityKey { get; set; } public abstract uint SecurityKey { get; set; }
public Span<byte> OriginalTrainerTrash => Small.AsSpan(0, 8);
public sealed override string OT public sealed override string OT
{ {
get => GetString(Small.AsSpan(0, 8)); get => GetString(OriginalTrainerTrash);
set set
{ {
int len = Japanese ? 5 : MaxStringLengthOT; int len = Japanese ? 5 : MaxStringLengthOT;
SetString(Small.AsSpan(0, len), value, len, StringConverterOption.ClearFF); SetString(OriginalTrainerTrash[..len], value, len, StringConverterOption.ClearFF); // match the game-init FF terminating pattern
} }
} }

View file

@ -395,7 +395,7 @@ public sealed partial class PKMEditor : UserControl, IMainEditor
UC_OTGender.Gender = (byte)(tr.Gender & 1); UC_OTGender.Gender = (byte)(tr.Gender & 1);
TID_Trainer.LoadInfo(tr); TID_Trainer.LoadInfo(tr);
if (tr.Version != 0) if (tr.Version.IsValidSavedVersion())
CB_GameOrigin.SelectedValue = (int)tr.Version; CB_GameOrigin.SelectedValue = (int)tr.Version;
var lang = tr.Language; var lang = tr.Language;

View file

@ -58,6 +58,8 @@ namespace PKHeX.WinForms
// CB_Species // CB_Species
// //
CB_Species.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right; CB_Species.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right;
CB_Species.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.SuggestAppend;
CB_Species.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.ListItems;
CB_Species.FormattingEnabled = true; CB_Species.FormattingEnabled = true;
CB_Species.Location = new System.Drawing.Point(89, 18); CB_Species.Location = new System.Drawing.Point(89, 18);
CB_Species.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); CB_Species.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);

View file

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using System.Linq;
using System.Windows.Forms; using System.Windows.Forms;
using PKHeX.Core; using PKHeX.Core;
@ -50,8 +51,16 @@ public partial class TrashEditor : Form
editing = false; editing = false;
CenterToParent(); CenterToParent();
B_ApplyTrash.MouseHover += (_, _) =>
{
var text = GetTrashString();
var data = SetString(text);
var display = $"{text} = {Environment.NewLine}{string.Join(' ', data.Select(z => $"{z:X2}"))}";
Tip.Show(display, B_ApplyTrash);
};
} }
private readonly ToolTip Tip = new() { InitialDelay = 200, IsBalloon = false, AutoPopDelay = 32_767 };
private readonly List<NumericUpDown> Bytes = []; private readonly List<NumericUpDown> Bytes = [];
public string FinalString; public string FinalString;
public byte[] FinalBytes; public byte[] FinalBytes;
@ -151,16 +160,9 @@ public partial class TrashEditor : Form
private void B_ApplyTrash_Click(object sender, EventArgs e) private void B_ApplyTrash_Click(object sender, EventArgs e)
{ {
var species = (ushort)WinFormsUtil.GetIndex(CB_Species); string text = GetTrashString();
var language = WinFormsUtil.GetIndex(CB_Language); byte[] data = SetString(text);
var gen = (byte)NUD_Generation.Value;
string speciesName = SpeciesName.GetSpeciesNameGeneration(species, language, gen);
if (string.IsNullOrEmpty(speciesName)) // no result
speciesName = CB_Species.Text;
byte[] current = SetString(TB_Text.Text); byte[] current = SetString(TB_Text.Text);
byte[] data = SetString(speciesName);
if (data.Length <= current.Length) if (data.Length <= current.Length)
{ {
WinFormsUtil.Alert("Trash byte layer is hidden by current text.", WinFormsUtil.Alert("Trash byte layer is hidden by current text.",
@ -176,6 +178,18 @@ public partial class TrashEditor : Form
Bytes[i].Value = data[i]; Bytes[i].Value = data[i];
} }
private string GetTrashString()
{
var species = (ushort)WinFormsUtil.GetIndex(CB_Species);
var language = WinFormsUtil.GetIndex(CB_Language);
var gen = (byte)NUD_Generation.Value;
string text = SpeciesName.GetSpeciesNameGeneration(species, language, gen);
if (string.IsNullOrEmpty(text)) // no result
text = CB_Species.Text;
return text;
}
private void B_ClearTrash_Click(object sender, EventArgs e) private void B_ClearTrash_Click(object sender, EventArgs e)
{ {
byte[] current = SetString(TB_Text.Text); byte[] current = SetString(TB_Text.Text);