public static void NetUpdateWeaponVisual(Mod mod, PlayerWOFX pfx) { if (Main.netMode == 1 && pfx.player.whoAmI == Main.myPlayer) { ModPacket message = mod.GetPacket(); message.Write(3); message.Write(Main.myPlayer); message.Write(pfx.WeaponVisual); message.Send(); } }
public override void PostUpdateInput() { if (Main.gameMenu || ControlToggleVisual == null || ModConf.ForceShowWeaponOut) { return; } if (ControlToggleVisual.JustPressed) { PlayerWOFX pfx = Main.LocalPlayer.GetModPlayer <PlayerWOFX>(this); ToggleWeaponVisual(pfx, !pfx.weaponVisual); } }
private void DrawInterfaceWeaponOutToggleEye(SpriteBatch spriteBatch) { //if (Disabled) return; // Janky quick inventory visibilty if (!Main.playerInventory || !ModConf.showWeaponOut || ModConf.forceShowWeaponOut) { return; } //Get vars PlayerWOFX pfx = Main.LocalPlayer.GetModPlayer <PlayerWOFX>(this); Texture2D eye = Main.inventoryTickOnTexture; string hoverText = GetTranslationTextValue("WOVisualShow"); // Visible Vector2 position = new Vector2(20, 10); // Show hidden instead if (!pfx.weaponVisual) { eye = Main.inventoryTickOffTexture; hoverText = GetTranslationTextValue("WOVisualHide"); // Hidden } // Get rectangle for eye Rectangle eyeRect = new Rectangle( (int)position.X, (int)position.Y - (eye.Height / 2), eye.Width, eye.Height); if (eyeRect.Contains(Main.mouseX, Main.mouseY)) { // Prevent item use and show text Main.hoverItemName = hoverText; Main.blockMouse = true; // On click if (Main.mouseLeft && Main.mouseLeftRelease) { ToggleWeaponVisual(pfx, !pfx.weaponVisual); } } // Draw this! spriteBatch.Draw( eye, new Vector2(20, 4), null, Color.White ); }
private void HandlePacketWeaponVisual(BinaryReader reader, int code, int sender) { bool weaponVis = reader.ReadBoolean(); if (Main.netMode == 2) { ModPacket me = GetPacket(); me.Write(code); me.Write(sender); me.Write(weaponVis); me.Send(-1, sender); } else { PlayerWOFX pfx = Main.player[sender].GetModPlayer <PlayerWOFX>(this); pfx.weaponVisual = weaponVis; } }
private void ToggleWeaponVisual(PlayerWOFX pfx, bool state) { Main.PlaySound(SoundID.MenuTick); pfx.weaponVisual = state; NetUpdateWeaponVisual(this, pfx); }
/// <summary> /// We gonna handle all the weapon identification and calls here /// </summary> /// <param name="drawInfo"></param> /// <param name="drawOnBack"></param> private static void drawPlayerItem(PlayerDrawInfo drawInfo, bool drawOnBack) { //don't draw when not ingame if (Main.gameMenu || !ModConf.showWeaponOut) { return; } //get player player Player drawPlayer = drawInfo.drawPlayer; //hide if dead, stoned etc. if (!drawPlayer.active || drawPlayer.dead || drawPlayer.stoned) { return; } try { if (//do nothing if player is doing something drawPlayer.itemAnimation > 0 || //also hide if visual is disabled (!ModConf.forceShowWeaponOut && !drawPlayer.GetModPlayer <PlayerWOFX>().weaponVisual)) { return; } } catch { } //player player's held item Item heldItem = drawPlayer.inventory[drawPlayer.selectedItem]; if (heldItem == null || heldItem.type == 0 || heldItem.holdStyle != 0) { return; //no item so nothing to show } //ignore projectile melee weapons bool isYoyo = false; // items work when checked at least once in singleplayer first...? if (DEBUG_BOOMERANGS) { Main.NewText("Shoot is " + heldItem.shoot + " (!=0)"); } if (heldItem.shoot != 0) { if (DEBUG_BOOMERANGS) { Main.NewText("heldItem.melee = " + heldItem.melee); } if (DEBUG_BOOMERANGS) { Main.NewText("heldItem.noMelee = " + heldItem.noMelee); } if (heldItem.melee && heldItem.noMelee) { for (int i = 0; i < Main.projectile.Length; i++) { if (!Main.projectile[i].active) { continue; } if (Main.projectile[i].owner == drawPlayer.whoAmI && Main.projectile[i].melee) { return; } } } // YOYO is aiStyle 99 Projectile p = new Projectile(); p.SetDefaults(heldItem.shoot); if (p.aiStyle == 99) { isYoyo = true; } } //item texture Texture2D weaponTex = weaponTex = Main.itemTexture[heldItem.type]; if (weaponTex == null) { return; //no texture to item so ignore too } int gWidth = weaponTex.Width; int gHeight = weaponTex.Height; //does the item have an animation? No vanilla weapons do Rectangle?sourceRect = null; if (heldItem.modItem != null) { if (Main.itemAnimations[heldItem.type] != null) // in the case of modded weapons with animations... { //get local player frame counting PlayerWOFX p = drawPlayer.GetModPlayer <PlayerWOFX>(); int frameCount = Main.itemAnimations[heldItem.type].FrameCount; int frameCounter = Main.itemAnimations[heldItem.type].TicksPerFrame * 2; //add them up if (Main.time % frameCounter == 0) { p.weaponFrame++; if (p.weaponFrame >= frameCount) { p.weaponFrame = 0; } } //set frame on source gHeight /= frameCount; sourceRect = new Rectangle(0, gHeight * p.weaponFrame, gWidth, gHeight); } } //get draw location of player int drawX = (int)(drawPlayer.MountedCenter.X - Main.screenPosition.X); int drawY = (int)(drawPlayer.MountedCenter.Y - Main.screenPosition.Y + drawPlayer.gfxOffY) - 3; //get the lighting on the player's tile Color lighting = Lighting.GetColor( (int)((drawInfo.position.X + drawPlayer.width / 2f) / 16f), (int)((drawInfo.position.Y + drawPlayer.height / 2f) / 16f)); //get item alpha (like starfury) then player stealth and alpha (inviciblity etc.) lighting = drawPlayer.GetImmuneAlpha(heldItem.GetAlpha(lighting) * drawPlayer.stealth, 0); float scale = heldItem.scale; if (isYoyo) { scale *= 0.6f; } //standard items SpriteEffects spriteEffects = SpriteEffects.None; if (drawPlayer.direction < 0) { spriteEffects = SpriteEffects.FlipHorizontally; } if (drawPlayer.gravDir < 0) { drawY += 6; spriteEffects = SpriteEffects.FlipVertically | spriteEffects; } DrawData data = new DrawData( weaponTex, new Vector2(drawX, drawY), sourceRect, lighting, 0f, new Vector2(gWidth / 2f, gHeight / 2f), scale, spriteEffects, 0); // Item customiser integration // https://github.com/gamrguy/ItemCustomizer if (itemCustomizer != null) { data.shader = ItemCustomizerGetShader(itemCustomizer, heldItem); } //work out what type of weapon it is! #region Weapon Algorithm float itemWidth = gWidth * heldItem.scale; float itemHeight = gHeight * heldItem.scale; //not all items have width/height set the same, so use largest as "length" including weapon sizemod float larger = Math.Max(itemWidth, itemHeight); float lesser = Math.Min(itemWidth, itemHeight); PickItemDrawType(drawOnBack, drawPlayer, heldItem, isYoyo, gWidth, gHeight, ref data, itemWidth, itemHeight, larger, lesser); #endregion if (DEBUG_WEAPONHOLD && drawPlayer.controlHook) { Main.NewText(heldItem.useStyle + "[]: " + itemWidth + " x " + itemHeight, 100, 200, 150); } }
private void DrawInterfaceWeaponOutToggleEye(SpriteBatch spriteBatch) { //if (Disabled) return; // Janky quick inventory visibilty if (!Main.playerInventory || !ModConf.showWeaponOut || ModConf.forceShowWeaponOut) { return; } //Get vars PlayerWOFX pfx = Main.LocalPlayer.GetModPlayer <PlayerWOFX>(this); Texture2D eye = Main.inventoryTickOnTexture; string hoverText = GetTranslationTextValue("WOVisualShow"); // Visible Vector2 position = new Vector2(20, 10); // Display custom styling int style; if (ModConfWeaponOutCustom.TryGetCustomHoldStyle(Main.LocalPlayer.HeldItem.type, out style)) { switch (style) { case 1: hoverText += ": " + GetTranslationTextValue("WOVisualTypeHand"); break; case 2: hoverText += ": " + GetTranslationTextValue("WOVisualTypeWaist"); break; case 3: hoverText += ": " + GetTranslationTextValue("WOVisualTypeBack"); break; case 4: hoverText += ": " + GetTranslationTextValue("WOVisualTypeSpear"); break; case 5: hoverText += ": " + GetTranslationTextValue("WOVisualTypePowerTool"); break; case 6: hoverText += ": " + GetTranslationTextValue("WOVisualTypeBow"); break; case 7: hoverText += ": " + GetTranslationTextValue("WOVisualTypeSmallGun"); break; case 8: hoverText += ": " + GetTranslationTextValue("WOVisualTypeLargeGun"); break; case 9: hoverText += ": " + GetTranslationTextValue("WOVisualTypeStaff"); break; } } // Show hidden instead if (!pfx.weaponVisual) { eye = Main.inventoryTickOffTexture; hoverText = GetTranslationTextValue("WOVisualHide"); // Hidden } // Get rectangle for eye Rectangle eyeRect = new Rectangle( (int)position.X, (int)position.Y - (eye.Height / 2), eye.Width, eye.Height); if (eyeRect.Contains(Main.mouseX, Main.mouseY)) { // Prevent item use and show text Main.hoverItemName = hoverText; Main.blockMouse = true; // On plain click if (!Main.mouseRight && Main.mouseLeft && Main.mouseLeftRelease) { ToggleWeaponVisual(pfx, !pfx.weaponVisual); } if (pfx.weaponVisual) { // On alt click if (Main.mouseRight && Main.mouseRightRelease) { ModConfWeaponOutCustom.UpdateCustomHoldIncrement(Main.LocalPlayer.HeldItem, 1); } // On click during alt if (Main.mouseRight && Main.mouseLeft && Main.mouseLeftRelease) { ModConfWeaponOutCustom.UpdateCustomHoldIncrement(Main.LocalPlayer.HeldItem, -1); } } } // Draw this! spriteBatch.Draw( eye, new Vector2(20, 4), null, Color.White ); }