Added in status for time remaining for the machine summary menu.

This commit is contained in:
JoshuaNavarro 2019-09-16 16:33:19 -07:00
parent fcf27bdc52
commit 45aad966c0
5 changed files with 135 additions and 3 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 349 B

View File

@ -43,6 +43,10 @@ namespace Revitalize.Framework.Menus.Machines
private Texture2D energyTexture;
private Vector2 itemDisplayOffset;
private AnimatedButton clockSprite;
private Vector2 timeDisplayLocation;
private EnergyManager energy
{
get
@ -74,13 +78,17 @@ namespace Revitalize.Framework.Menus.Machines
this.objectSource = SourceObject;
this.backgroundColor = BackgroundColor;
this.energyTexture = new Texture2D(Game1.graphics.GraphicsDevice, 1, 1);
this.colorSwap();
this.energyMeterColorSwap();
this.timeDisplayLocation = new Vector2(this.xPositionOnScreen + (this.width * .1f), this.yPositionOnScreen + (this.height * .25f));
this.energyPosition = new Vector2(this.xPositionOnScreen + this.width - 128, this.yPositionOnScreen + this.height - 72 * 4);
this.batteryBackground = new AnimatedButton(new StardustCore.Animations.AnimatedSprite("BatteryFrame", this.energyPosition, new StardustCore.Animations.AnimationManager(TextureManager.GetExtendedTexture(ModCore.Manifest, "Menus.EnergyMenu", "BatteryFrame"), new StardustCore.Animations.Animation(0, 0, 32, 64)), Color.White), new Rectangle(0, 0, 32, 64), 4f);
this.battergyEnergyGuage = new AnimatedButton(new StardustCore.Animations.AnimatedSprite("BatteryEnergyGuage", this.energyPosition, new StardustCore.Animations.AnimationManager(TextureManager.GetExtendedTexture(ModCore.Manifest, "Menus.EnergyMenu", "BatteryEnergyGuage"), new StardustCore.Animations.Animation(0, 0, 32, 64)), Color.White), new Rectangle(0, 0, 32, 64), 4f);
this.itemDisplayOffset = ObjectUtilities.GetDimensionOffsetFromItem(this.objectSource);
this.clockSprite= new AnimatedButton(new StardustCore.Animations.AnimatedSprite("Time Remaining",this.timeDisplayLocation, new StardustCore.Animations.AnimationManager(TextureManager.GetExtendedTexture(ModCore.Manifest, "Menus", "Clock"), new StardustCore.Animations.Animation(0, 0, 18, 18)), Color.White), new Rectangle(0, 0, 18, 18), 2f);
}
public override void performHoverAction(int x, int y)
@ -91,12 +99,19 @@ namespace Revitalize.Framework.Menus.Machines
this.hoverText = "Energy: " + this.energy.energyDisplayString;
hovered = true;
}
if (this.clockSprite.containsPoint(x, y))
{
this.hoverText = "Time Remaining: " + System.Environment.NewLine + TimeUtilities.GetVerboseTimeString(this.objectSource.MinutesUntilReady);
hovered = true;
}
if (hovered == false)
{
this.hoverText = "";
}
}
@ -113,11 +128,15 @@ namespace Revitalize.Framework.Menus.Machines
if (this.shouldDrawBattery)
{
this.batteryBackground.draw(b, 1f, 1f);
this.colorSwap();
this.energyMeterColorSwap();
b.Draw(this.energyTexture, new Rectangle((int)this.energyPosition.X + (int)(11 * this.batteryBackground.scale), (int)this.energyPosition.Y + (int)(18 * this.batteryBackground.scale)+ (int)(46 * this.batteryBackground.scale), (int)((9 * this.batteryBackground.scale)), (int)(46 * this.batteryBackground.scale * this.energy.energyPercentRemaining)), new Rectangle(0, 0, 1, 1), Color.White, 0f, new Vector2(0f,1f), SpriteEffects.None, 0.2f);
this.battergyEnergyGuage.draw(b, 1f, 1f);
}
this.clockSprite.draw(b);
b.DrawString(Game1.smallFont,TimeUtilities.GetTimeString(this.objectSource.MinutesUntilReady), this.timeDisplayLocation+new Vector2(0,36f), Color.Black);
this.objectSource.drawFullyInMenu(b, new Vector2((int)(this.xPositionOnScreen + (this.width / 2) - (this.itemDisplayOffset.X / 2)), (int)(this.yPositionOnScreen + 128f)), .24f);
Vector2 nameOffset = Game1.dialogueFont.MeasureString(this.objectSource.DisplayName);
@ -138,7 +157,7 @@ namespace Revitalize.Framework.Menus.Machines
/// Swaps the color for the energy bar meter depending on how much energy is left.
/// </summary>
private void colorSwap()
private void energyMeterColorSwap()
{
Color col = new Color();
//ModCore.log("Energy is: " + this.energy.energyPercentRemaining);
@ -169,5 +188,7 @@ namespace Revitalize.Framework.Menus.Machines
};
this.energyTexture.SetData<Color>(color);
}
}
}

View File

@ -3,11 +3,94 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using PyTK.Types;
namespace Revitalize.Framework.Utilities
{
public class TimeUtilities
{
/// <summary>
/// Wraps SDV time to be able to display it better.
/// </summary>
public class StardewTime
{
public int days;
public int hours;
public int minutes;
public int weeks;
public int seasons;
public int years;
public StardewTime()
{
}
public StardewTime(int Minutes)
{
this.parse(Minutes);
}
private void parse(int Minutes)
{
this.years = Minutes / 60 / 24 / 7 / 4 / 4;
Minutes -= (Minutes / 60 / 24 / 7 / 4 / 4);
this.seasons = Minutes / 60 / 24 / 7 / 4;
Minutes -= (Minutes / 60 / 24 / 7 / 4);
this.weeks = Minutes / 60 / 24 / 7;
Minutes -= (Minutes / 60 / 24 / 7);
this.days = Minutes / 60 / 24;
Minutes -= (Minutes / 60 / 24);
this.hours = Minutes / 60;
this.minutes -= (Minutes / 60);
this.minutes = Minutes;
}
public string GetTimeString()
{
StringBuilder b = new StringBuilder();
if (this.years > 0) b.Append("Y: " + this.years);
if (this.seasons > 0) b.Append("S: " + this.seasons);
if (this.weeks > 0) b.Append("W: " + this.weeks);
if (this.days > 0) b.Append("D: " + this.days);
if (this.hours > 0) b.Append("H: " + this.hours);
if (this.minutes > 0) b.Append("M: " + this.minutes);
else
{
b.Append("M: " + 0);
}
return b.ToString();
}
public string GetVerboseString()
{
StringBuilder b = new StringBuilder();
if (this.years > 0) b.Append("Years: " + this.years);
if (this.seasons > 0) b.Append("Seasons: " + this.seasons);
if (this.weeks > 0) b.Append("Weeks: " + this.weeks);
if (this.days > 0) b.Append("Days: " + this.days);
if (this.hours > 0) b.Append("Hours: " + this.hours);
if (this.minutes > 0) b.Append("Minutes: " + this.minutes);
else
{
b.Append("Minutes: " + 0);
}
return b.ToString();
}
}
/// <summary>
/// Gets the minutes for the time passed in.
/// </summary>
/// <param name="Days"></param>
/// <param name="Hours"></param>
/// <param name="Minutes"></param>
/// <returns></returns>
public static int GetMinutesFromTime(int Days, int Hours, int Minutes)
{
int amount=0;
@ -16,5 +99,27 @@ namespace Revitalize.Framework.Utilities
amount += Minutes;
return amount;
}
/// <summary>
/// Gets a shortened string representing the time.
/// </summary>
/// <param name="Minutes"></param>
/// <returns></returns>
public static string GetTimeString(int Minutes)
{
StardewTime s = new StardewTime(Minutes);
return s.GetTimeString();
}
/// <summary>
/// Gets a more detailed string representation of the time.
/// </summary>
/// <param name="Minutes"></param>
/// <returns></returns>
public static string GetVerboseTimeString(int Minutes)
{
StardewTime s = new StardewTime(Minutes);
return s.GetVerboseString();
}
}
}

View File

@ -7,6 +7,9 @@ using StardewValley;
namespace Revitalize.Framework.Utilities
{
/// <summary>
/// Deals with usefull utilities to help determine the weather and the effects it has.
/// </summary>
public class WeatherUtilities
{

View File

@ -375,6 +375,9 @@
<Content Include="Content\Graphics\Menus\InventoryMenu\TrashButton.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\Graphics\Menus\Misc\Clock.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\Graphics\Menus\Misc\MenuTab.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>