public static void AddToMenu(Menu menu, ResourceManagerArgs args) { try { if (Menues.ContainsKey(args.UniqueId)) { throw new ArgumentException( string.Format("ResourceManager: UniqueID \"{0}\" does already exist.", args.UniqueId)); } var prefix = string.IsNullOrEmpty(args.Prefix) ? string.Empty : args.Prefix + " "; var checkTypeString = args.CheckType == ResourceCheckType.Maximum ? "Max" : (args.CheckType == ResourceCheckType.Minimum ? "Min" : string.Empty); var valueTypeString = args.ValueType == ResourceValueType.Percent ? "%" : string.Empty; if (args.Advanced) { if (args.LevelRanges.Count <= 0 || args.DefaultValues.Count <= 0) { throw new ArgumentException( string.Format( "ResourceManager: \"{0}\" doesn't contain any \"LevelRanges\" or \"DefaultValues\".", args.UniqueId)); } if (args.LevelRanges.Count != args.DefaultValues.Count) { throw new ArgumentException( string.Format( "ResourceManager: \"{0}\" \"LevelRanges\" and \"DefaultValues\" doesn't match.", args.UniqueId)); } var subMenu = menu.AddSubMenu( new Menu( string.Format("{0}{1} Settings", prefix, args.Type), string.Format("{0}.{1}-{2}", menu.Name, args.Type, args.UniqueId))); subMenu.AddItem( new MenuItem( string.Format("{0}.header", subMenu.Name), string.Format("{0} {1} Values", args.CheckType, args.ValueType))); for (var i = 0; i < args.LevelRanges.Count; i++) { var levelFrom = args.LevelRanges.Keys[i]; var levelTo = args.LevelRanges.Values[i]; var defaultValue = args.DefaultValues[i]; subMenu.AddItem( new MenuItem( string.Format("{0}.{1}-{2}", subMenu.Name, levelFrom, levelTo), string.Format("Level {0} - {1}", levelFrom, levelTo)).SetValue( new Slider(defaultValue, args.MinValue, args.MaxValue))); } if (args.IgnoreJungleOption) { subMenu.AddItem( new MenuItem(string.Format("{0}.ignore-jungle", subMenu.Name), "Ignore for Jungle")) .SetValue(true); } } else { menu.AddItem( new MenuItem( string.Format("{0}.{1}-{2}", menu.Name, args.Type, args.UniqueId), string.Format("{0}{1} {2}. {3}", prefix, checkTypeString, args.Type, valueTypeString)) .SetValue(new Slider(args.DefaultValue, args.MinValue, args.MaxValue))); } Menues[args.UniqueId] = new Tuple<Menu, ResourceManagerArgs>(menu, args); } catch (Exception ex) { Global.Logger.AddItem(new LogItem(ex)); } }
private static bool Check(int menuValue, ResourceManagerArgs args) { var resourceValue = 0f; if (args.ValueType == ResourceValueType.Percent) { resourceValue = args.Type == ResourceType.Health ? ObjectManager.Player.HealthPercent : (args.Type == ResourceType.Mana ? ObjectManager.Player.ManaPercent : 0); } else if (args.ValueType == ResourceValueType.Total) { resourceValue = args.Type == ResourceType.Health ? ObjectManager.Player.Health : (args.Type == ResourceType.Mana ? ObjectManager.Player.Mana : 0); } if (args.CheckType == ResourceCheckType.Maximum) { return resourceValue <= menuValue; } if (args.CheckType == ResourceCheckType.Minimum) { return resourceValue >= menuValue; } return true; }