Пример #1
0
        /// <summary>
        /// Updates the display name of a specified menu component to match the new data
        /// </summary>
        /// <param name="component">The <see cref="AMenuComponent"/> instance to be updated</param>
        /// <param name="language">The specified language</param>
        /// <returns></returns>
        internal static void Update(AMenuComponent component, Language?language = null)
        {
            var name = component.Name;

            try
            {
                var translation = GetTranslation(name, language);

                component.DisplayName = (from Match match in BracesAroundTextRegex.Matches(translation)
                                         select match.Groups).SelectMany(
                    groups =>
                {
                    var list = new List <string>(groups.Count);

                    for (int i = 0; i < groups.Count; i++)
                    {
                        list.Add(groups[i].Value);
                    }

                    return(list);
                })
                                        .Aggregate(
                    translation,
                    (current, match) =>
                    current.Replace(match, Replacements[BraceFinderRegex.Replace(match, string.Empty)]()));
            }
            catch (KeyNotFoundException ex)
            {
                ex.Catch($"Couldn't translate {name}");
            }
            catch (Exception ex)
            {
                ex.Catch();
            }
        }
Пример #2
0
 /// <summary>
 ///     Gets the container rectangle.
 /// </summary>
 /// <param name="component">
 ///     The component.
 /// </param>
 /// <returns>
 ///     <see cref="Rectangle" /> with information.
 /// </returns>
 public static Rectangle GetContainerRectangle(AMenuComponent component)
 {
     return(new Rectangle(
                (int)component.Position.X,
                (int)component.Position.Y,
                component.MenuWidth,
                MenuSettings.ContainerHeight));
 }
 /// <summary>
 ///     Gets the container rectangle.
 /// </summary>
 /// <param name="component">
 ///     The component.
 /// </param>
 /// <returns>
 ///     <see cref="Rectangle" /> with information.
 /// </returns>
 public static Rectangle GetContainerRectangle(AMenuComponent component)
 {
     return new Rectangle(
         (int)component.Position.X, 
         (int)component.Position.Y, 
         component.MenuWidth, 
         MenuSettings.ContainerHeight);
 }
Пример #4
0
 /// <summary>
 ///     Removes a menu component from this menu.
 /// </summary>
 /// <param name="component"><see cref="AMenuComponent" /> component instance</param>
 public void Remove(AMenuComponent component)
 {
     if (Components.ContainsKey(component.Name))
     {
         component.Parent = null;
         Components.Remove(component.Name);
     }
 }
 /// <summary>
 ///     Get the preview boundaries
 /// </summary>
 /// <param name="component">The <see cref="MenuColor" /></param>
 /// <returns>The <see cref="Rectangle" /></returns>
 private static Rectangle PreviewBoundaries(AMenuComponent component)
 {
     return(new Rectangle(
                (int)(component.Position.X + component.MenuWidth - MenuSettings.ContainerHeight),
                (int)component.Position.Y,
                MenuSettings.ContainerHeight,
                MenuSettings.ContainerHeight));
 }
Пример #6
0
        private Rectangle GetContainerRectangle(Vector2 position, AMenuComponent component)
        {
            if (component == null)
            {
                Logging.Write(true)(LogLevel.Error, "Component is null");
            }

            return(new Rectangle(
                       (int)position.X, (int)position.Y, component.MenuWidth, DefaultSettings.ContainerHeight));
        }
Пример #7
0
        /// <summary>
        ///     Removes a menu component from this menu.
        /// </summary>
        /// <param name="component">
        ///     <see cref="AMenuComponent" /> component instance
        /// </param>
        /// <returns>
        ///     The <see cref="bool" />.
        /// </returns>
        public bool Remove(AMenuComponent component)
        {
            if (this.Components.ContainsKey(component.Name))
            {
                component.Save();
                component.Parent = null;
                return(this.Components.Remove(component.Name));
            }

            return(false);
        }
Пример #8
0
 /// <summary>
 ///     Add a menu component to this menu.
 /// </summary>
 /// <param name="component"><see cref="AMenuComponent" /> component</param>
 public void Add(AMenuComponent component)
 {
     if (!Components.ContainsKey(component.Name))
     {
         component.Parent           = this;
         Components[component.Name] = component;
     }
     else
     {
         throw new Exception("This menu already contains a component with the name " + component.Name);
     }
 }
Пример #9
0
        /// <summary>
        ///     Boolean Item Draw callback.
        /// </summary>
        /// <param name="component">Parent Component</param>
        /// <param name="position">Position</param>
        /// <param name="index">Item Index</param>
        public override void OnDraw(AMenuComponent component, Vector2 position, int index)
        {
            Position = position;

            Theme.Animation animation = ThemeManager.Current.Boolean.Animation;

            if (animation != null && animation.IsAnimating())
            {
                animation.OnDraw(component, position, index);

                return;
            }
            ThemeManager.Current.Boolean.OnDraw(component, position, index);
        }
Пример #10
0
        /// <summary>
        ///     Add a menu component to this menu.
        /// </summary>
        /// <typeparam name="T">
        ///     <see cref="AMenuComponent" /> type
        /// </typeparam>
        /// <param name="component">
        ///     <see cref="AMenuComponent" /> component
        /// </param>
        /// <returns>
        ///     The <see cref="AMenuComponent" /> instance.
        /// </returns>
        public virtual T Add <T>(T component) where T : AMenuComponent
        {
            if (!this.Components.ContainsKey(component.Name))
            {
                component.Parent = this;
                this.Components[component.Name] = component;

                AMenuComponent comp = this;
                while (comp.Parent != null)
                {
                    comp = comp.Parent;
                }

                if (comp.Root)
                {
                    comp.Load();
                }
            }
            else
            {
                var existingComponent = this.Components[component.Name] as Menu;
                var newComponent      = component as Menu;
                if (existingComponent != null && newComponent != null)
                {
                    foreach (var comp in newComponent.Components)
                    {
                        existingComponent.Add(comp.Value);
                    }
                }
                else
                {
                    throw new Exception("This menu already contains a component with the name " + component.Name);
                }
            }

            MenuManager.Instance.ResetWidth();
            return(component);
        }
Пример #11
0
 public static bool GetSliderBool(this AMenuComponent menu, string str)
 {
     return(menu[str].GetValue <MenuSliderButton>().BValue);
 }
Пример #12
0
 public static int GetSliderButton(this AMenuComponent menu, string str)
 {
     return(menu[str].GetValue <MenuSliderButton>().Value);
 }
Пример #13
0
 public static bool GetBool(this AMenuComponent menu, string str)
 {
     return(menu[str].GetValue <MenuBool>().Value);
 }
Пример #14
0
 public static bool GetKeyBind(this AMenuComponent menu, string str)
 {
     return(menu[str].GetValue <MenuKeyBind>().Active);
 }
Пример #15
0
        /// <summary>
        /// Called when the menu is drawn.
        /// </summary>
        /// <param name="menuComponent">The menu component.</param>
        /// <param name="position">The position.</param>
        /// <param name="index">The index.</param>
        public override void OnMenu(Menu menuComponent, Vector2 position, int index)
        {
            #region Hovering

            if (menuComponent.Hovering && !menuComponent.Toggled && menuComponent.Components.Count > 0)
            {
                DefaultSettings.HoverLine.Begin();
                DefaultSettings.HoverLine.Draw(
                    new[]
                {
                    new Vector2(position.X, position.Y + DefaultSettings.ContainerHeight / 2f),
                    new Vector2(
                        position.X + menuComponent.MenuWidth, position.Y + DefaultSettings.ContainerHeight / 2f)
                },
                    DefaultSettings.HoverColor);
                DefaultSettings.HoverLine.End();
            }

            #endregion

            #region Text Draw

            var centerY =
                (int)
                (GetContainerRectangle(position, menuComponent)
                 .GetCenteredText(null, menuComponent.DisplayName, CenteredFlags.VerticalCenter)
                 .Y);

            Font.DrawText(
                null, menuComponent.DisplayName, (int)(position.X + DefaultSettings.ContainerTextOffset), centerY,
                DefaultSettings.TextColor);

            Font.DrawText(
                null, "»",
                (int)
                (position.X + menuComponent.MenuWidth - DefaultSettings.ContainerTextMarkWidth +
                 DefaultSettings.ContainerTextMarkOffset), centerY,
                menuComponent.Components.Count > 0 ? DefaultSettings.TextColor : DefaultSettings.ContainerSeparatorColor);

            #endregion

            if (menuComponent.Toggled)
            {
                #region Selection Mark

                DefaultSettings.ContainerLine.Width = menuComponent.MenuWidth;
                DefaultSettings.ContainerLine.Begin();
                DefaultSettings.ContainerLine.Draw(
                    new[]
                {
                    new Vector2(position.X + menuComponent.MenuWidth / 2f, position.Y),
                    new Vector2(
                        position.X + menuComponent.MenuWidth / 2f, position.Y + DefaultSettings.ContainerHeight)
                },
                    DefaultSettings.ContainerSelectedColor);
                DefaultSettings.ContainerLine.End();

                #endregion

                float height = DefaultSettings.ContainerHeight * menuComponent.Components.Count;
                float width  = DefaultSettings.ContainerWidth;
                if (menuComponent.Components.Count > 0)
                {
                    width = menuComponent.Components.First().Value.MenuWidth;
                }

                DefaultSettings.ContainerLine.Width = width;
                DefaultSettings.ContainerLine.Begin();
                DefaultSettings.ContainerLine.Draw(
                    new[]
                {
                    new Vector2((position.X + menuComponent.MenuWidth) + width / 2, position.Y),
                    new Vector2((position.X + menuComponent.MenuWidth) + width / 2, position.Y + height)
                },
                    DefaultSettings.RootContainerColor);
                DefaultSettings.ContainerLine.End();


                for (int i = 0; i < menuComponent.Components.Count; ++i)
                {
                    AMenuComponent childComponent = menuComponent.Components.Values.ToList()[i];
                    if (childComponent != null)
                    {
                        var childPos = new Vector2(
                            position.X + menuComponent.MenuWidth, position.Y + i * DefaultSettings.ContainerHeight);

                        #region Separator

                        if (i < menuComponent.Components.Count - 1)
                        {
                            DefaultSettings.ContainerSeparatorLine.Begin();
                            DefaultSettings.ContainerSeparatorLine.Draw(
                                new[]
                            {
                                new Vector2(childPos.X, childPos.Y + DefaultSettings.ContainerHeight),
                                new Vector2(
                                    childPos.X + childComponent.MenuWidth,
                                    childPos.Y + DefaultSettings.ContainerHeight)
                            },
                                DefaultSettings.ContainerSeparatorColor);
                            DefaultSettings.ContainerSeparatorLine.End();
                        }

                        #endregion

                        childComponent.OnDraw(childPos, i);
                    }
                }
            }
        }
Пример #16
0
 /// <summary>
 /// Updates the display name of a specified menu component
 /// </summary>
 /// <param name="component">The <see cref="AMenuComponent"/> instance to be updated</param>
 /// <param name="language">The specified language</param>
 /// <returns></returns>
 internal static void Update(this AMenuComponent component, Language?language = null) => Translations.Update(component, language);
Пример #17
0
 /// <summary>
 ///     The minimum mana needed to cast the given Spell.
 /// </summary>
 public static int GetNeededHealth(SpellSlot slot, AMenuComponent value)
 =>
 value.GetValue <MenuSliderButton>().SValue
 + (int)(GameObjects.Player.Spellbook.GetSpell(slot).SData.Mana / GameObjects.Player.MaxHealth * 100);
Пример #18
0
 public static bool SafetyManager(this Obj_AI_Base target, AMenuComponent menu)
 {
     return(menu.GetSliderBool("danger") ? menu.GetSliderButton("danger") >= target.CountEnemyHeroesInRange(1000) && !target.IsUnderEnemyTurret() : true);
 }
 /// <summary>
 ///     Get the preview boundaries
 /// </summary>
 /// <param name="component">The <see cref="MenuColor" /></param>
 /// <returns>The <see cref="SharpDX.Rectangle" /></returns>
 private static Rectangle PreviewBoundaries(AMenuComponent component)
 {
     return new Rectangle(
         (int)(component.Position.X + component.MenuWidth - MenuSettings.ContainerHeight),
         (int)component.Position.Y,
         MenuSettings.ContainerHeight,
         MenuSettings.ContainerHeight);
 }
Пример #20
0
 /// <summary>
 ///     The minimum mana needed to cast the given Spell.
 /// </summary>
 public static int GetNeededMana(SpellSlot slot, AMenuComponent value)
     =>
         value.GetValue<MenuSliderButton>().SValue
         + (int)(GameObjects.Player.Spellbook.GetSpell(slot).ManaCost / GameObjects.Player.MaxMana * 100);
Пример #21
0
 public static bool ManaManager(this Spell spell, AMenuComponent menu)
 {
     return(menu.GetSliderBool("mana") ? Config.Player.ManaPercent >= menu.GetSliderButton("mana") : true);
 }
Пример #22
0
 public static bool SafetyManager(this Vector3 vector3, AMenuComponent menu)
 {
     return(menu.GetSliderBool("danger") ? menu.GetSliderButton("danger") >= vector3.CountEnemyHeroesInRange(1000) && !vector3.IsUnderEnemyTurret() : true);
 }
Пример #23
0
 public static int GetListIndex(this AMenuComponent menu, string str)
 {
     return(menu[str].GetValue <MenuList>().Index);
 }
 /// <summary>
 ///     InputText Draw callback.
 /// </summary>
 /// <param name="component">Parent Component</param>
 /// <param name="position">Position</param>
 /// <param name="index">Item Index</param>
 public override void OnDraw(AMenuComponent component, Vector2 position, int index)
 {
 }