public void drawHairAndAccesories(SpriteBatch b, int facingDirection, Farmer who, Vector2 position, Vector2 origin, float scale, int currentFrame, float rotation, Color overrideColor, float layerDepth) { int hair_style = who.getHair(); HairStyleMetadata hair_metadata = Farmer.GetHairStyleMetadata(who.hair.Value); if (who != null && who.hat.Value != null && who.hat.Value.hairDrawType.Value == 1 && hair_metadata != null && hair_metadata.coveredIndex != -1) { hair_style = hair_metadata.coveredIndex; hair_metadata = Farmer.GetHairStyleMetadata(hair_style); } executeRecolorActions(who); shirtSourceRect = new Rectangle(ClampShirt(who.GetShirtIndex()) * 8 % 128, ClampShirt(who.GetShirtIndex()) * 8 / 128 * 32, 8, 8); Texture2D hair_texture = hairStylesTexture; hairstyleSourceRect = new Rectangle(hair_style * 16 % hairStylesTexture.Width, hair_style * 16 / hairStylesTexture.Width * 96, 16, 32); if (hair_metadata != null) { hair_texture = hair_metadata.texture; hairstyleSourceRect = new Rectangle(hair_metadata.tileX * 16, hair_metadata.tileY * 16, 16, 32); } if ((int)who.accessory >= 0) { accessorySourceRect = new Rectangle((int)who.accessory * 16 % accessoriesTexture.Width, (int)who.accessory * 16 / accessoriesTexture.Width * 32, 16, 16); } if (who.hat.Value != null) { hatSourceRect = new Rectangle(20 * (int)who.hat.Value.which % hatsTexture.Width, 20 * (int)who.hat.Value.which / hatsTexture.Width * 20 * 4, 20, 20); } Rectangle dyed_shirt_source_rect = shirtSourceRect; float dye_layer_offset = 1E-07f; float hair_draw_layer = 2.2E-05f; switch (facingDirection) { case 0: shirtSourceRect.Offset(0, 24); hairstyleSourceRect.Offset(0, 64); dyed_shirt_source_rect = shirtSourceRect; dyed_shirt_source_rect.Offset(128, 0); if (who.hat.Value != null) { hatSourceRect.Offset(0, 60); } if (!who.bathingClothes) { b.Draw(shirtsTexture, position + origin + positionOffset + new Vector2(16f * scale + (float)(featureXOffsetPerFrame[currentFrame] * 4), (float)(56 + featureYOffsetPerFrame[currentFrame] * 4) + (float)(int)heightOffset * scale), shirtSourceRect, overrideColor.Equals(Color.White) ? Color.White : overrideColor, rotation, origin, 4f * scale, SpriteEffects.None, layerDepth + 1.8E-07f); b.Draw(shirtsTexture, position + origin + positionOffset + new Vector2(16f * scale + (float)(featureXOffsetPerFrame[currentFrame] * 4), (float)(56 + featureYOffsetPerFrame[currentFrame] * 4) + (float)(int)heightOffset * scale), dyed_shirt_source_rect, overrideColor.Equals(Color.White) ? Utility.MakeCompletelyOpaque(who.GetShirtColor()) : overrideColor, rotation, origin, 4f * scale, SpriteEffects.None, layerDepth + 1.8E-07f + dye_layer_offset); } b.Draw(hair_texture, position + origin + positionOffset + new Vector2(featureXOffsetPerFrame[currentFrame] * 4, featureYOffsetPerFrame[currentFrame] * 4 + 4 + ((who.IsMale && hair_style >= 16) ? (-4) : ((!who.IsMale && hair_style < 16) ? 4 : 0))), hairstyleSourceRect, overrideColor.Equals(Color.White) ? ((Color)who.hairstyleColor) : overrideColor, rotation, origin, 4f * scale, SpriteEffects.None, layerDepth + hair_draw_layer); break; case 1: shirtSourceRect.Offset(0, 8); hairstyleSourceRect.Offset(0, 32); dyed_shirt_source_rect = shirtSourceRect; dyed_shirt_source_rect.Offset(128, 0); if ((int)who.accessory >= 0) { accessorySourceRect.Offset(0, 16); } if (who.hat.Value != null) { hatSourceRect.Offset(0, 20); } if (rotation == -(float)Math.PI / 32f) { rotationAdjustment.X = 6f; rotationAdjustment.Y = -2f; } else if (rotation == (float)Math.PI / 32f) { rotationAdjustment.X = -6f; rotationAdjustment.Y = 1f; } if (!who.bathingClothes) { b.Draw(shirtsTexture, position + origin + positionOffset + rotationAdjustment + new Vector2(16f * scale + (float)(featureXOffsetPerFrame[currentFrame] * 4), 56f * scale + (float)(featureYOffsetPerFrame[currentFrame] * 4) + (float)(int)heightOffset * scale), shirtSourceRect, overrideColor.Equals(Color.White) ? Color.White : overrideColor, rotation, origin, 4f * scale + ((rotation != 0f) ? 0f : 0f), SpriteEffects.None, layerDepth + 1.8E-07f); b.Draw(shirtsTexture, position + origin + positionOffset + rotationAdjustment + new Vector2(16f * scale + (float)(featureXOffsetPerFrame[currentFrame] * 4), 56f * scale + (float)(featureYOffsetPerFrame[currentFrame] * 4) + (float)(int)heightOffset * scale), dyed_shirt_source_rect, overrideColor.Equals(Color.White) ? Utility.MakeCompletelyOpaque(who.GetShirtColor()) : overrideColor, rotation, origin, 4f * scale + ((rotation != 0f) ? 0f : 0f), SpriteEffects.None, layerDepth + 1.8E-07f + dye_layer_offset); } if ((int)who.accessory >= 0) { b.Draw(accessoriesTexture, position + origin + positionOffset + rotationAdjustment + new Vector2(featureXOffsetPerFrame[currentFrame] * 4, 4 + featureYOffsetPerFrame[currentFrame] * 4 + (int)heightOffset), accessorySourceRect, (overrideColor.Equals(Color.White) && (int)who.accessory < 6) ? ((Color)who.hairstyleColor) : overrideColor, rotation, origin, 4f * scale + ((rotation != 0f) ? 0f : 0f), SpriteEffects.None, layerDepth + (((int)who.accessory < 8) ? 1.9E-05f : 2.9E-05f)); } b.Draw(hair_texture, position + origin + positionOffset + new Vector2(featureXOffsetPerFrame[currentFrame] * 4, featureYOffsetPerFrame[currentFrame] * 4 + ((who.IsMale && (int)who.hair >= 16) ? (-4) : ((!who.IsMale && (int)who.hair < 16) ? 4 : 0))), hairstyleSourceRect, overrideColor.Equals(Color.White) ? ((Color)who.hairstyleColor) : overrideColor, rotation, origin, 4f * scale, SpriteEffects.None, layerDepth + hair_draw_layer); break; case 2: dyed_shirt_source_rect = shirtSourceRect; dyed_shirt_source_rect.Offset(128, 0); if (!who.bathingClothes) { b.Draw(shirtsTexture, position + origin + positionOffset + new Vector2(16 + featureXOffsetPerFrame[currentFrame] * 4, (float)(56 + featureYOffsetPerFrame[currentFrame] * 4) + (float)(int)heightOffset * scale - (float)(who.IsMale ? 0 : 0)), shirtSourceRect, overrideColor.Equals(Color.White) ? Color.White : overrideColor, rotation, origin, 4f * scale, SpriteEffects.None, layerDepth + 1.5E-07f); b.Draw(shirtsTexture, position + origin + positionOffset + new Vector2(16 + featureXOffsetPerFrame[currentFrame] * 4, (float)(56 + featureYOffsetPerFrame[currentFrame] * 4) + (float)(int)heightOffset * scale - (float)(who.IsMale ? 0 : 0)), dyed_shirt_source_rect, overrideColor.Equals(Color.White) ? Utility.MakeCompletelyOpaque(who.GetShirtColor()) : overrideColor, rotation, origin, 4f * scale, SpriteEffects.None, layerDepth + 1.5E-07f + dye_layer_offset); } if ((int)who.accessory >= 0) { b.Draw(accessoriesTexture, position + origin + positionOffset + rotationAdjustment + new Vector2(featureXOffsetPerFrame[currentFrame] * 4, 8 + featureYOffsetPerFrame[currentFrame] * 4 + (int)heightOffset - 4), accessorySourceRect, (overrideColor.Equals(Color.White) && (int)who.accessory < 6) ? ((Color)who.hairstyleColor) : overrideColor, rotation, origin, 4f * scale + ((rotation != 0f) ? 0f : 0f), SpriteEffects.None, layerDepth + (((int)who.accessory < 8) ? 1.9E-05f : 2.9E-05f)); } b.Draw(hair_texture, position + origin + positionOffset + new Vector2(featureXOffsetPerFrame[currentFrame] * 4, featureYOffsetPerFrame[currentFrame] * 4 + ((who.IsMale && (int)who.hair >= 16) ? (-4) : ((!who.IsMale && (int)who.hair < 16) ? 4 : 0))), hairstyleSourceRect, overrideColor.Equals(Color.White) ? ((Color)who.hairstyleColor) : overrideColor, rotation, origin, 4f * scale, SpriteEffects.None, layerDepth + hair_draw_layer); break; case 3: { bool flip2 = true; shirtSourceRect.Offset(0, 16); dyed_shirt_source_rect = shirtSourceRect; dyed_shirt_source_rect.Offset(128, 0); if ((int)who.accessory >= 0) { accessorySourceRect.Offset(0, 16); } if (hair_metadata != null && hair_metadata.usesUniqueLeftSprite) { flip2 = false; hairstyleSourceRect.Offset(0, 96); } else { hairstyleSourceRect.Offset(0, 32); } if (who.hat.Value != null) { hatSourceRect.Offset(0, 40); } if (rotation == -(float)Math.PI / 32f) { rotationAdjustment.X = 6f; rotationAdjustment.Y = -2f; } else if (rotation == (float)Math.PI / 32f) { rotationAdjustment.X = -5f; rotationAdjustment.Y = 1f; } if (!who.bathingClothes) { b.Draw(shirtsTexture, position + origin + positionOffset + rotationAdjustment + new Vector2(16 - featureXOffsetPerFrame[currentFrame] * 4, 56 + featureYOffsetPerFrame[currentFrame] * 4 + (int)heightOffset), shirtSourceRect, overrideColor.Equals(Color.White) ? Color.White : overrideColor, rotation, origin, 4f * scale + ((rotation != 0f) ? 0f : 0f), SpriteEffects.None, layerDepth + 1.5E-07f); b.Draw(shirtsTexture, position + origin + positionOffset + rotationAdjustment + new Vector2(16 - featureXOffsetPerFrame[currentFrame] * 4, 56 + featureYOffsetPerFrame[currentFrame] * 4 + (int)heightOffset), dyed_shirt_source_rect, overrideColor.Equals(Color.White) ? Utility.MakeCompletelyOpaque(who.GetShirtColor()) : overrideColor, rotation, origin, 4f * scale + ((rotation != 0f) ? 0f : 0f), SpriteEffects.None, layerDepth + 1.5E-07f + dye_layer_offset); } if ((int)who.accessory >= 0) { b.Draw(accessoriesTexture, position + origin + positionOffset + rotationAdjustment + new Vector2(-featureXOffsetPerFrame[currentFrame] * 4, 4 + featureYOffsetPerFrame[currentFrame] * 4 + (int)heightOffset), accessorySourceRect, (overrideColor.Equals(Color.White) && (int)who.accessory < 6) ? ((Color)who.hairstyleColor) : overrideColor, rotation, origin, 4f * scale + ((rotation != 0f) ? 0f : 0f), SpriteEffects.FlipHorizontally, layerDepth + (((int)who.accessory < 8) ? 1.9E-05f : 2.9E-05f)); } b.Draw(hair_texture, position + origin + positionOffset + new Vector2(-featureXOffsetPerFrame[currentFrame] * 4, featureYOffsetPerFrame[currentFrame] * 4 + ((who.IsMale && (int)who.hair >= 16) ? (-4) : ((!who.IsMale && (int)who.hair < 16) ? 4 : 0))), hairstyleSourceRect, overrideColor.Equals(Color.White) ? ((Color)who.hairstyleColor) : overrideColor, rotation, origin, 4f * scale, flip2 ? SpriteEffects.FlipHorizontally : SpriteEffects.None, layerDepth + hair_draw_layer); break; } } if (who.hat.Value != null && !who.bathingClothes) { bool flip = who.FarmerSprite.CurrentAnimationFrame.flip; float layer_offset = 3.9E-05f; if (who.hat.Value.isMask && facingDirection == 0) { Rectangle mask_draw_rect = hatSourceRect; mask_draw_rect.Height -= 11; mask_draw_rect.Y += 11; b.Draw(hatsTexture, position + origin + positionOffset + new Vector2(0f, 44f) + new Vector2(-8 + ((!flip) ? 1 : (-1)) * featureXOffsetPerFrame[currentFrame] * 4, -16 + featureYOffsetPerFrame[currentFrame] * 4 + ((!who.hat.Value.ignoreHairstyleOffset) ? hairstyleHatOffset[(int)who.hair % 16] : 0) + 4 + (int)heightOffset), mask_draw_rect, Color.White, rotation, origin, 4f * scale, SpriteEffects.None, layerDepth + layer_offset); mask_draw_rect = hatSourceRect; mask_draw_rect.Height = 11; layer_offset = -1E-06f; b.Draw(hatsTexture, position + origin + positionOffset + new Vector2(-8 + ((!flip) ? 1 : (-1)) * featureXOffsetPerFrame[currentFrame] * 4, -16 + featureYOffsetPerFrame[currentFrame] * 4 + ((!who.hat.Value.ignoreHairstyleOffset) ? hairstyleHatOffset[(int)who.hair % 16] : 0) + 4 + (int)heightOffset), mask_draw_rect, who.hat.Value.isPrismatic ? Utility.GetPrismaticColor() : Color.White, rotation, origin, 4f * scale, SpriteEffects.None, layerDepth + layer_offset); } else { b.Draw(hatsTexture, position + origin + positionOffset + new Vector2(-8 + ((!flip) ? 1 : (-1)) * featureXOffsetPerFrame[currentFrame] * 4, -16 + featureYOffsetPerFrame[currentFrame] * 4 + ((!who.hat.Value.ignoreHairstyleOffset) ? hairstyleHatOffset[(int)who.hair % 16] : 0) + 4 + (int)heightOffset), hatSourceRect, who.hat.Value.isPrismatic ? Utility.GetPrismaticColor() : Color.White, rotation, origin, 4f * scale, SpriteEffects.None, layerDepth + layer_offset); } } }
public void ApplySleeveColor(string texture_name, Color[] pixels, Farmer who) { Color[] shirtData = new Color[shirtsTexture.Bounds.Width * shirtsTexture.Bounds.Height]; shirtsTexture.GetData(shirtData); int index = ClampShirt(who.GetShirtIndex()) * 8 / 128 * 32 * shirtsTexture.Bounds.Width + ClampShirt(who.GetShirtIndex()) * 8 % 128 + shirtsTexture.Width * 4; int dye_index = index + 128; Color shirtSleeveColor = Color.White; if (who.GetShirtExtraData().Contains("Sleeveless") || index >= shirtData.Length) { Texture2D skinColors = farmerTextureManager.Load <Texture2D>("Characters\\Farmer\\skinColors"); Color[] skinColorsData = new Color[skinColors.Width * skinColors.Height]; int skin_index = skin.Value; if (skin_index < 0) { skin_index = skinColors.Height - 1; } if (skin_index > skinColors.Height - 1) { skin_index = 0; } skinColors.GetData(skinColorsData); Color darkest = skinColorsData[skin_index * 3 % (skinColors.Height * 3)]; Color medium = skinColorsData[skin_index * 3 % (skinColors.Height * 3) + 1]; Color lightest = skinColorsData[skin_index * 3 % (skinColors.Height * 3) + 2]; if (_sickFrame) { darkest = pixels[260 + baseTexture.Width]; medium = pixels[261 + baseTexture.Width]; lightest = pixels[262 + baseTexture.Width]; } shirtSleeveColor = darkest; _SwapColor(texture_name, pixels, 256, darkest); _SwapColor(texture_name, pixels, 257, medium); _SwapColor(texture_name, pixels, 258, lightest); return; } Color color = Utility.MakeCompletelyOpaque(who.GetShirtColor()); shirtSleeveColor = shirtData[dye_index]; Color clothes_color = color; if (shirtSleeveColor.A < byte.MaxValue) { shirtSleeveColor = shirtData[index]; clothes_color = Color.White; } shirtSleeveColor = Utility.MultiplyColor(shirtSleeveColor, clothes_color); _SwapColor(texture_name, pixels, 256, shirtSleeveColor); shirtSleeveColor = shirtData[dye_index - shirtsTexture.Width]; if (shirtSleeveColor.A < byte.MaxValue) { shirtSleeveColor = shirtData[index - shirtsTexture.Width]; clothes_color = Color.White; } shirtSleeveColor = Utility.MultiplyColor(shirtSleeveColor, clothes_color); _SwapColor(texture_name, pixels, 257, shirtSleeveColor); shirtSleeveColor = shirtData[dye_index - shirtsTexture.Width * 2]; if (shirtSleeveColor.A < byte.MaxValue) { shirtSleeveColor = shirtData[index - shirtsTexture.Width * 2]; clothes_color = Color.White; } shirtSleeveColor = Utility.MultiplyColor(shirtSleeveColor, clothes_color); _SwapColor(texture_name, pixels, 258, shirtSleeveColor); }