Skip to content

Commit

Permalink
Update ModEntry.cs
Browse files Browse the repository at this point in the history
Fixed MissDrawing for LocalCoop
  • Loading branch information
nofilenamed committed May 4, 2021
1 parent a718753 commit bbe49d7
Showing 1 changed file with 25 additions and 30 deletions.
55 changes: 25 additions & 30 deletions ModEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,12 @@ private void RegisterEvent()
if (!m_Registered)
{
m_Registered = true;
Helper.Events.Display.RenderingHud += OnRenderingHud;
Helper.Events.Display.RenderedWorld += OnRenderingHud;
}
else
{
m_Registered = false;
Helper.Events.Display.RenderingHud -= OnRenderingHud;
Helper.Events.Display.RenderedWorld -= OnRenderingHud;
}
}

Expand All @@ -141,7 +141,7 @@ private void OnRenderingHud(object sender, EventArgs e)
{
if (!farmAnimal.wasPet)
{
ShowEntity(farmAnimal, farmAnimal.home);
DrawEntity(farmAnimal, farmAnimal.home);
}
}
}
Expand All @@ -151,48 +151,43 @@ private void OnRenderingHud(object sender, EventArgs e)
Pet pet = GetPet(currentLocation);
if (pet != null && !pet.lastPetDay.Values.Any(x => x == Game1.Date.TotalDays))
{
ShowEntity(pet);
DrawEntity(pet);
}
}
}


private void ShowEntity(Character animal, Building home = null)
{
float factor = (float)(4.0 * Math.Round(Math.Sin(DateTime.Now.TimeOfDay.TotalMilliseconds / 250.0), 2)) - 32f;

Vector2 offsetForAnimal = GetOffsetForAnimal(home);

if (animal != null)
{
DrawEntity(Config.Bubble, animal, factor, offsetForAnimal);

private void DrawEntity(Character animal, Building home = null)
{
float factor = 4f * (float)Math.Round(Math.Sin(Game1.currentGameTime.TotalGameTime.TotalMilliseconds / 250.0), 2);

float num = 1f / (factor + 36.001f);
num = num <= 1f ? num : 1f;
Vector2 offsetForAnimal = GetOffsetForAnimal(home);

DrawEntity(Config.Heart, animal, factor, offsetForAnimal, num);
}
DrawEntity(Config.Bubble, animal, factor, offsetForAnimal);
DrawEntity(Config.Heart, animal, factor, offsetForAnimal);
}



private void DrawEntity(EntitiesConfig config, Character animal, float factor, Vector2 offset, float colorFactor = 1f)
private void DrawEntity(EntitiesConfig config, Character animal, float factor, Vector2 offset)
{
offset += config.Offset + animal.Position;
offset += animal.position;
offset += config.Offset;
offset += new Vector2(animal.Sprite.getWidth() / 2, factor);

DrawSprite(config, Game1.GlobalToLocal(Game1.uiViewport, offset));
}

private void DrawSprite(EntitiesConfig config, Vector2 position)
{
Game1.spriteBatch.Draw(
Game1.mouseCursors,
Game1.GlobalToLocal(Game1.viewport, new Vector2(animal.Sprite.getWidth() / 2 + offset.X, offset.Y + factor)),
GetRect(config),
config.Color * colorFactor,
config.Rotation,
config.Origin,
Game1.mouseCursors,
position,
new Rectangle(config.X, config.Y, config.Width, config.Height),
config.Color,
config.Rotation,
config.Origin,
config.Scale,
config.SpriteEffects,
0f);
}

public static Rectangle? GetRect(EntitiesConfig config) => new Rectangle(config.X, config.Y, config.Width, config.Height);
}
}

0 comments on commit bbe49d7

Please sign in to comment.