2017-07-20 11:51:05 +08:00
|
|
|
|
using Microsoft.Xna.Framework;
|
|
|
|
|
using UIInfoSuite.Extensions;
|
|
|
|
|
using StardewModdingAPI.Events;
|
|
|
|
|
using StardewValley;
|
|
|
|
|
using StardewValley.Menus;
|
|
|
|
|
using StardewValley.TerrainFeatures;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using StardewValley.Objects;
|
|
|
|
|
using StardewModdingAPI;
|
2017-11-28 13:27:52 +08:00
|
|
|
|
using StardewValley.Locations;
|
|
|
|
|
using StardewValley.Buildings;
|
2017-07-20 11:51:05 +08:00
|
|
|
|
|
|
|
|
|
namespace UIInfoSuite.UIElements
|
|
|
|
|
{
|
|
|
|
|
class ShowCropAndBarrelTime : IDisposable
|
|
|
|
|
{
|
|
|
|
|
private Dictionary<int, String> _indexOfCropNames = new Dictionary<int, string>();
|
|
|
|
|
private StardewValley.Object _currentTile;
|
|
|
|
|
private TerrainFeature _terrain;
|
2017-11-28 13:27:52 +08:00
|
|
|
|
private Building _currentTileBuilding = null;
|
2017-07-20 11:51:05 +08:00
|
|
|
|
private readonly IModHelper _helper;
|
|
|
|
|
|
|
|
|
|
public ShowCropAndBarrelTime(IModHelper helper)
|
|
|
|
|
{
|
|
|
|
|
_helper = helper;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ToggleOption(bool showCropAndBarrelTimes)
|
|
|
|
|
{
|
|
|
|
|
GraphicsEvents.OnPreRenderHudEvent -= DrawHoverTooltip;
|
|
|
|
|
GameEvents.FourthUpdateTick -= GetTileUnderCursor;
|
|
|
|
|
|
|
|
|
|
if (showCropAndBarrelTimes)
|
|
|
|
|
{
|
|
|
|
|
GraphicsEvents.OnPreRenderHudEvent += DrawHoverTooltip;
|
|
|
|
|
GameEvents.FourthUpdateTick += GetTileUnderCursor;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void GetTileUnderCursor(object sender, EventArgs e)
|
|
|
|
|
{
|
2017-11-28 13:27:52 +08:00
|
|
|
|
if (Game1.currentLocation is BuildableGameLocation buildableLocation)
|
|
|
|
|
{
|
|
|
|
|
_currentTileBuilding = buildableLocation.getBuildingAt(Game1.currentCursorTile);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_currentTileBuilding = null;
|
|
|
|
|
}
|
2018-05-06 12:21:18 +08:00
|
|
|
|
|
|
|
|
|
if (Game1.currentLocation != null)
|
|
|
|
|
{
|
|
|
|
|
if (Game1.currentLocation.Objects == null ||
|
|
|
|
|
!Game1.currentLocation.Objects.TryGetValue(Game1.currentCursorTile, out _currentTile))
|
|
|
|
|
{
|
|
|
|
|
_currentTile = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Game1.currentLocation.terrainFeatures == null ||
|
|
|
|
|
!Game1.currentLocation.terrainFeatures.TryGetValue(Game1.currentCursorTile, out _terrain))
|
|
|
|
|
{
|
2018-07-16 00:50:29 +08:00
|
|
|
|
if (_currentTile is IndoorPot pot &&
|
|
|
|
|
pot.hoeDirt.Value != null)
|
|
|
|
|
{
|
|
|
|
|
_terrain = pot.hoeDirt.Value;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_terrain = null;
|
|
|
|
|
}
|
2018-05-06 12:21:18 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_currentTile = null;
|
|
|
|
|
_terrain = null;
|
|
|
|
|
}
|
2017-07-20 11:51:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
ToggleOption(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void DrawHoverTooltip(object sender, EventArgs e)
|
|
|
|
|
{
|
2017-11-28 13:27:52 +08:00
|
|
|
|
if (_currentTileBuilding != null)
|
|
|
|
|
{
|
|
|
|
|
if (_currentTileBuilding is Mill millBuilding)
|
|
|
|
|
{
|
2018-05-06 12:21:18 +08:00
|
|
|
|
if (millBuilding.input.Value != null)
|
2017-11-28 13:27:52 +08:00
|
|
|
|
{
|
2018-05-06 12:21:18 +08:00
|
|
|
|
if (!millBuilding.input.Value.isEmpty())
|
2017-11-28 13:27:52 +08:00
|
|
|
|
{
|
2018-05-06 12:21:18 +08:00
|
|
|
|
int wheatCount = 0;
|
|
|
|
|
int beetCount = 0;
|
|
|
|
|
|
|
|
|
|
foreach (var item in millBuilding.input.Value.items)
|
2017-11-28 13:27:52 +08:00
|
|
|
|
{
|
2018-05-06 12:21:18 +08:00
|
|
|
|
if (item != null &&
|
|
|
|
|
!String.IsNullOrEmpty(item.Name))
|
|
|
|
|
{
|
|
|
|
|
switch (item.Name)
|
|
|
|
|
{
|
|
|
|
|
case "Wheat": wheatCount = item.Stack; break;
|
|
|
|
|
case "Beet": beetCount = item.Stack; break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-11-28 13:27:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-05-06 12:21:18 +08:00
|
|
|
|
StringBuilder builder = new StringBuilder();
|
2017-11-28 13:27:52 +08:00
|
|
|
|
|
|
|
|
|
if (wheatCount > 0)
|
2018-05-06 12:21:18 +08:00
|
|
|
|
builder.Append(wheatCount + " wheat");
|
2017-11-28 13:27:52 +08:00
|
|
|
|
|
2018-05-06 12:21:18 +08:00
|
|
|
|
if (beetCount > 0)
|
|
|
|
|
{
|
|
|
|
|
if (wheatCount > 0)
|
|
|
|
|
builder.Append(Environment.NewLine);
|
|
|
|
|
builder.Append(beetCount + " beets");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (builder.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
IClickableMenu.drawHoverText(
|
|
|
|
|
Game1.spriteBatch,
|
|
|
|
|
builder.ToString(),
|
|
|
|
|
Game1.smallFont);
|
|
|
|
|
}
|
2017-11-28 13:27:52 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (_currentTile != null &&
|
2018-05-06 12:21:18 +08:00
|
|
|
|
(!_currentTile.bigCraftable.Value ||
|
|
|
|
|
_currentTile.MinutesUntilReady > 0))
|
2017-07-20 11:51:05 +08:00
|
|
|
|
{
|
2018-05-06 12:21:18 +08:00
|
|
|
|
if (_currentTile.bigCraftable.Value &&
|
|
|
|
|
_currentTile.MinutesUntilReady > 0 &&
|
2018-08-20 05:57:45 +08:00
|
|
|
|
_currentTile.heldObject.Value != null &&
|
2017-07-20 11:51:05 +08:00
|
|
|
|
_currentTile.Name != "Heater")
|
|
|
|
|
{
|
|
|
|
|
StringBuilder hoverText = new StringBuilder();
|
2018-07-16 00:50:29 +08:00
|
|
|
|
hoverText.AppendLine(_currentTile.heldObject.Value.DisplayName);
|
2018-08-20 05:57:45 +08:00
|
|
|
|
|
2017-07-20 11:51:05 +08:00
|
|
|
|
if (_currentTile is Cask)
|
|
|
|
|
{
|
|
|
|
|
Cask currentCask = _currentTile as Cask;
|
2018-05-06 12:21:18 +08:00
|
|
|
|
hoverText.Append((int)(currentCask.daysToMature.Value / currentCask.agingRate.Value))
|
2017-07-20 11:51:05 +08:00
|
|
|
|
.Append(" " + _helper.SafeGetString(
|
|
|
|
|
LanguageKeys.DaysToMature));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2018-05-06 12:21:18 +08:00
|
|
|
|
int hours = _currentTile.MinutesUntilReady / 60;
|
|
|
|
|
int minutes = _currentTile.MinutesUntilReady % 60;
|
2017-07-20 11:51:05 +08:00
|
|
|
|
if (hours > 0)
|
|
|
|
|
hoverText.Append(hours).Append(" ")
|
|
|
|
|
.Append(_helper.SafeGetString(
|
|
|
|
|
LanguageKeys.Hours))
|
|
|
|
|
.Append(", ");
|
|
|
|
|
hoverText.Append(minutes).Append(" ")
|
|
|
|
|
.Append(_helper.SafeGetString(
|
|
|
|
|
LanguageKeys.Minutes));
|
|
|
|
|
}
|
|
|
|
|
IClickableMenu.drawHoverText(
|
|
|
|
|
Game1.spriteBatch,
|
|
|
|
|
hoverText.ToString(),
|
|
|
|
|
Game1.smallFont);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (_terrain != null)
|
|
|
|
|
{
|
|
|
|
|
if (_terrain is HoeDirt)
|
|
|
|
|
{
|
|
|
|
|
HoeDirt hoeDirt = _terrain as HoeDirt;
|
|
|
|
|
if (hoeDirt.crop != null &&
|
2018-05-06 12:21:18 +08:00
|
|
|
|
!hoeDirt.crop.dead.Value)
|
2017-07-20 11:51:05 +08:00
|
|
|
|
{
|
|
|
|
|
int num = 0;
|
|
|
|
|
|
2018-05-06 12:21:18 +08:00
|
|
|
|
if (hoeDirt.crop.fullyGrown.Value &&
|
|
|
|
|
hoeDirt.crop.dayOfCurrentPhase.Value > 0)
|
2017-07-20 11:51:05 +08:00
|
|
|
|
{
|
2018-05-06 12:21:18 +08:00
|
|
|
|
num = hoeDirt.crop.dayOfCurrentPhase.Value;
|
2017-07-20 11:51:05 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < hoeDirt.crop.phaseDays.Count - 1; ++i)
|
|
|
|
|
{
|
2018-05-06 12:21:18 +08:00
|
|
|
|
if (hoeDirt.crop.currentPhase.Value == i)
|
|
|
|
|
num -= hoeDirt.crop.dayOfCurrentPhase.Value;
|
2017-07-20 11:51:05 +08:00
|
|
|
|
|
2018-05-06 12:21:18 +08:00
|
|
|
|
if (hoeDirt.crop.currentPhase.Value <= i)
|
2017-07-20 11:51:05 +08:00
|
|
|
|
num += hoeDirt.crop.phaseDays[i];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-06 12:21:18 +08:00
|
|
|
|
if (hoeDirt.crop.indexOfHarvest.Value > 0)
|
2017-07-20 11:51:05 +08:00
|
|
|
|
{
|
2018-05-06 12:21:18 +08:00
|
|
|
|
String hoverText = _indexOfCropNames.SafeGet(hoeDirt.crop.indexOfHarvest.Value);
|
2017-07-20 11:51:05 +08:00
|
|
|
|
if (String.IsNullOrEmpty(hoverText))
|
|
|
|
|
{
|
2018-05-06 12:21:18 +08:00
|
|
|
|
hoverText = new StardewValley.Object(new Debris(hoeDirt.crop.indexOfHarvest.Value, Vector2.Zero, Vector2.Zero).chunkType.Value, 1).DisplayName;
|
|
|
|
|
_indexOfCropNames.Add(hoeDirt.crop.indexOfHarvest.Value, hoverText);
|
2017-07-20 11:51:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
StringBuilder finalHoverText = new StringBuilder();
|
|
|
|
|
finalHoverText.Append(hoverText).Append(": ");
|
|
|
|
|
if (num > 0)
|
|
|
|
|
{
|
|
|
|
|
finalHoverText.Append(num).Append(" ")
|
|
|
|
|
.Append(_helper.SafeGetString(
|
|
|
|
|
LanguageKeys.Days));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
finalHoverText.Append(_helper.SafeGetString(
|
|
|
|
|
LanguageKeys.ReadyToHarvest));
|
|
|
|
|
}
|
|
|
|
|
IClickableMenu.drawHoverText(
|
|
|
|
|
Game1.spriteBatch,
|
|
|
|
|
finalHoverText.ToString(),
|
|
|
|
|
Game1.smallFont);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (_terrain is FruitTree)
|
|
|
|
|
{
|
|
|
|
|
FruitTree tree = _terrain as FruitTree;
|
2018-07-16 00:50:29 +08:00
|
|
|
|
var text = new StardewValley.Object(new Debris(tree.indexOfFruit.Value, Vector2.Zero, Vector2.Zero).chunkType.Value, 1).DisplayName;
|
2018-05-06 12:21:18 +08:00
|
|
|
|
if (tree.daysUntilMature.Value > 0)
|
2017-07-20 11:51:05 +08:00
|
|
|
|
{
|
2018-07-16 00:50:29 +08:00
|
|
|
|
text += Environment.NewLine + tree.daysUntilMature.Value + " " +
|
2017-07-20 11:51:05 +08:00
|
|
|
|
_helper.SafeGetString(
|
2018-07-16 00:50:29 +08:00
|
|
|
|
LanguageKeys.DaysToMature);
|
|
|
|
|
|
2017-07-20 11:51:05 +08:00
|
|
|
|
}
|
2018-07-16 00:50:29 +08:00
|
|
|
|
IClickableMenu.drawHoverText(
|
|
|
|
|
Game1.spriteBatch,
|
|
|
|
|
text,
|
|
|
|
|
Game1.smallFont);
|
2017-07-20 11:51:05 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|