//////////////// 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); }
public bool CanPaintAt(Item paintItem, ushort tileX, ushort tileY) { var myworld = ModContent.GetInstance <BetterPaintWorld>(); if (this.CurrentBrush != PaintBrushType.Erase && PaintBlasterHelpers.GetPaintAmount(paintItem) <= 0) { return(false); } Tile tile = Main.tile[tileX, tileY]; switch (this.Layer) { case PaintLayerType.Foreground: return(myworld.Layers.Foreground.CanPaintAt(tile)); case PaintLayerType.Background: return(myworld.Layers.Background.CanPaintAt(tile)); case PaintLayerType.Anyground: return(myworld.Layers.Foreground.CanPaintAt(tile) || myworld.Layers.Background.CanPaintAt(tile)); default: throw new ModHelpersException("Not implemented."); } }
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); } } } }
//////////////// public Rectangle DrawColorIcon(SpriteBatch sb, int itemType, Color color, float amountPercent, int stack, int x, int y, double paletteAngle, double angleStep, bool isSelected) { bool hasGlow; Texture2D cartTex = this.GetPaintTexture(itemType); Texture2D overTex = this.GetPaintOverlayTexture(itemType, out hasGlow); bool isHover = this.IsHoveringIcon(paletteAngle, angleStep); var rect = new Rectangle(x - (cartTex.Width / 2), y - (cartTex.Height / 2), cartTex.Width, cartTex.Height); float colorMul = isSelected ? PaintBlasterUI.SelectedScale : (isHover ? PaintBlasterUI.HoveredScale : PaintBlasterUI.IdleScale); sb.Draw(cartTex, rect, Color.White * colorMul); if (overTex != null) { sb.Draw(overTex, rect, (hasGlow ? color : color * colorMul)); } if (isHover) { Color textColor = ColorCartridgeItem.GetCapacityColor(amountPercent); Color labelColor = hasGlow ? Color.GreenYellow * PaintBlasterUI.HoveredScale : Color.White * PaintBlasterUI.HoveredScale; Color bgColor = Color.Black * PaintBlasterUI.HoveredScale; Utils.DrawBorderStringFourWay(sb, Main.fontMouseText, "Capacity:", Main.mouseX, Main.mouseY - 16, labelColor, bgColor, default(Vector2), 1f); Utils.DrawBorderStringFourWay(sb, Main.fontMouseText, (int)(amountPercent * 100) + "%", Main.mouseX + 72, Main.mouseY - 16, labelColor, bgColor, default(Vector2), 1f); string colorStr = PaintBlasterHelpers.ColorString(color); Utils.DrawBorderStringFourWay(sb, Main.fontMouseText, "Color:", Main.mouseX, Main.mouseY + 8, labelColor, bgColor, default(Vector2), 1f); Utils.DrawBorderStringFourWay(sb, Main.fontMouseText, colorStr, Main.mouseX + 56, Main.mouseY + 8, color, bgColor, default(Vector2), 1f); } if (isSelected) { Rectangle selRect = rect; selRect.X -= 3; selRect.Y -= 3; selRect.Width += 6; selRect.Height += 6; HUDHelpers.DrawBorderedRect(sb, Color.Transparent, AnimatedColors.Air.CurrentColor * 0.5f, selRect, 2); } Utils.DrawBorderStringFourWay(sb, Main.fontItemStack, stack + "", (rect.X + cartTex.Width) - 4, (rect.Y + cartTex.Height) - 12, Color.White, Color.Black, default(Vector2), 1f); return(rect); }
//////////////// 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 Item GetCurrentPaintItem() { if (this.CurrentPaintItemInventoryIndex == -1) { return(null); } Item paintItem = Main.LocalPlayer.inventory[this.CurrentPaintItemInventoryIndex]; if (!PaintBlasterHelpers.IsPaint(paintItem)) { this.CurrentPaintItemInventoryIndex = -1; return(null); } return(paintItem); }
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); }
//////////////// public override void Action(CommandCaller caller, string input, string[] args) { var mymod = (BetterPaintMod)this.mod; int paintType = ModContent.ItemType <ColorCartridgeItem>(); int itemIdx = ItemHelpers.CreateItem(Main.LocalPlayer.position, paintType, 1, ColorCartridgeItem.Width, ColorCartridgeItem.Height); Item paintItem = Main.item[itemIdx]; if (paintItem == null || paintItem.IsAir) { throw new ModHelpersException("Could not create cheaty paint."); } Func <byte> rand = () => (byte)Main.rand.Next(0, 255); var randClr = new Color(rand(), rand(), rand()); var myitem = (ColorCartridgeItem)paintItem.modItem; myitem.SetPaint(randClr, mymod.Config.PaintCartridgeCapacity); caller.Reply("Random color cartridge created: " + PaintBlasterHelpers.ColorString(randClr), randClr); }
public override void ModifyTooltips(List <TooltipLine> tooltips) { if (!this.IsInitialized) { return; } var mymod = (BetterPaintMod)this.mod; float percent = this.Quantity / mymod.Config.PaintCartridgeCapacity; var tip1 = new TooltipLine(this.mod, "BetterPaint: Color Indicator", "Color value: " + PaintBlasterHelpers.ColorString(this.MyColor)) { overrideColor = this.MyColor }; var tip2 = new TooltipLine(this.mod, "BetterPaint: Capacity", "Capacity: " + (int)(percent * 100) + "%") { overrideColor = ColorCartridgeItem.GetCapacityColor(percent) }; tooltips.Add(tip1); tooltips.Add(tip2); }