/// <summary> /// A very verbose asset drawer. /// </summary> /// <param name="b"></param> /// <param name="npc"></param> /// <param name="position"></param> /// <param name="sourceRectangle"></param> /// <param name="color"></param> /// <param name="alpha"></param> /// <param name="origin"></param> /// <param name="scale"></param> /// <param name="effects"></param> /// <param name="layerDepth"></param> public override void draw(SpriteBatch b, ExtendedNPC npc, Vector2 position, Rectangle sourceRectangle, Color color, float alpha, Vector2 origin, float scale, SpriteEffects effects, float layerDepth) { //Class1.ModMonitor.Log(sourceRectangle.ToString()); Vector2 generalOffset = new Vector2(0, 1 * Game1.tileSize); //Puts the sprite at the correct positioning. position -= new Vector2(0, 0.25f * Game1.tileSize); float smallOffset = 0.001f; float tinyOffset = 0.0001f; //Class1.ModMonitor.Log((position - generalOffset).ToString()); float num = Math.Max(0.0f, (float)(Math.Ceiling(Math.Sin(Game1.currentGameTime.TotalGameTime.TotalMilliseconds / 600.0 + (double)npc.DefaultPosition.X * 20.0)) / 4.0)); this.body.draw(b, npc, position - generalOffset, sourceRectangle, StandardColorCollection.colorMult(color, this.drawColors.bodyColor), alpha, origin, scale * Game1.pixelZoom, effects, layerDepth + smallOffset); this.eyes.draw(b, npc, position - generalOffset, sourceRectangle, StandardColorCollection.colorMult(color, this.drawColors.eyeColor), alpha, origin, scale * Game1.pixelZoom, effects, layerDepth + smallOffset + (tinyOffset * 1)); this.hair.draw(b, npc, position - generalOffset, sourceRectangle, StandardColorCollection.colorMult(color, this.drawColors.hairColor), alpha, origin, scale * Game1.pixelZoom, effects, layerDepth + smallOffset + (tinyOffset * 2)); if (num > 0.0f) { Vector2 shirtOffset = new Vector2((1 * Game1.tileSize) / 4, (1 * Game1.tileSize) / 4); this.shirt.draw(b, npc, position - generalOffset, sourceRectangle, StandardColorCollection.colorMult(color, this.drawColors.shirtColor), alpha, new Vector2(0.5f, 1), scale * Game1.pixelZoom + num, effects, layerDepth + smallOffset + (tinyOffset * 3)); } else { this.shirt.draw(b, npc, position - generalOffset, sourceRectangle, StandardColorCollection.colorMult(color, this.drawColors.shirtColor), alpha, origin, scale * Game1.pixelZoom, effects, layerDepth + smallOffset + (tinyOffset * 3)); } this.pants.draw(b, npc, position - generalOffset, sourceRectangle, StandardColorCollection.colorMult(color, this.drawColors.bottomsColor), alpha, origin, scale * Game1.pixelZoom, effects, layerDepth + smallOffset + (tinyOffset * 4)); this.shoes.draw(b, npc, position - generalOffset, sourceRectangle, StandardColorCollection.colorMult(color, this.drawColors.shoesColor), alpha, origin, scale * Game1.pixelZoom, effects, layerDepth + smallOffset + (tinyOffset * 5)); foreach (var accessory in this.accessories) { accessory.draw(b, npc, position - generalOffset, sourceRectangle, color, alpha, origin, scale, effects, layerDepth + 0.0006f); } }
/// <summary> /// Constructor. /// </summary> /// <param name="bodyAnimation">The collection of textures to be used for the body part for the npc.</param> /// <param name="eyeAnimation">The collection of textures to be used for the eyes part for the npc.</param> /// <param name="hairAnimation">The collection of textures to be used for the hair part for the npc.</param> /// <param name="shirtAnimation">The collection of textures to be used for the shirt part for the npc.</param> /// <param name="pantsAnimation">The collection of textures to be used for the pants part for the npc.</param> /// <param name="shoesAnimation">The collection of textures to be used for the shoes part for the npc.</param> /// <param name="accessoriesWithAnimations">The collection of textures to be used for the accessories part for the npc.</param> /// <param name="DrawColors">The collection of draw colors for the different parts for the npc.</param> public StandardCharacterAnimation(AnimatedSpriteCollection bodyAnimation, AnimatedSpriteCollection eyeAnimation, AnimatedSpriteCollection hairAnimation, AnimatedSpriteCollection shirtAnimation, AnimatedSpriteCollection pantsAnimation, AnimatedSpriteCollection shoesAnimation, List <AnimatedSpriteCollection> accessoriesWithAnimations, StandardColorCollection DrawColors) : base() { this.body = bodyAnimation; this.hair = hairAnimation; this.eyes = eyeAnimation; this.shirt = shirtAnimation; this.pants = pantsAnimation; this.shoes = shoesAnimation; this.accessories = accessoriesWithAnimations; this.drawColors = DrawColors; }
/// <summary>Creates a character renderer (a collection of textures) from a bunch of different asset sheets.</summary> /// <param name="bodySheet">The textures for the NPC's body.</param> /// <param name="eyesSheet">The textures for the NPC's eyes.</param> /// <param name="hairSheet">The textures for the NPC's hair.</param> /// <param name="shirtSheet">The textures for the NPC's shirt.</param> /// <param name="pantsSheet">The textures for the NPC's pants.</param> /// <param name="shoesSheet">The textures for the NPC's shoes.</param> /// <param name="accessorySheet">The textures for the NPC's accessories.</param> /// <param name="drawColors">The colors for the NPC's different assets.</param> public virtual BasicRenderer generateBasicRenderer(AssetSheet bodySheet, AssetSheet eyesSheet, AssetSheet hairSheet, AssetSheet shirtSheet, AssetSheet pantsSheet, AssetSheet shoesSheet, List <AssetSheet> accessorySheet, StandardColorCollection drawColors = null) { if (drawColors == null) { drawColors = new StandardColorCollection(); } // Get all of the appropriate animations. StandardCharacterAnimation standingAnimation = this.generateCharacterAnimation(bodySheet, eyesSheet, hairSheet, shirtSheet, pantsSheet, shoesSheet, accessorySheet, AnimationType.standing, drawColors); StandardCharacterAnimation movingAnimation = this.generateCharacterAnimation(bodySheet, eyesSheet, hairSheet, shirtSheet, pantsSheet, shoesSheet, accessorySheet, AnimationType.walking, drawColors); StandardCharacterAnimation swimmingAnimation = this.generateCharacterAnimation(bodySheet, eyesSheet, hairSheet, shirtSheet, pantsSheet, shoesSheet, accessorySheet, AnimationType.swimming, drawColors); return(new BasicRenderer(standingAnimation, movingAnimation, swimmingAnimation)); }
/// <summary> /// Used to draw the sprite to the screen. /// </summary> /// <param name="b"></param> /// <param name="screenPosition"></param> /// <param name="layerDepth"></param> /// <param name="xOffset"></param> /// <param name="yOffset"></param> /// <param name="c"></param> /// <param name="flip"></param> /// <param name="scale"></param> /// <param name="rotation"></param> /// <param name="characterSourceRectOffset"></param> public override void draw(SpriteBatch b, Vector2 screenPosition, float layerDepth, int xOffset, int yOffset, Color c, bool flip = false, float scale = 1f, float rotation = 0.0f, bool characterSourceRectOffset = false) { // b.Draw(this.currentSprite.Texture, screenPosition, new Rectangle?(new Rectangle(this.currentSprite.sourceRect.X + xOffset, this.currentSprite.sourceRect.Y + yOffset, this.currentSprite.sourceRect.Width, this.currentSprite.sourceRect.Height)), c, rotation, characterSourceRectOffset ? new Vector2((float)(this.currentSprite.spriteWidth / 2), (float)((double)this.currentSprite.spriteHeight * 3.0 / 4.0)) : Vector2.Zero, scale, flip || this.currentSprite.currentAnimation != null && this.currentSprite.currentAnimation[this.currentSprite.currentAnimationIndex].flip ? SpriteEffects.FlipHorizontally : SpriteEffects.None, layerDepth); this.body.draw(b, screenPosition, layerDepth, xOffset, yOffset, StandardColorCollection.colorMult(c, this.drawColors.bodyColor), flip, scale, rotation, characterSourceRectOffset); this.hair.draw(b, screenPosition, layerDepth, xOffset, yOffset, StandardColorCollection.colorMult(c, this.drawColors.hairColor), flip, scale, rotation, characterSourceRectOffset); this.eyes.draw(b, screenPosition, layerDepth, xOffset, yOffset, StandardColorCollection.colorMult(c, this.drawColors.eyeColor), flip, scale, rotation, characterSourceRectOffset); this.shirt.draw(b, screenPosition, layerDepth, xOffset, yOffset, StandardColorCollection.colorMult(c, this.drawColors.shirtColor), flip, scale, rotation, characterSourceRectOffset); this.pants.draw(b, screenPosition, layerDepth, xOffset, yOffset, StandardColorCollection.colorMult(c, this.drawColors.bottomsColor), flip, scale, rotation, characterSourceRectOffset); this.shoes.draw(b, screenPosition, layerDepth, xOffset, yOffset, StandardColorCollection.colorMult(c, this.drawColors.shoesColor), flip, scale, rotation, characterSourceRectOffset); foreach (var accessory in this.accessories) { accessory.draw(b, screenPosition, layerDepth, xOffset, yOffset, c, flip, scale, rotation, characterSourceRectOffset); } }
/// <summary> /// Creates a character renderer (a collection of textures) from a bunch of different asset sheets. /// </summary> /// <param name="bodySheet">The textures for the npc's body.</param> /// <param name="eyesSheet">The textures for the npc's eyes.</param> /// <param name="hairSheet">The textures for the npc's hair.</param> /// <param name="shirtSheet">The textures for the npc's shirt.</param> /// <param name="pantsSheet">The textures for the npc's pants.</param> /// <param name="shoesSheet">The textures for the npc's shoes.</param> /// <param name="accessorySheet">The textures for the npc's accessories.</param> /// <param name="DrawColors">The colors for the npc's different assets.</param> /// <returns></returns> public virtual BasicRenderer generateBasicRenderer(AssetSheet bodySheet, AssetSheet eyesSheet, AssetSheet hairSheet, AssetSheet shirtSheet, AssetSheet pantsSheet, AssetSheet shoesSheet, List <AssetSheet> accessorySheet, StandardColorCollection DrawColors = null) { if (DrawColors == null) { DrawColors = new StandardColorCollection(); } //Get all of the appropriate animations. AnimationType type = AnimationType.standing; var standingAnimation = generateCharacterAnimation(bodySheet, eyesSheet, hairSheet, shirtSheet, pantsSheet, shoesSheet, accessorySheet, type, DrawColors); type = AnimationType.walking; var movingAnimation = generateCharacterAnimation(bodySheet, eyesSheet, hairSheet, shirtSheet, pantsSheet, shoesSheet, accessorySheet, type, DrawColors); type = AnimationType.swimming; var swimmingAnimation = generateCharacterAnimation(bodySheet, eyesSheet, hairSheet, shirtSheet, pantsSheet, shoesSheet, accessorySheet, type, DrawColors); BasicRenderer render = new BasicRenderer(standingAnimation, movingAnimation, swimmingAnimation); return(render); }
/// <summary> /// Get a collection of sprites to generate a collective animated sprite. /// </summary> /// <param name="BodySprites">The collection of sprites to be used for the boyd of the npc.</param> /// <param name="EyeSprites">The collection of sprites to be used for the eye of the npc.</param> /// <param name="HairSprites">The collection of sprites to be used for the hair of the npc.</param> /// <param name="ShirtsSprites">The collection of sprites to be used for the shirts of the npc.</param> /// <param name="PantsSprites">The collection of sprites to be used for the pants of the npc.</param> /// <param name="ShoesSprites">The collection of sprites to be used for the shoes of the npc.</param> /// <param name="AccessoriesSprites">The collection of sprites to be used for the accessories of the npc.</param> /// <param name="DrawColors">The collection of collors to be used for chaing the color of an individual asset.</param> /// <returns></returns> public StandardCharacterAnimation GetStandardCharacterAnimation(NamePairings BodySprites, NamePairings EyeSprites, NamePairings HairSprites, NamePairings ShirtsSprites, NamePairings PantsSprites, NamePairings ShoesSprites, List <NamePairings> AccessoriesSprites, StandardColorCollection DrawColors = null) { var body = getAnimatedSpriteCollectionFromAssets(BodySprites); var eyes = getAnimatedSpriteCollectionFromAssets(EyeSprites); var hair = getAnimatedSpriteCollectionFromAssets(HairSprites); var shirts = getAnimatedSpriteCollectionFromAssets(ShirtsSprites); var pants = getAnimatedSpriteCollectionFromAssets(PantsSprites); var shoes = getAnimatedSpriteCollectionFromAssets(ShoesSprites); List <AnimatedSpriteCollection> accessories = new List <AnimatedSpriteCollection>(); foreach (var v in AccessoriesSprites) { accessories.Add(getAnimatedSpriteCollectionFromAssets(v)); } if (DrawColors == null) { DrawColors = new StandardColorCollection(); } return(new StandardCharacterAnimation(body, eyes, hair, shirts, pants, shoes, accessories, DrawColors)); }
/// <summary> /// Generate a Standard Character Animation from some asset sheets. /// (collection of textures to animations) /// </summary> /// <param name="body">The textures for the npc's body.</param> /// <param name="eyes">The textures for the npc's eyes.</param> /// <param name="hair">The textures for the npc's hair.</param> /// <param name="shirt">The textures for the npc's shirt.</param> /// <param name="pants">The textures for the npc's pants.</param> /// <param name="shoes">The textures for the npc's shoes.</param> /// <param name="accessoryType">The textures for the npc's accessories.</param> /// <param name="DrawColors">The colors for the npc's different assets.</param> /// <returns></returns> public virtual StandardCharacterAnimation generateCharacterAnimation(AssetSheet body, AssetSheet eyes, AssetSheet hair, AssetSheet shirt, AssetSheet pants, AssetSheet shoes, List <AssetSheet> accessories, AnimationType animationType, StandardColorCollection DrawColors = null) { var bodySprite = getSpriteCollectionFromSheet(body, animationType); var eyesSprite = getSpriteCollectionFromSheet(eyes, animationType); var hairSprite = getSpriteCollectionFromSheet(hair, animationType); var shirtSprite = getSpriteCollectionFromSheet(shirt, animationType); var pantsSprite = getSpriteCollectionFromSheet(pants, animationType); var shoesSprite = getSpriteCollectionFromSheet(shoes, animationType); List <AnimatedSpriteCollection> accessoryCollection = new List <AnimatedSpriteCollection>(); foreach (var v in accessories) { AnimatedSpriteCollection acc = getSpriteCollectionFromSheet(v, AnimationType.standing); accessoryCollection.Add(acc); } if (DrawColors == null) { DrawColors = new StandardColorCollection(); } StandardCharacterAnimation standingAnimation = new StandardCharacterAnimation(bodySprite, eyesSprite, hairSprite, shirtSprite, pantsSprite, shoesSprite, accessoryCollection, DrawColors); return(standingAnimation); }
/// <summary>Generate a Standard Character Animation from some asset sheets. (collection of textures to animations)</summary> /// <param name="body">The textures for the NPC's body.</param> /// <param name="eyes">The textures for the NPC's eyes.</param> /// <param name="hair">The textures for the NPC's hair.</param> /// <param name="shirt">The textures for the NPC's shirt.</param> /// <param name="pants">The textures for the NPC's pants.</param> /// <param name="shoes">The textures for the NPC's shoes.</param> /// <param name="accessories">The textures for the NPC's accessories.</param> /// <param name="animationType">The animation type to generate.</param> /// <param name="drawColors">The colors for the NPC's different assets.</param> public virtual StandardCharacterAnimation generateCharacterAnimation(AssetSheet body, AssetSheet eyes, AssetSheet hair, AssetSheet shirt, AssetSheet pants, AssetSheet shoes, List <AssetSheet> accessories, AnimationType animationType, StandardColorCollection drawColors = null) { AnimatedSpriteCollection bodySprite = this.getSpriteCollectionFromSheet(body, animationType); AnimatedSpriteCollection eyesSprite = this.getSpriteCollectionFromSheet(eyes, animationType); AnimatedSpriteCollection hairSprite = this.getSpriteCollectionFromSheet(hair, animationType); AnimatedSpriteCollection shirtSprite = this.getSpriteCollectionFromSheet(shirt, animationType); AnimatedSpriteCollection pantsSprite = this.getSpriteCollectionFromSheet(pants, animationType); AnimatedSpriteCollection shoesSprite = this.getSpriteCollectionFromSheet(shoes, animationType); List <AnimatedSpriteCollection> accessoryCollection = new List <AnimatedSpriteCollection>(); foreach (var v in accessories) { AnimatedSpriteCollection acc = this.getSpriteCollectionFromSheet(v, AnimationType.standing); accessoryCollection.Add(acc); } if (drawColors == null) { drawColors = new StandardColorCollection(); } return(new StandardCharacterAnimation(bodySprite, eyesSprite, hairSprite, shirtSprite, pantsSprite, shoesSprite, accessoryCollection, drawColors)); }
/// <summary>Generate a basic NPC based on the NPC data here.</summary> /// <param name="gender">The NPC gender.</param> /// <param name="minNumOfAccessories">The minimum number of accessories to generate.</param> /// <param name="maxNumOfAccessories">The maximum number of accessories to generate.</param> /// <param name="drawColors">The colors for the NPC's different assets.</param> public ExtendedNpc generateNPC(Genders gender, int minNumOfAccessories, int maxNumOfAccessories, StandardColorCollection drawColors = null) { Seasons myseason = Seasons.spring; if (Game1.currentSeason == "spring") { myseason = Seasons.spring; } if (Game1.currentSeason == "summer") { myseason = Seasons.summer; } if (Game1.currentSeason == "fall") { myseason = Seasons.fall; } if (Game1.currentSeason == "winter") { myseason = Seasons.winter; } List <AssetSheet> bodyList = new List <AssetSheet>(); List <AssetSheet> eyesList = new List <AssetSheet>(); List <AssetSheet> hairList = new List <AssetSheet>(); List <AssetSheet> shirtList = new List <AssetSheet>(); List <AssetSheet> shoesList = new List <AssetSheet>(); List <AssetSheet> pantsList = new List <AssetSheet>(); List <AssetSheet> accessoryList = new List <AssetSheet>(); //Get all applicable parts from this current asset manager foreach (var assetManager in this.assetPool) { var body = this.getListOfApplicableBodyParts(assetManager.Key, gender, myseason, PartType.body); foreach (var piece in body) { bodyList.Add(piece); } var eyes = this.getListOfApplicableBodyParts(assetManager.Key, gender, myseason, PartType.eyes); foreach (var piece in eyes) { eyesList.Add(piece); } var hair = this.getListOfApplicableBodyParts(assetManager.Key, gender, myseason, PartType.hair); foreach (var piece in hair) { hairList.Add(piece); } var shirt = this.getListOfApplicableBodyParts(assetManager.Key, gender, myseason, PartType.shirt); foreach (var piece in shirt) { shirtList.Add(piece); } var pants = this.getListOfApplicableBodyParts(assetManager.Key, gender, myseason, PartType.pants); foreach (var piece in pants) { pantsList.Add(piece); } var shoes = this.getListOfApplicableBodyParts(assetManager.Key, gender, myseason, PartType.shoes); foreach (var piece in shoes) { shoesList.Add(piece); } var accessory = this.getListOfApplicableBodyParts(assetManager.Key, gender, myseason, PartType.accessory); foreach (var piece in accessory) { accessoryList.Add(piece); } } Random r = new Random(DateTime.Now.Millisecond); int amount = r.Next(minNumOfAccessories, maxNumOfAccessories + 1); int bodyIndex; int eyesIndex; int hairIndex; int shirtIndex; int pantsIndex; int shoesIndex; if (bodyList.Count != 0) { bodyIndex = r.Next(0, bodyList.Count - 1); } else { Class1.ModMonitor.Log("Error: Not enough body templates to generate an npc. Aborting", StardewModdingAPI.LogLevel.Error); return(null); } if (eyesList.Count != 0) { eyesIndex = r.Next(0, eyesList.Count - 1); } else { Class1.ModMonitor.Log("Error: Not enough eyes templates to generate an npc. Aborting", StardewModdingAPI.LogLevel.Error); return(null); } if (hairList.Count != 0) { hairIndex = r.Next(0, hairList.Count - 1); } else { Class1.ModMonitor.Log("Error: Not enough hair templates to generate an npc. Aborting", StardewModdingAPI.LogLevel.Error); return(null); } if (shirtList.Count != 0) { shirtIndex = r.Next(0, shirtList.Count - 1); } else { Class1.ModMonitor.Log("Error: Not enough shirt templates to generate an npc. Aborting", StardewModdingAPI.LogLevel.Error); return(null); } if (pantsList.Count != 0) { pantsIndex = r.Next(0, pantsList.Count - 1); } else { Class1.ModMonitor.Log("Error: Not enough pants templates to generate an npc. Aborting", StardewModdingAPI.LogLevel.Error); return(null); } if (shoesList.Count != 0) { shoesIndex = r.Next(0, shoesList.Count - 1); } else { Class1.ModMonitor.Log("Error: Not enough shoes templates to generate an npc. Aborting", StardewModdingAPI.LogLevel.Error); return(null); } List <int> accIntList = new List <int>(); if (accessoryList.Count != 0) { for (int i = 0; i < amount; i++) { int acc = r.Next(0, accessoryList.Count - 1); accIntList.Add(acc); } } //Get a single sheet to pull from. AssetSheet bodySheet = bodyList.ElementAt(bodyIndex); AssetSheet eyesSheet = eyesList.ElementAt(eyesIndex); AssetSheet hairSheet = hairList.ElementAt(hairIndex); AssetSheet shirtSheet = shirtList.ElementAt(shirtIndex); AssetSheet pantsSheet = pantsList.ElementAt(pantsIndex); AssetSheet shoesSheet = shoesList.ElementAt(shoesIndex); List <AssetSheet> accessorySheet = new List <AssetSheet>(); foreach (int v in accIntList) { accessorySheet.Add(accessoryList.ElementAt(v)); } if (drawColors == null) { drawColors = new StandardColorCollection(); } var render = this.generateBasicRenderer(bodySheet, eyesSheet, hairSheet, shirtSheet, pantsSheet, shoesSheet, accessorySheet, drawColors); return(new ExtendedNpc(new Sprite(this.getDefaultSpriteImage(bodySheet)), render, new Microsoft.Xna.Framework.Vector2(0, 0) * Game1.tileSize, 2, NpcNames.getRandomNpcName(gender))); }