void AddLayer(int bodyID, int hue, bool asMount = false) { int facing = MirrorFacingForDraw(Facing); int animation = 0; float frame = 0; if (Entity is Mobile) { animation = (Entity as Mobile).Animation.ActionIndex; if (asMount) { animation = PatchMountAction(animation); } frame = (Entity as Mobile).Animation.AnimationFrame; } else if (Entity is Corpse) { animation = ActionTranslator.GetActionIndex(Entity, MobileAction.Death); frame = (Entity as Corpse).Frame * BodyConverter.DeathAnimationFrameCount(Body); } int frameCount; AAnimationFrame animframe = getFrame(bodyID, ref hue, facing, animation, frame, out frameCount); m_MobileLayers[m_LayerCount++] = new MobileViewLayer(bodyID, hue, animframe); m_FrameCount = frameCount; }
void MobilePick(MouseOverList mouseOver, Vector3 drawPosition, RectInt area, AAnimationFrame frame) { int x, y; if (DrawFlip) { // when flipped, the upper right pixel = drawPosition.x + DrawArea.x + 44 // the upper left pixel = drawposition.x + drawarea.x + 44 - drawarea.width. // don't forget to reverse the mouse position! x = (int)drawPosition.x + area.x + IsometricRenderer.TILE_SIZE_INTEGER - mouseOver.MousePosition.x; } else { // ul pixel = (drawposition - drawarea.x) x = mouseOver.MousePosition.x - (int)drawPosition.x + area.x; } y = mouseOver.MousePosition.y - ((int)drawPosition.y - area.y); if (frame.IsPointInTexture(x, y)) { mouseOver.AddItem(Entity, drawPosition); } }
AAnimationFrame[] CheckCache(int body, int action, int direction) { // Make sure the cache is complete. if (m_Cache[body] == null) { m_Cache[body] = new AAnimationFrame[COUNT_ACTIONS][][]; // max 35 actions } if (m_Cache[body][action] == null) { m_Cache[body][action] = new AAnimationFrame[COUNT_DIRECTIONS][]; } if (m_Cache[body][action][direction] == null) { m_Cache[body][action][direction] = new AAnimationFrame[1]; } if (m_Cache[body][action][direction][0] != null) { return(m_Cache[body][action][direction]); } else { return(null); } }
public MobileViewLayer(int bodyID, int hue, AAnimationFrame frame) { BodyID = bodyID; Hue = hue; Frame = frame; }
// ============================================================================================================ // draw // ============================================================================================================ public override bool DrawInternal(SpriteBatch3D spriteBatch, Vector3 drawPosition, MouseOverList mouseOver, Map map, bool roofHideFlag) { if (Entity.IsDisposed) { return(false); } // get a z index underneath all this mobile's sprite layers. We will place the shadow on this z index. DrawShadowZDepth = spriteBatch.GetNextUniqueZ(); // get running moving and sitting booleans, which are used when drawing mobiles but not corpses. bool isRunning = false, isMoving = false, isSitting = false; if (Entity is Mobile) { isRunning = (Entity as Mobile).IsRunning; isMoving = (Entity as Mobile).IsMoving; isSitting = (Entity as Mobile).IsSitting; } // flip the facing (anim directions are reversed from the client-server protocol's directions). DrawFlip = (MirrorFacingForDraw(Facing) > 4); InternalSetupLayers(); if (m_MobileLayers[0].Frame == null) { m_MobileLayers[0].Frame = AnimationFrame.NullFrame; } int drawCenterY = m_MobileLayers[0].Frame.Center.Y; int drawX; int drawY; if (DrawFlip) { drawX = -IsometricRenderer.TILE_SIZE_INTEGER_HALF + (int)((Entity.Position.X_offset - Entity.Position.Y_offset) * IsometricRenderer.TILE_SIZE_INTEGER_HALF); drawY = drawCenterY + (int)((Entity.Position.Z_offset + Entity.Z) * 4) - IsometricRenderer.TILE_SIZE_INTEGER_HALF - (int)((Entity.Position.X_offset + Entity.Position.Y_offset) * IsometricRenderer.TILE_SIZE_INTEGER_HALF); } else { drawX = -IsometricRenderer.TILE_SIZE_INTEGER_HALF - (int)((Entity.Position.X_offset - Entity.Position.Y_offset) * IsometricRenderer.TILE_SIZE_INTEGER_HALF); drawY = drawCenterY + (int)((Entity.Position.Z_offset + Entity.Z) * 4) - IsometricRenderer.TILE_SIZE_INTEGER_HALF - (int)((Entity.Position.X_offset + Entity.Position.Y_offset) * IsometricRenderer.TILE_SIZE_INTEGER_HALF); } if (isSitting) { drawX -= 1; drawY -= 6 + (Entity as Mobile).ChairData.SittingPixelOffset; if (Facing == Direction.North || Facing == Direction.West) { drawY -= 16; } } IsShadowCastingView = !isSitting; int yOffset = 0; for (int i = 0; i < m_LayerCount; i++) { if (m_MobileLayers[i].Frame != null) { AAnimationFrame frame = m_MobileLayers[i].Frame; int x = (drawX + frame.Center.X); int y = -drawY - (frame.Texture.Height + frame.Center.Y) + drawCenterY; if (yOffset > y) { yOffset = y; } DrawTexture = frame.Texture; DrawArea = new Rectangle(x, -y, DrawTexture.Width, DrawTexture.Height); HueVector = Utility.GetHueVector(m_MobileLayers[i].Hue); base.Draw(spriteBatch, drawPosition, mouseOver, map, roofHideFlag); MobilePick(mouseOver, drawPosition, DrawArea, frame); } } Vector3 overheadDrawPosition = new Vector3(drawPosition.X + (int)((Entity.Position.X_offset - Entity.Position.Y_offset) * IsometricRenderer.TILE_SIZE_INTEGER_HALF), drawPosition.Y - (int)((Entity.Position.Z_offset + Entity.Z) * 4), drawPosition.Z); if (m_MobileLayers[0].Frame != null) { yOffset = m_MobileLayers[0].Frame.Texture.Height + drawY - (int)((Entity.Z + Entity.Position.Z_offset) * 4); } else { yOffset = -(yOffset + IsometricRenderer.TILE_SIZE_INTEGER); } // this is where we would draw the reverse of the chair texture. bool isMounted = (Entity is Mobile) && (Entity as Mobile).IsMounted; DrawOverheads(spriteBatch, overheadDrawPosition, mouseOver, map, isMounted ? yOffset + 16 : yOffset); return(true); }