From f3ea73787b2ed835dcc4ec4db9a5bc0122f86191 Mon Sep 17 00:00:00 2001 From: Kurt Date: Sat, 14 Nov 2015 19:41:39 -0800 Subject: [PATCH] Add alt/shift click Shift click setting is not accessible without the hotkey, not going to add it as a Right Click Menu. Main had to expose more methods (to access info from tabs); standardized all references to the database path as well. --- PKX/f1-Main.cs | 12 ++++++------ SAV/SAV_Database.cs | 38 +++++++++++++++++++++++++++++++++++++- 2 files changed, 43 insertions(+), 7 deletions(-) diff --git a/PKX/f1-Main.cs b/PKX/f1-Main.cs index 6b0c5c241..3cecb38d2 100644 --- a/PKX/f1-Main.cs +++ b/PKX/f1-Main.cs @@ -206,6 +206,7 @@ public Main() public static int colorizedslot; public static int largeWidth, shortWidth; public static string eggname = ""; + public static string DatabasePath = "db"; public static string[] lang_val = { "en", "ja", "fr", "it", "de", "es", "ko", "zh", "pt" }; public static string[] main_langlist = { @@ -408,17 +409,16 @@ private void mainMenuBoxDumpLoad(object sender, EventArgs e) { DialogResult dr = Util.Prompt(MessageBoxButtons.YesNoCancel, "Press Yes to Import All from Folder." + Environment.NewLine + "Press No to Dump All to Folder.", "Press Cancel to Abort."); if (dr == DialogResult.Cancel) return; - string exepath = Application.StartupPath; string path = ""; bool dumptoboxes = false; { if (dr == DialogResult.Yes) // Import { - if (Directory.Exists(Path.Combine(exepath, "db"))) + if (Directory.Exists(DatabasePath)) { DialogResult ld = Util.Prompt(MessageBoxButtons.YesNo, "Load from PKHeX's database?"); if (ld == DialogResult.Yes) - path = Path.Combine(exepath, "db"); + path = DatabasePath; else if (ld == DialogResult.No) { // open folder dialog @@ -443,7 +443,7 @@ private void mainMenuBoxDumpLoad(object sender, EventArgs e) DialogResult ld = Util.Prompt(MessageBoxButtons.YesNo, "Save to PKHeX's database?"); if (ld == DialogResult.Yes) { - path = Path.Combine(exepath, "db"); + path = DatabasePath; if (!Directory.Exists(path)) Directory.CreateDirectory(path); } @@ -2140,7 +2140,7 @@ private void openHistory(object sender, EventArgs e) TB_Friendship.Text = (pk6.CurrentHandler == 0 ? pk6.OT_Friendship : pk6.HT_Friendship).ToString(); } // Open/Save Array Manipulation // - private bool verifiedPKX() + public bool verifiedPKX() { if (ModifierKeys == (Keys.Control | Keys.Shift | Keys.Alt)) return true; // Override @@ -2178,7 +2178,7 @@ private bool verifiedPKX() invalid: { System.Media.SystemSounds.Exclamation.Play(); return false; } } - private byte[] preparepkx(bool click = true) + public byte[] preparepkx(bool click = true) { if (click) tabMain.Select(); // hack to make sure comboboxes are set (users scrolling through and immediately setting causes this) diff --git a/SAV/SAV_Database.cs b/SAV/SAV_Database.cs index 9278f58d7..64389993c 100644 --- a/SAV/SAV_Database.cs +++ b/SAV/SAV_Database.cs @@ -50,6 +50,10 @@ public SAV_Database(Main f1) { if (ModifierKeys == Keys.Control) clickView(sender, args); + else if (ModifierKeys == Keys.Alt) + clickDelete(sender, args); + else if (ModifierKeys == Keys.Shift) + clickSet(sender, args); }; } @@ -103,7 +107,7 @@ public SAV_Database(Main f1) } private Main m_parent; private PictureBox[] PKXBOXES; - private const string DatabasePath = "db"; + private string DatabasePath = Main.DatabasePath; private List Database = new List(); private List Results; private List RawDB; @@ -179,9 +183,41 @@ private void clickDelete(object sender, EventArgs e) RawDB.Remove(pk); Results.Remove(pk); // Refresh database view. + L_Count.Text = String.Format(Counter, Results.Count); FillPKXBoxes(SCR_Box.Value); + System.Media.SystemSounds.Asterisk.Play(); } } + private void clickSet(object sender, EventArgs e) + { + // Don't care what slot was clicked, just add it to the database + if (!m_parent.verifiedPKX()) + return; + + PK6 pk = new PK6(m_parent.preparepkx()); + if (!Directory.Exists(DatabasePath)) + Directory.CreateDirectory(DatabasePath); + + string path = Path.Combine(DatabasePath, Util.CleanFileName(pk.FileName)); + + if (RawDB.Any(p => p.Identifier == path)) + { + Util.Alert("File already exists in database!"); + return; + } + + File.WriteAllBytes(path, pk.Data.Take(PK6.SIZE_STORED).ToArray()); + pk.Identifier = path; + + RawDB.Add(pk); + RawDB = new List(RawDB.Distinct()); // just in case + Results.Add(pk); + Results = new List(Results.Distinct()); // just in case + // Refresh database view. + L_Count.Text = String.Format(Counter, Results.Count); + FillPKXBoxes(SCR_Box.Value); + Util.Alert("Added Pokémon from tabs to database", "Please refresh the search to ensure it shows up; it may be at the bottom of the results."); + } private void populateComboBoxes() { // Set the Text