From 98d763d592fabb1815b019e92e6bc785746a03da Mon Sep 17 00:00:00 2001 From: Kurt Date: Sun, 17 Dec 2017 12:33:41 -0800 Subject: [PATCH] Misc fixes range check on click move for typechart --- pk3DS/Subforms/Gen6/TypeChart6.cs | 8 +++++++- pk3DS/Subforms/Gen7/TMEditor7.Designer.cs | 9 +++++---- pk3DS/Subforms/Gen7/TypeChart7.cs | 9 +++++++-- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/pk3DS/Subforms/Gen6/TypeChart6.cs b/pk3DS/Subforms/Gen6/TypeChart6.cs index 88dbb6f..459de25 100644 --- a/pk3DS/Subforms/Gen6/TypeChart6.cs +++ b/pk3DS/Subforms/Gen6/TypeChart6.cs @@ -48,13 +48,17 @@ private void moveMouse(object sender, MouseEventArgs e) { GetCoordinate((PictureBox)sender, e, out int X, out int Y); int index = Y * TypeCount + X; - + if (index >= chart.Length) + return; updateLabel(X, Y, chart[index]); } private void clickMouse(object sender, MouseEventArgs e) { GetCoordinate((PictureBox)sender, e, out int X, out int Y); int index = Y * TypeCount + X; + if (index >= chart.Length) + return; + chart[index] = ToggleEffectiveness(chart[index], e.Button == MouseButtons.Left); updateLabel(X, Y, chart[index]); @@ -62,6 +66,8 @@ private void clickMouse(object sender, MouseEventArgs e) } private void updateLabel(int X, int Y, int value) { + if (value >= effects.Length || X >= types.Length || Y >= types.Length) + return; // clicking and moving outside the box has invalid values L_Hover.Text = $"[{X:00}x{Y:00}: {value:00}] {types[Y]} attacking {types[X]} {effects[value]}"; } private readonly string[] effects = diff --git a/pk3DS/Subforms/Gen7/TMEditor7.Designer.cs b/pk3DS/Subforms/Gen7/TMEditor7.Designer.cs index 350bf49..ea7b5c9 100644 --- a/pk3DS/Subforms/Gen7/TMEditor7.Designer.cs +++ b/pk3DS/Subforms/Gen7/TMEditor7.Designer.cs @@ -40,8 +40,9 @@ private void InitializeComponent() this.dgvTM.AllowUserToDeleteRows = false; this.dgvTM.AllowUserToResizeColumns = false; this.dgvTM.AllowUserToResizeRows = false; - this.dgvTM.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left))); + this.dgvTM.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); this.dgvTM.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.dgvTM.Location = new System.Drawing.Point(9, 25); this.dgvTM.Name = "dgvTM"; @@ -67,7 +68,7 @@ private void InitializeComponent() this.B_RTM.UseVisualStyleBackColor = true; this.B_RTM.Click += new System.EventHandler(this.B_RandomTM_Click); // - // TMHMEditor7 + // TMEditor7 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; @@ -78,7 +79,7 @@ private void InitializeComponent() this.MaximizeBox = false; this.MaximumSize = new System.Drawing.Size(520, 670); this.MinimumSize = new System.Drawing.Size(275, 370); - this.Name = "TMHMEditor7"; + this.Name = "TMEditor7"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; this.Text = "TM Editor"; this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.formClosing); diff --git a/pk3DS/Subforms/Gen7/TypeChart7.cs b/pk3DS/Subforms/Gen7/TypeChart7.cs index 1e109b3..499fab2 100644 --- a/pk3DS/Subforms/Gen7/TypeChart7.cs +++ b/pk3DS/Subforms/Gen7/TypeChart7.cs @@ -62,21 +62,26 @@ private void moveMouse(object sender, MouseEventArgs e) { TypeChart6.GetCoordinate((PictureBox)sender, e, out int X, out int Y); int index = Y*TypeCount + X; - + if (index >= chart.Length) + return; updateLabel(X, Y, chart[index]); } private void clickMouse(object sender, MouseEventArgs e) { TypeChart6.GetCoordinate((PictureBox)sender, e, out int X, out int Y); int index = Y * TypeCount + X; + if (index >= chart.Length) + return; + chart[index] = TypeChart6.ToggleEffectiveness(chart[index], e.Button == MouseButtons.Left); updateLabel(X, Y, chart[index]); populateChart(); } - private void updateLabel(int X, int Y, int value) { + if (value >= effects.Length || X >= types.Length || Y >= types.Length) + return; // clicking and moving outside the box has invalid values L_Hover.Text = $"[{X:00}x{Y:00}: {value:00}] {types[Y]} attacking {types[X]} {effects[value]}"; } private readonly string[] effects =