mirror of
https://github.com/kwsch/PKHeX.git
synced 2026-03-21 17:48:28 -05:00
ZA Fashion: Less GUI lag when Set All Owned
Pretty much instant now. Requires a little bit of allocation but good enough. Clone the save file so we don't mutate the original if the user opts to cancel.
This commit is contained in:
parent
048f7cfe30
commit
8933fb06d4
|
|
@ -58,4 +58,17 @@ public static void SetArray(ReadOnlySpan<FashionItem9a> items, Span<byte> data)
|
|||
for (int i = 0; i < items.Length; i++)
|
||||
items[i].Write(data.Slice(i * SIZE, SIZE));
|
||||
}
|
||||
|
||||
public static void ModifyAll(Span<byte> data, Action<FashionItem9a> action)
|
||||
{
|
||||
int count = data.Length / SIZE;
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
var slice = data.Slice(i * SIZE, SIZE);
|
||||
var item = Read(slice);
|
||||
if (item.Value is not None)
|
||||
action(item);
|
||||
item.Write(slice);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,10 +9,14 @@ namespace PKHeX.WinForms;
|
|||
public sealed partial class SAV_Fashion9a : Form
|
||||
{
|
||||
private readonly IFashionBlockEditor[] _grids;
|
||||
private readonly SAV9ZA SAV;
|
||||
private readonly SAV9ZA Origin;
|
||||
|
||||
public SAV_Fashion9a(SAV9ZA sav)
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
SAV = (SAV9ZA)(Origin = sav).Clone();
|
||||
WinFormsUtil.TranslateInterface(this, Main.CurrentLanguage);
|
||||
|
||||
// Allow drag/drop on form and main tab control
|
||||
|
|
@ -25,7 +29,7 @@ public SAV_Fashion9a(SAV9ZA sav)
|
|||
TC_Features.Multiline = true;
|
||||
|
||||
// Create grids for each block
|
||||
var accessor = sav.Blocks;
|
||||
var accessor = SAV.Blocks;
|
||||
_grids =
|
||||
[
|
||||
Create(accessor.GetBlock(KFashionTops), nameof(KFashionTops)),
|
||||
|
|
@ -151,6 +155,7 @@ private void B_Save_Click(object sender, EventArgs e)
|
|||
{
|
||||
foreach (var grid in _grids)
|
||||
grid.Save();
|
||||
Origin.CopyChangesFrom(SAV);
|
||||
Close();
|
||||
}
|
||||
|
||||
|
|
@ -328,14 +333,12 @@ public void Save()
|
|||
|
||||
public void SetAllOwned(bool state)
|
||||
{
|
||||
for (int i = 0; i < Grid.RowCount; i++)
|
||||
{
|
||||
var cells = Grid.Rows[i].Cells;
|
||||
var value = cells[ColValue].Value?.ToString();
|
||||
if (value == (FashionItem9a.None.ToString()))
|
||||
continue;
|
||||
cells[ColIsOwned].Value = state;
|
||||
}
|
||||
Grid.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None;
|
||||
Save();
|
||||
FashionItem9a.ModifyAll(Block.Data, z => z.IsOwned = state);
|
||||
Load();
|
||||
Grid.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
|
||||
System.Media.SystemSounds.Asterisk.Play();
|
||||
}
|
||||
|
||||
private void LoadItem(int index, FashionItem9a item)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user