//////////////// private bool ModifyDrawLayersForGun(List <PlayerLayer> layers, bool aimGun) { PlayerLayer plrLayer; Action <PlayerDrawInfo> armLayer, itemLayer, handLayer; int newBodyFrameY; if (aimGun) { newBodyFrameY = PlayerLogic.GetBodyFrameForItemAimAsIfForHeldGun(this.player); } else { newBodyFrameY = this.player.bodyFrame.Height * 3; } // if (!PlayerDraw.GetPlayerLayersForItemHolding(this.player, newBodyFrameY, out armLayer, out itemLayer, out handLayer)) { return(false); } // int armLayerIdx = layers.FindIndex(lyr => lyr == PlayerLayer.Arms); if (armLayerIdx != -1) { plrLayer = new PlayerLayer("TheMadRanger", "Item Holding Arm", armLayer); layers.Insert(armLayerIdx + 1, plrLayer); } int itemLayerIdx = layers.FindIndex(lyr => lyr == PlayerLayer.HeldItem); if (itemLayerIdx != -1) { plrLayer = new PlayerLayer("TheMadRanger", "Held Item", itemLayer); layers.Insert(itemLayerIdx + 1, plrLayer); } int handLayerIdx = layers.FindIndex(lyr => lyr == PlayerLayer.HandOnAcc); if (handLayerIdx != -1) { plrLayer = new PlayerLayer("TheMadRanger", "Item Holding Hand", handLayer); layers.Insert(handLayerIdx + 1, plrLayer); } PlayerLayer.HeldItem.visible = false; PlayerLayer.Arms.visible = false; PlayerLayer.HandOnAcc.visible = false; PlayerLayer.HandOffAcc.visible = false; this.player.handon = 0; this.player.handoff = 0; return(true); }
public static bool GetPlayerLayersForItemHolding( Player plr, int newBodyFrameY, out Action <PlayerDrawInfo> armLayer, out Action <PlayerDrawInfo> itemLayer, out Action <PlayerDrawInfo> handLayer) { armLayer = itemLayer = handLayer = null; if (plr.frozen || plr.dead) { return(false); } if (plr.HeldItem.IsAir) { return(false); } int lightTileX = (int)((plr.position.X + ((float)plr.width * 0.5f)) / 16f); int lightTileY = (int)((plr.position.Y + ((float)plr.height * 0.5f)) / 16f); Color plrLight = Lighting.GetColor(lightTileX, lightTileY); ItemSlot.GetItemLight(ref plrLight, plr.HeldItem, false); Rectangle newFrame, oldFrame; newFrame = oldFrame = plr.bodyFrame; newFrame.Y = newBodyFrameY; armLayer = (plrDrawInfo) => { foreach (DrawData drawData in PlayerDraw.GetPlayerLayerForArms(plrDrawInfo, newFrame)) { Main.playerDrawData.Add(drawData); } }; itemLayer = (plrDrawInfo) => { foreach (DrawData drawData in PlayerDraw.GetPlayerLayerForHeldItem(plrDrawInfo, plrLight)) { Main.playerDrawData.Add(drawData); } }; handLayer = (plrDrawInfo) => { foreach (DrawData drawData in PlayerDraw.GetPlayerLayerForHand(plrDrawInfo, plrLight, newFrame)) { Main.playerDrawData.Add(drawData); } }; return(true); }
//////////////// public static IEnumerable <DrawData> GetPlayerLayerForHeldItem( PlayerDrawInfo plrDrawInfo, Color plrLight, float shadow = 0f) { DrawData drawData; Player plr = plrDrawInfo.drawPlayer; Color itemLight = PlayerDraw.GetItemLightColor(plr, plrLight); Vector2 itemScrPos; ReflectionLibraries.RunMethod( Main.instance, "DrawPlayerItemPos", new object[] { plr.gravDir, plr.HeldItem.type }, out itemScrPos ); Texture2D itemTex = Main.itemTexture[plr.HeldItem.type]; var itemTexOffset = new Vector2(itemTex.Width / 2, itemScrPos.Y); Vector2 itemWldPos = plr.itemLocation.Floor(); //plr.position + (plr.itemLocation - plr.position); Vector2 origin = new Vector2( (float)(-itemScrPos.X), (float)(itemTex.Height / 2) ); if (plr.direction == -1) { origin.X = (float)(itemTex.Width + itemScrPos.X); } // Vector2 pos = (itemWldPos - Main.screenPosition) + itemTexOffset; pos.Y += plrDrawInfo.drawPlayer.gfxOffY; pos.Y *= plr.gravDir; DrawData getDrawData(Texture2D tex, Color color) { return(new DrawData( texture: tex, position: pos, sourceRect: new Rectangle(0, 0, itemTex.Width, itemTex.Height), color: color, rotation: plr.itemRotation, origin: origin, scale: plr.HeldItem.scale, effect: plrDrawInfo.spriteEffects, inactiveLayerDepth: 0 )); } // drawData = getDrawData(itemTex, plr.HeldItem.GetAlpha(itemLight)); //drawInfo.Draw( Main.spriteBatch ); yield return(drawData); if (plr.HeldItem.color != default(Color)) { drawData = getDrawData(itemTex, plr.HeldItem.GetColor(itemLight)); //drawInfo.Draw( Main.spriteBatch ); yield return(drawData); } if (plr.HeldItem.glowMask != -1) { drawData = getDrawData( Main.glowMaskTexture[(int)plr.HeldItem.glowMask], new Color(250, 250, 250, plr.HeldItem.alpha) ); //drawInfo.Draw( Main.spriteBatch ); yield return(drawData); } }