From 0c4757b0310304affc48906814e9bb78c76ea2e0 Mon Sep 17 00:00:00 2001 From: Kurt Date: Tue, 19 Dec 2017 20:55:35 -0800 Subject: [PATCH] Add table copy/paste(all) closes #182 --- pk3DS.Core/Randomizers/SpeciesRandomizer.cs | 2 +- pk3DS/Subforms/Gen7/SMTE.cs | 1 - pk3DS/Subforms/Gen7/SMWE.Designer.cs | 71 +++++++++++---- pk3DS/Subforms/Gen7/SMWE.cs | 97 +++++++++++++++++---- pk3DS/Subforms/Gen7/Wild/EncounterTable.cs | 16 +++- 5 files changed, 149 insertions(+), 38 deletions(-) diff --git a/pk3DS.Core/Randomizers/SpeciesRandomizer.cs b/pk3DS.Core/Randomizers/SpeciesRandomizer.cs index 20cc884..ed7769c 100644 --- a/pk3DS.Core/Randomizers/SpeciesRandomizer.cs +++ b/pk3DS.Core/Randomizers/SpeciesRandomizer.cs @@ -38,7 +38,7 @@ public void Initialize() public bool L = false; public bool E = false; public bool Shedinja = false; - public bool rEXP = true; + public bool rEXP = false; public bool rBST = true; public bool rType = false; #endregion diff --git a/pk3DS/Subforms/Gen7/SMTE.cs b/pk3DS/Subforms/Gen7/SMTE.cs index 17205c2..03f3891 100644 --- a/pk3DS/Subforms/Gen7/SMTE.cs +++ b/pk3DS/Subforms/Gen7/SMTE.cs @@ -592,7 +592,6 @@ private void B_Randomize_Click(object sender, EventArgs e) E = CHK_E.Checked, L = CHK_L.Checked, rBST = CHK_BST.Checked, - rEXP = false, }; rnd.Initialize(); diff --git a/pk3DS/Subforms/Gen7/SMWE.Designer.cs b/pk3DS/Subforms/Gen7/SMWE.Designer.cs index ef83517..777ea3f 100644 --- a/pk3DS/Subforms/Gen7/SMWE.Designer.cs +++ b/pk3DS/Subforms/Gen7/SMWE.Designer.cs @@ -256,6 +256,9 @@ private void InitializeComponent() this.CB_TableID = new System.Windows.Forms.ComboBox(); this.B_Export = new System.Windows.Forms.Button(); this.CopySOS = new System.Windows.Forms.Button(); + this.B_Copy = new System.Windows.Forms.Button(); + this.B_Paste = new System.Windows.Forms.Button(); + this.B_PasteAll = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.NUP_Min)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.NUP_Max)).BeginInit(); this.GB_Encounters.SuspendLayout(); @@ -478,6 +481,9 @@ private void InitializeComponent() // // GB_Encounters // + this.GB_Encounters.Controls.Add(this.B_PasteAll); + this.GB_Encounters.Controls.Add(this.B_Paste); + this.GB_Encounters.Controls.Add(this.B_Copy); this.GB_Encounters.Controls.Add(this.GB_Tweak); this.GB_Encounters.Controls.Add(this.PB_NightIcon); this.GB_Encounters.Controls.Add(this.PB_DayIcon); @@ -701,9 +707,9 @@ private void InitializeComponent() this.GB_Tweak.Controls.Add(this.B_LevelPlus); this.GB_Tweak.Controls.Add(this.NUD_LevelAmp); this.GB_Tweak.Controls.Add(this.CHK_Level); - this.GB_Tweak.Location = new System.Drawing.Point(14, 388); + this.GB_Tweak.Location = new System.Drawing.Point(14, 405); this.GB_Tweak.Name = "GB_Tweak"; - this.GB_Tweak.Size = new System.Drawing.Size(282, 159); + this.GB_Tweak.Size = new System.Drawing.Size(282, 150); this.GB_Tweak.TabIndex = 507; this.GB_Tweak.TabStop = false; this.GB_Tweak.Text = "Extra Randomization Tweaks"; @@ -937,7 +943,7 @@ private void InitializeComponent() // // NUP_WeatherForme6 // - this.NUP_WeatherForme6.Location = new System.Drawing.Point(216, 346); + this.NUP_WeatherForme6.Location = new System.Drawing.Point(219, 333); this.NUP_WeatherForme6.Maximum = new decimal(new int[] { 31, 0, @@ -949,7 +955,7 @@ private void InitializeComponent() // // NUP_WeatherForme3 // - this.NUP_WeatherForme3.Location = new System.Drawing.Point(108, 320); + this.NUP_WeatherForme3.Location = new System.Drawing.Point(111, 307); this.NUP_WeatherForme3.Maximum = new decimal(new int[] { 31, 0, @@ -964,14 +970,14 @@ private void InitializeComponent() this.CB_WeatherEnc6.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.Suggest; this.CB_WeatherEnc6.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.ListItems; this.CB_WeatherEnc6.FormattingEnabled = true; - this.CB_WeatherEnc6.Location = new System.Drawing.Point(141, 345); + this.CB_WeatherEnc6.Location = new System.Drawing.Point(144, 332); this.CB_WeatherEnc6.Name = "CB_WeatherEnc6"; this.CB_WeatherEnc6.Size = new System.Drawing.Size(72, 21); this.CB_WeatherEnc6.TabIndex = 502; // // NUP_WeatherForme5 // - this.NUP_WeatherForme5.Location = new System.Drawing.Point(108, 346); + this.NUP_WeatherForme5.Location = new System.Drawing.Point(111, 333); this.NUP_WeatherForme5.Maximum = new decimal(new int[] { 31, 0, @@ -986,14 +992,14 @@ private void InitializeComponent() this.CB_WeatherEnc5.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.Suggest; this.CB_WeatherEnc5.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.ListItems; this.CB_WeatherEnc5.FormattingEnabled = true; - this.CB_WeatherEnc5.Location = new System.Drawing.Point(33, 345); + this.CB_WeatherEnc5.Location = new System.Drawing.Point(36, 332); this.CB_WeatherEnc5.Name = "CB_WeatherEnc5"; this.CB_WeatherEnc5.Size = new System.Drawing.Size(72, 21); this.CB_WeatherEnc5.TabIndex = 500; // // NUP_WeatherForme4 // - this.NUP_WeatherForme4.Location = new System.Drawing.Point(217, 320); + this.NUP_WeatherForme4.Location = new System.Drawing.Point(220, 307); this.NUP_WeatherForme4.Maximum = new decimal(new int[] { 31, 0, @@ -1008,7 +1014,7 @@ private void InitializeComponent() this.CB_WeatherEnc4.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.Suggest; this.CB_WeatherEnc4.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.ListItems; this.CB_WeatherEnc4.FormattingEnabled = true; - this.CB_WeatherEnc4.Location = new System.Drawing.Point(142, 319); + this.CB_WeatherEnc4.Location = new System.Drawing.Point(145, 306); this.CB_WeatherEnc4.Name = "CB_WeatherEnc4"; this.CB_WeatherEnc4.Size = new System.Drawing.Size(72, 21); this.CB_WeatherEnc4.TabIndex = 498; @@ -1018,14 +1024,14 @@ private void InitializeComponent() this.CB_WeatherEnc3.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.Suggest; this.CB_WeatherEnc3.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.ListItems; this.CB_WeatherEnc3.FormattingEnabled = true; - this.CB_WeatherEnc3.Location = new System.Drawing.Point(33, 319); + this.CB_WeatherEnc3.Location = new System.Drawing.Point(36, 306); this.CB_WeatherEnc3.Name = "CB_WeatherEnc3"; this.CB_WeatherEnc3.Size = new System.Drawing.Size(72, 21); this.CB_WeatherEnc3.TabIndex = 497; // // NUP_WeatherForme2 // - this.NUP_WeatherForme2.Location = new System.Drawing.Point(217, 293); + this.NUP_WeatherForme2.Location = new System.Drawing.Point(220, 280); this.NUP_WeatherForme2.Maximum = new decimal(new int[] { 31, 0, @@ -1040,14 +1046,14 @@ private void InitializeComponent() this.CB_WeatherEnc2.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.Suggest; this.CB_WeatherEnc2.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.ListItems; this.CB_WeatherEnc2.FormattingEnabled = true; - this.CB_WeatherEnc2.Location = new System.Drawing.Point(142, 292); + this.CB_WeatherEnc2.Location = new System.Drawing.Point(145, 279); this.CB_WeatherEnc2.Name = "CB_WeatherEnc2"; this.CB_WeatherEnc2.Size = new System.Drawing.Size(72, 21); this.CB_WeatherEnc2.TabIndex = 495; // // NUP_WeatherForme1 // - this.NUP_WeatherForme1.Location = new System.Drawing.Point(108, 293); + this.NUP_WeatherForme1.Location = new System.Drawing.Point(111, 280); this.NUP_WeatherForme1.Maximum = new decimal(new int[] { 31, 0, @@ -1062,7 +1068,7 @@ private void InitializeComponent() this.CB_WeatherEnc1.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.Suggest; this.CB_WeatherEnc1.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.ListItems; this.CB_WeatherEnc1.FormattingEnabled = true; - this.CB_WeatherEnc1.Location = new System.Drawing.Point(33, 292); + this.CB_WeatherEnc1.Location = new System.Drawing.Point(36, 279); this.CB_WeatherEnc1.Name = "CB_WeatherEnc1"; this.CB_WeatherEnc1.Size = new System.Drawing.Size(72, 21); this.CB_WeatherEnc1.TabIndex = 493; @@ -1070,7 +1076,7 @@ private void InitializeComponent() // L_AddSOS // this.L_AddSOS.AutoSize = true; - this.L_AddSOS.Location = new System.Drawing.Point(12, 269); + this.L_AddSOS.Location = new System.Drawing.Point(15, 256); this.L_AddSOS.Name = "L_AddSOS"; this.L_AddSOS.Size = new System.Drawing.Size(76, 13); this.L_AddSOS.TabIndex = 492; @@ -3046,6 +3052,38 @@ private void InitializeComponent() this.CopySOS.UseVisualStyleBackColor = true; this.CopySOS.Click += new System.EventHandler(this.CopySOS_Click); // + // B_Copy + // + this.B_Copy.Location = new System.Drawing.Point(14, 359); + this.B_Copy.Name = "B_Copy"; + this.B_Copy.Size = new System.Drawing.Size(90, 40); + this.B_Copy.TabIndex = 508; + this.B_Copy.Text = "Copy Current Table"; + this.B_Copy.UseVisualStyleBackColor = true; + this.B_Copy.Click += new System.EventHandler(this.B_Copy_Click); + // + // B_Paste + // + this.B_Paste.Enabled = false; + this.B_Paste.Location = new System.Drawing.Point(110, 359); + this.B_Paste.Name = "B_Paste"; + this.B_Paste.Size = new System.Drawing.Size(90, 40); + this.B_Paste.TabIndex = 509; + this.B_Paste.Text = "Paste Current Table"; + this.B_Paste.UseVisualStyleBackColor = true; + this.B_Paste.Click += new System.EventHandler(this.B_Paste_Click); + // + // B_PasteAll + // + this.B_PasteAll.Enabled = false; + this.B_PasteAll.Location = new System.Drawing.Point(206, 359); + this.B_PasteAll.Name = "B_PasteAll"; + this.B_PasteAll.Size = new System.Drawing.Size(90, 40); + this.B_PasteAll.TabIndex = 510; + this.B_PasteAll.Text = "Paste To All (Location)"; + this.B_PasteAll.UseVisualStyleBackColor = true; + this.B_PasteAll.Click += new System.EventHandler(this.B_PasteAll_Click); + // // SMWE // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -3409,5 +3447,8 @@ private void InitializeComponent() private System.Windows.Forms.Button CopySOS; private System.Windows.Forms.Label L_SOS; private System.Windows.Forms.ComboBox CB_SlotRand; + private System.Windows.Forms.Button B_PasteAll; + private System.Windows.Forms.Button B_Paste; + private System.Windows.Forms.Button B_Copy; } } \ No newline at end of file diff --git a/pk3DS/Subforms/Gen7/SMWE.cs b/pk3DS/Subforms/Gen7/SMWE.cs index d270488..a6348eb 100644 --- a/pk3DS/Subforms/Gen7/SMWE.cs +++ b/pk3DS/Subforms/Gen7/SMWE.cs @@ -143,6 +143,7 @@ private void UpdatePanel(object sender, EventArgs e) if (loadingdata) return; loadingdata = true; + var Map = Areas[CB_LocationID.SelectedIndex]; GB_Encounters.Enabled = Map.HasTables; if (!Map.HasTables) @@ -151,26 +152,37 @@ private void UpdatePanel(object sender, EventArgs e) return; } CurrentTable = new EncounterTable(Map.Tables[CB_TableID.SelectedIndex].Data); - NUP_Min.Value = CurrentTable.MinLevel; - NUP_Max.Minimum = CurrentTable.MinLevel; - NUP_Max.Value = CurrentTable.MaxLevel; - for (int slot = 0; slot < CurrentTable.Encounter7s.Length; slot++) - for (int i = 0; i < CurrentTable.Encounter7s[slot].Length; i++) - { - var sl = CurrentTable.Encounter7s[slot]; - if (slot == 8) - sl = CurrentTable.AdditionalSOS; - rate_spec[i].Value = CurrentTable.Rates[i]; - cb_spec[slot][i].SelectedIndex = (int)sl[i].Species; - nup_spec[slot][i].Value = (int)sl[i].Forme; - } - loadingdata = false; + LoadTable(CurrentTable); - int base_id = CB_TableID.SelectedIndex/2; + loadingdata = false; + RefreshTableImages(Map); + } + + private void RefreshTableImages(Area7 Map) + { + int base_id = CB_TableID.SelectedIndex / 2; base_id *= 2; PB_DayTable.Image = Map.Tables[base_id].GetTableImg(font); PB_NightTable.Image = Map.Tables[base_id + 1].GetTableImg(font); } + + private void LoadTable(EncounterTable table) + { + NUP_Min.Value = table.MinLevel; + NUP_Max.Minimum = table.MinLevel; + NUP_Max.Value = table.MaxLevel; + for (int slot = 0; slot < table.Encounter7s.Length; slot++) + for (int i = 0; i < table.Encounter7s[slot].Length; i++) + { + var sl = table.Encounter7s[slot]; + if (slot == 8) + sl = table.AdditionalSOS; + rate_spec[i].Value = table.Rates[i]; + cb_spec[slot][i].SelectedIndex = (int)sl[i].Species; + nup_spec[slot][i].Value = (int)sl[i].Forme; + } + } + private void UpdateMinMax(object sender, EventArgs e) { if (loadingdata) @@ -202,13 +214,15 @@ private void UpdateSpeciesForm(object sender, EventArgs e) var cb_l = cb_spec[table]; var nup_l = nup_spec[table]; + var species = (uint) cb_l[slot].SelectedIndex; + var form = (uint) nup_l[slot].Value; if (table == 8) { - CurrentTable.AdditionalSOS[slot].Species = (uint)cb_l[slot].SelectedIndex; - CurrentTable.AdditionalSOS[slot].Forme = (uint)nup_l[slot].Value; + CurrentTable.AdditionalSOS[slot].Species = species; + CurrentTable.AdditionalSOS[slot].Forme = form; } - CurrentTable.Encounter7s[table][slot].Species = (uint)cb_l[slot].SelectedIndex; - CurrentTable.Encounter7s[table][slot].Forme = (uint)nup_l[slot].Value; + CurrentTable.Encounter7s[table][slot].Species = species; + CurrentTable.Encounter7s[table][slot].Forme = form; using (var g = Graphics.FromImage(cur_img)) { @@ -255,6 +269,51 @@ private void UpdateEncounterRate(object sender, EventArgs e) GB_Encounters.Text = $"Encounters ({sum}%)"; } + private byte[] CopyTable; + private int CopyCount; + private void B_Copy_Click(object sender, EventArgs e) + { + var Map = Areas[CB_LocationID.SelectedIndex]; + if (!Map.HasTables) + { + WinFormsUtil.Alert("No tables to copy."); + return; + } + CurrentTable.Write(); + CopyTable = (byte[])CurrentTable.Data.Clone(); + CopyCount = CurrentTable.Encounter7s[0].Count(z => z.Species != 0); + B_Paste.Enabled = B_PasteAll.Enabled = true; + WinFormsUtil.Alert("Copied table data."); + } + private void B_Paste_Click(object sender, EventArgs e) + { + var Map = Areas[CB_LocationID.SelectedIndex]; + if (!Map.HasTables) + { + WinFormsUtil.Alert("No table to paste to."); + return; + } + CurrentTable.Reset(CopyTable); + loadingdata = true; + LoadTable(CurrentTable); + var area = Areas[CB_LocationID.SelectedIndex]; + area.Tables[CB_TableID.SelectedIndex] = CurrentTable; + loadingdata = false; + RefreshTableImages(Map); + System.Media.SystemSounds.Asterisk.Play(); + } + private void B_PasteAll_Click(object sender, EventArgs e) + { + var Map = Areas[CB_LocationID.SelectedIndex]; + if (!Map.HasTables) + { + WinFormsUtil.Alert("No table to paste to."); + return; + } + B_Paste_Click(sender, e); + foreach (var t in Map.Tables.Where(t => CopyCount == t.Encounter7s[0].Count(z => z.Species != 0))) + t.Reset(CopyTable); + } private void B_Save_Click(object sender, EventArgs e) { var sum = TotalEncounterRate; diff --git a/pk3DS/Subforms/Gen7/Wild/EncounterTable.cs b/pk3DS/Subforms/Gen7/Wild/EncounterTable.cs index 03d8f39..a104b51 100644 --- a/pk3DS/Subforms/Gen7/Wild/EncounterTable.cs +++ b/pk3DS/Subforms/Gen7/Wild/EncounterTable.cs @@ -19,6 +19,14 @@ public EncounterTable(byte[] t) { Rates = new int[10]; Encounter7s = new Encounter7[9][]; + AdditionalSOS = new Encounter7[6]; + Data = (byte[])t.Clone(); + Reset(); + } + + public void Reset() + { + var t = Data; MinLevel = t[0]; MaxLevel = t[1]; @@ -33,12 +41,10 @@ public EncounterTable(byte[] t) Encounter7s[i][j] = new Encounter7(BitConverter.ToUInt32(t, ofs + 4 * j)); } - AdditionalSOS = new Encounter7[6]; for (var i = 0; i < AdditionalSOS.Length; i++) AdditionalSOS[i] = new Encounter7(BitConverter.ToUInt32(t, 0x14C + 4 * i)); Encounter7s[8] = AdditionalSOS; - Data = (byte[])t.Clone(); } /// @@ -119,5 +125,11 @@ private string GetSlotSetSummary(string[] speciesList, int setNumber) var summaries = list.Select(e => $"{e.GetSummary(speciesList)} ({specToRate[e.RawValue]}%)"); return string.Join(", ", summaries); } + + public void Reset(byte[] data) + { + Buffer.BlockCopy(data, 0, Data, 0, 0x164); + Reset(); + } } }