Started work on the machine summary menu.
This commit is contained in:
parent
82d4fceabf
commit
c7b6ba8495
Binary file not shown.
After Width: | Height: | Size: 175 B |
Binary file not shown.
After Width: | Height: | Size: 140 B |
Binary file not shown.
After Width: | Height: | Size: 353 B |
Binary file not shown.
After Width: | Height: | Size: 173 B |
|
@ -94,6 +94,29 @@ namespace Revitalize.Framework.Energy
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the energy remaining as a percent value.
|
||||
/// </summary>
|
||||
public double energyPercentRemaining
|
||||
{
|
||||
get
|
||||
{
|
||||
return (double)this.remainingEnergy / (double)this.maxEnergy;
|
||||
}
|
||||
}
|
||||
|
||||
public string energyDisplayString
|
||||
{
|
||||
get
|
||||
{
|
||||
StringBuilder b = new StringBuilder();
|
||||
b.Append(this.remainingEnergy);
|
||||
b.Append("/");
|
||||
b.Append(this.maxEnergy);
|
||||
return b.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
public EnergyManager()
|
||||
{
|
||||
|
||||
|
|
|
@ -0,0 +1,163 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Revitalize.Framework.Energy;
|
||||
using Revitalize.Framework.Objects;
|
||||
using Revitalize.Framework.Utilities;
|
||||
using StardewValley;
|
||||
using StardustCore.UIUtilities;
|
||||
using StardustCore.UIUtilities.MenuComponents.ComponentsV2.Buttons;
|
||||
|
||||
namespace Revitalize.Framework.Menus
|
||||
{
|
||||
public class MachineSummaryMenu : IClickableMenuExtended
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// The custom object to be gathering information from.
|
||||
/// </summary>
|
||||
private CustomObject objectSource;
|
||||
/// <summary>
|
||||
/// The background color for the menu.
|
||||
/// </summary>
|
||||
private Color backgroundColor;
|
||||
/// <summary>
|
||||
/// The hover text to display for the menu.
|
||||
/// </summary>
|
||||
private string hoverText;
|
||||
|
||||
|
||||
private AnimatedButton batteryBackground;
|
||||
private AnimatedButton battergyEnergyGuage;
|
||||
private Vector2 energyPosition;
|
||||
private Texture2D energyTexture;
|
||||
private Rectangle energyMeterBounds;
|
||||
private Vector2 itemDisplayOffset;
|
||||
|
||||
private EnergyManager energy
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.objectSource.EnergyManager;
|
||||
}
|
||||
}
|
||||
|
||||
public MachineSummaryMenu()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public MachineSummaryMenu(int x, int y, int width, int height, Color BackgroundColor, CustomObject SourceObject):base(x,y,width,height,false)
|
||||
{
|
||||
|
||||
this.objectSource = SourceObject;
|
||||
this.backgroundColor = BackgroundColor;
|
||||
this.energyTexture = new Texture2D(Game1.graphics.GraphicsDevice, 1, 1);
|
||||
this.colorSwap();
|
||||
|
||||
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=this.getDimensionOffsetFromItem();
|
||||
}
|
||||
|
||||
public override void performHoverAction(int x, int y)
|
||||
{
|
||||
bool hovered = false;
|
||||
if (this.batteryBackground.containsPoint(x, y))
|
||||
{
|
||||
this.hoverText ="Energy: "+this.energy.energyDisplayString;
|
||||
hovered = true;
|
||||
}
|
||||
|
||||
if (hovered == false)
|
||||
{
|
||||
this.hoverText = "";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Draws the menu to the screen.
|
||||
/// </summary>
|
||||
/// <param name="b"></param>
|
||||
public override void draw(SpriteBatch b)
|
||||
{
|
||||
this.drawDialogueBoxBackground(this.xPositionOnScreen, this.yPositionOnScreen, this.width, this.height, this.backgroundColor);
|
||||
|
||||
this.batteryBackground.draw(b, 1f, 1f);
|
||||
this.colorSwap();
|
||||
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)(9*this.batteryBackground.scale), (int)(46*this.batteryBackground.scale)), new Rectangle(0, 0, 1, 1), Color.White, 0f, Vector2.Zero, SpriteEffects.None, 0.2f);
|
||||
this.battergyEnergyGuage.draw(b, 1f, 1f);
|
||||
|
||||
|
||||
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);
|
||||
|
||||
b.DrawString(Game1.dialogueFont, this.objectSource.DisplayName, new Vector2(this.xPositionOnScreen + (this.width / 2)-nameOffset.X/2, (this.yPositionOnScreen + 150f)) + new Vector2(0,ObjectUtilities.GetHeightOffsetFromItem(this.objectSource)), Color.Black);
|
||||
|
||||
if (string.IsNullOrEmpty(this.hoverText) == false)
|
||||
{
|
||||
IClickableMenuExtended.drawHoverText(b, this.hoverText, Game1.dialogueFont);
|
||||
}
|
||||
|
||||
|
||||
this.drawMouse(b);
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void colorSwap()
|
||||
{
|
||||
Color col = new Color();
|
||||
ModCore.log("Energy is: " + this.energy.energyPercentRemaining);
|
||||
if (this.energy.energyPercentRemaining > .75d)
|
||||
{
|
||||
col = Color.Green;
|
||||
}
|
||||
else if (this.energy.energyPercentRemaining > .5d && this.energy.energyPercentRemaining <= .75d)
|
||||
{
|
||||
col = Color.GreenYellow;
|
||||
}
|
||||
else if(this.energy.energyPercentRemaining>.25d && this.energy.energyPercentRemaining <= .5d)
|
||||
{
|
||||
col = Color.Yellow;
|
||||
}
|
||||
else if (this.energy.energyPercentRemaining > .10d && this.energy.energyPercentRemaining <= .25d)
|
||||
{
|
||||
col = Color.Orange;
|
||||
}
|
||||
else
|
||||
{
|
||||
col = Color.Red;
|
||||
}
|
||||
|
||||
Color[] color = new Color[1]
|
||||
{
|
||||
col
|
||||
};
|
||||
this.energyTexture.SetData<Color>(color);
|
||||
}
|
||||
|
||||
|
||||
private Vector2 getDimensionOffsetFromItem()
|
||||
{
|
||||
if (ObjectUtilities.IsSameType(typeof(StardewValley.Object), this.objectSource.GetType()))
|
||||
{
|
||||
return new Vector2(64f, 64f);
|
||||
}
|
||||
if (ObjectUtilities.IsSameType(typeof(Revitalize.Framework.Objects.MultiTiledObject), this.objectSource.GetType()))
|
||||
{
|
||||
return new Vector2(64f * (this.objectSource as MultiTiledObject).Width, 64f * (this.objectSource as MultiTiledObject).Height);
|
||||
}
|
||||
|
||||
return new Vector2(64f, 64f);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -539,25 +539,6 @@ namespace Revitalize.Framework.Objects
|
|||
public override void draw(SpriteBatch spriteBatch, int xNonTile, int yNonTile, float layerDepth, float alpha = 1f)
|
||||
{
|
||||
this.updateInfo();
|
||||
/*
|
||||
if (Game1.eventUp && Game1.CurrentEvent.isTileWalkedOn(xNonTile / 64, yNonTile / 64))
|
||||
return;
|
||||
if ((int)(this.ParentSheetIndex) != 590 && (int)(this.Fragility) != 2)
|
||||
spriteBatch.Draw(Game1.shadowTexture, Game1.GlobalToLocal(Game1.viewport, new Vector2((float)(xNonTile + 32), (float)(yNonTile + 51 + 4))), new Microsoft.Xna.Framework.Rectangle?(Game1.shadowTexture.Bounds), Color.White * alpha, 0.0f, new Vector2((float)Game1.shadowTexture.Bounds.Center.X, (float)Game1.shadowTexture.Bounds.Center.Y), 4f, SpriteEffects.None, layerDepth - 1E-06f);
|
||||
SpriteBatch spriteBatch1 = spriteBatch;
|
||||
Texture2D objectSpriteSheet = Game1.objectSpriteSheet;
|
||||
Vector2 local = Game1.GlobalToLocal(Game1.viewport, new Vector2((float)(xNonTile + 32 + (this.shakeTimer > 0 ? Game1.random.Next(-1, 2) : 0)), (float)(yNonTile + 32 + (this.shakeTimer > 0 ? Game1.random.Next(-1, 2) : 0))));
|
||||
Microsoft.Xna.Framework.Rectangle? sourceRectangle = new Microsoft.Xna.Framework.Rectangle?(GameLocation.getSourceRectForObject(this.ParentSheetIndex));
|
||||
Color color = Color.White * alpha;
|
||||
double num1 = 0.0;
|
||||
Vector2 origin = new Vector2(8f, 8f);
|
||||
Vector2 scale = this.scale;
|
||||
double num2 = (double)this.scale.Y > 1.0 ? (double)this.getScale().Y : 4.0;
|
||||
int num3 = (bool)(this.flipped) ? 1 : 0;
|
||||
double num4 = (double)layerDepth;
|
||||
|
||||
spriteBatch1.Draw(this.displayTexture, local, this.animationManager.defaultDrawFrame.sourceRectangle, this.info.drawColor * alpha, (float)num1, origin, (float)4f, (SpriteEffects)num3, (float)num4);
|
||||
*/
|
||||
//The actual planter box being drawn.
|
||||
if (this.animationManager == null)
|
||||
{
|
||||
|
@ -591,6 +572,9 @@ namespace Revitalize.Framework.Objects
|
|||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>What happens when the object is drawn in a menu.</summary>
|
||||
public override void drawInMenu(SpriteBatch spriteBatch, Vector2 location, float scaleSize, float transparency, float layerDepth, bool drawStackNumber, Color c, bool drawShadow)
|
||||
{
|
||||
|
@ -637,6 +621,21 @@ namespace Revitalize.Framework.Objects
|
|||
//base.drawWhenHeld(spriteBatch, objectPosition, f);
|
||||
}
|
||||
|
||||
/// <summary>What happens when the object is drawn when held by a player.</summary>
|
||||
public virtual void drawFullyInMenu(SpriteBatch spriteBatch, Vector2 objectPosition,float Depth)
|
||||
{
|
||||
this.updateInfo();
|
||||
if (this.animationManager == null)
|
||||
{
|
||||
Revitalize.ModCore.log("Animation Manager Null");
|
||||
}
|
||||
if (this.displayTexture == null) Revitalize.ModCore.log("Display texture is null");
|
||||
|
||||
spriteBatch.Draw(this.displayTexture, objectPosition, this.animationManager.currentAnimation.sourceRectangle, this.info.drawColor, 0f, Vector2.Zero, (float)Game1.pixelZoom, SpriteEffects.None,Depth);
|
||||
//base.drawWhenHeld(spriteBatch, objectPosition, f);
|
||||
}
|
||||
|
||||
|
||||
public override void drawPlacementBounds(SpriteBatch spriteBatch, GameLocation location)
|
||||
{
|
||||
//Do nothing because this shouldn't be placeable anywhere.
|
||||
|
|
|
@ -404,6 +404,19 @@ namespace Revitalize.Framework.Objects
|
|||
|
||||
}
|
||||
|
||||
public override void drawFullyInMenu(SpriteBatch spriteBatch, Vector2 objectPosition, float Depth)
|
||||
{
|
||||
this.updateInfo();
|
||||
if (this.animationManager == null)
|
||||
{
|
||||
Revitalize.ModCore.log("Animation Manager Null");
|
||||
}
|
||||
if (this.displayTexture == null) Revitalize.ModCore.log("Display texture is null");
|
||||
|
||||
spriteBatch.Draw(this.displayTexture, objectPosition, this.animationManager.currentAnimation.sourceRectangle, this.info.drawColor, 0f, Vector2.Zero, (float)Game1.pixelZoom, SpriteEffects.None, Depth);
|
||||
//base.drawWhenHeld(spriteBatch, objectPosition, f);
|
||||
}
|
||||
|
||||
public override void updateInfo()
|
||||
{
|
||||
if (this.info == null || this.containerObject==null)
|
||||
|
|
|
@ -262,7 +262,13 @@ namespace Revitalize.Framework.Objects
|
|||
}
|
||||
}
|
||||
|
||||
public override void drawFullyInMenu(SpriteBatch spriteBatch, Vector2 objectPosition, float Depth)
|
||||
{
|
||||
this.updateInfo();
|
||||
|
||||
foreach (KeyValuePair<Vector2, StardewValley.Object> pair in this.objects)
|
||||
(pair.Value as CustomObject).drawFullyInMenu(spriteBatch, objectPosition + (pair.Key * Game1.tileSize),Depth);
|
||||
}
|
||||
|
||||
public virtual void pickUp(Farmer who)
|
||||
{
|
||||
|
|
|
@ -3,6 +3,8 @@ using System.Collections.Generic;
|
|||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Revitalize.Framework.Objects;
|
||||
|
||||
namespace Revitalize.Framework.Utilities
|
||||
{
|
||||
|
@ -44,5 +46,43 @@ namespace Revitalize.Framework.Utilities
|
|||
return potentialDescendant.IsSubclassOf(potentialBase);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a dimension offset depending on the size of the object passed in.
|
||||
/// </summary>
|
||||
/// <param name="obj"></param>
|
||||
/// <returns></returns>
|
||||
public static Vector2 GetDimensionOffsetFromItem(StardewValley.Object obj)
|
||||
{
|
||||
if (ObjectUtilities.IsSameType(typeof(StardewValley.Object), obj.GetType()))
|
||||
{
|
||||
return new Vector2(64f, 64f);
|
||||
}
|
||||
if (ObjectUtilities.IsSameType(typeof(Revitalize.Framework.Objects.MultiTiledObject), obj.GetType()))
|
||||
{
|
||||
return new Vector2(64f * (obj as MultiTiledObject).Width, 64f * (obj as MultiTiledObject).Height);
|
||||
}
|
||||
|
||||
return new Vector2(64f, 64f);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the height of an object.
|
||||
/// </summary>
|
||||
/// <param name="obj"></param>
|
||||
/// <returns></returns>
|
||||
public static float GetHeightOffsetFromItem(StardewValley.Object obj)
|
||||
{
|
||||
return GetDimensionOffsetFromItem(obj).Y;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the width of an item.
|
||||
/// </summary>
|
||||
/// <param name="obj"></param>
|
||||
/// <returns></returns>
|
||||
public static float GetWidthOffsetFromItem(StardewValley.Object obj)
|
||||
{
|
||||
return GetDimensionOffsetFromItem(obj).X;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -309,6 +309,10 @@ namespace Revitalize
|
|||
|
||||
TextureManager.AddTextureManager(Manifest, "Menus");
|
||||
TextureManager.GetTextureManager(Manifest, "Menus").searchForTextures(ModHelper, this.ModManifest, Path.Combine("Content", "Graphics", "Menus", "Misc"));
|
||||
|
||||
TextureManager.AddTextureManager(Manifest, "Menus.EnergyMenu");
|
||||
TextureManager.GetTextureManager(Manifest, "Menus.EnergyMenu").searchForTextures(ModHelper, this.ModManifest, Path.Combine("Content", "Graphics", "Menus", "EnergyMenu"));
|
||||
|
||||
TextureManager.AddTextureManager(Manifest, "CraftingMenu");
|
||||
TextureManager.GetTextureManager(Manifest, "CraftingMenu").searchForTextures(ModHelper, this.ModManifest, Path.Combine("Content", "Graphics", "Menus", "CraftingMenu"));
|
||||
|
||||
|
@ -326,6 +330,13 @@ namespace Revitalize
|
|||
Game1.currentMinigame = new Revitalize.Framework.Minigame.SeasideScrambleMinigame.SeasideScramble();
|
||||
}
|
||||
*/
|
||||
if (e.Button == SButton.U)
|
||||
{
|
||||
CustomObject test = ObjectManager.GetItem("SandBox");
|
||||
test.EnergyManager.maxEnergy = 100;
|
||||
test.EnergyManager.produceEnergy(100);
|
||||
if (Game1.activeClickableMenu == null) Game1.activeClickableMenu = new MachineSummaryMenu((Game1.viewport.Width/2)-400, 0, 800, 600,Color.White,test);
|
||||
}
|
||||
/*
|
||||
if (e.Button == SButton.Y)
|
||||
{
|
||||
|
|
|
@ -86,6 +86,7 @@
|
|||
<Compile Include="Framework\Illuminate\LightManager.cs" />
|
||||
<Compile Include="Framework\Menus\CraftingInformationPage.cs" />
|
||||
<Compile Include="Framework\Menus\CraftingMenuV1.cs" />
|
||||
<Compile Include="Framework\Menus\MachineSummaryMenu.cs" />
|
||||
<Compile Include="Framework\Menus\InventoryMenuPage.cs" />
|
||||
<Compile Include="Framework\Menus\InventoryTransferMenu.cs" />
|
||||
<Compile Include="Framework\Menus\MenuComponents\CraftingRecipeButton.cs" />
|
||||
|
@ -342,6 +343,18 @@
|
|||
<Content Include="Content\Graphics\Menus\CraftingMenu\CraftButton.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="Content\Graphics\Menus\EnergyMenu\BatteryEnergyGuage.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="Content\Graphics\Menus\EnergyMenu\BatteryEnergyMeter.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="Content\Graphics\Menus\EnergyMenu\BatteryFrame.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="Content\Graphics\Menus\EnergyMenu\LightningBolt.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="Content\Graphics\Menus\InventoryMenu\ItemBackground.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
|
|
Loading…
Reference in New Issue