Skip to content

Commit

Permalink
Merge pull request #465 from Zamiell/trees-tooltip-2
Browse files Browse the repository at this point in the history
feat: tree stage tooltip
  • Loading branch information
drewhoener authored Apr 9, 2024
2 parents 8eb68a1 + a57fa6d commit 3adad50
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 25 deletions.
3 changes: 3 additions & 0 deletions UIInfoSuite2/Infrastructure/LanguageKeys.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ public static class LanguageKeys
public const string Hours = "Hours";
public const string Minutes = "Minutes";
public const string ReadyToHarvest = "ReadyToHarvest";
public const string With = "With";
public const string Fertilized = "Fertilized";
public const string Tree = "Tree";
public const string TodaysRecipe = "TodaysRecipe";
public const string TravelingMerchantIsInTown = "TravelingMerchantIsInTown";
public const string RainNextDay = "RainNextDay";
Expand Down
6 changes: 3 additions & 3 deletions UIInfoSuite2/Options/ModOptionsPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ private void OnMenuChanged(object sender, MenuChangedEventArgs e)
{
if (e.NewMenu is GameMenu)
{
xPositionOnScreen = Game1.activeClickableMenu.xPositionOnScreen;
yPositionOnScreen = Game1.activeClickableMenu.yPositionOnScreen + 10;
height = Game1.activeClickableMenu.height;
xPositionOnScreen = e.NewMenu.xPositionOnScreen;
yPositionOnScreen = e.NewMenu.yPositionOnScreen + 10;
height = e.NewMenu.height;

for (var i = 0; i < _optionSlots.Count; ++i)
{
Expand Down
118 changes: 97 additions & 21 deletions UIInfoSuite2/UIElements/ShowCropAndBarrelTime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ namespace UIInfoSuite2.UIElements;

internal class ShowCropAndBarrelTime : IDisposable
{
private const int MAX_TREE_GROWTH_STAGE = 5;

private readonly PerScreen<Object> _currentTile = new();
private readonly PerScreen<Building> _currentTileBuilding = new();
private readonly IModHelper _helper;
Expand Down Expand Up @@ -53,7 +55,7 @@ public void ToggleOption(bool showCropAndBarrelTimes)
/// <summary>Raised after the game state is updated (≈60 times per second).</summary>
/// <param name="sender">The event sender.</param>
/// <param name="e">The event arguments.</param>
private void OnUpdateTicked(object sender, UpdateTickedEventArgs e)
private void OnUpdateTicked(object? sender, UpdateTickedEventArgs e)
{
if (!e.IsMultipleOf(4))
{
Expand Down Expand Up @@ -112,7 +114,7 @@ private void OnUpdateTicked(object sender, UpdateTickedEventArgs e)
/// </summary>
/// <param name="sender">The event sender.</param>
/// <param name="e">The event arguments.</param>
private void OnRenderingHud(object sender, RenderingHudEventArgs e)
private void OnRenderingHud(object? sender, RenderingHudEventArgs e)
{
if (Game1.activeClickableMenu != null)
{
Expand All @@ -138,9 +140,9 @@ private void OnRenderingHud(object sender, RenderingHudEventArgs e)
currentTileBuilding.buildingChests.Count > inputKey &&
!currentTileBuilding.buildingChests[inputKey].isEmpty())
{
var wheatCount = 0;
var beetCount = 0;
var unmilledriceCount = 0;
int wheatCount = 0;
int beetCount = 0;
int unmilledriceCount = 0;

foreach (Item item in currentTileBuilding.buildingChests[inputKey].Items)
{
Expand Down Expand Up @@ -221,10 +223,9 @@ private void OnRenderingHud(object sender, RenderingHudEventArgs e)

hoverText.AppendLine(currentTile.heldObject.Value.DisplayName);

if (currentTile is Cask)
if (currentTile is Cask cask)
{
var currentCask = currentTile as Cask;
hoverText.Append((int)(currentCask.daysToMature.Value / currentCask.agingRate.Value))
hoverText.Append((int)(cask.daysToMature.Value / cask.agingRate.Value))
.Append(" " + _helper.SafeGetString(LanguageKeys.DaysToMature));
}
else
Expand Down Expand Up @@ -290,20 +291,19 @@ private void OnRenderingHud(object sender, RenderingHudEventArgs e)
}
else if (terrain != null)
{
if (terrain is HoeDirt)
if (terrain is HoeDirt hoeDirt)
{
var hoeDirt = terrain as HoeDirt;
if (hoeDirt.crop != null && !hoeDirt.crop.dead.Value)
{
var num = 0;
int num = 0;

if (hoeDirt.crop.fullyGrown.Value && hoeDirt.crop.dayOfCurrentPhase.Value > 0)
{
num = hoeDirt.crop.dayOfCurrentPhase.Value;
}
else
{
for (var i = 0; i < hoeDirt.crop.phaseDays.Count - 1; ++i)
for (int i = 0; i < hoeDirt.crop.phaseDays.Count - 1; ++i)
{
if (hoeDirt.crop.currentPhase.Value == i)
{
Expand All @@ -330,6 +330,13 @@ private void OnRenderingHud(object sender, RenderingHudEventArgs e)
hoverText.Append(_helper.SafeGetString(LanguageKeys.ReadyToHarvest));
}

if (!string.IsNullOrEmpty(hoeDirt.fertilizer.Value))
{
string fertilizerName = ItemRegistry.GetData(hoeDirt.fertilizer.Value).DisplayName ?? "Unknown Fertilizer";
string withText = _helper.SafeGetString(LanguageKeys.With);
hoverText.Append($"\n({withText} {fertilizerName})");
}

if (Game1.options.gamepadControls && Game1.timerUntilMouseFade <= 0)
{
Vector2 tilePosition = Utility.ModifyCoordinatesForUIScale(
Expand All @@ -349,17 +356,66 @@ private void OnRenderingHud(object sender, RenderingHudEventArgs e)
}
}
}
else if (terrain is FruitTree tree)
else if (terrain is Tree tree)
{
string treeTypeName = GetTreeTypeName(tree.treeType.Value);
string treeText = _helper.SafeGetString(LanguageKeys.Tree);
string treeName = $"{treeTypeName} {treeText}";
if (tree.stump.Value)
{
treeName += " (stump)";
}

string text;

if (tree.growthStage.Value < MAX_TREE_GROWTH_STAGE)
{
text = $"{treeName}\nstage {tree.growthStage.Value} / {MAX_TREE_GROWTH_STAGE}";

if (tree.fertilized.Value)
{
string fertilizedText = _helper.SafeGetString(LanguageKeys.Fertilized);
text += $"\n({fertilizedText})";
}
}
else
{
text = treeName;
}

if (Game1.options.gamepadControls && Game1.timerUntilMouseFade <= 0)
{
Vector2 tilePosition =
Utility.ModifyCoordinatesForUIScale(Game1.GlobalToLocal(terrain.Tile * Game1.tileSize));
overrideX = (int)(tilePosition.X + Utility.ModifyCoordinateForUIScale(32));
overrideY = (int)(tilePosition.Y + Utility.ModifyCoordinateForUIScale(32));
}

IClickableMenu.drawHoverText(
Game1.spriteBatch,
text,
Game1.smallFont,
overrideX: overrideX,
overrideY: overrideY
);
}
else if (terrain is FruitTree fruitTree)
{
string itemIdOfFruit =
tree.GetData().Fruit.First().ItemId; // TODO 1.6: Might be broken because of more than one item.
string? text = ItemRegistry.GetData(itemIdOfFruit).DisplayName;
if (tree.daysUntilMature.Value > 0)
string itemIdOfFruit = fruitTree.GetData().Fruit.First().ItemId; // TODO 1.6: Might be broken because of more than one item.
string fruitName = ItemRegistry.GetData(itemIdOfFruit).DisplayName ?? "Unknown";
string treeText = _helper.SafeGetString(LanguageKeys.Tree);
string treeName = $"{fruitName} {treeText}";

string text;

if (fruitTree.daysUntilMature.Value > 0)
{
string daysToMatureText = _helper.SafeGetString(LanguageKeys.DaysToMature);
text = $"{treeName}\n{fruitTree.daysUntilMature.Value} {daysToMatureText}";
}
else
{
text += Environment.NewLine +
tree.daysUntilMature.Value +
" " +
_helper.SafeGetString(LanguageKeys.DaysToMature);
text = treeName;
}

if (Game1.options.gamepadControls && Game1.timerUntilMouseFade <= 0)
Expand Down Expand Up @@ -412,6 +468,26 @@ private void OnRenderingHud(object sender, RenderingHudEventArgs e)
}
}

// See: https://stardewvalleywiki.com/Trees
private static string GetTreeTypeName(string treeType)
{
switch (treeType)
{
case "1": return "Oak";
case "2": return "Maple";
case "3": return "Pine";
case "6": return "Palm";
case "7": return "Mushroom";
case "8": return "Mahogany";
case "9": return "Palm (Jungle)";
case "10": return "Green Rain Type 1";
case "11": return "Green Rain Type 2";
case "12": return "Green Rain Type 3";
case "13": return "Mystic";
default: return $"Unknown (#{treeType})";
}
}

private string? GetCropHarvestName(Crop crop)
{
if (crop.indexOfHarvest.Value is not null)
Expand Down
5 changes: 4 additions & 1 deletion UIInfoSuite2/i18n/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
"Minutes": "minutes",
//Harvest
"DaysToMature": "days to mature",
"ReadyToHarvest": "Ready To Harvest!",
"ReadyToHarvest": "Ready to harvest!",
"With": "with",
"Fertilized": "fertilized",
"Tree": "Tree",
//Display icons - General
"TodaysRecipe": "Today's Recipe: ",
"TravelingMerchantIsInTown": "Traveling merchant is in town!",
Expand Down

0 comments on commit 3adad50

Please sign in to comment.