private void PopulateRegimens(string Type, TableLayoutPanel TLP, List <RegimenInfo> list) { // Get a list of all Regimen Attregutes in the PKM var RegimenNames = ReflectFrameworkUtil.GetPropertiesStartWithPrefix(pkm.GetType(), Type); list.AddRange(from RegimenName in RegimenNames let RegimenValue = ReflectUtil.GetValue(pkm, RegimenName) where RegimenValue is bool select new RegimenInfo(RegimenName, (bool)RegimenValue)); TLP.ColumnCount = 1; TLP.RowCount = 0; // Add Regimens foreach (var reg in list) { AddRegimenChoice(reg, TLP); } // Force auto-size foreach (RowStyle style in TLP.RowStyles) { style.SizeType = SizeType.AutoSize; } foreach (ColumnStyle style in TLP.ColumnStyles) { style.SizeType = SizeType.AutoSize; } }
private static void SetRandomIVs(PKM PKM, StringInstruction cmd) { int MaxIV = PKM.Format <= 2 ? 15 : 31; if (cmd.PropertyName == "IVs") { int[] IVs = new int[6]; for (int i = 0; i < 6; i++) { IVs[i] = (int)(Util.Rand32() & MaxIV); } if (Legal.Legends.Contains(PKM.Species) || Legal.SubLegends.Contains(PKM.Species)) { for (int i = 0; i < 3; i++) { IVs[i] = MaxIV; } } Util.Shuffle(IVs); PKM.IVs = IVs; } else { ReflectFrameworkUtil.SetValue(PKM, cmd.PropertyName, Util.Rand32() & MaxIV); } }
private static void SetRandomIVs(PKM PKM, StringInstruction cmd) { if (cmd.PropertyName == nameof(PKM.IVs)) { PKM.SetRandomIVs(); return; } ReflectFrameworkUtil.SetValue(PKM, cmd.PropertyName, Util.Rand32() & PKM.MaxIV); }
private static void SetProperty(PKM PKM, StringInstruction cmd) { if (cmd.PropertyName == nameof(PKM.MetDate)) { PKM.MetDate = DateTime.ParseExact(cmd.PropertyValue, "yyyyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.None); } else if (cmd.PropertyName == nameof(PKM.EggMetDate)) { PKM.EggMetDate = DateTime.ParseExact(cmd.PropertyValue, "yyyyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.None); } else if (cmd.PropertyName == nameof(PKM.EncryptionConstant) && cmd.PropertyValue == CONST_RAND) { ReflectFrameworkUtil.SetValue(PKM, cmd.PropertyName, Util.Rand32().ToString()); } else if ((cmd.PropertyName == nameof(PKM.Ability) || cmd.PropertyName == nameof(PKM.AbilityNumber)) && cmd.PropertyValue.StartsWith("$")) { PKM.RefreshAbility(Convert.ToInt16(cmd.PropertyValue[1]) - 0x30); } else if (cmd.PropertyName == nameof(PKM.PID) && cmd.PropertyValue == CONST_RAND) { PKM.SetPIDGender(PKM.Gender); } else if (cmd.PropertyName == nameof(PKM.EncryptionConstant) && cmd.PropertyValue == nameof(PKM.PID)) { PKM.EncryptionConstant = PKM.PID; } else if (cmd.PropertyName == nameof(PKM.PID) && cmd.PropertyValue == CONST_SHINY) { PKM.SetShinyPID(); } else if (cmd.PropertyName == nameof(PKM.Species) && cmd.PropertyValue == "0") { PKM.Data = new byte[PKM.Data.Length]; } else if (cmd.PropertyName.StartsWith("IV") && cmd.PropertyValue == CONST_RAND) { SetRandomIVs(PKM, cmd); } else if (cmd.Random) { ReflectFrameworkUtil.SetValue(PKM, cmd.PropertyName, cmd.RandomValue); } else if (cmd.PropertyName == nameof(PKM.IsNicknamed) && cmd.PropertyValue.ToLower() == "false") { PKM.IsNicknamed = false; PKM.Nickname = PKX.GetSpeciesName(PKM.Species, PKM.Language); } else { ReflectFrameworkUtil.SetValue(PKM, cmd.PropertyName, cmd.PropertyValue); } }
private void CB_Property_SelectedIndexChanged(object sender, EventArgs e) { L_PropType.Text = GetPropertyType(CB_Property.Text); if (pkmref.GetType().HasProperty(CB_Property.Text)) { L_PropValue.Text = ReflectFrameworkUtil.GetValue(pkmref, CB_Property.Text).ToString(); L_PropType.ForeColor = L_PropValue.ForeColor; // reset color } else // no property, flag { L_PropValue.Text = string.Empty; L_PropType.ForeColor = Color.Red; } }
private void PopulateRibbons() { // Get a list of all Ribbon Attributes in the PKM var RibbonNames = ReflectFrameworkUtil.GetPropertiesStartWithPrefix(pkm.GetType(), "Ribbon"); foreach (var RibbonName in RibbonNames) { object RibbonValue = ReflectUtil.GetValue(pkm, RibbonName); if (RibbonValue is int) { riblist.Add(new RibbonInfo(RibbonName, (int)RibbonValue)); } if (RibbonValue is bool) { riblist.Add(new RibbonInfo(RibbonName, (bool)RibbonValue)); } } TLP_Ribbons.ColumnCount = 2; TLP_Ribbons.RowCount = 0; // Add Ribbons foreach (var rib in riblist) { AddRibbonSprite(rib); } foreach (var rib in riblist.OrderBy(z => RibbonStrings.GetName(z.Name))) { AddRibbonChoice(rib); } // Force auto-size foreach (RowStyle style in TLP_Ribbons.RowStyles) { style.SizeType = SizeType.AutoSize; } foreach (ColumnStyle style in TLP_Ribbons.ColumnStyles) { style.SizeType = SizeType.AutoSize; } }
private static string[][] GetPropArray() { var p = new string[types.Length][]; for (int i = 0; i < p.Length; i++) { p[i] = ReflectFrameworkUtil.GetPropertiesCanWritePublicDeclared(types[i]).Concat(CustomProperties).OrderBy(a => a).ToArray(); } // Properties for any PKM var any = ReflectFrameworkUtil.GetPropertiesCanWritePublic(typeof(PK1)).Union(p.SelectMany(a => a)).OrderBy(a => a).ToArray(); // Properties shared by all PKM var all = p.Aggregate(new HashSet <string>(p.First()), (h, e) => { h.IntersectWith(e); return(h); }).OrderBy(a => a).ToArray(); var p1 = new string[types.Length + 2][]; Array.Copy(p, 0, p1, 1, p.Length); p1[0] = any; p1[p1.Length - 1] = all; return(p1); }