From 5df994dbae9a70f78ecbadbe67dc7683f716af07 Mon Sep 17 00:00:00 2001 From: Kurt Date: Sat, 9 May 2026 17:56:40 -0500 Subject: [PATCH] database: settings to specify row count Default rows changed from 11 => 9 min,max is now [5,20] to prevent stupid entry ergonomics: 6 min for encdb, 4 min for mgdb, 9 min for pkmdb --- .../Settings/EncounterDatabaseSettings.cs | 12 ++++++ .../Settings/EntityDatabaseSettings.cs | 12 ++++++ .../Settings/MysteryGiftDatabaseSettings.cs | 12 ++++++ PKHeX.WinForms/Controls/Slots/PokeGrid.cs | 21 ++++++++-- PKHeX.WinForms/Subforms/SAV_Database.cs | 41 ++++++++++++------ PKHeX.WinForms/Subforms/SAV_Encounters.cs | 40 ++++++++++++------ PKHeX.WinForms/Subforms/SAV_MysteryGiftDB.cs | 42 +++++++++++++------ 7 files changed, 139 insertions(+), 41 deletions(-) diff --git a/PKHeX.Core/Editing/Program/Settings/EncounterDatabaseSettings.cs b/PKHeX.Core/Editing/Program/Settings/EncounterDatabaseSettings.cs index b1667a257..fd3211c5b 100644 --- a/PKHeX.Core/Editing/Program/Settings/EncounterDatabaseSettings.cs +++ b/PKHeX.Core/Editing/Program/Settings/EncounterDatabaseSettings.cs @@ -1,7 +1,12 @@ +using System; + namespace PKHeX.Core; public sealed class EncounterDatabaseSettings { + private const int ResultsGridRowCountMin = 5; + private const int ResultsGridRowCountMax = 20; + [LocalizedDescription("Skips searching if the user forgot to enter Species / Move(s) into the search criteria.")] public bool ReturnNoneIfEmptySearch { get; set; } = true; @@ -13,4 +18,11 @@ public sealed class EncounterDatabaseSettings [LocalizedDescription("Use properties from the PKM Editor tabs even if the new encounter isn't the same evolution chain.")] public bool UseTabsAsCriteriaAnySpecies { get; set; } = true; + + [LocalizedDescription("Visible row count for the Encounter Database sprite grid. Clamped from 5 to 20.")] + public int ResultsGridRowCount + { + get; + set => field = Math.Clamp(value, ResultsGridRowCountMin, ResultsGridRowCountMax); + } = 11; } diff --git a/PKHeX.Core/Editing/Program/Settings/EntityDatabaseSettings.cs b/PKHeX.Core/Editing/Program/Settings/EntityDatabaseSettings.cs index 86cc09015..2d5aaaf80 100644 --- a/PKHeX.Core/Editing/Program/Settings/EntityDatabaseSettings.cs +++ b/PKHeX.Core/Editing/Program/Settings/EntityDatabaseSettings.cs @@ -1,7 +1,12 @@ +using System; + namespace PKHeX.Core; public sealed class EntityDatabaseSettings { + private const int ResultsGridRowCountMin = 5; + private const int ResultsGridRowCountMax = 20; + [LocalizedDescription("When loading content for the PKM Database, search within backup save files.")] public bool SearchBackups { get; set; } = true; @@ -16,6 +21,13 @@ public sealed class EntityDatabaseSettings [LocalizedDescription("Hides unavailable Species if the currently loaded save file cannot import them.")] public bool FilterUnavailableSpecies { get; set; } = true; + + [LocalizedDescription("Visible row count for the PKM Database sprite grid. Clamped from 5 to 20.")] + public int ResultsGridRowCount + { + get; + set => field = Math.Clamp(value, ResultsGridRowCountMin, ResultsGridRowCountMax); + } = 9; } public enum DatabaseSortMode diff --git a/PKHeX.Core/Editing/Program/Settings/MysteryGiftDatabaseSettings.cs b/PKHeX.Core/Editing/Program/Settings/MysteryGiftDatabaseSettings.cs index 231ab6f76..54de79f88 100644 --- a/PKHeX.Core/Editing/Program/Settings/MysteryGiftDatabaseSettings.cs +++ b/PKHeX.Core/Editing/Program/Settings/MysteryGiftDatabaseSettings.cs @@ -1,7 +1,19 @@ +using System; + namespace PKHeX.Core; public sealed class MysteryGiftDatabaseSettings { + private const int ResultsGridRowCountMin = 5; + private const int ResultsGridRowCountMax = 20; + [LocalizedDescription("Hides gifts if the currently loaded save file cannot (indirectly) receive them.")] public bool FilterUnavailableSpecies { get; set; } = true; + + [LocalizedDescription("Visible row count for the Mystery Gift Database sprite grid. Clamped from 5 to 20.")] + public int ResultsGridRowCount + { + get; + set => field = Math.Clamp(value, ResultsGridRowCountMin, ResultsGridRowCountMax); + } = 9; } diff --git a/PKHeX.WinForms/Controls/Slots/PokeGrid.cs b/PKHeX.WinForms/Controls/Slots/PokeGrid.cs index 973043d72..68df04812 100644 --- a/PKHeX.WinForms/Controls/Slots/PokeGrid.cs +++ b/PKHeX.WinForms/Controls/Slots/PokeGrid.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.Drawing; using System.Linq; @@ -39,6 +40,22 @@ public bool InitializeGrid(int width, int height, SpriteBuilder info) private const int padEdge = 1; // edges private const int border = 1; // between + public static Size GetGridSize(int width, int height, int spriteWidth, int spriteHeight) + { + int w = (2 * padEdge) + border + (width * (spriteWidth + border)); + int h = (2 * padEdge) + border + (height * (spriteHeight + border)); + return new Size(w, h); + } + + public static int GetMaxRowCount(int availableHeight, int spriteHeight) + { + var heightOffset = (2 * padEdge) + border; + var rowHeight = spriteHeight + border; + if (rowHeight <= 0) + return 1; + return Math.Max(1, (availableHeight - heightOffset) / rowHeight); + } + private void Generate(int width, int height) { SuspendLayout(); @@ -64,9 +81,7 @@ private void Generate(int width, int height) } } - int w = (2 * padEdge) + border + (width * (colWidth + border)); - int h = (2 * padEdge) + border + (height * (rowHeight + border)); - Size = new Size(w, h); + Size = GetGridSize(width, height, colWidth, rowHeight); Controls.AddRange(Entries.Cast().ToArray()); ResumeLayout(); } diff --git a/PKHeX.WinForms/Subforms/SAV_Database.cs b/PKHeX.WinForms/Subforms/SAV_Database.cs index 173f14eae..6ad103af1 100644 --- a/PKHeX.WinForms/Subforms/SAV_Database.cs +++ b/PKHeX.WinForms/Subforms/SAV_Database.cs @@ -20,13 +20,15 @@ namespace PKHeX.WinForms; public partial class SAV_Database : Form { + private const int GridHeightMin = 5; + private const int GridHeightMax = 20; private readonly SaveFile SAV; private readonly SAVEditor BoxView; private readonly PKMEditor PKME_Tabs; private readonly EntityInstructionBuilder UC_Builder; private const int GridWidth = 6; - private const int GridHeight = 11; + private readonly int GridHeight; private readonly PictureBox[] PKXBOXES; private readonly string DatabasePath = Main.DatabasePath; @@ -35,10 +37,9 @@ public partial class SAV_Database : Form private int slotSelected = -1; // = null; private Image? slotColor; private const int RES_MIN = GridWidth * 1; - private const int RES_MAX = GridWidth * GridHeight; + private int RES_MAX => PKXBOXES.Length; private readonly string Counter; private readonly string Viewed; - private const int MAXFORMAT = Latest.Generation; private readonly SummaryPreviewer ShowSet = new(); private readonly CancellationTokenSource cts = new(); @@ -67,23 +68,16 @@ public SAV_Database(PKMEditor f1, SAVEditor saveditor) SAV = saveditor.SAV; BoxView = saveditor; PKME_Tabs = f1; + GridHeight = GetGridHeight(Main.Settings.EntityDb.ResultsGridRowCount, DatabasePokeGrid); // Preset Filters to only show PKM available for loaded save UC_EntitySearch.InitializeSelections(SAV); var grid = DatabasePokeGrid; - var smallWidth = grid.Width; - var smallHeight = grid.Height; + var originalGridSize = grid.Size; grid.InitializeGrid(GridWidth, GridHeight, SpriteUtil.Spriter); grid.SetBackground(Resources.box_wp_clean); - var newWidth = grid.Width; - var newHeight = grid.Height; - var wdelta = newWidth - smallWidth; - if (wdelta != 0) - Width += wdelta; - var hdelta = newHeight - smallHeight; - if (hdelta != 0) - Height += hdelta; + ResizeForGrid(grid, originalGridSize); PKXBOXES = [.. grid.Entries]; // Enable Scrolling when hovered over @@ -168,6 +162,27 @@ protected override void OnShown(EventArgs e) UC_EntitySearch.ResetComboBoxSelections(); } + private int GetGridHeight(int requestedRows, PokeGrid grid) + { + requestedRows = Math.Clamp(requestedRows, GridHeightMin, GridHeightMax); + var workingAreaHeight = Screen.FromControl(this).WorkingArea.Height; + var otherHeight = Height - grid.Height; + var maxGridHeight = Math.Max(grid.Height, workingAreaHeight - otherHeight); + var maxRows = PokeGrid.GetMaxRowCount(maxGridHeight, SpriteUtil.Spriter.Height); + return Math.Max(1, Math.Min(requestedRows, maxRows)); + } + + private void ResizeForGrid(PokeGrid grid, Size originalGridSize) + { + var widthDelta = grid.Width - originalGridSize.Width; + if (widthDelta != 0) + Width += widthDelta; + + var heightDelta = grid.Height - originalGridSize.Height; + if (heightDelta != 0) + Height += heightDelta; + } + private void ClickView(object sender, EventArgs e) { if (!WinFormsUtil.TryGetUnderlying(sender, out var pb)) diff --git a/PKHeX.WinForms/Subforms/SAV_Encounters.cs b/PKHeX.WinForms/Subforms/SAV_Encounters.cs index ceb2c3be5..2bcd02216 100644 --- a/PKHeX.WinForms/Subforms/SAV_Encounters.cs +++ b/PKHeX.WinForms/Subforms/SAV_Encounters.cs @@ -18,6 +18,8 @@ namespace PKHeX.WinForms; public partial class SAV_Encounters : Form { + private const int GridHeightMin = 5; + private const int GridHeightMax = 20; private readonly PKMEditor PKME_Tabs; private SaveFile SAV => PKME_Tabs.RequestSaveFile; private readonly SummaryPreviewer ShowSet = new(); @@ -26,7 +28,7 @@ public partial class SAV_Encounters : Form private readonly EntityInstructionBuilder UC_Builder; private const int GridWidth = 6; - private const int GridHeight = 11; + private readonly int GridHeight; // Criteria backing value (edited via PropertyGrid) private EncounterCriteria _criteriaValue = EncounterCriteria.Unrestricted; @@ -52,20 +54,13 @@ public SAV_Encounters(PKMEditor f1, TrainerDatabase db) PKME_Tabs = f1; Trainers = db; + GridHeight = GetGridHeight(Main.Settings.EncounterDb.ResultsGridRowCount, EncounterPokeGrid); var grid = EncounterPokeGrid; - var smallWidth = grid.Width; - var smallHeight = grid.Height; + var originalGridSize = grid.Size; grid.InitializeGrid(GridWidth, GridHeight, SpriteUtil.Spriter); grid.SetBackground(Resources.box_wp_clean); - var newWidth = grid.Width; - var newHeight = grid.Height; - var wdelta = newWidth - smallWidth; - if (wdelta != 0) - Width += wdelta; - var hdelta = newHeight - smallHeight; - if (hdelta != 0) - Height += hdelta; + ResizeForGrid(grid, originalGridSize); PKXBOXES = [..grid.Entries]; @@ -192,9 +187,30 @@ private EncounterTypeGroup[] GetTypes() private int slotSelected = -1; // = null; private Image? slotColor; private const int RES_MIN = GridWidth * 1; - private const int RES_MAX = GridWidth * GridHeight; + private int RES_MAX => PKXBOXES.Length; private readonly string Counter; + private int GetGridHeight(int requestedRows, PokeGrid grid) + { + requestedRows = Math.Clamp(requestedRows, GridHeightMin, GridHeightMax); + var workingAreaHeight = Screen.FromControl(this).WorkingArea.Height; + var otherHeight = Height - grid.Height; + var maxGridHeight = Math.Max(grid.Height, workingAreaHeight - otherHeight); + var maxRows = PokeGrid.GetMaxRowCount(maxGridHeight, SpriteUtil.Spriter.Height); + return Math.Max(1, Math.Min(requestedRows, maxRows)); + } + + private void ResizeForGrid(PokeGrid grid, Size originalGridSize) + { + var widthDelta = grid.Width - originalGridSize.Width; + if (widthDelta != 0) + Width += widthDelta; + + var heightDelta = grid.Height - originalGridSize.Height; + if (heightDelta != 0) + Height += heightDelta; + } + private bool GetShiftedIndex(ref int index) { if (index >= RES_MAX) diff --git a/PKHeX.WinForms/Subforms/SAV_MysteryGiftDB.cs b/PKHeX.WinForms/Subforms/SAV_MysteryGiftDB.cs index ae385fe07..aeb35cd79 100644 --- a/PKHeX.WinForms/Subforms/SAV_MysteryGiftDB.cs +++ b/PKHeX.WinForms/Subforms/SAV_MysteryGiftDB.cs @@ -17,6 +17,8 @@ namespace PKHeX.WinForms; public partial class SAV_MysteryGiftDB : Form { + private const int GridHeightMin = 5; + private const int GridHeightMax = 20; private readonly PKMEditor PKME_Tabs; private readonly SaveFile SAV; private readonly SAVEditor BoxView; @@ -24,14 +26,14 @@ public partial class SAV_MysteryGiftDB : Form private readonly EntityInstructionBuilder UC_Builder; private const int GridWidth = 6; - private const int GridHeight = 11; + private readonly int GridHeight; public SAV_MysteryGiftDB(PKMEditor tabs, SAVEditor sav) { InitializeComponent(); var settings = new TabPage { Text = "Settings", Name = "Tab_Settings" }; - settings.Controls.Add(new PropertyGrid { Dock = DockStyle.Fill, SelectedObject = Main.Settings.EncounterDb }); + settings.Controls.Add(new PropertyGrid { Dock = DockStyle.Fill, SelectedObject = Main.Settings.MysteryDb }); TC_SearchSettings.Controls.Add(settings); WinFormsUtil.TranslateInterface(this, Main.CurrentLanguage); @@ -50,23 +52,16 @@ public SAV_MysteryGiftDB(PKMEditor tabs, SAVEditor sav) SAV = sav.SAV; BoxView = sav; PKME_Tabs = tabs; + GridHeight = GetGridHeight(Main.Settings.MysteryDb.ResultsGridRowCount, MysteryPokeGrid); // Preset Filters to only show PKM available for loaded save CB_FormatComparator.SelectedIndex = 3; // <= var grid = MysteryPokeGrid; - var smallWidth = grid.Width; - var smallHeight = grid.Height; + var originalGridSize = grid.Size; grid.InitializeGrid(GridWidth, GridHeight, SpriteUtil.Spriter); grid.SetBackground(Resources.box_wp_clean); - var newWidth = grid.Width; - var newHeight = grid.Height; - var wDelta = newWidth - smallWidth; - if (wDelta != 0) - Width += wDelta; - var hDelta = newHeight - smallHeight; - if (hDelta != 0) - Height += hDelta; + ResizeForGrid(grid, originalGridSize); PKXBOXES = [.. grid.Entries]; @@ -130,11 +125,32 @@ protected override void OnShown(EventArgs e) private int slotSelected = -1; // = null; private Image? slotColor; private const int RES_MIN = GridWidth * 1; - private const int RES_MAX = GridWidth * GridHeight; + private int RES_MAX => PKXBOXES.Length; private readonly string Counter; private readonly string Viewed; private const int MAXFORMAT = Latest.Generation; + private int GetGridHeight(int requestedRows, PokeGrid grid) + { + requestedRows = Math.Clamp(requestedRows, GridHeightMin, GridHeightMax); + var workingAreaHeight = Screen.FromControl(this).WorkingArea.Height; + var otherHeight = Height - grid.Height; + var maxGridHeight = Math.Max(grid.Height, workingAreaHeight - otherHeight); + var maxRows = PokeGrid.GetMaxRowCount(maxGridHeight, SpriteUtil.Spriter.Height); + return Math.Max(1, Math.Min(requestedRows, maxRows)); + } + + private void ResizeForGrid(PokeGrid grid, Size originalGridSize) + { + var widthDelta = grid.Width - originalGridSize.Width; + if (widthDelta != 0) + Width += widthDelta; + + var heightDelta = grid.Height - originalGridSize.Height; + if (heightDelta != 0) + Height += heightDelta; + } + private bool GetShiftedIndex(ref int index) { if (index >= RES_MAX)