From 643b2afb52e15822e3ced8c43a0aac1447da99dc Mon Sep 17 00:00:00 2001 From: Kaphotics Date: Wed, 24 Feb 2016 14:59:03 -0800 Subject: [PATCH] Cleanup Safe casts aren't needed for Array.IndexOf Initial Ribbon images are already set up, no need to rereference Slicker way of inverting checkboxes. --- PKX/f1-Main.cs | 5 ++--- PKX/f3-MemoryAmie.cs | 4 ++-- PKX/f4-RibbMedal.cs | 32 ++++++++------------------------ SAV/SAV_Trainer.cs | 16 +++++++--------- 4 files changed, 19 insertions(+), 38 deletions(-) diff --git a/PKX/f1-Main.cs b/PKX/f1-Main.cs index c672006cd..0845f7865 100644 --- a/PKX/f1-Main.cs +++ b/PKX/f1-Main.cs @@ -1325,8 +1325,7 @@ namespace PKHeX PictureBox[] pba = { PB_Mark1, PB_Mark2, PB_Mark3, PB_Mark4, PB_Mark5, PB_Mark6 }; CheckBox[] cba = { CHK_Circle, CHK_Triangle, CHK_Square, CHK_Heart, CHK_Star, CHK_Diamond }; - CheckBox cb = cba[Array.IndexOf(pba, sender as PictureBox)]; - cb.Checked = !cb.Checked; + cba[Array.IndexOf(pba, sender)].Checked ^= true; setMarkings(); } private void clickStatLabel(object sender, MouseEventArgs e) @@ -1334,7 +1333,7 @@ namespace PKHeX if (!(ModifierKeys == Keys.Control || ModifierKeys == Keys.Alt)) return; - int index = Array.IndexOf(new[] { Label_HP, Label_ATK, Label_DEF, Label_SPA, Label_SPD, Label_SPE }, sender as Label); + int index = Array.IndexOf(new[] { Label_HP, Label_ATK, Label_DEF, Label_SPA, Label_SPD, Label_SPE }, sender); if (ModifierKeys == Keys.Alt) // EV { diff --git a/PKX/f3-MemoryAmie.cs b/PKX/f3-MemoryAmie.cs index 9b849e9ab..64ebbd223 100644 --- a/PKX/f3-MemoryAmie.cs +++ b/PKX/f3-MemoryAmie.cs @@ -407,7 +407,7 @@ namespace PKHeX ComboBox[] cba = { CB_Country0, CB_Country1, CB_Country2, CB_Country3, CB_Country4 }; ComboBox[] mta = { CB_Region0, CB_Region1, CB_Region2, CB_Region3, CB_Region4, }; - int index = Array.IndexOf(cba, sender as ComboBox); + int index = Array.IndexOf(cba, sender); if (Util.getIndex(sender as ComboBox) > 0) { Main.setCountrySubRegion(mta[index], "sr_" + Util.getIndex(sender as ComboBox).ToString("000")); @@ -445,7 +445,7 @@ namespace PKHeX Label[] senderarr = { L_Geo0, L_Geo1, L_Geo2, L_Geo3, L_Geo4, }; ComboBox[] cba = { CB_Country0, CB_Country1, CB_Country2, CB_Country3, CB_Country4, }; ComboBox[] mta = { CB_Region0, CB_Region1, CB_Region2, CB_Region3, CB_Region4, }; - int index = Array.IndexOf(senderarr, sender as Label); + int index = Array.IndexOf(senderarr, sender); cba[index].SelectedValue = 0; mta[index].DisplayMember = "Text"; diff --git a/PKX/f4-RibbMedal.cs b/PKX/f4-RibbMedal.cs index 8177ef516..586751384 100644 --- a/PKX/f4-RibbMedal.cs +++ b/PKX/f4-RibbMedal.cs @@ -7,31 +7,12 @@ namespace PKHeX { public partial class RibbMedal : Form { - private readonly Bitmap[] bma; private readonly PictureBox[] pba; private readonly CheckBox[] cba; + private readonly Image[] bma; public RibbMedal() { InitializeComponent(); - bma = new[] { - Properties.Resources.kaloschamp, Properties.Resources.hoennchamp, Properties.Resources.sinnohchamp, Properties.Resources.bestfriends, - Properties.Resources.training, Properties.Resources.skillfullbattler, Properties.Resources.expertbattler, Properties.Resources.effort, - - Properties.Resources.alert, Properties.Resources.shock, Properties.Resources.downcast, Properties.Resources.careless, - Properties.Resources.relax, Properties.Resources.snooze, Properties.Resources.smile, Properties.Resources.gorgeous, - - Properties.Resources.royal, Properties.Resources.gorgeousroyal, Properties.Resources.artist, Properties.Resources.footprint, - Properties.Resources.record, Properties.Resources.legend, Properties.Resources.country, Properties.Resources.national, - - Properties.Resources.earth, Properties.Resources.world, Properties.Resources.classic, Properties.Resources.premier, - Properties.Resources._event, Properties.Resources.birthday, Properties.Resources.special, Properties.Resources.souvenir, - - Properties.Resources.wishing, Properties.Resources.battlechamp, Properties.Resources.regionalchamp, Properties.Resources.nationalchamp, - Properties.Resources.worldchamp, - - Properties.Resources.ribbon_40,Properties.Resources.ribbon_41,Properties.Resources.ribbon_42,Properties.Resources.ribbon_43, - Properties.Resources.ribbon_44,Properties.Resources.ribbon_45,Properties.Resources.ribbon_46, - }; pba = new[] { PB_10, PB_11, PB_12, PB_13, PB_14, PB_15, PB_16, PB_17, @@ -60,8 +41,12 @@ namespace PKHeX Extra1_7, ORAS_0, ORAS_1, ORAS_2, ORAS_3, ORAS_4, ORAS_5, }; + bma = new Image[pba.Length]; for (int i = 0; i < bma.Length; i++) + { + bma[i] = pba[i].Image; pba[i].Image = Util.ChangeOpacity(bma[i], 0.1); + } Util.TranslateInterface(this, Main.curlanguage); // Set up Training Bag Data @@ -363,12 +348,12 @@ namespace PKHeX private void updateRibbon(object sender, EventArgs e) { - int index = Array.IndexOf(cba, sender as CheckBox); + int index = Array.IndexOf(cba, sender); pba[index].Image = Util.ChangeOpacity(bma[index], (cba[index].Checked ? 1 : 0) * 0.9 + 0.1); } private void updateMemoryRibbon(object sender, EventArgs e) { - if ((sender as MaskedTextBox).Text.Length == 0) { (sender as MaskedTextBox).Text = 0.ToString(); return; } + if ((sender as MaskedTextBox).Text.Length == 0) { (sender as MaskedTextBox).Text = "0"; return; } if (sender as MaskedTextBox == TB_PastContest) { var val = Util.ToInt32(TB_PastContest.Text); @@ -386,8 +371,7 @@ namespace PKHeX } private void clickRibbon(object sender, EventArgs e) { - CheckBox cb = cba[Array.IndexOf(pba, sender as PictureBox)]; - cb.Checked = !cb.Checked; + cba[Array.IndexOf(pba, sender)].Checked ^= true; } } } diff --git a/SAV/SAV_Trainer.cs b/SAV/SAV_Trainer.cs index 2cf5b15b5..de6d7b0d7 100644 --- a/SAV/SAV_Trainer.cs +++ b/SAV/SAV_Trainer.cs @@ -25,6 +25,8 @@ namespace PKHeX TB_MCRN,TB_MCRS,TB_MBRN,TB_MBRS, TB_MCMN,TB_MCMS,TB_MBMN,TB_MBMS, }; + cba = new[] { CHK_Badge1, CHK_Badge2, CHK_Badge3, CHK_Badge4, CHK_Badge5, CHK_Badge6, CHK_Badge7, CHK_Badge8, }; + pba = new [] { PB_Badge1, PB_Badge2, PB_Badge3, PB_Badge4, PB_Badge5, PB_Badge6, PB_Badge7, PB_Badge8, }; L_MultiplayerSprite.Enabled = CB_MultiplayerSprite.Enabled = Main.SAV.ORAS; L_Style.Visible = TB_Style.Visible = SAV.XY; @@ -204,6 +206,8 @@ namespace PKHeX private bool editing; private readonly ToolTip Tip1 = new ToolTip(), Tip2 = new ToolTip(); private readonly MaskedTextBox[] MaisonRecords; + private readonly CheckBox[] cba; + private readonly PictureBox[] pba; private void getComboBoxes() { @@ -349,16 +353,13 @@ namespace PKHeX Properties.Resources.badge_7, Properties.Resources.badge_8, }; - CheckBox[] cba = { CHK_Badge1, CHK_Badge2, CHK_Badge3, CHK_Badge4, CHK_Badge5, CHK_Badge6, CHK_Badge7, CHK_Badge8, }; - PictureBox[] pba = { PB_Badge1, PB_Badge2, PB_Badge3, PB_Badge4, PB_Badge5, PB_Badge6, PB_Badge7, PB_Badge8, }; for (int i = 0; i < 8; i++) - pba[i].Image = Util.ChangeOpacity(bma[i], !cba[i].Checked ? 0.1 : 1); + pba[i].Image = Util.ChangeOpacity(bma[i], cba[i].Checked ? 1 : 0.1); } private void getTextBoxes() { int badgeval = SAV.Badges; - CheckBox[] cba = { CHK_Badge1, CHK_Badge2, CHK_Badge3, CHK_Badge4, CHK_Badge5, CHK_Badge6, CHK_Badge7, CHK_Badge8, }; for (int i = 0; i < 8; i++) cba[i].Checked = (badgeval & 1 << i) != 0; @@ -491,7 +492,6 @@ namespace PKHeX // Copy Badges int badgeval = 0; - CheckBox[] cba = { CHK_Badge1, CHK_Badge2, CHK_Badge3, CHK_Badge4, CHK_Badge5, CHK_Badge6, CHK_Badge7, CHK_Badge8, }; for (int i = 0; i < 8; i++) badgeval |= (cba[i].Checked ? 1 : 0) << i; SAV.Badges = badgeval; @@ -542,7 +542,7 @@ namespace PKHeX private void clickOT(object sender, MouseEventArgs e) { - TextBox tb = !(sender is TextBox) ? TB_OTName : sender as TextBox; + TextBox tb = sender as TextBox ?? TB_OTName; // Special Character Form if (ModifierKeys != Keys.Control) return; @@ -636,9 +636,7 @@ namespace PKHeX } private void toggleBadge(object sender, EventArgs e) { - int val = Convert.ToInt16(((PictureBox)sender).Name.Last().ToString()) - 1; - CheckBox[] chka = { CHK_Badge1, CHK_Badge2, CHK_Badge3, CHK_Badge4, CHK_Badge5, CHK_Badge6, CHK_Badge7, CHK_Badge8 }; - chka[val].Checked = !chka[val].Checked; + cba[Array.IndexOf(pba, sender)].Checked ^= true; } private void CB_Multi_SelectedIndexChanged(object sender, EventArgs e)