Exemplo n.º 1
0
        public virtual void Draw(float x, float y, float width, float height)
        {
            float rectWidth  = width;
            float rectHeight = height;
            float rectX      = x + rectWidth * 0.5f;
            float rectY      = y + rectHeight * 0.5f;

            Color barColor = Selected ? HighlightedBackColor : BackColor;

            if (barColor != Color.Empty)
            {
                UIMenu.DrawSprite(UIMenu.CommonTxd, UIMenu.NavBarTextureName,
                                  rectX, rectY,
                                  rectWidth, rectHeight,
                                  barColor);
            }

            if (Hovered && !Selected)
            {
                Color hoveredColor = Color.FromArgb(25, 255, 255, 255);
                UIMenu.DrawRect(rectX, rectY - 0.00138888f * 0.5f,
                                rectWidth, rectHeight - 0.00138888f,
                                hoveredColor);
            }

            if (LeftBadgeInfo != null)
            {
                DrawBadge(LeftBadgeInfo, true, x, y, width, height, out leftBadgeOffset);
            }
            else
            {
                leftBadgeOffset = 0.0f;
            }

            if (RightBadgeInfo != null)
            {
                DrawBadge(RightBadgeInfo, false, x, y, width, height, out rightBadgeOffset);
            }
            else
            {
                rightBadgeOffset = 0.0f;
            }

            SetTextCommandOptions();
            TextCommands.Display(Text, x + 0.0046875f + leftBadgeOffset, y + 0.00277776f);

            if (!String.IsNullOrEmpty(RightLabel))
            {
                SetTextCommandOptions(false);
                float labelWidth = TextCommands.GetWidth(RightLabel);

                float labelX = x + width - 0.00390625f - labelWidth - rightBadgeOffset;
                float labelY = y + 0.00277776f;

                SetTextCommandOptions(false);
                TextCommands.Display(RightLabel, labelX, labelY);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Draw item.
        /// </summary>
        public override void Draw(float x, float y, float width, float height)
        {
            base.Draw(x, y, width, height);

            string selectedOption = Collection == null ?
                                (_items.Count > 0 ? _items[Index].ToString() : " ") :
                                (Collection.Count > 0 ? Collection[Index].DisplayText : " ");

            SetTextCommandOptions(false);
            float optTextWidth = TextCommands.GetWidth(selectedOption);

            GetBadgeOffsets(out _, out float badgeOffset);

            if (Selected && Enabled)
            {
                Color textColor = CurrentForeColor;
                float optTextX = x + width - 0.00390625f - optTextWidth - (0.0046875f * 1.5f) - badgeOffset;
                float optTextY = y + 0.00277776f;

                SetTextCommandOptions(false);
                TextCommands.Display(selectedOption, optTextX, optTextY);

                {
                    UIMenu.GetTextureDrawSize(UIMenu.CommonTxd, UIMenu.ArrowRightTextureName, out float w, out float h);
                    w *= 0.65f;
                    h *= 0.65f;

                    float spriteX = x + width - (0.00390625f * 1.0f) - (w * 0.5f) - badgeOffset;
                    float spriteY = y + (0.034722f * 0.5f);

                    UIMenu.DrawSprite(UIMenu.CommonTxd, UIMenu.ArrowRightTextureName, spriteX, spriteY, w, h, textColor);
                }
                {
                    UIMenu.GetTextureDrawSize(UIMenu.CommonTxd, UIMenu.ArrowLeftTextureName, out float w, out float h);
                    w *= 0.65f;
                    h *= 0.65f;

                    float spriteX = x + width - (0.00390625f * 1.0f) - (w * 0.5f) - optTextWidth - (0.0046875f * 1.5f) - badgeOffset;
                    float spriteY = y + (0.034722f * 0.5f);

                    UIMenu.DrawSprite(UIMenu.CommonTxd, UIMenu.ArrowLeftTextureName, spriteX, spriteY, w, h, textColor);
                }
            }
            else
            {
                float optTextX = x + width - 0.00390625f - optTextWidth - badgeOffset;
                float optTextY = y + 0.00277776f;// + 0.00416664f;

                SetTextCommandOptions(false);
                TextCommands.Display(selectedOption, optTextX, optTextY);
            }
        }
Exemplo n.º 3
0
        public override void Draw()
        {
            if (!Visible)
            {
                return;
            }

            base.Draw();

            int blackAlpha = Focused ? 200 : 100;
            int fullAlpha  = Focused ? 255 : 150;

            int  subMenuWidth = (BottomRight.X - TopLeft.X);
            Size itemSize     = new Size(subMenuWidth, 40);

            int i = 0;

            for (int c = minItem; c < Math.Min(Items.Count, maxItem); c++)
            {
                //bool hovering = UIMenu.IsMouseInBounds(SafeSize.AddPoints(new Point(0, (itemSize.Height + 3) * i)), itemSize);

                bool hasLeftBadge  = Items[c].LeftBadgeInfo != null;
                bool hasRightBadge = Items[c].RightBadgeInfo != null;

                bool hasBothBadges = hasRightBadge && hasLeftBadge;
                bool hasAnyBadge   = hasRightBadge || hasLeftBadge;

                ResRectangle.Draw(SafeSize.AddPoints(new Point(0, (itemSize.Height + 3) * i)), itemSize, (Index == c && Focused) ? Color.FromArgb(fullAlpha, Color.White) : /*Focused && hovering ? Color.FromArgb(100, 50, 50, 50) :*/ Color.FromArgb(blackAlpha, Color.Black));
                ResText.Draw(Items[c].Text, SafeSize.AddPoints(new Point((hasBothBadges ? 60 : hasAnyBadge ? 30 : 6), 5 + (itemSize.Height + 3) * i)), 0.35f, Color.FromArgb(fullAlpha, (Index == c && Focused) ? Color.Black : Color.White), Common.EFont.ChaletLondon, false);

                bool selected = (Index == c && Focused);
                if (hasLeftBadge && !hasRightBadge && !Items[c].LeftBadgeInfo.IsBlank &&
                    BadgeToSprite(Items[c].LeftBadgeInfo, selected, out string badgeTxd, out string badgeTex))
                {
                    Sprite.Draw(badgeTxd, badgeTex,
                                SafeSize.AddPoints(new Point(-2, 1 + (itemSize.Height + 3) * i)), new Size(40, 40), 0f,
                                BadgeToColor(Items[c].LeftBadgeInfo, selected));
                }

                if (!hasLeftBadge && hasRightBadge && !Items[c].RightBadgeInfo.IsBlank &&
                    BadgeToSprite(Items[c].RightBadgeInfo, selected, out badgeTxd, out badgeTex))
                {
                    Sprite.Draw(badgeTxd, badgeTex,
                                SafeSize.AddPoints(new Point(-2, 1 + (itemSize.Height + 3) * i)), new Size(40, 40), 0f,
                                BadgeToColor(Items[c].RightBadgeInfo, selected));
                }

                if (hasLeftBadge && hasRightBadge)
                {
                    if (!Items[c].LeftBadgeInfo.IsBlank && BadgeToSprite(Items[c].LeftBadgeInfo, selected, out badgeTxd, out badgeTex))
                    {
                        Sprite.Draw(badgeTxd, badgeTex,
                                    SafeSize.AddPoints(new Point(-2, 1 + (itemSize.Height + 3) * i)), new Size(40, 40), 0f,
                                    BadgeToColor(Items[c].LeftBadgeInfo, selected));
                    }

                    if (!Items[c].RightBadgeInfo.IsBlank && BadgeToSprite(Items[c].RightBadgeInfo, selected, out badgeTxd, out badgeTex))
                    {
                        Sprite.Draw(badgeTxd, badgeTex,
                                    SafeSize.AddPoints(new Point(25, 1 + (itemSize.Height + 3) * i)), new Size(40, 40), 0f,
                                    BadgeToColor(Items[c].RightBadgeInfo, selected));
                    }
                }

                if (!String.IsNullOrEmpty(Items[c].RightLabel))
                {
                    ResText.Draw(Items[c].RightLabel,
                                 SafeSize.AddPoints(new Point(BottomRight.X - SafeSize.X - 5, 5 + (itemSize.Height + 3) * i)),
                                 0.35f, Color.FromArgb(fullAlpha, (Index == c && Focused) ? Color.Black : Color.White),
                                 Common.EFont.ChaletLondon, ResText.Alignment.Right, false, false, Size.Empty);
                }

                if (Items[c] is UIMenuCheckboxItem)
                {
                    string textureName;
                    if (c == Index && Focused)
                    {
                        textureName = ((UIMenuCheckboxItem)Items[c]).Checked ? "shop_box_tickb" : "shop_box_blankb";
                    }
                    else
                    {
                        textureName = ((UIMenuCheckboxItem)Items[c]).Checked ? "shop_box_tick" : "shop_box_blank";
                    }
                    Sprite.Draw("commonmenu", textureName, SafeSize.AddPoints(new Point(BottomRight.X - SafeSize.X - 60, -5 + (itemSize.Height + 3) * i)), new Size(50, 50), 0f, Color.White);
                }
                else if (Items[c] is UIMenuListItem)
                {
                    var convItem = (UIMenuListItem)Items[c];

                    var yoffset = 5;
                    var basePos =
                        SafeSize.AddPoints(new Point(BottomRight.X - SafeSize.X - 30, yoffset + (itemSize.Height + 3) * i));

                    var arrowLeft  = new Sprite("commonmenu", "arrowleft", basePos, new Size(30, 30));
                    var arrowRight = new Sprite("commonmenu", "arrowright", basePos, new Size(30, 30));
                    var itemText   = new ResText("", basePos, 0.35f, Color.White, Common.EFont.ChaletLondon, ResText.Alignment.Right);

                    string caption = (convItem.Collection == null ? convItem.IndexToItem(convItem.Index) : convItem.Collection[convItem.Index]).ToString();
                    {
                        // prepare text style for TextCommands.GetWidth
                        int         screenw = Game.Resolution.Width;
                        int         screenh = Game.Resolution.Height;
                        const float height  = 1080f;
                        float       ratio   = (float)screenw / screenh;
                        var         width   = height * ratio;
                        float       x       = (itemText.Position.X) / width;
                        N.SetTextFont((int)itemText.FontEnum);
                        N.SetTextScale(0.0f, itemText.Scale);
                        N.SetTextRightJustify(true);
                        N.SetTextWrap(0.0f, x);
                    }
                    int offset = (int)(TextCommands.GetWidth(caption) * Game.Resolution.Width);

                    itemText.Color = convItem.Enabled ? selected ? Color.Black : Color.WhiteSmoke : Color.FromArgb(163, 159, 148);

                    itemText.Caption = caption;

                    arrowLeft.Color  = convItem.Enabled ? selected ? Color.Black : Color.WhiteSmoke : Color.FromArgb(163, 159, 148);
                    arrowRight.Color = convItem.Enabled ? selected ? Color.Black : Color.WhiteSmoke : Color.FromArgb(163, 159, 148);

                    arrowLeft.Position = SafeSize.AddPoints(new Point(BottomRight.X - SafeSize.X - 60 - offset, yoffset + (itemSize.Height + 3) * i));
                    if (selected)
                    {
                        arrowLeft.Draw();
                        arrowRight.Draw();
                        itemText.Position = SafeSize.AddPoints(new Point(BottomRight.X - SafeSize.X - 30, yoffset + (itemSize.Height + 3) * i));
                    }
                    else
                    {
                        itemText.Position = SafeSize.AddPoints(new Point(BottomRight.X - SafeSize.X - 5, yoffset + (itemSize.Height + 3) * i));
                    }

                    itemText.Draw();
                }

                //if (Focused && hovering && (Common.IsDisabledControlJustPressed(0, GameControl.CursorAccept) || Game.IsControlJustPressed(0, GameControl.CursorAccept)))
                //{
                //    bool open = Index == c;
                //    Index = (1000 - (1000 % Items.Count) + c) % Items.Count;
                //    if (!open)
                //        Common.PlaySound("NAV_UP_DOWN", "HUD_FRONTEND_DEFAULT_SOUNDSET");
                //    else
                //    {
                //        if (Items[Index] is UIMenuCheckboxItem)
                //        {
                //            Common.PlaySound("SELECT", "HUD_FRONTEND_DEFAULT_SOUNDSET");
                //            UIMenuCheckboxItem cb = (UIMenuCheckboxItem)Items[Index];
                //            cb.Checked = !cb.Checked;
                //            cb.CheckboxEventTrigger();
                //        }
                //        else
                //        {
                //            Common.PlaySound("SELECT", "HUD_FRONTEND_DEFAULT_SOUNDSET");
                //            Items[Index].ItemActivate(null);
                //        }
                //    }
                //}

                i++;
            }
        }