Exemplo n.º 1
0
        public override void RenderInteractiveElements(float deltaTime)
        {
            (inventory as InventoryBase).InvNetworkUtil.AcceptServerUpdates = !isLeftMouseDownStartedInsideElem;

            // Slot sizes
            double absSlotWidth     = scaled(GuiElementPassiveItemSlot.unscaledSlotSize);
            double absItemstackSize = scaled(GuiElementPassiveItemSlot.unscaledItemSize);

            double offset = absSlotWidth / 2;

            int i = 0;

            foreach (var val in renderedSlots)
            {
                ElementBounds bounds = slotBounds[i];

                // Don't need to render stuff completely outside, saves us many render calls (~down to 100 draw calls instead of 600 for creative inventory)
                if (bounds.PartiallyInside(Bounds.ParentBounds))
                {
                    ItemSlot slot   = val.Value;
                    int      slotId = val.Key;

                    if (((slot.Itemstack == null || AlwaysRenderIcon) && slot.BackgroundIcon != null) || slot.HexBackgroundColor != null)
                    {
                        string key = slot.BackgroundIcon + "-" + slot.HexBackgroundColor;
                        api.Render.Render2DTexturePremultipliedAlpha(slotTextureIdsByBgIconAndColor[key], bounds);
                    }
                    else
                    {
                        api.Render.Render2DTexturePremultipliedAlpha(slotTexture.TextureId, bounds);
                    }


                    if (highlightSlotId == slotId || hoverSlotId == slotId || leftMouseDownDistributeSlotsBySlotid.ContainsKey(slotId))
                    {
                        api.Render.Render2DTexturePremultipliedAlpha(
                            highlightSlotTexture.TextureId, (int)(bounds.renderX - 2), (int)(bounds.renderY - 2), bounds.OuterWidthInt + 4, bounds.OuterHeightInt + 4
                            );
                    }

                    if (slot.Itemstack == null)
                    {
                        i++; continue;
                    }


                    float dx = 0;
                    float dy = 0;
                    if (slotNotifiedZoomEffect.ContainsKey(slotId))
                    {
                        dx = 4 * (float)api.World.Rand.NextDouble() - 2f;
                        dy = 4 * (float)api.World.Rand.NextDouble() - 2f;
                    }

                    api.Render.PushScissor(scissorBounds[i], true);

                    api.Render.RenderItemstackToGui(
                        slot,
                        slotBounds[i].renderX + offset + dy,
                        slotBounds[i].renderY + offset + dx,
                        90,
                        (float)(absItemstackSize),
                        ColorUtil.WhiteArgb
                        );

                    api.Render.PopScissor();

                    if (slot.DrawUnavailable)
                    {
                        api.Render.Render2DTexturePremultipliedAlpha(crossedOutTexture.TextureId, (int)(bounds.renderX), (int)(bounds.renderY), crossedOutTexture.Width, crossedOutTexture.Height, 250);
                    }

                    if (slotQuantityTextures[i].TextureId != 0)
                    {
                        api.Render.Render2DTexturePremultipliedAlpha(slotQuantityTextures[i].TextureId, slotBounds[i]);
                    }
                }

                i++;
            }
        }
        public override void RenderInteractiveElements(float deltaTime)
        {
            double absSlotWidth     = scaled(GuiElementPassiveItemSlot.unscaledSlotSize);
            double absItemstackSize = scaled(GuiElementPassiveItemSlot.unscaledItemSize);

            double offset = absSlotWidth / 2;

            //double visibleStartY = InsideClipBounds?.absFixedY ?? 0;
            //double visibleEndY = visibleStartY + (InsideClipBounds?.OuterHeight ?? 0);

            int i = 0;

            foreach (var val in renderedSlots)
            {
                ElementBounds bounds = slotBounds[i];

                double slotStartY = bounds.absFixedY;
                double slotEndY   = slotStartY + bounds.OuterHeight;

                // The partially inside test is actually very expensive when done 5000+ times a frame, so we do a much quicker pretest here
                //if (InsideClipBounds != null && (slotEndY < visibleStartY || slotStartY > visibleEndY)) { i++; continue; }

                // Don't need to render stuff completely outside, saves us many render calls (~down to 100 draw calls instead of 600 for creative inventory)
                if (bounds.PartiallyInside(Bounds.ParentBounds))
                {
                    ItemSlot slot   = val.Value;
                    int      slotId = val.Key;

                    if (((slot.Itemstack == null || AlwaysRenderIcon) && slot.BackgroundIcon != null) || slot.HexBackgroundColor != null)
                    {
                        string key = slot.BackgroundIcon + "-" + slot.HexBackgroundColor;
                        api.Render.Render2DTexturePremultipliedAlpha(slotTextureIdsByBgIconAndColor[key], bounds);
                    }
                    else
                    {
                        api.Render.Render2DTexturePremultipliedAlpha(slotTexture.TextureId, bounds);
                    }


                    if (highlightSlotId == slotId || hoverSlotId == slotId || distributeStacksPrevStackSizeBySlotId.ContainsKey(slotId))
                    {
                        api.Render.Render2DTexturePremultipliedAlpha(
                            highlightSlotTexture.TextureId, (int)(bounds.renderX - 2), (int)(bounds.renderY - 2), bounds.OuterWidthInt + 4, bounds.OuterHeightInt + 4
                            );
                    }

                    if (slot.Itemstack == null)
                    {
                        i++; continue;
                    }


                    float dx = 0;
                    float dy = 0;
                    if (slotNotifiedZoomEffect.ContainsKey(slotId))
                    {
                        dx = 4 * (float)api.World.Rand.NextDouble() - 2f;
                        dy = 4 * (float)api.World.Rand.NextDouble() - 2f;
                    }

                    api.Render.PushScissor(scissorBounds[i], true);

                    api.Render.RenderItemstackToGui(
                        slot,
                        slotBounds[i].renderX + offset + dy,
                        slotBounds[i].renderY + offset + dx,
                        90,
                        (float)(absItemstackSize),
                        ColorUtil.WhiteArgb
                        );

                    api.Render.PopScissor();

                    if (slot.DrawUnavailable)
                    {
                        api.Render.Render2DTexturePremultipliedAlpha(crossedOutTexture.TextureId, (int)(bounds.renderX), (int)(bounds.renderY), crossedOutTexture.Width, crossedOutTexture.Height, 250);
                    }

                    if (slotQuantityTextures[i].TextureId != 0)
                    {
                        api.Render.Render2DTexturePremultipliedAlpha(slotQuantityTextures[i].TextureId, slotBounds[i]);
                    }
                }

                i++;
            }
        }