示例#1
0
        /// <summary>
        ///     The drawing event.
        /// </summary>
        /// <param name="args">
        ///     The event args.
        /// </param>
        internal void OnDraw(EventArgs args)
        {
            if (!this.Visible)
            {
                return;
            }

            Drawing.Direct3DDevice.SetRenderState(RenderState.AlphaBlendEnable, true);
            MenuDrawHelper.DrawBox(
                this.Position,
                this.Width,
                this.Height,
                (this.Children.Count > 0 && this.Children[0].Visible || this.Items.Count > 0 && this.Items[0].Visible)
                    ? MenuSettings.ActiveBackgroundColor
                    : MenuSettings.BackgroundColor,
                1,
                System.Drawing.Color.Black);

            MenuDrawHelper.Font.DrawText(
                null,
                MultiLanguage._(this.DisplayName),
                new Rectangle((int)this.Position.X + 5, (int)this.Position.Y, this.Width, this.Height),
                FontDrawFlags.VerticalCenter,
                this.Color);
            MenuDrawHelper.Font.DrawText(
                null,
                ">",
                new Rectangle((int)this.Position.X - 5, (int)this.Position.Y, this.Width, this.Height),
                FontDrawFlags.Right | FontDrawFlags.VerticalCenter,
                this.Color);

            //Draw the menu submenus
            foreach (var child in this.Children.Where(child => child.Visible))
            {
                child.OnDraw(args);
            }

            //Draw the items
            for (var i = this.Items.Count - 1; i >= 0; i--)
            {
                var item = this.Items[i];
                if (item.Visible)
                {
                    item.OnDraw();
                }
            }
        }
示例#2
0
        /// <summary>
        ///     Adds a menuitem to PermaShow, can be used without any arguements or with if you want to customize. The bool can be
        ///     set to false to remove the item from permashow.
        ///     When removing, you can simply set the bool parameter to false and everything else can be null. The default color is
        ///     White.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="enabled">if set to <c>true</c> the instance will be enabled.</param>
        /// <param name="customdisplayname">The customdisplayname.</param>
        /// <param name="col">The color.</param>
        public static void Permashow(
            this MenuItem item,
            bool enabled             = true,
            string customdisplayname = null,
            Color?col = null)
        {
            if (!IsEnabled())
            {
                return;
            }
            if (enabled && PermaShowItems.All(x => x.Item != item))
            {
                if (!PermaShowItems.Any())
                {
                    Sub();
                }
                //修改的位置,支持汉化
                string dispName = MultiLanguage._(customdisplayname ?? item.DisplayName);
                Color? color    = col ?? new ColorBGRA(255, 255, 255, 255);
                PermaShowItems.Add(
                    new PermaShowItem
                {
                    DisplayName = dispName, Item = item, ItemType = item.ValueType, Color = (Color)color
                });
            }

            else if (!enabled)
            {
                var itemtoremove = PermaShowItems.FirstOrDefault(x => x.Item == item);
                if (itemtoremove != null)
                {
                    PermaShowItems.Remove(itemtoremove);
                    if (!PermaShowItems.Any())
                    {
                        Unsub();
                    }
                }
            }
        }
示例#3
0
        /// <summary>
        ///     The drawing event.
        /// </summary>
        /// <param name="args">
        ///     The event args.
        /// </param>
        internal void OnDraw(EventArgs args)
        {
            if (!this.Visible)
            {
                return;
            }

            Drawing.Direct3DDevice.SetRenderState(RenderState.AlphaBlendEnable, true);
            MenuDrawHelper.DrawBox(
                this.Position,
                this.Width,
                this.Height,
                (this.Children.Count > 0 && this.Children[0].Visible || this.Items.Count > 0 && this.Items[0].Visible)
                    ? MenuSettings.ActiveBackgroundColor
                    : MenuSettings.BackgroundColor,
                1,
                System.Drawing.Color.Black);

            var style = this.Style;

            style &= ~FontStyle.Strikeout;
            style &= ~FontStyle.Underline;

            var font = MenuDrawHelper.GetFont(style);

            font.DrawText(
                null,
                MultiLanguage._(this.DisplayName),
                new Rectangle((int)this.Position.X + 5, (int)this.Position.Y, this.Width, this.Height),
                FontDrawFlags.VerticalCenter,
                this.Color);
            font.DrawText(
                null,
                ">",
                new Rectangle((int)this.Position.X - 5, (int)this.Position.Y, this.Width, this.Height),
                FontDrawFlags.Right | FontDrawFlags.VerticalCenter,
                this.Color);

            var textWidth = font.MeasureText(null, MultiLanguage._(this.DisplayName));

            if ((this.Style & FontStyle.Strikeout) != 0)
            {
                Drawing.DrawLine(
                    this.Position.X + 5,
                    this.Position.Y + (MenuSettings.MenuItemHeight / 2f),
                    this.Position.X + 5 + textWidth.Width,
                    this.Position.Y + (MenuSettings.MenuItemHeight / 2f),
                    1f,
                    System.Drawing.Color.FromArgb(this.Color.A, this.Color.R, this.Color.G, this.Color.B));
            }

            if ((this.Style & FontStyle.Underline) != 0)
            {
                Drawing.DrawLine(
                    this.Position.X + 5,
                    this.Position.Y + (MenuSettings.MenuItemHeight / 1.5f),
                    this.Position.X + 5 + textWidth.Width,
                    this.Position.Y + (MenuSettings.MenuItemHeight / 1.5f),
                    1f,
                    System.Drawing.Color.FromArgb(this.Color.A, this.Color.R, this.Color.G, this.Color.B));
            }

            //Draw the menu submenus
            foreach (var child in this.Children.Where(child => child.Visible))
            {
                child.OnDraw(args);
            }

            //Draw the items
            for (var i = this.Items.Count - 1; i >= 0; i--)
            {
                var item = this.Items[i];
                if (item.Visible)
                {
                    item.OnDraw();
                }
            }
        }
示例#4
0
        /// <summary>
        ///     On draw event.
        /// </summary>
        internal void OnDraw()
        {
            var s = MultiLanguage._(this.DisplayName);

            MenuDrawHelper.DrawBox(
                this.Position,
                this.Width,
                this.Height,
                MenuSettings.BackgroundColor,
                1,
                System.Drawing.Color.Black);

            if (this.DrawingTooltip)
            {
                MenuDrawHelper.DrawToolTipText(
                    new Vector2(this.Position.X + this.Width, this.Position.Y),
                    this,
                    this.TooltipColor);
            }

            var style = this.FontStyle;

            style &= ~FontStyle.Strikeout;
            style &= ~FontStyle.Underline;

            var font = MenuDrawHelper.GetFont(style);

            switch (this.ValueType)
            {
            case MenuValueType.Boolean:
                MenuDrawHelper.DrawOnOff(
                    this.GetValue <bool>(),
                    new Vector2(this.Position.X + this.Width - this.Height, this.Position.Y),
                    this);
                break;

            case MenuValueType.Slider:
                MenuDrawHelper.DrawSlider(this.Position, this);
                break;

            case MenuValueType.KeyBind:
                var val = this.GetValue <KeyBind>();

                if (this.Interacting)
                {
                    s = MultiLanguage._("Press new key(s)");
                }

                if (val.Key != 0)
                {
                    var x = !string.IsNullOrEmpty(this.Tooltip)
                                    ? (int)this.Position.X + this.Width - this.Height
                            - font.MeasureText("[" + Utils.KeyToText(val.Key) + "]").Width - 35
                                    : (int)this.Position.X + this.Width - this.Height
                            - font.MeasureText("[" + Utils.KeyToText(val.Key) + "]").Width - 10;

                    font.DrawText(
                        null,
                        "[" + Utils.KeyToText(val.Key) + "]",
                        new Rectangle(x, (int)this.Position.Y, this.Width, this.Height),
                        FontDrawFlags.VerticalCenter,
                        new ColorBGRA(1, 169, 234, 255));
                }

                if (val.SecondaryKey != 0)
                {
                    var x_secondary = !string.IsNullOrEmpty(this.Tooltip)
                                              ? (int)this.Position.X + this.Width - this.Height
                                      - font.MeasureText("[" + Utils.KeyToText(val.Key) + "]").Width
                                      - font.MeasureText("[" + Utils.KeyToText(val.Key) + "]").Width / 4
                                      - font.MeasureText("[" + Utils.KeyToText(val.SecondaryKey) + "]").Width
                                      - 35
                                              : (int)this.Position.X + this.Width - this.Height
                                      - font.MeasureText("[" + Utils.KeyToText(val.Key) + "]").Width
                                      - font.MeasureText("[" + Utils.KeyToText(val.Key) + "]").Width / 4
                                      - font.MeasureText("[" + Utils.KeyToText(val.SecondaryKey) + "]").Width
                                      - 10;

                    font.DrawText(
                        null,
                        "[" + Utils.KeyToText(val.SecondaryKey) + "]",
                        new Rectangle(x_secondary, (int)this.Position.Y, this.Width, this.Height),
                        FontDrawFlags.VerticalCenter,
                        new ColorBGRA(1, 169, 234, 255));
                }

                MenuDrawHelper.DrawOnOff(
                    val.Active,
                    new Vector2(this.Position.X + this.Width - this.Height, this.Position.Y),
                    this);

                break;

            case MenuValueType.Integer:
                var intVal = this.GetValue <int>();
                MenuDrawHelper.Font.DrawText(
                    null,
                    intVal.ToString(),
                    new Rectangle((int)this.Position.X + 5, (int)this.Position.Y, this.Width, this.Height),
                    FontDrawFlags.VerticalCenter | FontDrawFlags.Right,
                    new ColorBGRA(255, 255, 255, 255));
                break;

            case MenuValueType.Color:
                var colorVal = this.GetValue <System.Drawing.Color>();
                MenuDrawHelper.DrawBox(
                    this.Position + new Vector2(this.Width - this.Height, 0),
                    this.Height,
                    this.Height,
                    colorVal,
                    1,
                    System.Drawing.Color.Black);
                break;

            case MenuValueType.Circle:
                var circleVal = this.GetValue <Circle>();
                MenuDrawHelper.DrawBox(
                    this.Position + new Vector2(this.Width - this.Height * 2, 0),
                    this.Height,
                    this.Height,
                    circleVal.Color,
                    1,
                    System.Drawing.Color.Black);
                MenuDrawHelper.DrawOnOff(
                    circleVal.Active,
                    new Vector2(this.Position.X + this.Width - this.Height, this.Position.Y),
                    this);
                break;

            case MenuValueType.StringList:
                var slVal = this.GetValue <StringList>();

                var t = slVal.SList[slVal.SelectedIndex];

                MenuDrawHelper.DrawArrow(
                    "<<",
                    this.Position + new Vector2(this.Width - this.Height * 2, 0),
                    this,
                    System.Drawing.Color.Black);
                MenuDrawHelper.DrawArrow(
                    ">>",
                    this.Position + new Vector2(this.Width - this.Height, 0),
                    this,
                    System.Drawing.Color.Black);

                MenuDrawHelper.Font.DrawText(
                    null,
                    MultiLanguage._(t),
                    new Rectangle(
                        (int)this.Position.X - 5 - 2 * this.Height,
                        (int)this.Position.Y,
                        this.Width,
                        this.Height),
                    FontDrawFlags.VerticalCenter | FontDrawFlags.Right,
                    new ColorBGRA(255, 255, 255, 255));
                break;
            }

            if (!string.IsNullOrEmpty(this.Tooltip))
            {
                MenuDrawHelper.DrawToolTipButton(new Vector2(this.Position.X + this.Width, this.Position.Y), this);
            }

            font.DrawText(
                null,
                s,
                new Rectangle((int)this.Position.X + 5, (int)this.Position.Y, this.Width, this.Height),
                FontDrawFlags.VerticalCenter,
                this.FontColor);

            var textWidth = font.MeasureText(null, MultiLanguage._(this.DisplayName));

            if ((this.FontStyle & FontStyle.Strikeout) != 0)
            {
                Drawing.DrawLine(
                    this.Position.X + 5,
                    this.Position.Y + (MenuSettings.MenuItemHeight / 2f),
                    this.Position.X + 5 + textWidth.Width,
                    this.Position.Y + (MenuSettings.MenuItemHeight / 2f),
                    1f,
                    System.Drawing.Color.FromArgb(
                        this.FontColor.A,
                        this.FontColor.R,
                        this.FontColor.G,
                        this.FontColor.B));
            }

            if ((this.FontStyle & FontStyle.Underline) != 0)
            {
                Drawing.DrawLine(
                    this.Position.X + 5,
                    this.Position.Y + (MenuSettings.MenuItemHeight / 1.5f),
                    this.Position.X + 5 + textWidth.Width,
                    this.Position.Y + (MenuSettings.MenuItemHeight / 1.5f),
                    1f,
                    System.Drawing.Color.FromArgb(
                        this.FontColor.A,
                        this.FontColor.R,
                        this.FontColor.G,
                        this.FontColor.B));
            }
        }
示例#5
0
 public static void DrawText(this Font font, Sprite sprite, string text, int x, int y, ColorBGRA color)
 {
     font.DrawText(sprite, MultiLanguage._(text), x, y, color);
 }