Example #1
0
        ////////////////

        public float ApplyBrushAt(int worldX, int worldY)
        {
            var   mymod   = (BetterPaintMod)this.mod;
            var   myworld = ModContent.GetInstance <BetterPaintWorld>();
            float uses    = 0;
            Color color   = Color.White;
            byte  glow    = 0;

            Item paintItem = this.GetCurrentPaintItem();

            if (paintItem != null)                      // Eraser doesn't need paint
            {
                color = PaintBlasterHelpers.GetPaintColor(paintItem);
                glow  = PaintBlasterHelpers.GetPaintGlow(paintItem);
            }

            uses = myworld.Layers.ApplyColorAt(mymod, this.Layer, this.CurrentBrush, color, glow, this.BrushSize, this.PressurePercent, worldX, worldY);

            if (paintItem != null && uses > 0)
            {
                PaintBlasterHelpers.ConsumePaint(paintItem, uses);
            }

            return(uses);
        }
Example #2
0
        public override bool Shoot(Player player, ref Vector2 pos, ref float velX, ref float velY, ref int type, ref int dmg,
                                   ref float kb)
        {
            Vector2 worldMousePos = new Vector2(Main.mouseX, Main.mouseY) + Main.screenPosition;
            int     worldX        = (int)worldMousePos.X;
            int     worldY        = (int)worldMousePos.Y;
            ushort  tileX         = (ushort)(worldX / 16);
            ushort  tileY         = (ushort)(worldY / 16);
            Color?  dustColor     = null;

            if (this.IsCopying)
            {
                if (!this.AttemptCopyColorAt(player, tileX, tileY))
                {
                    Main.NewText("No color found to copy from.", Color.Yellow);
                }

                this.IsCopying = false;
            }
            else
            {
                Item paintItem = this.GetCurrentPaintItem();

                if (paintItem != null)
                {
                    if (PaintBlasterHelpers.GetPaintAmount(paintItem) <= 0)
                    {
                        if (this.SwitchToNextMatchingNonemptyPaint())
                        {
                            paintItem = this.GetCurrentPaintItem();
                        }
                        else
                        {
                            paintItem = null;
                        }
                    }

                    if (paintItem != null)
                    {
                        Color paintColor = PaintBlasterHelpers.GetPaintColor(paintItem);

                        if (this.HasMatchingPaintAt(paintColor, tileX, tileY))
                        {
                            dustColor = paintColor;
                        }
                    }
                }
            }

            if (this.BufferedPaintUses > 0 && dustColor != null)
            {
                this.BufferedPaintUses = 0f;

                pos = PlayerItemHelpers.TipOfHeldItem(player) - Main.screenPosition;
                Dust.NewDust(pos, 8, 8, 2, velX, velY, 0, (Color)dustColor, 1f);
            }

            return(false);
        }
        ////////////////

        public void DrawHUD(BetterPaintMod mymod, SpriteBatch sb, PaintBlasterItem myblaster)
        {
            int x = mymod.Config.HudPaintAmmoOffsetX >= 0 ?
                    mymod.Config.HudPaintAmmoOffsetX :
                    (Main.screenWidth + mymod.Config.HudPaintAmmoOffsetX);
            int y = mymod.Config.HudPaintAmmoOffsetY >= 0 ?
                    mymod.Config.HudPaintAmmoOffsetY :
                    (Main.screenHeight + mymod.Config.HudPaintAmmoOffsetY);

            sb.Draw(PaintBlasterHUD.AmmoCan, new Vector2(x, y), Color.White);

            Item paintItem = myblaster.GetCurrentPaintItem();

            if (paintItem != null)
            {
                BlasterPaintType paintType  = PaintBlasterHelpers.GetPaintType(paintItem);
                Color            paintColor = PaintBlasterHelpers.GetPaintColor(paintItem);
                float            quantity   = PaintBlasterHelpers.GetPaintAmount(paintItem);
                float            capacity   = paintType == BlasterPaintType.Can ?
                                              (float)paintItem.maxStack :
                                              (float)mymod.Config.PaintCartridgeCapacity;

                float capacityPercent = quantity / capacity;

                int height = (int)(capacityPercent * 50f) * 2;
                int top    = 100 - height;

                Color color = capacityPercent >= 0.01f ? paintColor : paintColor * 0.25f;

                sb.Draw(PaintBlasterHUD.AmmoTop, new Vector2(x, y + 16 + top), color);
                sb.Draw(PaintBlasterHUD.AmmoBot, new Vector2(x, y + 124), color);
                sb.Draw(Main.magicPixel, new Rectangle(x + 4, y + 24 + top, 16, height), color);

                if (Main.mouseX >= x && Main.mouseX < (x + PaintBlasterHUD.AmmoCan.Width))
                {
                    if (Main.mouseY >= y && Main.mouseY < (y + PaintBlasterHUD.AmmoCan.Height))
                    {
                        string percentStr = capacityPercent.ToString("P", CultureInfo.InvariantCulture);

                        Utils.DrawBorderStringFourWay(sb, Main.fontMouseText, percentStr, Main.mouseX - 40, Main.mouseY + 16, Color.White, Color.Black, default(Vector2), 1f);
                    }
                }
            }
            else
            {
                if (Main.mouseX >= x && Main.mouseX < (x + PaintBlasterHUD.AmmoCan.Width))
                {
                    if (Main.mouseY >= y && Main.mouseY < (y + PaintBlasterHUD.AmmoCan.Height))
                    {
                        string str = "Color Cartridge needed";

                        Utils.DrawBorderStringFourWay(sb, Main.fontMouseText, str, Main.mouseX - 160, Main.mouseY + 16, Color.White, Color.Black, default(Vector2), 1f);
                    }
                }
            }
        }
Example #4
0
        ////////////////

        public bool SwitchToNextMatchingNonemptyPaint()
        {
            Item paintItem = this.GetCurrentPaintItem();

            if (paintItem == null)
            {
                return(false);
            }

            Color currColor = PaintBlasterHelpers.GetPaintColor(paintItem);

            Item[] inv      = Main.LocalPlayer.inventory;
            int    cartType = ModContent.ItemType <ColorCartridgeItem>();
            bool   found    = false;

            for (int i = 0; i < inv.Length; i++)
            {
                if (i == this.CurrentPaintItemInventoryIndex)
                {
                    continue;
                }

                Item item = inv[i];
                if (item == null || item.IsAir)
                {
                    continue;
                }

                if (PaintBlasterHelpers.IsPaint(item))
                {
                    if (PaintBlasterHelpers.GetPaintAmount(item) <= 0)
                    {
                        continue;
                    }
                    if (PaintBlasterHelpers.GetPaintColor(item) != currColor)
                    {
                        continue;
                    }

                    this.CurrentPaintItemInventoryIndex = i;
                    found = true;

                    break;
                }
            }

            return(found);
        }
        public static IDictionary <string, PaintDisplayInfo> GetPaintSelection(Player player)
        {
            var         mymod     = BetterPaintMod.Instance;
            IList <int> paintIdxs = new List <int>();

            Item[] inv = player.inventory;

            for (int i = 0; i < inv.Length; i++)
            {
                Item item = inv[i];
                if (item == null || item.IsAir)
                {
                    continue;
                }

                if (PaintBlasterHelpers.IsPaint(item))
                {
                    paintIdxs.Add(i);
                }
            }

            var paintInfo = new Dictionary <string, PaintDisplayInfo>(paintIdxs.Count);

            foreach (int idx in paintIdxs)
            {
                Item item = Main.LocalPlayer.inventory[idx];
                if (PaintBlasterHelpers.GetPaintAmount(item) <= 0)
                {
                    continue;
                }

                string key = PaintBlasterHelpers.GetPaintColor(item).ToString() + "_" + PaintBlasterHelpers.GetPaintType(item);

                if (!paintInfo.ContainsKey(key))
                {
                    paintInfo[key] = new PaintDisplayInfo(idx, item);
                }
                else
                {
                    paintInfo[key].Copies++;
                }
            }

            return(paintInfo);
        }