Skip to content

Commit

Permalink
Extract LevelUp display
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Toth committed Jan 5, 2023
1 parent 817b285 commit c3a21d3
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 24 deletions.
34 changes: 34 additions & 0 deletions UIInfoSuite2/UIElements/DisplayedLevelUpMessage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using StardewValley;

namespace UIInfoSuite2.UIElements
{
public class DisplayedLevelUpMessage
{
public void Draw(Rectangle levelUpIconRectangle, string levelUpMessage)
{
Vector2 playerLocalPosition = Game1.player.getLocalPosition(Game1.viewport);

Game1.spriteBatch.Draw(
Game1.mouseCursors,
Utility.ModifyCoordinatesForUIScale(new Vector2(
playerLocalPosition.X - 74,
playerLocalPosition.Y - 130)), levelUpIconRectangle,
Color.White,
0,
Vector2.Zero,
Game1.pixelZoom,
SpriteEffects.None,
0.85f);

Game1.drawWithBorder(
levelUpMessage,
Color.DarkSlateGray,
Color.PaleTurquoise,
Utility.ModifyCoordinatesForUIScale(new Vector2(
playerLocalPosition.X - 28,
playerLocalPosition.Y - 130)));
}
}
}
26 changes: 2 additions & 24 deletions UIInfoSuite2/UIElements/ExperienceBar.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Graphics;
using StardewModdingAPI;
using StardewModdingAPI.Enums;
using StardewModdingAPI.Events;
Expand Down Expand Up @@ -30,6 +29,7 @@ public class ExperienceBar : IDisposable
private readonly PerScreen<int> _experienceEarnedThisLevel = new(createNewState: () => -1);

private readonly PerScreen<DisplayedExperienceBar> _displayedExperienceBar = new(createNewState: () => new DisplayedExperienceBar());
private readonly PerScreen<DisplayedLevelUpMessage> _displayedLevelUpMessage = new(createNewState: () => new DisplayedLevelUpMessage());
private readonly PerScreen<List<DisplayedExperienceValue>> _displayedExperienceValues = new(createNewState: () => new List<DisplayedExperienceValue>());

private const int LevelUpVisibleTicks = 120;
Expand Down Expand Up @@ -239,29 +239,7 @@ private void OnRenderingHud(object sender, RenderingHudEventArgs e)
// Level up text
if (LevelUpAnimationEnabled && _levelUpVisibleTimer.Value != 0)
{
Vector2 playerLocalPosition = Game1.player.getLocalPosition(Game1.viewport);

Game1.spriteBatch.Draw(
Game1.mouseCursors,
Utility.ModifyCoordinatesForUIScale(new Vector2(
playerLocalPosition.X - 74,
playerLocalPosition.Y - 130)),
_levelUpIconRectangle.Value,
Color.White,
0,
Vector2.Zero,
Game1.pixelZoom,
SpriteEffects.None,
0.85f);

Game1.drawWithBorder(
_helper.SafeGetString(
LanguageKeys.LevelUp),
Color.DarkSlateGray,
Color.PaleTurquoise,
Utility.ModifyCoordinatesForUIScale(new Vector2(
playerLocalPosition.X - 28,
playerLocalPosition.Y - 130)));
_displayedLevelUpMessage.Value.Draw(_levelUpIconRectangle.Value, _helper.SafeGetString(LanguageKeys.LevelUp));
}

// Experience values
Expand Down

0 comments on commit c3a21d3

Please sign in to comment.