コード例 #1
0
        public override void drawInMenu(SpriteBatch spriteBatch, Vector2 location, float scaleSize, float transparency, float layerDepth, StackDrawType drawStackNumber, Color color, bool drawShadow)
        {
            spriteBatch.Draw(Game1.mouseCursors, location + new Vector2(32f, 32f), GetPrimaryIconSourceRect(2), GetPrimaryIconColor() * transparency, 0f, new Vector2(8f, 8f), 4f * scaleSize, SpriteEffects.None, layerDepth);

            if (drawStackNumber != StackDrawType.Hide)
            {
                float   QuantityScale       = 2.7f * scaleSize;
                int     NumDigits           = DrawHelpers.GetNumDigits(Stack);
                Vector2 BottomRightPosition = new Vector2(location.X + 64f - DrawHelpers.MeasureNumber(Stack, QuantityScale),
                                                          location.Y + 64f - DrawHelpers.TinyDigitBaseHeight * QuantityScale);
                Utility.drawTinyDigits(Stack, spriteBatch, BottomRightPosition, QuantityScale, 0f, Color.White);
            }

            float   Offset             = (64f - 64f * scaleSize) / 2f;
            Vector2 BottomLeftPosition = new Vector2(location.X + Offset, location.Y + 64f + Offset);

            DrawIcon(spriteBatch, AugmentorType, BottomLeftPosition, scaleSize, transparency, 1f);
        }
コード例 #2
0
        public void DrawToolTips(SpriteBatch b)
        {
            if (IsEmptyMenu)
            {
                return;
            }

            //  Draw tooltip over hovered item
            if (HoveredSlot.HasValue)
            {
                //  Get the hovered Item Id and ColumnType
                int?       ItemId = null;
                ColumnType?Column = null;
                foreach (var KVP in SlotBounds)
                {
                    foreach (var KVP2 in KVP.Value)
                    {
                        if (KVP2.Value == HoveredSlot.Value)
                        {
                            ItemId = KVP.Key;
                            Column = KVP2.Key;
                            break;
                        }
                    }

                    if (ItemId.HasValue && Column.HasValue)
                    {
                        break;
                    }
                }

                if (ItemId.HasValue && Column.HasValue)
                {
                    if (Column == ColumnType.RowValue)
                    {
                        List <Object> Items            = Placeholders[ItemId.Value].Values.ToList();
                        List <int>    Quantities       = Items.Select(x => x.Stack).ToList();
                        List <int>    SingleValues     = Items.Select(x => ItemBag.GetSingleItemPrice(x)).ToList();
                        List <int>    MultipliedValues = Items.Select(x => x.Stack * ItemBag.GetSingleItemPrice(x)).ToList();

                        //  Compute how many digits each column needs so that we can align each number properly by making each number take up the maximum size of other numbers in the same column
                        int   SingleValueColumnDigits     = SingleValues.Max(x => DrawHelpers.GetNumDigits(x));
                        int   QuantityColumnDigits        = Quantities.Max(x => DrawHelpers.GetNumDigits(x));
                        int   MultipliedValueColumnDigits = MultipliedValues.Max(x => DrawHelpers.GetNumDigits(x));
                        float DigitScale                 = 3.0f;
                        float SingleValueColumnWidth     = SingleValueColumnDigits * DigitScale * DrawHelpers.TinyDigitBaseWidth;
                        float QuantityColumnWidth        = QuantityColumnDigits * DigitScale * DrawHelpers.TinyDigitBaseWidth;
                        float MultipliedValueColumnWidth = MultipliedValueColumnDigits * DigitScale * DrawHelpers.TinyDigitBaseWidth;

                        //  Compute how big the tooltip needs to be
                        int   Margin     = 32;
                        int   LineHeight = 28;
                        int   HorizontalSeparatorHeight = 6;
                        int   SeparatorMargin           = 4;
                        float PlusCharacterWidth        = Game1.tinyFont.MeasureString("+").X;
                        float MultiplyCharacterWidth    = Game1.tinyFont.MeasureString("*").X;
                        float EqualsCharacterWidth      = Game1.tinyFont.MeasureString("=").X;
                        float SpaceWidth  = 7f;
                        int   TotalWidth  = (int)(Margin + PlusCharacterWidth + SpaceWidth + SingleValueColumnWidth + SpaceWidth + MultiplyCharacterWidth + SpaceWidth + QuantityColumnWidth + SpaceWidth + EqualsCharacterWidth + SpaceWidth + MultipliedValueColumnWidth + Margin);
                        int   TotalHeight = (int)(Margin + Items.Count * LineHeight + SeparatorMargin + HorizontalSeparatorHeight + SeparatorMargin + LineHeight + Margin);

                        //  Ensure tooltip is fully visible on screen
                        Rectangle ToolTipLocation = new Rectangle(HoveredSlot.Value.Right, HoveredSlot.Value.Top, TotalWidth, TotalHeight);
                        if (ToolTipLocation.Right > Game1.viewport.Size.Width)
                        {
                            ToolTipLocation = new Rectangle(HoveredSlot.Value.Left - TotalWidth, HoveredSlot.Value.Top, TotalWidth, TotalHeight);
                        }

                        //  Draw background
                        DrawHelpers.DrawBox(b, ToolTipLocation);

                        //  Draw each row of values
                        int ShadowOffset     = 2;
                        int CurrentYPosition = ToolTipLocation.Y + Margin;
                        for (int i = 0; i < Items.Count; i++)
                        {
                            float CurrentXPosition = ToolTipLocation.X + Margin;
                            if (i != 0)
                            {
                                DrawHelpers.DrawStringWithShadow(b, Game1.tinyFont, "+", CurrentXPosition, CurrentYPosition, Color.White, Color.Black, ShadowOffset, ShadowOffset);
                            }
                            CurrentXPosition += PlusCharacterWidth + SpaceWidth;
                            Utility.drawTinyDigits(SingleValues[i], b, new Vector2(CurrentXPosition + SingleValueColumnWidth - DrawHelpers.MeasureNumber(SingleValues[i], DigitScale), CurrentYPosition), DigitScale, 1.0f, Color.White);
                            CurrentXPosition += SingleValueColumnWidth + SpaceWidth;
                            DrawHelpers.DrawStringWithShadow(b, Game1.tinyFont, "*", CurrentXPosition, CurrentYPosition + LineHeight / 4, Color.White, Color.Black, ShadowOffset, ShadowOffset);
                            CurrentXPosition += MultiplyCharacterWidth + SpaceWidth;
                            Utility.drawTinyDigits(Quantities[i], b, new Vector2(CurrentXPosition + QuantityColumnWidth - DrawHelpers.MeasureNumber(Quantities[i], DigitScale), CurrentYPosition), DigitScale, 1.0f, Color.White);
                            CurrentXPosition += QuantityColumnWidth + SpaceWidth;
                            DrawHelpers.DrawStringWithShadow(b, Game1.tinyFont, "=", CurrentXPosition, CurrentYPosition - LineHeight / 6, Color.White, Color.Black, ShadowOffset, ShadowOffset);
                            CurrentXPosition += EqualsCharacterWidth + SpaceWidth;
                            Utility.drawTinyDigits(MultipliedValues[i], b, new Vector2(CurrentXPosition + MultipliedValueColumnWidth - DrawHelpers.MeasureNumber(MultipliedValues[i], DigitScale), CurrentYPosition), DigitScale, 1.0f, Color.White);

                            CurrentYPosition += LineHeight;
                        }

                        //  Draw separator
                        CurrentYPosition += SeparatorMargin;
                        DrawHelpers.DrawHorizontalSeparator(b, ToolTipLocation.X + Margin, CurrentYPosition, TotalWidth - Margin * 2, HorizontalSeparatorHeight);
                        CurrentYPosition += HorizontalSeparatorHeight + SeparatorMargin;

                        //  Draw total value
                        int       SummedValue         = MultipliedValues.Sum();
                        float     SummedValueWidth    = DrawHelpers.MeasureNumber(SummedValue, DigitScale) + GoldIconSourceRect.Width * 2f + 8;
                        Vector2   SummedValuePosition = new Vector2(ToolTipLocation.X + ((ToolTipLocation.Width - SummedValueWidth) / 2), CurrentYPosition + 6);
                        Rectangle IconDestination     = new Rectangle((int)SummedValuePosition.X, (int)(SummedValuePosition.Y + (DrawHelpers.TinyDigitBaseHeight * DigitScale - GoldIconSourceRect.Height * 2) / 2), GoldIconSourceRect.Width * 2, GoldIconSourceRect.Height * 2);
                        b.Draw(GoldIconTexture, IconDestination, GoldIconSourceRect, Color.White);
                        Utility.drawTinyDigits(SummedValue, b, new Vector2(SummedValuePosition.X + GoldIconSourceRect.Width * 2f + 8, SummedValuePosition.Y), DigitScale, 1.0f, GetValueColor(SummedValue));
                    }
                    else
                    {
                        Object    HoveredItem = Placeholders[ItemId.Value][ConvertColumnTypeToObjectQuality(Column.Value)];
                        Rectangle Location;
                        if (IsNavigatingWithGamepad)
                        {
                            Location = HoveredSlot.Value; //new Rectangle(HoveredSlot.Value.Right, HoveredSlot.Value.Bottom, 1, 1);
                        }
                        else
                        {
                            Location = new Rectangle(Game1.getMouseX() - 8, Game1.getMouseY() + 36, 8 + 36, 1);
                        }
                        DrawHelpers.DrawToolTipInfo(b, Location, HoveredItem, true, true, true, true, true, true, Bag.MaxStackSize);
                    }
                }
            }
        }
コード例 #3
0
        public void Draw(SpriteBatch b)
        {
            if (IsEmptyMenu)
            {
                return;
            }

            //b.Draw(TextureHelpers.GetSolidColorTexture(Game1.graphics.GraphicsDevice, Color.Orange), Bounds, Color.White);

            //  Draw column headers
            for (int i = 0; i < ColumnHeaderBounds.Count; i++)
            {
                Rectangle Destination = ColumnHeaderBounds[i];

                b.Draw(Game1.menuTexture, Destination, new Rectangle(64, 896, 64, 64), Color.White);

                Rectangle IconDestination = new Rectangle(Destination.X + Destination.Width / 4, Destination.Y + Destination.Height / 4, Destination.Width / 2, Destination.Height / 2);

                ColumnType Type = (ColumnType)(i % ColumnsPerGroup);

                if (Type == ColumnType.RowValue)
                {
                    //Could also use Game1.mouseCursors with SourceSprite = new Rectangle(280, 411, 16, 16);
                    b.Draw(GoldIconTexture, IconDestination, GoldIconSourceRect, Color.White);
                }
                else
                {
                    Rectangle SourceRect = ItemBag.QualityIconTexturePositions[ConvertColumnTypeToObjectQuality(Type)];
                    b.Draw(Game1.mouseCursors, IconDestination, SourceRect, Color.White);
                }
            }

            //  Draw cells
            foreach (var KVP in SlotBounds)
            {
                int ItemId = KVP.Key;

                foreach (var KVP2 in KVP.Value)
                {
                    ColumnType ColumnType  = KVP2.Key;
                    Rectangle  Destination = KVP2.Value;
                    b.Draw(Game1.menuTexture, Destination, new Rectangle(128, 128, 64, 64), Color.White);

                    //  Draw a thin yellow border if mouse is hovering this slot
                    bool IsHovered = Destination == HoveredSlot;
                    if (IsHovered)
                    {
                        Color     HighlightColor = Color.Yellow;
                        Texture2D Highlight      = TextureHelpers.GetSolidColorTexture(Game1.graphics.GraphicsDevice, HighlightColor);
                        b.Draw(Highlight, Destination, Color.White * 0.25f);

                        int BorderThickness = Destination.Width / 16;
                        DrawHelpers.DrawBorder(b, Destination, BorderThickness, HighlightColor);
                    }

                    if (ColumnType != ColumnType.RowValue)
                    {
                        ObjectQuality Quality     = ConvertColumnTypeToObjectQuality(ColumnType);
                        Object        CurrentItem = Placeholders[ItemId][Quality];

                        float IconScale = IsHovered ? 1.25f : 1.0f;
                        Color Overlay   = CurrentItem.Stack == 0 ? Color.White * 0.30f : Color.White;
                        DrawHelpers.DrawItem(b, Destination, CurrentItem, CurrentItem.Stack > 0, true, IconScale, 1.0f, Overlay, CurrentItem.Stack >= Bag.MaxStackSize ? Color.Red : Color.White);

                        OnItemSlotRendered?.Invoke(this, new ItemSlotRenderedEventArgs(b, Destination, CurrentItem, IsHovered));
                    }
                    else
                    {
                        //  Sum up the value of all different qualities of this item
                        int SummedValue = Placeholders[ItemId].Values.Sum(x => x.Stack * ItemBag.GetSingleItemPrice(x));
                        int NumDigits   = DrawHelpers.GetNumDigits(SummedValue);

                        //  Compute width/height of the number
                        float ValueScale;
                        int   ValueWidth, ValueHeight, CurrentIteration = 0;
                        do
                        {
                            ValueScale  = (2.7f - CurrentIteration * 0.1f) * Destination.Width / (float)BagInventoryMenu.DefaultInventoryIconSize;
                            ValueWidth  = (int)DrawHelpers.MeasureNumber(SummedValue, ValueScale);
                            ValueHeight = (int)(DrawHelpers.TinyDigitBaseHeight * ValueScale);
                            CurrentIteration++;
                        } while (ValueWidth > Destination.Width * 1.04); // * 1.04 to let the value extend very slightly outside the bounds of the slot

                        //  Draw the number in the center of the slot
                        Vector2 TopLeftPosition = new Vector2(Destination.X + (Destination.Width - ValueWidth) / 2 + 1, Destination.Y + (Destination.Height - ValueHeight) / 2);
                        Color   ValueColor      = GetValueColor(SummedValue);
                        Utility.drawTinyDigits(SummedValue, b, TopLeftPosition, ValueScale, 0f, ValueColor);
                    }
                }
            }
        }