mirror of
https://github.com/kwsch/pk3DS.git
synced 2026-08-24 18:56:20 -05:00
Simplify typechart GUI logic
extract common methods can probably make this a shared usercontrol but meh
This commit is contained in:
3
pk3DS/Subforms/Gen6/TypeChart6.Designer.cs
generated
3
pk3DS/Subforms/Gen6/TypeChart6.Designer.cs
generated
@@ -77,7 +77,7 @@ private void InitializeComponent()
|
||||
this.L_Hover.TabIndex = 468;
|
||||
this.L_Hover.Text = "Effectiveness Summary";
|
||||
//
|
||||
// TypeChart
|
||||
// TypeChart6
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
@@ -86,6 +86,7 @@ private void InitializeComponent()
|
||||
this.Controls.Add(this.B_Cancel);
|
||||
this.Controls.Add(this.B_Save);
|
||||
this.Controls.Add(this.PB_Chart);
|
||||
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
|
||||
this.MaximizeBox = false;
|
||||
this.MinimumSize = new System.Drawing.Size(355, 220);
|
||||
this.Name = "TypeChart6";
|
||||
|
||||
@@ -19,10 +19,8 @@ public partial class TypeChart6 : Form
|
||||
public TypeChart6()
|
||||
{
|
||||
if (!File.Exists(CROPath))
|
||||
{
|
||||
WinFormsUtil.Error("CRO does not exist! Closing.", CROPath);
|
||||
Close();
|
||||
}
|
||||
{ WinFormsUtil.Error("CRO does not exist! Closing.", CROPath); Close(); }
|
||||
|
||||
InitializeComponent();
|
||||
|
||||
CROData = File.ReadAllBytes(CROPath);
|
||||
@@ -48,65 +46,23 @@ private void B_Cancel_Click(object sender, EventArgs e)
|
||||
|
||||
private void moveMouse(object sender, MouseEventArgs e)
|
||||
{
|
||||
int X = e.X / TypeWidth;
|
||||
int Y = e.Y / TypeWidth;
|
||||
if (e.X == (sender as PictureBox).Width - 1 - 2) // tweak because the furthest pixel is unused for transparent effect, and 2 px are used for border
|
||||
X -= 1;
|
||||
if (e.Y == (sender as PictureBox).Height - 1 - 2)
|
||||
Y -= 1;
|
||||
|
||||
GetCoordinate((PictureBox)sender, e, out int X, out int Y);
|
||||
int index = Y * TypeCount + X;
|
||||
|
||||
updateLabel(X, Y, chart[index]);
|
||||
}
|
||||
private void clickMouse(object sender, MouseEventArgs e)
|
||||
{
|
||||
int X = e.X / TypeWidth;
|
||||
int Y = e.Y / TypeWidth;
|
||||
if (e.X == (sender as PictureBox).Width - 1 - 2) // tweak because the furthest pixel is unused for transparent effect, and 2 px are used for border
|
||||
X -= 1;
|
||||
if (e.Y == (sender as PictureBox).Height - 1 - 2)
|
||||
Y -= 1;
|
||||
|
||||
GetCoordinate((PictureBox)sender, e, out int X, out int Y);
|
||||
int index = Y * TypeCount + X;
|
||||
if (e.Button == MouseButtons.Left) // Increase
|
||||
switch (chart[index])
|
||||
{
|
||||
case 08:
|
||||
chart[index] = 4;
|
||||
break;
|
||||
case 04:
|
||||
chart[index] = 2;
|
||||
break;
|
||||
case 02:
|
||||
chart[index] = 0;
|
||||
break;
|
||||
case 00:
|
||||
chart[index] = 8;
|
||||
break;
|
||||
}
|
||||
else // Decrease
|
||||
switch (chart[index])
|
||||
{
|
||||
case 08:
|
||||
chart[index] = 0;
|
||||
break;
|
||||
case 04:
|
||||
chart[index] = 8;
|
||||
break;
|
||||
case 02:
|
||||
chart[index] = 4;
|
||||
break;
|
||||
case 00:
|
||||
chart[index] = 2;
|
||||
break;
|
||||
}
|
||||
chart[index] = ToggleEffectiveness(chart[index], e.Button == MouseButtons.Left);
|
||||
|
||||
updateLabel(X, Y, chart[index]);
|
||||
populateChart();
|
||||
}
|
||||
private void updateLabel(int X, int Y, int value)
|
||||
{
|
||||
L_Hover.Text = string.Format("[{0}x{1}: {2}] {4} attacking {3} {5}", X.ToString("00"), Y.ToString("00"),
|
||||
value.ToString("00"), types[X], types[Y], effects[value]);
|
||||
L_Hover.Text = $"[{X:00}x{Y:00}: {value:00}] {types[Y]} attacking {types[X]} {effects[value]}";
|
||||
}
|
||||
private readonly string[] effects =
|
||||
{
|
||||
@@ -118,5 +74,26 @@ private void updateLabel(int X, int Y, int value)
|
||||
"", "", "",
|
||||
"is super effective!"
|
||||
};
|
||||
|
||||
public static void GetCoordinate(Control sender, MouseEventArgs e, out int X, out int Y)
|
||||
{
|
||||
X = e.X / TypeWidth;
|
||||
Y = e.Y / TypeWidth;
|
||||
if (e.X == sender.Width - 1 - 2) // tweak because the furthest pixel is unused for transparent effect, and 2 px are used for border
|
||||
X -= 1;
|
||||
if (e.Y == sender.Height - 1 - 2)
|
||||
Y -= 1;
|
||||
}
|
||||
public static byte ToggleEffectiveness(byte currentValue, bool increase)
|
||||
{
|
||||
byte[] vals = { 0, 2, 4, 8 };
|
||||
int curIndex = Array.IndexOf(vals, currentValue);
|
||||
if (curIndex < 0)
|
||||
return currentValue;
|
||||
|
||||
uint shift = (uint) (curIndex + (increase ? 1 : -1));
|
||||
var newIndex = shift % vals.Length;
|
||||
return vals[newIndex];
|
||||
}
|
||||
}
|
||||
}
|
||||
5
pk3DS/Subforms/Gen7/TypeChart7.Designer.cs
generated
5
pk3DS/Subforms/Gen7/TypeChart7.Designer.cs
generated
@@ -77,7 +77,7 @@ private void InitializeComponent()
|
||||
this.L_Hover.TabIndex = 468;
|
||||
this.L_Hover.Text = "Effectiveness Summary";
|
||||
//
|
||||
// TypeChart
|
||||
// TypeChart7
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
@@ -86,9 +86,10 @@ private void InitializeComponent()
|
||||
this.Controls.Add(this.B_Cancel);
|
||||
this.Controls.Add(this.B_Save);
|
||||
this.Controls.Add(this.PB_Chart);
|
||||
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
|
||||
this.MaximizeBox = false;
|
||||
this.MinimumSize = new System.Drawing.Size(355, 220);
|
||||
this.Name = "TypeChart6";
|
||||
this.Name = "TypeChart7";
|
||||
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
|
||||
this.Text = "Type Chart Editor";
|
||||
((System.ComponentModel.ISupportInitialize)(this.PB_Chart)).EndInit();
|
||||
|
||||
@@ -18,10 +18,15 @@ public partial class TypeChart7 : Form
|
||||
|
||||
public TypeChart7()
|
||||
{
|
||||
InitializeComponent();
|
||||
if (Main.ExeFSPath == null) { WinFormsUtil.Alert("No exeFS code to load."); Close(); }
|
||||
if (Main.ExeFSPath == null)
|
||||
{ WinFormsUtil.Alert("No exeFS code to load."); Close(); }
|
||||
|
||||
string[] files = Directory.GetFiles(Main.ExeFSPath);
|
||||
if (!File.Exists(files[0]) || !Path.GetFileNameWithoutExtension(files[0]).Contains("code")) { WinFormsUtil.Alert("No .code.bin detected."); Close(); }
|
||||
if (!File.Exists(files[0]) || !Path.GetFileNameWithoutExtension(files[0]).Contains("code"))
|
||||
{ WinFormsUtil.Alert("No .code.bin detected."); Close(); }
|
||||
|
||||
InitializeComponent();
|
||||
|
||||
codebin = files[0];
|
||||
exefs = File.ReadAllBytes(codebin);
|
||||
if (exefs.Length % 0x200 != 0) { WinFormsUtil.Alert(".code.bin not decompressed. Aborting."); Close(); }
|
||||
@@ -55,65 +60,24 @@ private void B_Cancel_Click(object sender, EventArgs e)
|
||||
|
||||
private void moveMouse(object sender, MouseEventArgs e)
|
||||
{
|
||||
int X = e.X / TypeWidth;
|
||||
int Y = e.Y / TypeWidth;
|
||||
if (e.X == (sender as PictureBox).Width - 1 - 2) // tweak because the furthest pixel is unused for transparent effect, and 2 px are used for border
|
||||
X -= 1;
|
||||
if (e.Y == (sender as PictureBox).Height - 1 - 2)
|
||||
Y -= 1;
|
||||
|
||||
TypeChart6.GetCoordinate((PictureBox)sender, e, out int X, out int Y);
|
||||
int index = Y*TypeCount + X;
|
||||
|
||||
updateLabel(X, Y, chart[index]);
|
||||
}
|
||||
private void clickMouse(object sender, MouseEventArgs e)
|
||||
{
|
||||
int X = e.X / TypeWidth;
|
||||
int Y = e.Y / TypeWidth;
|
||||
if (e.X == (sender as PictureBox).Width - 1 - 2) // tweak because the furthest pixel is unused for transparent effect, and 2 px are used for border
|
||||
X -= 1;
|
||||
if (e.Y == (sender as PictureBox).Height - 1 - 2)
|
||||
Y -= 1;
|
||||
|
||||
TypeChart6.GetCoordinate((PictureBox)sender, e, out int X, out int Y);
|
||||
int index = Y * TypeCount + X;
|
||||
if (e.Button == MouseButtons.Left) // Increase
|
||||
switch (chart[index])
|
||||
{
|
||||
case 08:
|
||||
chart[index] = 4;
|
||||
break;
|
||||
case 04:
|
||||
chart[index] = 2;
|
||||
break;
|
||||
case 02:
|
||||
chart[index] = 0;
|
||||
break;
|
||||
case 00:
|
||||
chart[index] = 8;
|
||||
break;
|
||||
}
|
||||
else // Decrease
|
||||
switch (chart[index])
|
||||
{
|
||||
case 08:
|
||||
chart[index] = 0;
|
||||
break;
|
||||
case 04:
|
||||
chart[index] = 8;
|
||||
break;
|
||||
case 02:
|
||||
chart[index] = 4;
|
||||
break;
|
||||
case 00:
|
||||
chart[index] = 2;
|
||||
break;
|
||||
}
|
||||
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)
|
||||
{
|
||||
L_Hover.Text = string.Format("[{0}x{1}: {2}] {4} attacking {3} {5}", X.ToString("00"), Y.ToString("00"),
|
||||
value.ToString("00"), types[X], types[Y], effects[value]);
|
||||
L_Hover.Text = $"[{X:00}x{Y:00}: {value:00}] {types[Y]} attacking {types[X]} {effects[value]}";
|
||||
}
|
||||
private readonly string[] effects =
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user