Esempio n. 1
0
 private static void autoPriorityItem_ValueChanged(object sender, OnValueChangeEventArgs e)
 {
     if (!e.GetNewValue <bool>())
     {
         return;
     }
     foreach (var enemy in HeroManager.Enemies)
     {
         _configMenu.Item("TargetSelector" + enemy.ChampionName + "Priority")
         .SetValue(new Slider(GetPriorityFromDb(enemy.ChampionName), 5, 1));
     }
 }
 private static void autoPriorityItem_ValueChanged(object sender, OnValueChangeEventArgs e)
 {
     if (e.GetNewValue <bool>())
     {
         foreach (
             var enemy in ObjectManager.Get <Obj_AI_Hero>().Where(hero => hero.Team != ObjectManager.Player.Team))
         {
             _config.Item("SimpleTS" + enemy.ChampionName + "Priority")
             .SetValue(new Slider(GetPriorityFromDb(enemy.ChampionName), 5, 1));
         }
     }
 }
Esempio n. 3
0
        /// <summary>
        ///     Sets the value.
        /// </summary>
        /// <typeparam name="T">
        ///     The value type.
        /// </typeparam>
        /// <param name="newValue">
        ///     The new value.
        /// </param>
        /// <returns>
        ///     The item instance.
        /// </returns>
        public MenuItem SetValue <T>(T newValue)
        {
            this.ValueType = MenuValueType.None;
            if (newValue.GetType().ToString().Contains("Boolean"))
            {
                this.ValueType = MenuValueType.Boolean;
            }
            else if (newValue.GetType().ToString().Contains("Slider"))
            {
                this.ValueType = MenuValueType.Slider;
            }
            else if (newValue.GetType().ToString().Contains("KeyBind"))
            {
                this.ValueType = MenuValueType.KeyBind;
            }
            else if (newValue.GetType().ToString().Contains("Int"))
            {
                this.ValueType = MenuValueType.Integer;
            }
            else if (newValue.GetType().ToString().Contains("Circle"))
            {
                this.ValueType = MenuValueType.Circle;
            }
            else if (newValue.GetType().ToString().Contains("StringList"))
            {
                this.ValueType = MenuValueType.StringList;
            }
            else if (newValue.GetType().ToString().Contains("Color"))
            {
                this.ValueType = MenuValueType.Color;
            }
            else
            {
                Console.WriteLine(@"CommonLibMenu: Data type not supported");
            }

            var readBytes = SavedSettings.GetSavedData(this.SaveFileName, this.SaveKey);
            var v         = newValue;

            try
            {
                if (!this.ValueSet && readBytes != null)
                {
                    switch (this.ValueType)
                    {
                    case MenuValueType.KeyBind:
                        var savedKeyValue = (KeyBind)(object)Utils.Deserialize <T>(readBytes);
                        if (savedKeyValue.Type == KeyBindType.Press)
                        {
                            savedKeyValue.Active = false;
                        }

                        newValue = (T)(object)savedKeyValue;
                        break;

                    case MenuValueType.Circle:
                        var savedCircleValue = (Circle)(object)Utils.Deserialize <T>(readBytes);
                        var newCircleValue   = (Circle)(object)newValue;
                        savedCircleValue.Radius = newCircleValue.Radius;
                        newValue = (T)(object)savedCircleValue;
                        break;

                    case MenuValueType.Slider:
                        var savedSliderValue = (Slider)(object)Utils.Deserialize <T>(readBytes);
                        var newSliderValue   = (Slider)(object)newValue;
                        if (savedSliderValue.MinValue == newSliderValue.MinValue &&
                            savedSliderValue.MaxValue == newSliderValue.MaxValue)
                        {
                            newValue = (T)(object)savedSliderValue;
                        }

                        break;

                    case MenuValueType.StringList:
                        var savedListValue = (StringList)(object)Utils.Deserialize <T>(readBytes);
                        var newListValue   = (StringList)(object)newValue;
                        if (savedListValue.SList.SequenceEqual(newListValue.SList))
                        {
                            newValue = (T)(object)savedListValue;
                        }

                        break;

                    default:
                        newValue = Utils.Deserialize <T>(readBytes);
                        break;
                    }
                }
            }
            catch (Exception e)
            {
                newValue = v;
                Console.WriteLine(e);
            }

            OnValueChangeEventArgs valueChangedEvent = null;

            if (this.ValueSet)
            {
                var handler = this.ValueChanged;
                if (handler != null)
                {
                    valueChangedEvent = new OnValueChangeEventArgs(this.value, newValue);
                    handler(this, valueChangedEvent);
                }
            }

            if (valueChangedEvent != null)
            {
                if (valueChangedEvent.Process)
                {
                    this.value = newValue;
                }
            }
            else
            {
                this.value = newValue;
            }

            this.ValueSet   = true;
            this.serialized = Utils.Serialize(this.value);
            return(this);
        }