Esempio n. 1
0
        public void Draw(SpriteBatch b)
        {
            if (IsEmptyMenu)
            {
                return;
            }

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

            //  Draw the backgrounds of each slot
            foreach (Rectangle LockedSlot in LockedSlotBounds)
            {
                b.Draw(Game1.menuTexture, LockedSlot, new Rectangle(64, 896, 64, 64), Color.White);
            }
            foreach (Rectangle UnlockedSlot in SlotBounds)
            {
                b.Draw(Game1.menuTexture, UnlockedSlot, new Rectangle(128, 128, 64, 64), Color.White);
            }

            //  Draw the items of each slot
            for (int i = 0; i < SlotBounds.Count; i++)
            {
                Rectangle Destination = SlotBounds[i];

                //  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);
                }

                Object CurrentItem = PlaceholderItems[i];

                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));
            }

            foreach (Rectangle LockedSlot in LockedSlotBounds)
            {
                if (HoveredSlot == LockedSlot)
                {
                    Color     HighlightColor = Color.Yellow;
                    Texture2D Highlight      = TextureHelpers.GetSolidColorTexture(Game1.graphics.GraphicsDevice, HighlightColor);
                    b.Draw(Highlight, LockedSlot, Color.White * 0.25f);

                    int BorderThickness = LockedSlot.Width / 16;
                    DrawHelpers.DrawBorder(b, LockedSlot, BorderThickness, HighlightColor);
                }
            }
        }
Esempio n. 2
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);
                    }
                }
            }
        }