Exemplo n.º 1
0
        private void DrawOutputOverLay(SpriteBatch spriteBatch, GUICustomComponent overlayComponent)
        {
            overlayComponent.RectTransform.SetAsLastChild();

            FabricationRecipe targetItem = fabricatedItem ?? selectedItem;

            if (targetItem != null)
            {
                var itemIcon = targetItem.TargetItem.InventoryIcon ?? targetItem.TargetItem.sprite;

                Rectangle slotRect = outputContainer.Inventory.slots[0].Rect;

                if (fabricatedItem != null)
                {
                    GUI.DrawRectangle(spriteBatch,
                                      new Rectangle(
                                          slotRect.X, slotRect.Y + (int)(slotRect.Height * (1.0f - progressState)),
                                          slotRect.Width, (int)(slotRect.Height * progressState)),
                                      Color.Green * 0.5f, isFilled: true);
                }

                itemIcon.Draw(
                    spriteBatch,
                    slotRect.Center.ToVector2(),
                    color: targetItem.TargetItem.InventoryIconColor * 0.4f,
                    scale: Math.Min(slotRect.Width / itemIcon.size.X, slotRect.Height / itemIcon.size.Y) * 0.9f);
            }

            if (tooltip != null)
            {
                GUIComponent.DrawToolTip(spriteBatch, tooltip.Second, tooltip.First);
                tooltip = null;
            }
        }
Exemplo n.º 2
0
        public override void DrawHUD(SpriteBatch spriteBatch, Character character)
        {
            if (HudTint.A > 0)
            {
                GUI.DrawRectangle(spriteBatch, new Rectangle(0, 0, GameMain.GraphicsWidth, GameMain.GraphicsHeight),
                                  new Color(HudTint.R, HudTint.G, HudTint.B) * (HudTint.A / 255.0f), true);
            }

            GetAvailablePower(out float batteryCharge, out float batteryCapacity);

            List <Item> availableAmmo = new List <Item>();

            foreach (MapEntity e in item.linkedTo)
            {
                if (!(e is Item linkedItem))
                {
                    continue;
                }
                var itemContainer = linkedItem.GetComponent <ItemContainer>();
                if (itemContainer == null)
                {
                    continue;
                }
                availableAmmo.AddRange(itemContainer.Inventory.AllItems);
                for (int i = 0; i < itemContainer.Inventory.Capacity - itemContainer.Inventory.AllItems.Count(); i++)
                {
                    availableAmmo.Add(null);
                }
            }

            float chargeRate =
                powerConsumption <= 0.0f ?
                1.0f :
                batteryCapacity > 0.0f ? batteryCharge / batteryCapacity : 0.0f;
            bool charged     = batteryCharge * 3600.0f > powerConsumption;
            bool readyToFire = reload <= 0.0f && charged && availableAmmo.Any(p => p != null);

            if (ShowChargeIndicator && PowerConsumption > 0.0f)
            {
                powerIndicator.Color = charged ? GUI.Style.Green : GUI.Style.Red;
                if (flashLowPower)
                {
                    powerIndicator.BarSize = 1;
                    powerIndicator.Color  *= (float)Math.Sin(flashTimer * 12);
                    powerIndicator.RectTransform.ChangeScale(Vector2.Lerp(Vector2.One, Vector2.One * 1.01f, 2 * (float)Math.Sin(flashTimer * 15)));
                }
                else
                {
                    powerIndicator.BarSize = chargeRate;
                }
                powerIndicator.DrawManually(spriteBatch, true);

                Rectangle sliderRect = powerIndicator.GetSliderRect(1.0f);
                int       requiredChargeIndicatorPos = (int)(powerConsumption / (batteryCapacity * 3600.0f) * sliderRect.Width);
                GUI.DrawRectangle(spriteBatch,
                                  new Rectangle(sliderRect.X + requiredChargeIndicatorPos, sliderRect.Y, 2, sliderRect.Height),
                                  Color.White * 0.5f, true);
            }

            if (ShowProjectileIndicator)
            {
                Point slotSize    = (Inventory.SlotSpriteSmall.size * Inventory.UIScale).ToPoint();
                Point spacing     = new Point(GUI.IntScale(5), GUI.IntScale(20));
                int   slotsPerRow = Math.Min(availableAmmo.Count, 6);
                int   totalWidth  = slotSize.X * slotsPerRow + spacing.X * (slotsPerRow - 1);
                int   rows        = (int)Math.Ceiling(availableAmmo.Count / (float)slotsPerRow);
                Point invSlotPos  = new Point(GameMain.GraphicsWidth / 2 - totalWidth / 2, powerIndicator.Rect.Y - (slotSize.Y + spacing.Y) * rows);
                for (int i = 0; i < availableAmmo.Count; i++)
                {
                    // TODO: Optimize? Creates multiple new objects per frame?
                    Inventory.DrawSlot(spriteBatch, null,
                                       new VisualSlot(new Rectangle(invSlotPos + new Point((i % slotsPerRow) * (slotSize.X + spacing.X), (int)Math.Floor(i / (float)slotsPerRow) * (slotSize.Y + spacing.Y)), slotSize)),
                                       availableAmmo[i], -1, true);
                }
                Rectangle rect    = new Rectangle(invSlotPos.X, invSlotPos.Y, totalWidth, slotSize.Y);
                float     inflate = MathHelper.Lerp(3, 8, (float)Math.Abs(Math.Sin(flashTimer * 5)));
                rect.Inflate(inflate, inflate);
                Color color = GUI.Style.Red * Math.Max(0.5f, (float)Math.Sin(flashTimer * 12));
                if (flashNoAmmo)
                {
                    GUI.DrawRectangle(spriteBatch, rect, color, thickness: 3);
                }
                else if (flashLoaderBroken)
                {
                    GUI.DrawRectangle(spriteBatch, rect, color, thickness: 3);
                    GUI.BrokenIcon.Draw(spriteBatch, rect.Center.ToVector2(), color, scale: rect.Height / GUI.BrokenIcon.size.Y);
                    GUIComponent.DrawToolTip(spriteBatch, TextManager.Get("turretloaderbroken"), new Rectangle(invSlotPos.X + totalWidth + GUI.IntScale(10), invSlotPos.Y + slotSize.Y / 2 - GUI.IntScale(9), 0, 0));
                }
            }

            float zoom = cam == null ? 1.0f : (float)Math.Sqrt(cam.Zoom);

            GUI.HideCursor = (crosshairSprite != null || crosshairPointerSprite != null) && GUI.MouseOn == null && !GameMain.Instance.Paused;
            if (GUI.HideCursor)
            {
                crosshairSprite?.Draw(spriteBatch, crosshairPos, readyToFire ? Color.White : Color.White * 0.2f, 0, zoom);
                crosshairPointerSprite?.Draw(spriteBatch, crosshairPointerPos, 0, zoom);
            }
        }