diff --git a/GeneralMods/Revitalize/Framework/Menus/CraftingMenuV1.cs b/GeneralMods/Revitalize/Framework/Menus/CraftingMenuV1.cs index 996e3b1c..202207c5 100644 --- a/GeneralMods/Revitalize/Framework/Menus/CraftingMenuV1.cs +++ b/GeneralMods/Revitalize/Framework/Menus/CraftingMenuV1.cs @@ -258,7 +258,7 @@ namespace Revitalize.Framework.Menus } else { - Vector2 newPos = new Vector2(100 + (48) * (count + 1), this.yPositionOnScreen + (24 * 4) * (count + 1)); + Vector2 newPos = new Vector2(100 + (48), this.yPositionOnScreen + (24 * 4) * (count + 1)); Button.Position = newPos; this.CraftingTabs.Add(name, Button); this.craftingItemsToDisplay.Add(name, new List()); diff --git a/GeneralMods/Revitalize/Framework/Menus/InventoryTransferMenu.cs b/GeneralMods/Revitalize/Framework/Menus/InventoryTransferMenu.cs index a3edbeda..9870c167 100644 --- a/GeneralMods/Revitalize/Framework/Menus/InventoryTransferMenu.cs +++ b/GeneralMods/Revitalize/Framework/Menus/InventoryTransferMenu.cs @@ -209,7 +209,22 @@ namespace Revitalize.Framework.Menus } if (To.isFull == false) { - To.items.Add(From.activeItem); + // + bool addedItem = false; + for(int i = 0; i < To.items.Count; i++) + { + if (To.items[i] == null) + { + To.items[i] = From.activeItem; + addedItem = true; + break; + } + } + if (addedItem == false) + { + To.items.Add(From.activeItem); + } + From.items.Remove(From.activeItem); From.activeItem = null; From.populateClickableItems(); diff --git a/GeneralMods/Revitalize/Framework/Menus/Machines/MachineMenu.cs b/GeneralMods/Revitalize/Framework/Menus/Machines/MachineMenu.cs new file mode 100644 index 00000000..835bf21c --- /dev/null +++ b/GeneralMods/Revitalize/Framework/Menus/Machines/MachineMenu.cs @@ -0,0 +1,151 @@ +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 Microsoft.Xna.Framework.Input; +using StardewValley; +using StardustCore.UIUtilities; +using StardustCore.UIUtilities.MenuComponents.ComponentsV2.Buttons; + +namespace Revitalize.Framework.Menus.Machines +{ + public class MachineMenu : IClickableMenuExtended + { + + public Dictionary> menuPages; + public string currentTab; + public string hoverText; + + public IClickableMenuExtended CurrentMenu + { + get + { + if(string.IsNullOrEmpty(this.currentTab)) return null; + else + { + if (this.menuPages.ContainsKey(this.currentTab)) + { + return this.menuPages[this.currentTab].Value; + } + else + { + return null; + } + } + } + } + + + public MachineMenu() + { + + } + + public MachineMenu(int x, int y, int width, int height) : base(x, y, width, height, false) + { + this.menuPages = new Dictionary>(); + } + + public void addInMenuTab(string Name,AnimatedButton Button, IClickableMenuExtended Menu,bool DefaultTab=false) + { + int count = this.menuPages.Count; + + Vector2 newPos = new Vector2(208 + (24 * 2) * (count+1), this.yPositionOnScreen+(80)); + Button.Position = newPos; + this.menuPages.Add(Name,new KeyValuePair(Button, Menu)); + + if (DefaultTab) + { + this.currentTab = Name; + } + } + + public override void receiveLeftClick(int x, int y, bool playSound = true) + { + foreach (var v in this.menuPages) + { + if (v.Value.Key.containsPoint(x, y)) + { + this.currentTab = v.Key; + } + } + + if (this.CurrentMenu != null) + { + this.CurrentMenu.receiveLeftClick(x, y, playSound); + } + + + } + public override void receiveKeyPress(Keys key) + { + if (this.CurrentMenu != null) + { + this.CurrentMenu.receiveKeyPress(key); + } + } + + public override void performHoverAction(int x, int y) + { + + bool hovered = false; + + foreach(var v in this.menuPages) + { + if (v.Value.Key.containsPoint(x, y)) + { + this.hoverText = v.Key; + hovered = true; + } + } + + if (this.CurrentMenu != null) + { + this.CurrentMenu.performHoverAction(x, y); + } + + if (hovered == false) + { + this.hoverText = ""; + } + } + + public override void receiveRightClick(int x, int y, bool playSound = true) + { + if (this.CurrentMenu != null) + { + this.CurrentMenu.receiveRightClick(x, y,playSound); + } + } + + public override void update(GameTime time) + { + if (this.CurrentMenu != null) + { + this.CurrentMenu.update(time); + } + } + + public override void draw(SpriteBatch b) + { + foreach(KeyValuePair button in this.menuPages.Values) + { + button.Key.draw(b); + } + if (this.CurrentMenu != null) + { + this.CurrentMenu.draw(b); + } + + if (string.IsNullOrEmpty(this.hoverText) == false) + { + IClickableMenuExtended.drawHoverText(b, this.hoverText, Game1.dialogueFont); + } + + this.drawMouse(b); + } + } +} diff --git a/GeneralMods/Revitalize/Framework/Menus/MachineSummaryMenu.cs b/GeneralMods/Revitalize/Framework/Menus/Machines/MachineSummaryMenu.cs similarity index 87% rename from GeneralMods/Revitalize/Framework/Menus/MachineSummaryMenu.cs rename to GeneralMods/Revitalize/Framework/Menus/Machines/MachineSummaryMenu.cs index 9106f227..9f2b42f7 100644 --- a/GeneralMods/Revitalize/Framework/Menus/MachineSummaryMenu.cs +++ b/GeneralMods/Revitalize/Framework/Menus/Machines/MachineSummaryMenu.cs @@ -12,7 +12,7 @@ using StardewValley; using StardustCore.UIUtilities; using StardustCore.UIUtilities.MenuComponents.ComponentsV2.Buttons; -namespace Revitalize.Framework.Menus +namespace Revitalize.Framework.Menus.Machines { public class MachineSummaryMenu : IClickableMenuExtended { @@ -35,7 +35,6 @@ namespace Revitalize.Framework.Menus private AnimatedButton battergyEnergyGuage; private Vector2 energyPosition; private Texture2D energyTexture; - private Rectangle energyMeterBounds; private Vector2 itemDisplayOffset; private EnergyManager energy @@ -63,7 +62,7 @@ namespace Revitalize.Framework.Menus 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(); + this.itemDisplayOffset = ObjectUtilities.GetDimensionOffsetFromItem(this.objectSource); } public override void performHoverAction(int x, int y) @@ -112,11 +111,14 @@ namespace Revitalize.Framework.Menus } + /// + /// Swaps the color for the energy bar meter depending on how much energy is left. + /// private void colorSwap() { Color col = new Color(); - ModCore.log("Energy is: " + this.energy.energyPercentRemaining); + //ModCore.log("Energy is: " + this.energy.energyPercentRemaining); if (this.energy.energyPercentRemaining > .75d) { col = Color.Green; @@ -144,20 +146,5 @@ namespace Revitalize.Framework.Menus }; this.energyTexture.SetData(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); - } } } diff --git a/GeneralMods/Revitalize/ModCore.cs b/GeneralMods/Revitalize/ModCore.cs index 897e2399..98f8a122 100644 --- a/GeneralMods/Revitalize/ModCore.cs +++ b/GeneralMods/Revitalize/ModCore.cs @@ -31,6 +31,7 @@ using Revitalize.Framework.Menus; using Revitalize.Framework.Objects.CraftingTables; using Revitalize.Framework.Objects.Items.Tools; using StardewValley.Tools; +using Revitalize.Framework.Menus.Machines; namespace Revitalize { @@ -332,10 +333,17 @@ namespace Revitalize */ if (e.Button == SButton.U) { - CustomObject test = ObjectManager.GetItem("SandBox"); + MultiTiledObject test =(MultiTiledObject) 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); + MachineSummaryMenu m= new Framework.Menus.Machines.MachineSummaryMenu((Game1.viewport.Width/2)-400, 48, 800, 600,Color.White,test); + InventoryTransferMenu transferMenu = new InventoryTransferMenu(100, 150, 500, 600, test.info.inventory.items, 36); + MachineMenu machineMenu = new MachineMenu((Game1.viewport.Width / 2) - 400, 0, 800, 600); + + machineMenu.addInMenuTab("Summary",new AnimatedButton(new StardustCore.Animations.AnimatedSprite("SummaryTab",new Vector2(),new AnimationManager(TextureManager.GetExtendedTexture(ModCore.Manifest,"Menus","MenuTab"),new Animation(0,0,24,24)),Color.White),new Rectangle(0,0,24,24),2f),m,true); + machineMenu.addInMenuTab("Inventory", new AnimatedButton(new StardustCore.Animations.AnimatedSprite("Inventory Tab", new Vector2(), new AnimationManager(TextureManager.GetExtendedTexture(ModCore.Manifest, "Menus", "MenuTab"), new Animation(0, 0, 24, 24)), Color.White), new Rectangle(0, 0, 24, 24), 2f), transferMenu, true); + + if (Game1.activeClickableMenu == null) Game1.activeClickableMenu = machineMenu; } /* if (e.Button == SButton.Y) diff --git a/GeneralMods/Revitalize/Revitalize.csproj b/GeneralMods/Revitalize/Revitalize.csproj index 7a3cf76e..acdcba05 100644 --- a/GeneralMods/Revitalize/Revitalize.csproj +++ b/GeneralMods/Revitalize/Revitalize.csproj @@ -86,7 +86,8 @@ - + +