diff --git a/Revitalize/Revitalize/Revitalize/Class1.cs b/Revitalize/Revitalize/Revitalize/Class1.cs index e2018e07..0da30192 100644 --- a/Revitalize/Revitalize/Revitalize/Class1.cs +++ b/Revitalize/Revitalize/Revitalize/Class1.cs @@ -323,6 +323,7 @@ namespace Revitalize TextureDataNode font; Dictionaries.spriteFontList.TryGetValue("0", out font); + objShopList.Add(new TestMachine(3, Vector2.Zero, Util.invertColor(LightColors.White), LightColors.White, false, 9, true)); objShopList.Add(new SpriteFontObject(0, Vector2.Zero, font.path, Color.White)); objShopList.Add(new Magic.Alchemy.Objects.BagofHolding(0, Vector2.Zero, new List>() { @@ -343,6 +344,7 @@ namespace Revitalize objShopList.Add(new Light(0, Vector2.Zero, LightColors.Aquamarine,LightColors.Aquamarine,false)); objShopList.Add(new Quarry(3, Vector2.Zero,9,"copper")); objShopList.Add(new Quarry(3, Vector2.Zero, 9, "iron")); + objShopList.Add(new Spawner(3, Vector2.Zero, 9)); // objShopList.Add(new StardewValley.Tools.Raft()); objShopList.Add(new Decoration(3, Vector2.Zero)); objShopList.Add(new StardewValley.Object(495, 1)); @@ -412,6 +414,11 @@ namespace Revitalize newDebris(); } + if (e.KeyPressed.ToString() == "U") + { + Serialize.cleanUpWorld(); + } + if (e.KeyPressed.ToString() == "G") { WeatherDebrisSystem.speedUpWindAndClear(0.001f); diff --git a/Revitalize/Revitalize/Revitalize/Menus/Machines/MachineInventory.cs b/Revitalize/Revitalize/Revitalize/Menus/Machines/MachineInventory.cs new file mode 100644 index 00000000..a45b75d0 --- /dev/null +++ b/Revitalize/Revitalize/Revitalize/Menus/Machines/MachineInventory.cs @@ -0,0 +1,825 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Microsoft.Xna.Framework.Input; +using StardewModdingAPI; +using StardewValley; +using StardewValley.Menus; +using StardewValley.Objects; +using System; +using System.Collections.Generic; +using Revitalize.Objects.Generic; +using Revitalize.Resources; +using Revitalize.Resources.DataNodes; +using System.IO; +using Revitalize.Objects; + +namespace Revitalize.Menus.Machines +{ + public class MachineInventory : MenuWithInventory + { + public delegate void behaviorOnItemSelect(Item item, StardewValley.Farmer who); + + public const int source_none = 0; + + public const int source_chest = 1; + + public const int source_gift = 2; + + public const int source_fishingChest = 3; + + private StardewValley.Menus.InventoryMenu inputInventory; + private StardewValley.Menus.InventoryMenu outputInventory; + + private TemporaryAnimatedSprite poof; + + public bool reverseGrab; + + public bool showReceivingMenu = true; + + public bool drawBG = true; + + public bool destroyItemOnClick; + + public bool canExitOnKey; + + public bool playRightClickSound; + + public bool allowRightClick; + + public bool shippingBin; + + private string message; + + private MachineInventory.behaviorOnItemSelect behaviorFunction; + + public MachineInventory.behaviorOnItemSelect behaviorOnItemGrab; + + private Item hoverItem; + + private Item sourceItem; + + private ClickableTextureComponent organizeButton; + + private ClickableTextureComponent LeftButton; + private ClickableTextureComponent RightButton; + + private ClickableTextureComponent colorPickerToggleButton; + + private ClickableTextureComponent lastShippedHolder; + + public int source; + + private bool snappedtoBottom; + + private DiscreteColorPicker chestColorPicker; + + public int capacity; + + public int Rows; + + public Revitalize.Objects.Machines.Machine machine; + + public MachineInventory(Revitalize.Objects.Machines.Machine Machine, List InputInventory,List OutputInventory, int rows) : base(null, true, true, 0, 0) + { + machine = Machine; + Rows = rows; + Log.AsyncC(InputInventory.Capacity); + this.inputInventory = new StardewValley.Menus.InventoryMenu(this.xPositionOnScreen + Game1.tileSize / 2, this.yPositionOnScreen, false, InputInventory, null, 9, 3, 0, 0, true); + this.outputInventory = new StardewValley.Menus.InventoryMenu(this.xPositionOnScreen + Game1.tileSize *8, this.yPositionOnScreen, false, OutputInventory, null, 9, 3, 0, 0, true); + Log.AsyncM(this.inputInventory.actualInventory.Capacity); + this.inputInventory.capacity = 9; + this.outputInventory.capacity = 9; + this.inputInventory.actualInventory.Capacity = 9; + this.outputInventory.actualInventory.Capacity = 9; + // Log.AsyncO("MAX LOAD"+this.capacity); + this.reverseGrab = true; + + this.organizeButton = new ClickableTextureComponent("", new Rectangle(this.xPositionOnScreen + this.width, this.yPositionOnScreen + this.height / 3 - Game1.tileSize, Game1.tileSize, Game1.tileSize), "", Game1.content.LoadString("Strings\\UI:ItemGrab_Organize", new object[0]), Game1.mouseCursors, new Rectangle(162, 440, 16, 16), (float)Game1.pixelZoom, false); + + + TextureDataNode d; + Dictionaries.spriteFontList.TryGetValue("leftArrow", out d); + TextureDataNode f; + Dictionaries.spriteFontList.TryGetValue("rightArrow", out f); + this.LeftButton = new ClickableTextureComponent(new Rectangle(this.xPositionOnScreen + Game1.tileSize / 3, this.yPositionOnScreen / 4, Game1.tileSize, Game1.tileSize), d.texture, new Rectangle(0, 0, 16, 16), 4f, false); + this.RightButton = new ClickableTextureComponent(new Rectangle(this.xPositionOnScreen + Game1.tileSize, this.yPositionOnScreen / 4, Game1.tileSize, Game1.tileSize), f.texture, new Rectangle(0, 0, 16, 16), 4f, false); + this.inventory.showGrayedOutSlots = true; + } + + public MachineInventory(Revitalize.Objects.Machines.Machine Machine, List InputInventory,List OutputInventory, int rows, bool reverseGrab, bool showReceivingMenu, InventoryMenu.highlightThisItem highlightFunction, MachineInventory.behaviorOnItemSelect behaviorOnItemSelectFunction, string message, MachineInventory.behaviorOnItemSelect behaviorOnItemGrab = null, bool snapToBottom = false, bool canBeExitedWithKey = false, bool playRightClickSound = true, bool allowRightClick = true, bool showOrganizeButton = false, int source = 0, Item sourceItem = null) : base(highlightFunction, true, true, 0, 0) + { + this.machine = Machine; + this.source = source; + this.message = message; + this.reverseGrab = reverseGrab; + this.showReceivingMenu = showReceivingMenu; + this.playRightClickSound = playRightClickSound; + this.allowRightClick = allowRightClick; + this.inventory.showGrayedOutSlots = true; + this.sourceItem = sourceItem; + this.Rows = rows; + + if (source == 1 && sourceItem != null && sourceItem is Chest) + { + this.chestColorPicker = new DiscreteColorPicker(this.xPositionOnScreen, this.yPositionOnScreen - Game1.tileSize - IClickableMenu.borderWidth * 2, 0, new Chest(true)); + this.chestColorPicker.colorSelection = this.chestColorPicker.getSelectionFromColor((sourceItem as Chest).playerChoiceColor); + (this.chestColorPicker.itemToDrawColored as Chest).playerChoiceColor = this.chestColorPicker.getColorFromSelection(this.chestColorPicker.colorSelection); + this.colorPickerToggleButton = new ClickableTextureComponent(new Rectangle(this.xPositionOnScreen + this.width, this.yPositionOnScreen + Game1.tileSize + Game1.pixelZoom * 5, 16 * Game1.pixelZoom, 16 * Game1.pixelZoom), Game1.mouseCursors, new Rectangle(119, 469, 16, 16), (float)Game1.pixelZoom, false) + { + hoverText = Game1.content.LoadString("Strings\\UI:Toggle_ColorPicker", new object[0]) + }; + } + if (snapToBottom) + { + base.movePosition(0, Game1.viewport.Height - (this.yPositionOnScreen + this.height - IClickableMenu.spaceToClearTopBorder)); + this.snappedtoBottom = true; + } + this.inputInventory = new InventoryMenu(this.xPositionOnScreen + Game1.tileSize / 2, this.yPositionOnScreen, false, InputInventory, highlightFunction, 9, 3, 0, 0, true); + this.outputInventory = new StardewValley.Menus.InventoryMenu(this.xPositionOnScreen + Game1.tileSize * 8, this.yPositionOnScreen, false, OutputInventory, null, 9, 3, 0, 0, true); + Log.AsyncM(this.inputInventory.actualInventory.Capacity); + this.inputInventory.capacity = 9; + this.inputInventory.capacity = 9; + this.inputInventory.actualInventory.Capacity = 9; + this.outputInventory.actualInventory.Capacity = 9; + this.behaviorFunction = behaviorOnItemSelectFunction; + this.behaviorOnItemGrab = behaviorOnItemGrab; + this.canExitOnKey = canBeExitedWithKey; + if (showOrganizeButton) + { + this.organizeButton = new ClickableTextureComponent("", new Rectangle(this.xPositionOnScreen + this.width, this.yPositionOnScreen + this.height / 3 - Game1.tileSize, Game1.tileSize, Game1.tileSize), "", Game1.content.LoadString("Strings\\UI:ItemGrab_Organize", new object[0]), Game1.mouseCursors, new Rectangle(162, 440, 16, 16), (float)Game1.pixelZoom, false); + } + if ((Game1.isAnyGamePadButtonBeingPressed() || !Game1.lastCursorMotionWasMouse) && this.inputInventory.actualInventory.Count > 0 && Game1.activeClickableMenu == null) + { + Game1.setMousePosition(this.inventory.inventory[0].bounds.Center); + } + TextureDataNode d; + Dictionaries.spriteFontList.TryGetValue("leftArrow", out d); + TextureDataNode f; + Dictionaries.spriteFontList.TryGetValue("rightArrow", out f); + this.LeftButton = new ClickableTextureComponent(new Rectangle(this.xPositionOnScreen + Game1.tileSize / 3, this.yPositionOnScreen / 4, Game1.tileSize, Game1.tileSize), d.texture, new Rectangle(0, 0, 16, 16), 4f, false); + this.RightButton = new ClickableTextureComponent(new Rectangle(this.xPositionOnScreen + Game1.tileSize, this.yPositionOnScreen / 4, Game1.tileSize, Game1.tileSize), f.texture, new Rectangle(0, 0, 16, 16), 4f, false); + } + + public void initializeShippingBin() + { + this.shippingBin = true; + this.lastShippedHolder = new ClickableTextureComponent("", new Rectangle(this.xPositionOnScreen + this.width / 2 - 12 * Game1.pixelZoom, this.yPositionOnScreen + this.height / 2 - 20 * Game1.pixelZoom - Game1.tileSize, 24 * Game1.pixelZoom, 24 * Game1.pixelZoom), "", Game1.content.LoadString("Strings\\UI:ShippingBin_LastItem", new object[0]), Game1.mouseCursors, new Rectangle(293, 360, 24, 24), (float)Game1.pixelZoom, false); + } + + public void setSourceItem(Item item) + { + this.sourceItem = item; + this.chestColorPicker = null; + this.colorPickerToggleButton = null; + if (this.source == 1 && this.sourceItem != null && this.sourceItem is Chest) + { + this.chestColorPicker = new DiscreteColorPicker(this.xPositionOnScreen, this.yPositionOnScreen - Game1.tileSize - IClickableMenu.borderWidth * 2, 0, new Chest(true)); + this.chestColorPicker.colorSelection = this.chestColorPicker.getSelectionFromColor((this.sourceItem as Chest).playerChoiceColor); + (this.chestColorPicker.itemToDrawColored as Chest).playerChoiceColor = this.chestColorPicker.getColorFromSelection(this.chestColorPicker.colorSelection); + this.colorPickerToggleButton = new ClickableTextureComponent(new Rectangle(this.xPositionOnScreen + this.width, this.yPositionOnScreen + Game1.tileSize + Game1.pixelZoom * 5, 16 * Game1.pixelZoom, 16 * Game1.pixelZoom), Game1.mouseCursors, new Rectangle(119, 469, 16, 16), (float)Game1.pixelZoom, false) + { + hoverText = Game1.content.LoadString("Strings\\UI:Toggle_ColorPicker", new object[0]) + }; + } + } + + public void setBackgroundTransparency(bool b) + { + this.drawBG = b; + } + + public void setDestroyItemOnClick(bool b) + { + this.destroyItemOnClick = b; + } + + public override void receiveRightClick(int x, int y, bool playSound = true) + { + if (!this.allowRightClick) + { + return; + } + base.receiveRightClick(x, y, playSound && this.playRightClickSound); + if (this.heldItem == null && this.showReceivingMenu) + { + this.heldItem = this.inputInventory.rightClick(x, y, this.heldItem, false); + if (this.heldItem != null && this.behaviorOnItemGrab != null) + { + this.behaviorOnItemGrab(this.heldItem, Game1.player); + if (Game1.activeClickableMenu != null && Game1.activeClickableMenu is MachineInventory) + { + (Game1.activeClickableMenu as MachineInventory).setSourceItem(this.sourceItem); + } + } + if (this.heldItem is StardewValley.Object && (this.heldItem as StardewValley.Object).parentSheetIndex == 326) + { + this.heldItem = null; + Game1.player.canUnderstandDwarves = true; + this.poof = new TemporaryAnimatedSprite(Game1.animations, new Rectangle(0, 320, 64, 64), 50f, 8, 0, new Vector2((float)(x - x % Game1.tileSize + Game1.tileSize / 4), (float)(y - y % Game1.tileSize + Game1.tileSize / 4)), false, false); + Game1.playSound("fireball"); + return; + } + if (this.heldItem is StardewValley.Object && (this.heldItem as StardewValley.Object).isRecipe) + { + string key = this.heldItem.Name.Substring(0, this.heldItem.Name.IndexOf("Recipe") - 1); + try + { + if ((this.heldItem as StardewValley.Object).category == -7) + { + Game1.player.cookingRecipes.Add(key, 0); + } + else + { + Game1.player.craftingRecipes.Add(key, 0); + } + this.poof = new TemporaryAnimatedSprite(Game1.animations, new Rectangle(0, 320, 64, 64), 50f, 8, 0, new Vector2((float)(x - x % Game1.tileSize + Game1.tileSize / 4), (float)(y - y % Game1.tileSize + Game1.tileSize / 4)), false, false); + Game1.playSound("newRecipe"); + } + catch (Exception) + { + } + this.heldItem = null; + return; + } + if (Game1.player.addItemToInventoryBool(this.heldItem, false)) + { + this.heldItem = null; + Game1.playSound("coin"); + return; + } + } + else if (this.reverseGrab || this.behaviorFunction != null) + { + this.behaviorFunction(this.heldItem, Game1.player); + if (Game1.activeClickableMenu != null && Game1.activeClickableMenu is MachineInventory) + { + (Game1.activeClickableMenu as MachineInventory).setSourceItem(this.sourceItem); + } + if (this.destroyItemOnClick) + { + this.heldItem = null; + return; + } + } + } + + public override void gameWindowSizeChanged(Rectangle oldBounds, Rectangle newBounds) + { + if (this.snappedtoBottom) + { + base.movePosition((newBounds.Width - oldBounds.Width) / 2, Game1.viewport.Height - (this.yPositionOnScreen + this.height - IClickableMenu.spaceToClearTopBorder)); + } + if (this.inputInventory != null) + { + this.inputInventory.gameWindowSizeChanged(oldBounds, newBounds); + } + if (this.organizeButton != null) + { + this.organizeButton = new ClickableTextureComponent("", new Rectangle(this.xPositionOnScreen + this.width, this.yPositionOnScreen + this.height / 3 - Game1.tileSize, Game1.tileSize, Game1.tileSize), "", Game1.content.LoadString("Strings\\UI:ItemGrab_Organize", new object[0]), Game1.mouseCursors, new Rectangle(162, 440, 16, 16), (float)Game1.pixelZoom, false); + } + if (this.source == 1 && this.sourceItem != null && this.sourceItem is Chest) + { + this.chestColorPicker = new DiscreteColorPicker(this.xPositionOnScreen, this.yPositionOnScreen - Game1.tileSize - IClickableMenu.borderWidth * 2, 0, null); + this.chestColorPicker.colorSelection = this.chestColorPicker.getSelectionFromColor((this.sourceItem as Chest).playerChoiceColor); + } + } + + public override void receiveLeftClick(int x, int y, bool playSound = true) + { + base.receiveLeftClick(x, y, !this.destroyItemOnClick); + // Item test= this.inputInventory.leftClick(x, y, this.heldItem, false); + + Item test = this.heldItem; + /* + if (test == machine) + { + if ((test as ExpandableInventoryObject).inventory == expandableObject.inventory) + { + if (this.inputInventory.isWithinBounds(x, y) == false) + { + //if this is within my inventory return. Don't want to shove a bag into itself. + return; + } + + } + } + */ + + + if (this.organizeButton.containsPoint(x, y)) + { + MachineInventory.organizeItemsInList(this.inputInventory.actualInventory); + } + if (this.organizeButton.containsPoint(x, y)) + { + MachineInventory.organizeItemsInList(this.outputInventory.actualInventory); + } + + + + if (inventory.isWithinBounds(x, y) == true) + { + + if (this.inputInventory.actualInventory == null) + { + Log.AsyncG("WTF HOW IS THIS NULL!?!?!?!?!"); + } + bool f = Util.isInventoryFull(this.inputInventory.actualInventory,true); + if (f == false) + { + this.heldItem = this.inputInventory.leftClick(x, y, this.heldItem, false); + if (this.heldItem != null) + { + //if (Serialize.WriteToXMLFileSafetyCheck(Path.Combine(Serialize.PlayerDataPath, ""), i, false) == false) + //{ + // return; + // } + + Util.addItemToOtherInventory(this.inputInventory.actualInventory, this.heldItem); + // Log.AsyncG("item swap"); + if (this.machine == null) Log.AsyncC("OK MY MACHINE IS NULL"); + if (this.inputInventory == null) Log.AsyncG("Input is null"); + if (this.outputInventory == null) Log.AsyncO("output is null"); + //Game1.activeClickableMenu = new MachineInventory(this.machine, this.inputInventory.actualInventory,this.outputInventory.actualInventory, this.Rows, false, true, new InventoryMenu.highlightThisItem(InventoryMenu.highlightAllItems), this.behaviorFunction, null, this.behaviorOnItemGrab, false, true, true, true, true, this.source, this.sourceItem); + Game1.activeClickableMenu = new Revitalize.Menus.Machines.MachineInventory(this.machine, this.inputInventory.actualInventory, this.outputInventory.actualInventory, 3); + // Game1.playSound("Ship"); + this.heldItem = null; + return; + // Log.AsyncG("not full"); + + } + } + else + { + Log.AsyncO("Inventory is full?????"); + return; + } + // this.inputInventory.inventory.Add(new ClickableComponent(new Rectangle(inputInventory.xPositionOnScreen + inputInventory.actualInventory.Count-1 % (this.capacity / this.inputInventory.rows) * Game1.tileSize + this.inputInventory.horizontalGap * (inputInventory.actualInventory.Count-1 % (this.capacity / this.inputInventory.rows)), inputInventory.yPositionOnScreen + inputInventory.actualInventory.Count-1 / (this.capacity / this.inputInventory.rows) * (Game1.tileSize + this.inputInventory.verticalGap) + (inputInventory.actualInventory.Count-1 / (this.capacity / this.inputInventory.rows) - 1) * Game1.pixelZoom - (Game1.tileSize / 5), Game1.tileSize, Game1.tileSize), string.Concat(inputInventory.actualInventory.Count-1))); + if (this.okButton.containsPoint(x, y) == false && this.organizeButton.containsPoint(x, y) == false && f == false && this.LeftButton.containsPoint(x, y) == false && this.RightButton.containsPoint(x, y) == false) + { + // + Game1.activeClickableMenu = new Revitalize.Menus.Machines.MachineInventory(this.machine, this.inputInventory.actualInventory, this.outputInventory.actualInventory, 3); + //Game1.activeClickableMenu = new MachineInventory(this.machine, machine.inputInventory,machine.outputInventory, this.Rows, false, true, new InventoryMenu.highlightThisItem(InventoryMenu.highlightAllItems), this.behaviorFunction, null, this.behaviorOnItemGrab, false, true, true, true, true, this.source, this.sourceItem); + // Game1.playSound("Ship"); + } + + } + + else if (outputInventory.isWithinBounds(x, y) == true) + { + //outputInventory.actualInventory.Add(new Decoration(3, Vector2.Zero)); + if (this.outputInventory.actualInventory == null) + { + Log.AsyncG("WTF HOW IS THIS NULL!?!?!?!?!"); + } + + this.heldItem = this.outputInventory.leftClick(x, y, this.heldItem, false); + if (this.heldItem != null) + { + // if (Serialize.WriteToXMLFileSafetyCheck(Path.Combine(Serialize.PlayerDataPath, ""), this.heldItem, false) == false) + // { + // return; + // } + + foreach (ClickableComponent current in outputInventory.inventory) + { + if (current.containsPoint(x, y)) + { + int num = Convert.ToInt32(current.name); + // Log.AsyncO(num); + + this.outputInventory.actualInventory.RemoveAt(num); + // Log.AsyncO("Remaining " + inputInventory.actualInventory.Count); + + } + } + // j= this.inputInventory.leftClick(x, y, this.heldItem, false); + Util.addItemToInventoryElseDrop(this.heldItem); + this.heldItem = null; + return; + } + //Util.addItemToOtherInventory(this.inputInventory.actualInventory, this.heldItem); + // Log.AsyncG("not full"); + + + // this.inputInventory.inventory.Add(new ClickableComponent(new Rectangle(inputInventory.xPositionOnScreen + inputInventory.actualInventory.Count-1 % (this.capacity / this.inputInventory.rows) * Game1.tileSize + this.inputInventory.horizontalGap * (inputInventory.actualInventory.Count-1 % (this.capacity / this.inputInventory.rows)), inputInventory.yPositionOnScreen + inputInventory.actualInventory.Count-1 / (this.capacity / this.inputInventory.rows) * (Game1.tileSize + this.inputInventory.verticalGap) + (inputInventory.actualInventory.Count-1 / (this.capacity / this.inputInventory.rows) - 1) * Game1.pixelZoom - (Game1.tileSize / 5), Game1.tileSize, Game1.tileSize), string.Concat(inputInventory.actualInventory.Count-1))); + if (this.okButton.containsPoint(x, y) == false && this.organizeButton.containsPoint(x, y) == false && this.LeftButton.containsPoint(x, y) == false && this.RightButton.containsPoint(x, y) == false) + { + // + Game1.activeClickableMenu = new Revitalize.Menus.Machines.MachineInventory(this.machine, this.inputInventory.actualInventory, this.outputInventory.actualInventory, 3); + //Game1.activeClickableMenu = new MachineInventory(this.machine, machine.inputInventory,machine.outputInventory, this.Rows, false, true, new InventoryMenu.highlightThisItem(InventoryMenu.highlightAllItems), this.behaviorFunction, null, this.behaviorOnItemGrab, false, true, true, true, true, this.source, this.sourceItem); + // Game1.playSound("Ship"); + + } + + } + else if(inputInventory.isWithinBounds(x,y)==true) + { + + if (Game1.player.isInventoryFull() == true) + { + Item i = new StardewValley.Object(); + Item j = new StardewValley.Object(); + j = this.inputInventory.leftClick(x, y, this.heldItem, false); + i = this.heldItem; + if (i != null) + { + //if (Serialize.WriteToXMLFileSafetyCheck(Path.Combine(Serialize.PlayerDataPath, ""), i, false) == false) + //{ + // return; + // } + } + + Util.addItemToInventoryElseDrop(this.heldItem); + // this.heldItem = null; + + foreach (ClickableComponent current in inputInventory.inventory) + { + if (current.containsPoint(x, y)) + { + int num = Convert.ToInt32(current.name); + // Log.AsyncO(num); + + this.inputInventory.actualInventory.RemoveAt(num); + // Log.AsyncO("Remaining " + inputInventory.actualInventory.Count); + + } + } + // j= this.inputInventory.leftClick(x, y, this.heldItem, false); + // Util.addItemToOtherInventory(this.inputInventory.actualInventory, i); + // Log.AsyncG("item swap"); + if (this.machine == null) Log.AsyncC("OK MY MACHINE IS NULL"); + if (this.inputInventory == null) Log.AsyncG("Input is null"); + if (this.outputInventory == null) Log.AsyncO("output is null"); + //Game1.activeClickableMenu = new MachineInventory(this.machine, this.inputInventory.actualInventory,this.outputInventory.actualInventory, this.Rows, false, true, new InventoryMenu.highlightThisItem(InventoryMenu.highlightAllItems), this.behaviorFunction, null, this.behaviorOnItemGrab, false, true, true, true, true, this.source, this.sourceItem); + Game1.activeClickableMenu = new Revitalize.Menus.Machines.MachineInventory(this.machine, this.inputInventory.actualInventory, this.outputInventory.actualInventory, 3); + // Game1.playSound("Ship"); + this.heldItem = null; + return; + } + + + + this.heldItem = this.inputInventory.leftClick(x, y, this.heldItem, false); + Util.addItemToInventoryElseDrop(this.heldItem); + this.heldItem = null; + + foreach (ClickableComponent current in inputInventory.inventory) + { + if (current.containsPoint(x, y)) + { + int num = Convert.ToInt32(current.name); + // Log.AsyncO(num); + this.inputInventory.actualInventory.RemoveAt(num); + // Log.AsyncO("Remaining " + inputInventory.actualInventory.Count); + + } + } + Game1.activeClickableMenu = new MachineInventory(this.machine, this.inputInventory.actualInventory,this.outputInventory.actualInventory ,this.Rows, false, true, new InventoryMenu.highlightThisItem(InventoryMenu.highlightAllItems), this.behaviorFunction, null, this.behaviorOnItemGrab, false, true, true, true, true, this.source, this.sourceItem); + // Game1.playSound("Ship"); + + } + return; + if (this.shippingBin && this.lastShippedHolder.containsPoint(x, y)) + { + if (Game1.getFarm().lastItemShipped != null && Game1.player.addItemToInventoryBool(Game1.getFarm().lastItemShipped, false)) + { + Game1.playSound("coin"); + Game1.getFarm().shippingBin.Remove(Game1.getFarm().lastItemShipped); + Game1.getFarm().lastItemShipped = null; + if (Game1.player.ActiveObject != null) + { + Game1.player.showCarrying(); + Game1.player.Halt(); + } + } + return; + } + if (this.chestColorPicker != null) + { + this.chestColorPicker.receiveLeftClick(x, y, true); + if (this.sourceItem != null && this.sourceItem is Chest) + { + (this.sourceItem as Chest).playerChoiceColor = this.chestColorPicker.getColorFromSelection(this.chestColorPicker.colorSelection); + } + } + if (this.colorPickerToggleButton != null && this.colorPickerToggleButton.containsPoint(x, y)) + { + Game1.player.showChestColorPicker = !Game1.player.showChestColorPicker; + this.chestColorPicker.visible = Game1.player.showChestColorPicker; + Game1.soundBank.PlayCue("drumkit6"); + } + if (this.heldItem == null && this.showReceivingMenu) + { + this.heldItem = this.inputInventory.leftClick(x, y, this.heldItem, false); + // Log.AsyncC("YAY"); + + + + + if (this.heldItem != null && this.behaviorOnItemGrab != null) + { + this.behaviorOnItemGrab(this.heldItem, Game1.player); + if (Game1.activeClickableMenu != null && Game1.activeClickableMenu is MachineInventory) + { + (Game1.activeClickableMenu as MachineInventory).setSourceItem(this.sourceItem); + } + } + if (this.heldItem is StardewValley.Object && (this.heldItem as StardewValley.Object).parentSheetIndex == 326) + { + this.heldItem = null; + Game1.player.canUnderstandDwarves = true; + this.poof = new TemporaryAnimatedSprite(Game1.animations, new Rectangle(0, 320, 64, 64), 50f, 8, 0, new Vector2((float)(x - x % Game1.tileSize + Game1.tileSize / 4), (float)(y - y % Game1.tileSize + Game1.tileSize / 4)), false, false); + Game1.playSound("fireball"); + } + else if (this.heldItem is StardewValley.Object && (this.heldItem as StardewValley.Object).parentSheetIndex == 102) + { + this.heldItem = null; + Game1.player.foundArtifact(102, 1); + this.poof = new TemporaryAnimatedSprite(Game1.animations, new Rectangle(0, 320, 64, 64), 50f, 8, 0, new Vector2((float)(x - x % Game1.tileSize + Game1.tileSize / 4), (float)(y - y % Game1.tileSize + Game1.tileSize / 4)), false, false); + Game1.playSound("fireball"); + } + else if (this.heldItem is StardewValley.Object && (this.heldItem as StardewValley.Object).isRecipe) + { + string key = this.heldItem.Name.Substring(0, this.heldItem.Name.IndexOf("Recipe") - 1); + try + { + if ((this.heldItem as StardewValley.Object).category == -7) + { + Game1.player.cookingRecipes.Add(key, 0); + } + else + { + Game1.player.craftingRecipes.Add(key, 0); + } + this.poof = new TemporaryAnimatedSprite(Game1.animations, new Rectangle(0, 320, 64, 64), 50f, 8, 0, new Vector2((float)(x - x % Game1.tileSize + Game1.tileSize / 4), (float)(y - y % Game1.tileSize + Game1.tileSize / 4)), false, false); + Game1.playSound("newRecipe"); + } + catch (Exception) + { + } + this.heldItem = null; + } + else if (Game1.player.addItemToInventoryBool(this.heldItem, false)) + { + this.heldItem = null; + Game1.playSound("coin"); + } + } + else if ((this.reverseGrab || this.behaviorFunction != null) && this.isWithinBounds(x, y)) + { + this.behaviorFunction(this.heldItem, Game1.player); + if (Game1.activeClickableMenu != null && Game1.activeClickableMenu is MachineInventory) + { + (Game1.activeClickableMenu as MachineInventory).setSourceItem(this.sourceItem); + } + if (this.destroyItemOnClick) + { + this.heldItem = null; + return; + } + } + if (this.organizeButton != null && this.organizeButton.containsPoint(x, y)) + { + MachineInventory.organizeItemsInList(this.inputInventory.actualInventory); + Game1.activeClickableMenu = new MachineInventory(this.machine, this.inputInventory.actualInventory,this.outputInventory.actualInventory, this.Rows, false, true, new InventoryMenu.highlightThisItem(InventoryMenu.highlightAllItems), this.behaviorFunction, null, this.behaviorOnItemGrab, false, true, true, true, true, this.source, this.sourceItem); + Game1.playSound("Ship"); + return; + } + if (this.heldItem != null && !this.isWithinBounds(x, y) && this.heldItem.canBeTrashed()) + { + Game1.playSound("throwDownITem"); + Game1.createItemDebris(this.heldItem, Game1.player.getStandingPosition(), Game1.player.FacingDirection); + this.heldItem = null; + } + } + + public static void organizeItemsInList(List items) + { + items.Sort(); + items.Reverse(); + } + + public bool areAllItemsTaken() + { + for (int i = 0; i < this.inputInventory.actualInventory.Count; i++) + { + if (this.inputInventory.actualInventory[i] != null) + { + return false; + } + } + return true; + } + + public override void receiveKeyPress(Keys key) + { + if ((this.canExitOnKey || this.areAllItemsTaken()) && Game1.options.doesInputListContain(Game1.options.menuButton, key) && this.readyToClose()) + { + base.exitThisMenu(true); + if (Game1.currentLocation.currentEvent != null) + { + Event expr_4C = Game1.currentLocation.currentEvent; + int currentCommand = expr_4C.CurrentCommand; + expr_4C.CurrentCommand = currentCommand + 1; + } + } + else if (Game1.options.doesInputListContain(Game1.options.menuButton, key) && this.heldItem != null) + { + Game1.setMousePosition(this.trashCan.bounds.Center); + } + if (key == Keys.Delete && this.heldItem != null && this.heldItem.canBeTrashed()) + { + if (this.heldItem is StardewValley.Object && Game1.player.specialItems.Contains((this.heldItem as StardewValley.Object).parentSheetIndex)) + { + Game1.player.specialItems.Remove((this.heldItem as StardewValley.Object).parentSheetIndex); + } + this.heldItem = null; + Game1.playSound("trashcan"); + } + } + + public override void update(GameTime time) + { + base.update(time); + if (this.poof != null && this.poof.update(time)) + { + this.poof = null; + } + if (this.chestColorPicker != null) + { + this.chestColorPicker.update(time); + } + } + + public override void performHoverAction(int x, int y) + { + + if (this.colorPickerToggleButton != null) + { + this.colorPickerToggleButton.tryHover(x, y, 0.25f); + if (this.colorPickerToggleButton.containsPoint(x, y)) + { + this.hoverText = this.colorPickerToggleButton.hoverText; + return; + } + } + if (this.inputInventory.isWithinBounds(x, y) && this.showReceivingMenu) + { + if (inputInventory.actualInventory.Count == 0) return; + this.hoveredItem = this.inputInventory.hover(x, y, this.heldItem); + } + else + { + base.performHoverAction(x, y); + } + if (this.organizeButton != null) + { + this.hoverText = null; + this.organizeButton.tryHover(x, y, 0.1f); + if (this.organizeButton.containsPoint(x, y)) + { + this.hoverText = this.organizeButton.hoverText; + } + } + if (this.shippingBin) + { + this.hoverText = null; + if (this.lastShippedHolder.containsPoint(x, y) && Game1.getFarm().lastItemShipped != null) + { + this.hoverText = this.lastShippedHolder.hoverText; + } + } + if (this.chestColorPicker != null) + { + this.chestColorPicker.performHoverAction(x, y); + } + } + + public override void draw(SpriteBatch b) + { + // Game1.drawDialogueBox(this.inputInventory.xPositionOnScreen - IClickableMenu.borderWidth - IClickableMenu.spaceToClearSideBorder, this.inputInventory.yPositionOnScreen - IClickableMenu.borderWidth - IClickableMenu.spaceToClearTopBorder, this.inputInventory.width + IClickableMenu.borderWidth * 2 + IClickableMenu.spaceToClearSideBorder * 2, this.inputInventory.height + IClickableMenu.spaceToClearTopBorder + IClickableMenu.borderWidth * 2, false, true, null, false); + + if (this.drawBG) + { + b.Draw(Game1.fadeToBlackRect, new Rectangle(0, 0, Game1.viewport.Width, Game1.viewport.Height), Color.Black * 0.5f); + } + base.draw(b, false, false); + + if (this.showReceivingMenu) + { + b.Draw(Game1.mouseCursors, new Vector2((float)(this.xPositionOnScreen - 16 * Game1.pixelZoom), (float)(this.yPositionOnScreen + this.height / 2 + Game1.tileSize + Game1.pixelZoom * 4)), new Rectangle?(new Rectangle(16, 368, 12, 16)), Color.White, 4.712389f, Vector2.Zero, (float)Game1.pixelZoom, SpriteEffects.None, 1f); + b.Draw(Game1.mouseCursors, new Vector2((float)(this.xPositionOnScreen - 16 * Game1.pixelZoom), (float)(this.yPositionOnScreen + this.height / 2 + Game1.tileSize - Game1.pixelZoom * 4)), new Rectangle?(new Rectangle(21, 368, 11, 16)), Color.White, 4.712389f, Vector2.Zero, (float)Game1.pixelZoom, SpriteEffects.None, 1f); + b.Draw(Game1.mouseCursors, new Vector2((float)(this.xPositionOnScreen - 10 * Game1.pixelZoom), (float)(this.yPositionOnScreen + this.height / 2 + Game1.tileSize - Game1.pixelZoom * 11)), new Rectangle?(new Rectangle(4, 372, 8, 11)), Color.White, 0f, Vector2.Zero, (float)Game1.pixelZoom, SpriteEffects.None, 1f); + if (this.source != 0) + { + b.Draw(Game1.mouseCursors, new Vector2((float)(this.xPositionOnScreen - 18 * Game1.pixelZoom), (float)(this.yPositionOnScreen + Game1.tileSize + Game1.pixelZoom * 4)), new Rectangle?(new Rectangle(16, 368, 12, 16)), Color.White, 4.712389f, Vector2.Zero, (float)Game1.pixelZoom, SpriteEffects.None, 1f); + b.Draw(Game1.mouseCursors, new Vector2((float)(this.xPositionOnScreen - 18 * Game1.pixelZoom), (float)(this.yPositionOnScreen + Game1.tileSize - Game1.pixelZoom * 4)), new Rectangle?(new Rectangle(21, 368, 11, 16)), Color.White, 4.712389f, Vector2.Zero, (float)Game1.pixelZoom, SpriteEffects.None, 1f); + Rectangle value = new Rectangle(127, 412, 10, 11); + int num = this.source; + if (num != 2) + { + if (num == 3) + { + value.X += 10; + } + } + else + { + value.X += 20; + } + b.Draw(Game1.mouseCursors, new Vector2((float)(this.xPositionOnScreen - 13 * Game1.pixelZoom), (float)(this.yPositionOnScreen + Game1.tileSize - Game1.pixelZoom * 11)), new Rectangle?(value), Color.White, 0f, Vector2.Zero, (float)Game1.pixelZoom, SpriteEffects.None, 1f); + } + Game1.drawDialogueBox(this.inputInventory.xPositionOnScreen - IClickableMenu.borderWidth - IClickableMenu.spaceToClearSideBorder, this.inputInventory.yPositionOnScreen - IClickableMenu.borderWidth - IClickableMenu.spaceToClearTopBorder, this.inputInventory.width + IClickableMenu.borderWidth * 2 + IClickableMenu.spaceToClearSideBorder * 2, this.inputInventory.height + IClickableMenu.spaceToClearTopBorder + IClickableMenu.borderWidth * 2, false, true, null, false); + Game1.drawDialogueBox(this.outputInventory.xPositionOnScreen - IClickableMenu.borderWidth - IClickableMenu.spaceToClearSideBorder, this.outputInventory.yPositionOnScreen - IClickableMenu.borderWidth - IClickableMenu.spaceToClearTopBorder, this.outputInventory.width + IClickableMenu.borderWidth * 2 + IClickableMenu.spaceToClearSideBorder * 2, this.outputInventory.height + IClickableMenu.spaceToClearTopBorder + IClickableMenu.borderWidth * 2, false, true, null, false); + this.inputInventory.draw(b); + this.outputInventory.draw(b); + } + else if (this.message != null) + { + Game1.drawDialogueBox(Game1.viewport.Width / 2, this.inputInventory.yPositionOnScreen + this.inputInventory.height / 2, false, false, this.message); + } + if (this.poof != null) + { + this.poof.draw(b, true, 0, 0); + } + if (this.shippingBin && Game1.getFarm().lastItemShipped != null) + { + this.lastShippedHolder.draw(b); + Game1.getFarm().lastItemShipped.drawInMenu(b, new Vector2((float)(this.lastShippedHolder.bounds.X + Game1.pixelZoom * 4), (float)(this.lastShippedHolder.bounds.Y + Game1.pixelZoom * 4)), 1f); + b.Draw(Game1.mouseCursors, new Vector2((float)(this.lastShippedHolder.bounds.X + Game1.pixelZoom * -2), (float)(this.lastShippedHolder.bounds.Bottom - Game1.pixelZoom * 25)), new Rectangle?(new Rectangle(325, 448, 5, 14)), Color.White, 0f, Vector2.Zero, (float)Game1.pixelZoom, SpriteEffects.None, 1f); + b.Draw(Game1.mouseCursors, new Vector2((float)(this.lastShippedHolder.bounds.X + Game1.pixelZoom * 21), (float)(this.lastShippedHolder.bounds.Bottom - Game1.pixelZoom * 25)), new Rectangle?(new Rectangle(325, 448, 5, 14)), Color.White, 0f, Vector2.Zero, (float)Game1.pixelZoom, SpriteEffects.None, 1f); + b.Draw(Game1.mouseCursors, new Vector2((float)(this.lastShippedHolder.bounds.X + Game1.pixelZoom * -2), (float)(this.lastShippedHolder.bounds.Bottom - Game1.pixelZoom * 11)), new Rectangle?(new Rectangle(325, 452, 5, 13)), Color.White, 0f, Vector2.Zero, (float)Game1.pixelZoom, SpriteEffects.None, 1f); + b.Draw(Game1.mouseCursors, new Vector2((float)(this.lastShippedHolder.bounds.X + Game1.pixelZoom * 21), (float)(this.lastShippedHolder.bounds.Bottom - Game1.pixelZoom * 11)), new Rectangle?(new Rectangle(325, 452, 5, 13)), Color.White, 0f, Vector2.Zero, (float)Game1.pixelZoom, SpriteEffects.None, 1f); + } + if (this.colorPickerToggleButton != null) + { + this.colorPickerToggleButton.draw(b); + } + if (this.chestColorPicker != null) + { + this.chestColorPicker.draw(b); + } + if (this.organizeButton != null) + { + this.organizeButton.draw(b); + } + if (this.hoverText != null && (this.hoveredItem == null || this.hoveredItem == null || this.inputInventory == null)) + { + IClickableMenu.drawHoverText(b, this.hoverText, Game1.smallFont, 0, 0, -1, null, -1, null, null, 0, -1, -1, -1, -1, 1f, null); + } + if (this.hoveredItem != null) + { + IClickableMenu.drawToolTip(b, this.hoveredItem.getDescription(), this.hoveredItem.Name, this.hoveredItem, this.heldItem != null, -1, 0, -1, -1, null, -1); + } + else if (this.hoveredItem != null && this.inputInventory != null) + { + IClickableMenu.drawToolTip(b, this.inputInventory.descriptionText, this.inputInventory.descriptionTitle, this.hoveredItem, this.heldItem != null, -1, 0, -1, -1, null, -1); + } + if (this.heldItem != null) + { + this.heldItem.drawInMenu(b, new Vector2((float)(Game1.getOldMouseX() + 8), (float)(Game1.getOldMouseY() + 8)), 1f); + } + Game1.mouseCursorTransparency = 1f; + //this.LeftButton.draw(b); + //this.RightButton.draw(b); + base.drawMouse(b); + } + + /* + public void getNextInventory(bool getPrevious) + { + if (getPrevious == false) + { + if (expandableObject.inventoryIndex < expandableObject.allInventories.Count - 1) + { + expandableObject.inventoryIndex++; + expandableObject.inventory = expandableObject.allInventories[expandableObject.inventoryIndex]; + Game1.activeClickableMenu = new MachineInventory(this.expandableObject, expandableObject.inventory, this.Rows, false, true, new InventoryMenu.highlightThisItem(InventoryMenu.highlightAllItems), this.behaviorFunction, null, this.behaviorOnItemGrab, false, true, true, true, true, this.source, this.sourceItem); + return; + } + else + { + return; + } + } + else + { + if (expandableObject.inventoryIndex > 0) + { + expandableObject.inventoryIndex--; + expandableObject.inventory = expandableObject.allInventories[expandableObject.inventoryIndex]; + Game1.activeClickableMenu = new MachineInventory(this.expandableObject, expandableObject.inventory, this.Rows, false, true, new InventoryMenu.highlightThisItem(InventoryMenu.highlightAllItems), this.behaviorFunction, null, this.behaviorOnItemGrab, false, true, true, true, true, this.source, this.sourceItem); + return; + } + else + { + return; + } + } + } + */ + + + } +} diff --git a/Revitalize/Revitalize/Revitalize/Menus/SpriteKeyboard.cs b/Revitalize/Revitalize/Revitalize/Menus/SpriteKeyboard.cs deleted file mode 100644 index b58902b2..00000000 --- a/Revitalize/Revitalize/Revitalize/Menus/SpriteKeyboard.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Revitalize.Menus -{ - class SpriteKeyboard - { - } -} diff --git a/Revitalize/Revitalize/Revitalize/Objects/Generic/CoreObject.cs b/Revitalize/Revitalize/Revitalize/Objects/Generic/CoreObject.cs index e6b146b4..1aa14ae1 100644 --- a/Revitalize/Revitalize/Revitalize/Objects/Generic/CoreObject.cs +++ b/Revitalize/Revitalize/Revitalize/Objects/Generic/CoreObject.cs @@ -18,7 +18,7 @@ namespace Revitalize /// Revitalize CoreObject Class. This is a core class and should only be extended upon. /// /// - [XmlInclude(typeof(Revitalize.Objects.Light)),XmlInclude(typeof(Revitalize.Objects.SpriteFontObject))] + [XmlInclude(typeof(Revitalize.Objects.Light)),XmlInclude(typeof(Revitalize.Objects.SpriteFontObject)), XmlInclude(typeof(Revitalize.Objects.Machines.Machine)), XmlInclude(typeof(Revitalize.Objects.Machines.TestMachine))] public class CoreObject : StardewValley.Object { public const int chair = 0; @@ -101,6 +101,8 @@ namespace Revitalize public Color drawColor; + public bool useXML; + public override string Name { get @@ -1454,7 +1456,7 @@ public override bool isPlaceable() public virtual void spillInventoryEverywhere() { - Game1.activeClickableMenu = new StorageContainer(this.inventory, this.inventoryMaxSize, 3); + Game1.activeClickableMenu = new StorageContainer(this.inventory, 3, 3); this.itemReadyForHarvest = false; /* Log.AsyncC("DROPPING INVENTORY!"); diff --git a/Revitalize/Revitalize/Revitalize/Objects/Machines/Machine.cs b/Revitalize/Revitalize/Revitalize/Objects/Machines/Machine.cs index 463a49e5..df063e69 100644 --- a/Revitalize/Revitalize/Revitalize/Objects/Machines/Machine.cs +++ b/Revitalize/Revitalize/Revitalize/Objects/Machines/Machine.cs @@ -1,115 +1,26 @@ - -using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Revitalize.Resources; using StardewModdingAPI; using StardewValley; using StardewValley.Locations; using StardewValley.Menus; -using StardewValley.Objects; using System; using System.Collections.Generic; +using System.IO; using System.Xml.Serialization; namespace Revitalize.Objects.Machines { /// - /// Revitalize Machine Class. This is a core class and should only be extended upon. + /// Machine Core class. Only extend off of this. /// /// public class Machine : Revitalize.CoreObject { - public const int chair = 0; - - public const int bench = 1; - - public const int couch = 2; - - public const int armchair = 3; - - public const int dresser = 4; - - public const int longTable = 5; - - public const int painting = 6; - - public const int lamp = 7; - - public const int decor = 8; - - public const int other = 9; - - public const int bookcase = 10; - - public const int table = 11; - - public const int rug = 12; - - public const int window = 13; - - public new int price; - - public int Decoration_type; - - public int rotations; - - public int currentRotation; - - public int sourceIndexOffset; - - protected Vector2 drawPosition; - - public Rectangle sourceRect; - - public Rectangle defaultSourceRect; - - public Rectangle defaultBoundingBox; - - public string description; - - public Texture2D TextureSheet; - - public new bool flipped; - - [XmlIgnore] - public bool flaggedForPickUp; - - public bool lightGlowAdded; - - public string texturePath; - - public List inventory; - - public int inventoryMaxSize; - - public bool itemReadyForHarvest; - - public bool lightsOn; - - public GameLocation thisLocation; - - public Color lightColor; - - - //Extra stuff. May or may not be used. - - - - public bool producePollution; - - public bool consumeEnergy; - - public bool doesOverrideGlobalConsumeEnergy; - - public float currentEnergy; - - public float MaxEnergy; - - public float currentPollutionOutput; - - public float maxPollutionOutput; - - + public List inputInventory; + public List outputInventory; + public bool areLightAndDrawColorsDifferent; public override string Name { get @@ -118,14 +29,16 @@ namespace Revitalize.Objects.Machines } } - public virtual void InitializeBasics(int InvMaxSize, Vector2 tile) + public override void InitializeBasics(int InvMaxSize, Vector2 tile) { this.inventory = new List(); + this.inputInventory = this.inventory; + this.outputInventory = new List(); this.inventoryMaxSize = InvMaxSize; this.tileLocation = tile; lightsOn = false; - lightColor = Color.Black; + thisType = this.GetType().ToString(); } public Machine() @@ -138,22 +51,32 @@ namespace Revitalize.Objects.Machines //does nothng } - public Machine(int which, Vector2 Tile, int InventoryMaxSize) + public Machine(int which, Vector2 Tile, Color LightColor, Color DrawColor, bool differentColors = true, int InventoryMaxSize = 0, bool isRemovable = true) { - InitializeBasics(InventoryMaxSize, Tile); - if (TextureSheet == null) - { - TextureSheet = Game1.content.Load("TileSheets\\furniture"); - texturePath = "TileSheets\\furniture"; - } - Dictionary dictionary = Game1.content.Load>("Data\\Furniture"); + removable = isRemovable; + this.InitializeBasics(InventoryMaxSize, Tile); + this.lightColor = LightColor; + this.drawColor = DrawColor; + areLightAndDrawColorsDifferent = differentColors; + TextureSheet = Game1.content.Load(Path.Combine("Revitalize", "Lights", "AdjustableLights", "Graphics", "AdjustableLights")); + texturePath = Path.Combine("Revitalize", "Lights", "AdjustableLights", "Graphics", "AdjustableLights"); + Dictionary dictionary = Game1.content.Load>(Path.Combine("Revitalize", "Lights", "AdjustableLights", "Data", "AdjustableLights")); string[] array = dictionary[which].Split(new char[] { '/' }); this.name = array[0]; - this.Decoration_type = this.getTypeNumberFromName(array[1]); - this.description = "Can be placed inside your house."; + this.Decoration_type = 1; + + try + { + this.description = array[6]; + } + catch (Exception err) + { + this.description = "A light thats color can be adjusted."; + } + this.defaultSourceRect = new Rectangle(which * 16 % TextureSheet.Width, which * 16 / TextureSheet.Width * 16, 1, 1); if (array[2].Equals("-1")) { @@ -209,6 +132,16 @@ namespace Revitalize.Objects.Machines return false; } + public override void resetOnPlayerEntry(GameLocation environment) + { + + if (Game1.isDarkOut() || Game1.timeOfDay <= 500) + { + this.addLights(thisLocation); + } + base.resetOnPlayerEntry(environment); + } + public override void hoverAction() { base.hoverAction(); @@ -223,20 +156,22 @@ namespace Revitalize.Objects.Machines var mState = Microsoft.Xna.Framework.Input.Mouse.GetState(); if (mState.RightButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed) { + return this.RightClicked(who); + // Game1.showRedMessage("YOOO"); //do some stuff when the right button is down // rotate(); if (this.heldObject != null) { - // Game1.player.addItemByMenuIfNecessary(this.heldObject); - // this.heldObject = null; + // Game1.player.addItemByMenuIfNecessary(this.heldObject); + // this.heldObject = null; } - else { - // this.heldObject = Game1.player.ActiveObject; - // Game1.player.removeItemFromInventory(heldObject); + else + { + // this.heldObject = Game1.player.ActiveObject; + // Game1.player.removeItemFromInventory(heldObject); } - //this.minutesUntilReady = 30; - // Log.AsyncC("placed item!"); + //this.minutesUntilReady = 30; } else { @@ -254,67 +189,56 @@ namespace Revitalize.Objects.Machines public override bool clicked(StardewValley.Farmer who) { - // Game1.showRedMessage("THIS IS CLICKED!!!"); - Game1.haltAfterCheck = false; + // Game1.showRedMessage("THIS IS CLICKED!!!"); + //var mState = Microsoft.Xna.Framework.Input.Mouse.GetState(); - if (this.heldObject != null) + + if (removable == false) return false; + + + Game1.haltAfterCheck = false; + if (this.Decoration_type == 11 && who.ActiveObject != null && who.ActiveObject != null && this.heldObject == null) { - this.spillInventoryEverywhere(); + // Game1.showRedMessage("Why1?"); return false; } - - if (this.heldObject == null && (who.ActiveObject == null || !(who.ActiveObject is Machine))) + if (this.heldObject == null && (who.ActiveObject == null || !(who.ActiveObject is Light))) { if (Game1.player.currentLocation is FarmHouse) { - // Game1.showRedMessage("Why2?"); - // this.spillInventoryEverywhere(); - - if (this.heldObject != null) Util.addItemToInventoryElseDrop(this.heldObject.getOne()); - this.heldObject = new Machine(parentSheetIndex, Vector2.Zero, this.inventoryMaxSize); + // Util.addItemToInventoryAndCleanTrackedList(this); - this.heldObject = null; - this.flaggedForPickUp = true; - this.thisLocation = null; + removeLights(this.thisLocation); + this.lightsOn = false; + Game1.playSound("coin"); + // this.flaggedForPickUp = true; + thisLocation = null; return true; } else { // return true; - - this.flaggedForPickUp = true; - if (this is TV) - { - // this.heldObject = new TV(parentSheetIndex, Vector2.Zero); - } - else { - - // Util.addItemToInventoryElseDrop(this.heldObject); - - var obj = new Machine(parentSheetIndex, Vector2.Zero, this.inventoryMaxSize); - Util.addItemToInventoryAndCleanTrackedList(this); - // this.spillInventoryEverywhere(); - if (this.heldObject != null) this.heldObject.performRemoveAction(this.tileLocation, who.currentLocation); - - this.heldObject = null; - Game1.playSound("coin"); - this.thisLocation = null; - return true; - } + // this.heldObject = new Light(parentSheetIndex, Vector2.Zero, this.lightColor, this.inventoryMaxSize); + Util.addItemToInventoryAndCleanTrackedList(this); + removeLights(this.thisLocation); + this.lightsOn = false; + Game1.playSound("coin"); + thisLocation = null; + return true; } } if (this.heldObject != null && who.addItemToInventoryBool(this.heldObject, false)) { - // Game1.showRedMessage("Why3?"); + // Game1.showRedMessage("Why3?"); // if(this.heldObject!=null) Game1.player.addItemByMenuIfNecessary((Item)this.heldObject); - // this.spillInventoryEverywhere(); - var obj = new Machine(parentSheetIndex, Vector2.Zero, this.inventoryMaxSize); Util.addItemToInventoryAndCleanTrackedList(this); - if (this.heldObject != null) this.heldObject.performRemoveAction(this.tileLocation, who.currentLocation); + this.heldObject.performRemoveAction(this.tileLocation, who.currentLocation); this.heldObject = null; Game1.playSound("coin"); - this.thisLocation = null; + removeLights(this.thisLocation); + this.lightsOn = false; + thisLocation = null; return true; } @@ -323,42 +247,41 @@ namespace Revitalize.Objects.Machines return false; } + public override bool RightClicked(StardewValley.Farmer who) + { + //Game1.activeClickableMenu = new Revitalize.Menus.LightCustomizer(this); + Game1.activeClickableMenu = new Revitalize.Menus.Machines.MachineInventory(this, this.inputInventory, this.outputInventory, 3); + return false; + } + public override void DayUpdate(GameLocation location) { base.DayUpdate(location); this.lightGlowAdded = false; - if (!Game1.isDarkOut() || (Game1.newDay && !Game1.isRaining)) + if (!Game1.isDarkOut() || (Game1.newDay && !Game1.isRaining) || Game1.timeOfDay <= 500) { this.removeLights(location); return; } - this.addLights(location); - } - - public virtual void resetOnPlayerEntry(GameLocation environment) - { - this.removeLights(environment); - if (Game1.isDarkOut()) - { - this.addLights(environment); - } + // this.addLights(thisLocation, lightColor); + this.addLights(thisLocation, lightColor); } public override bool performObjectDropInAction(StardewValley.Object dropIn, bool probe, StardewValley.Farmer who) { - // Log.AsyncG("HEY!"); - if ((this.Decoration_type == 11 || this.Decoration_type == 5) && this.heldObject == null && !dropIn.bigCraftable && (!(dropIn is Machine) || ((dropIn as Machine).getTilesWide() == 1 && (dropIn as Machine).getTilesHigh() == 1))) + // Log.AsyncG("HEY!"); + if ((this.Decoration_type == 11 || this.Decoration_type == 5) && this.heldObject == null && !dropIn.bigCraftable && (!(dropIn is Light) || ((dropIn as Light).getTilesWide() == 1 && (dropIn as Light).getTilesHigh() == 1))) { this.heldObject = (StardewValley.Object)dropIn.getOne(); this.heldObject.tileLocation = this.tileLocation; this.heldObject.boundingBox.X = this.boundingBox.X; this.heldObject.boundingBox.Y = this.boundingBox.Y; - // Log.AsyncO(getDefaultBoundingBoxForType((dropIn as Machine).Decoration_type)); + // Log.AsyncO(getDefaultBoundingBoxForType((dropIn as Light).Decoration_type)); this.heldObject.performDropDownAction(who); if (!probe) { Game1.playSound("woodyStep"); - // Log.AsyncC("HUH?"); + // Log.AsyncC("HUH?"); if (who != null) { who.reduceActiveItemByOne(); @@ -369,180 +292,19 @@ namespace Revitalize.Objects.Machines return false; } - public virtual void addLights(GameLocation environment) - { - if (this.Decoration_type == 7) - { - if (this.sourceIndexOffset == 0) - { - this.sourceRect = this.defaultSourceRect; - this.sourceRect.X = this.sourceRect.X + this.sourceRect.Width; - } - this.sourceIndexOffset = 1; - if (this.lightSource == null) - { - Utility.removeLightSource((int)(this.tileLocation.X * 2000f + this.tileLocation.Y)); - this.lightSource = new LightSource(4, new Vector2((float)(this.boundingBox.X + Game1.tileSize / 2), (float)(this.boundingBox.Y - Game1.tileSize)), 2f, lightColor, (int)(this.tileLocation.X * 2000f + this.tileLocation.Y)); - Game1.currentLightSources.Add(this.lightSource); - // Log.AsyncG("LIGHT SOURCE ADDED FFFFFFF"); - return; - } - } - else if (this.Decoration_type == 13) - { - if (this.sourceIndexOffset == 0) - { - this.sourceRect = this.defaultSourceRect; - this.sourceRect.X = this.sourceRect.X + this.sourceRect.Width; - } - this.sourceIndexOffset = 1; - if (this.lightGlowAdded) - { - environment.lightGlows.Remove(new Vector2((float)(this.boundingBox.X + Game1.tileSize / 2), (float)(this.boundingBox.Y + Game1.tileSize))); - this.lightGlowAdded = false; - } - } - else - { - - if (this.sourceIndexOffset == 0) - { - this.sourceRect = this.defaultSourceRect; - this.sourceRect.X = this.sourceRect.X + this.sourceRect.Width; - } - this.sourceIndexOffset = 1; - if (this.lightSource == null) - { - Utility.removeLightSource((int)(this.tileLocation.X * 2000f + this.tileLocation.Y)); - this.lightSource = new LightSource(4, new Vector2((float)(this.boundingBox.X + Game1.tileSize / 2), (float)(this.boundingBox.Y - Game1.tileSize)), 2f, lightColor, (int)(this.tileLocation.X * 2000f + this.tileLocation.Y)); - Game1.currentLightSources.Add(this.lightSource); - return; - } - - } - } - - - public virtual void addLights(GameLocation environment, Color c) - { - if (this.Decoration_type == 7) - { - if (this.sourceIndexOffset == 0) - { - this.sourceRect = this.defaultSourceRect; - this.sourceRect.X = this.sourceRect.X + this.sourceRect.Width; - } - this.sourceIndexOffset = 1; - if (this.lightSource == null) - { - Utility.removeLightSource((int)(this.tileLocation.X * 2000f + this.tileLocation.Y)); - this.lightSource = new LightSource(4, new Vector2((float)(this.boundingBox.X + Game1.tileSize / 2), (float)(this.boundingBox.Y - Game1.tileSize)), 2f, c, (int)(this.tileLocation.X * 2000f + this.tileLocation.Y)); - // this.lightSource.lightTexture = Game1.content.Load("LooseSprites\\Lighting\\BlueLight"); - Game1.currentLightSources.Add(this.lightSource); - // Log.AsyncG("LIGHT SOURCE ADDED FFFFFFF"); - return; - } - } - else if (this.Decoration_type == 13) - { - if (this.sourceIndexOffset == 0) - { - this.sourceRect = this.defaultSourceRect; - this.sourceRect.X = this.sourceRect.X + this.sourceRect.Width; - } - this.sourceIndexOffset = 1; - if (this.lightGlowAdded) - { - environment.lightGlows.Remove(new Vector2((float)(this.boundingBox.X + Game1.tileSize / 2), (float)(this.boundingBox.Y + Game1.tileSize))); - this.lightGlowAdded = false; - } - } - else - { - - if (this.sourceIndexOffset == 0) - { - this.sourceRect = this.defaultSourceRect; - this.sourceRect.X = this.sourceRect.X + this.sourceRect.Width; - } - this.sourceIndexOffset = 1; - if (this.lightSource == null) - { - Utility.removeLightSource((int)(this.tileLocation.X * 2000f + this.tileLocation.Y)); - this.lightSource = new LightSource(4, new Vector2((float)(this.boundingBox.X + Game1.tileSize / 2), (float)(this.boundingBox.Y - Game1.tileSize)), 2f, c, (int)(this.tileLocation.X * 2000f + this.tileLocation.Y)); - Game1.currentLightSources.Add(this.lightSource); - return; - } - - } - } - - public void removeLights(GameLocation environment) - { - if (this.Decoration_type == 7) - { - if (this.sourceIndexOffset == 1) - { - this.sourceRect = this.defaultSourceRect; - } - this.sourceIndexOffset = 0; - Utility.removeLightSource((int)(this.tileLocation.X * 2000f + this.tileLocation.Y)); - this.lightSource = null; - return; - } - if (this.Decoration_type == 13) - { - if (this.sourceIndexOffset == 1) - { - this.sourceRect = this.defaultSourceRect; - } - this.sourceIndexOffset = 0; - if (Game1.isRaining) - { - this.sourceRect = this.defaultSourceRect; - this.sourceRect.X = this.sourceRect.X + this.sourceRect.Width; - this.sourceIndexOffset = 1; - return; - } - if (!this.lightGlowAdded && !environment.lightGlows.Contains(new Vector2((float)(this.boundingBox.X + Game1.tileSize / 2), (float)(this.boundingBox.Y + Game1.tileSize)))) - { - environment.lightGlows.Add(new Vector2((float)(this.boundingBox.X + Game1.tileSize / 2), (float)(this.boundingBox.Y + Game1.tileSize))); - } - this.lightGlowAdded = true; - } - - if (this.sourceIndexOffset == 1) - { - this.sourceRect = this.defaultSourceRect; - } - this.sourceIndexOffset = 0; - Utility.removeLightSource((int)(this.tileLocation.X * 2000f + this.tileLocation.Y)); - this.lightSource = null; - return; - } public override bool minutesElapsed(int minutes, GameLocation environment) { - // Log.Info("minutes passed in"+minutes); - // Log.Info("minues remaining" + this.minutesUntilReady); + this.minutesUntilReady = (this.minutesUntilReady - minutes); - if (Game1.isDarkOut()) + + if (Game1.isDarkOut() || Game1.timeOfDay <= 500) { - // this.addLights(environment,this.lightColor); - this.addLights(environment); - } - else - { - this.removeLights(environment); + this.addLights(thisLocation); } if (minutesUntilReady == 0) { - // Log.AsyncC(this.name + "Is ready!"); - // Log.AsyncC(Game1.player.getStandingPosition()); - // Vector2 v2 = new Vector2(this.tileLocation.X * Game1.tileSize, this.tileLocation.Y * Game1.tileSize); - //Game1.createItemDebris((Item)this.heldObject, v2, Game1.player.getDirection()); - // minutesUntilReady = 30; } return false; @@ -560,111 +322,8 @@ namespace Revitalize.Objects.Machines base.performRemoveAction(tileLocation, environment); } - public virtual void rotate() - { - if (this.rotations < 2) - { - return; - } - int num = (this.rotations == 4) ? 1 : 2; - this.currentRotation += num; - this.currentRotation %= 4; - this.flipped = false; - Point point = default(Point); - int num2 = this.Decoration_type; - switch (num2) - { - case 2: - point.Y = 1; - point.X = -1; - break; - case 3: - point.X = -1; - point.Y = 1; - break; - case 4: - break; - case 5: - point.Y = 0; - point.X = -1; - break; - default: - if (num2 == 12) - { - point.X = 0; - point.Y = 0; - } - break; - } - bool flag = this.Decoration_type == 5 || this.Decoration_type == 12 || this.parentSheetIndex == 724 || this.parentSheetIndex == 727; - bool flag2 = this.defaultBoundingBox.Width != this.defaultBoundingBox.Height; - if (flag && this.currentRotation == 2) - { - this.currentRotation = 1; - } - if (flag2) - { - int height = this.boundingBox.Height; - switch (this.currentRotation) - { - case 0: - case 2: - this.boundingBox.Height = this.defaultBoundingBox.Height; - this.boundingBox.Width = this.defaultBoundingBox.Width; - break; - case 1: - case 3: - this.boundingBox.Height = this.boundingBox.Width + point.X * Game1.tileSize; - this.boundingBox.Width = height + point.Y * Game1.tileSize; - break; - } - } - Point point2 = default(Point); - int num3 = this.Decoration_type; - if (num3 == 12) - { - point2.X = 1; - point2.Y = -1; - } - if (flag2) - { - switch (this.currentRotation) - { - case 0: - this.sourceRect = this.defaultSourceRect; - break; - case 1: - this.sourceRect = new Rectangle(this.defaultSourceRect.X + this.defaultSourceRect.Width, this.defaultSourceRect.Y, this.defaultSourceRect.Height - 16 + point.Y * 16 + point2.X * 16, this.defaultSourceRect.Width + 16 + point.X * 16 + point2.Y * 16); - break; - case 2: - this.sourceRect = new Rectangle(this.defaultSourceRect.X + this.defaultSourceRect.Width + this.defaultSourceRect.Height - 16 + point.Y * 16 + point2.X * 16, this.defaultSourceRect.Y, this.defaultSourceRect.Width, this.defaultSourceRect.Height); - break; - case 3: - this.sourceRect = new Rectangle(this.defaultSourceRect.X + this.defaultSourceRect.Width, this.defaultSourceRect.Y, this.defaultSourceRect.Height - 16 + point.Y * 16 + point2.X * 16, this.defaultSourceRect.Width + 16 + point.X * 16 + point2.Y * 16); - this.flipped = true; - break; - } - } - else - { - this.flipped = (this.currentRotation == 3); - if (this.rotations == 2) - { - this.sourceRect = new Rectangle(this.defaultSourceRect.X + ((this.currentRotation == 2) ? 1 : 0) * this.defaultSourceRect.Width, this.defaultSourceRect.Y, this.defaultSourceRect.Width, this.defaultSourceRect.Height); - } - else - { - this.sourceRect = new Rectangle(this.defaultSourceRect.X + ((this.currentRotation == 3) ? 1 : this.currentRotation) * this.defaultSourceRect.Width, this.defaultSourceRect.Y, this.defaultSourceRect.Width, this.defaultSourceRect.Height); - } - } - if (flag && this.currentRotation == 1) - { - this.currentRotation = 2; - } - this.updateDrawPosition(); - } - public virtual bool isGroundFurniture() + public override bool isGroundFurniture() { return this.Decoration_type != 13 && this.Decoration_type != 6 && this.Decoration_type != 13; } @@ -688,9 +347,9 @@ namespace Revitalize.Objects.Machines foreach (KeyValuePair something in l.objects) { StardewValley.Object obj = something.Value; - if ((obj.GetType()).ToString().Contains("Machine")) + if ((obj.GetType()).ToString().Contains("Light")) { - Machine current = (Machine)obj; + Light current = (Light)obj; if (current.Decoration_type == 11 && current.getBoundingBox(current.tileLocation).Contains((int)vector.X, (int)vector.Y) && current.heldObject == null && this.getTilesWide() == 1) { bool result = true; @@ -717,46 +376,31 @@ namespace Revitalize.Objects.Machines Vector2 vector = tile * (float)Game1.tileSize + new Vector2((float)i, (float)j) * (float)Game1.tileSize; vector.X += (float)(Game1.tileSize / 2); vector.Y += (float)(Game1.tileSize / 2); - /* - foreach (Machine current in (l as FarmHouse).Machine) - { - if (current.Decoration_type == 11 && current.getBoundingBox(current.tileLocation).Contains((int)vector.X, (int)vector.Y) && current.heldObject == null && this.getTilesWide() == 1) - { - bool result = true; - return result; - } - if ((current.Decoration_type != 12 || this.Decoration_type == 12) && current.getBoundingBox(current.tileLocation).Contains((int)vector.X, (int)vector.Y)) - { - bool result = false; - return result; - } - } - */ + } } - return base.canBePlacedHere(l, tile); + return Util.canBePlacedHere(this, l, tile); } } - public virtual void updateDrawPosition() + public override void updateDrawPosition() { this.drawPosition = new Vector2((float)this.boundingBox.X, (float)(this.boundingBox.Y - (this.sourceRect.Height * Game1.pixelZoom - this.boundingBox.Height))); } - public virtual int getTilesWide() + public override int getTilesWide() { return this.boundingBox.Width / Game1.tileSize; } - public virtual int getTilesHigh() + public override int getTilesHigh() { return this.boundingBox.Height / Game1.tileSize; } public override bool placementAction(GameLocation location, int x, int y, StardewValley.Farmer who = null) { - // Log.AsyncC(x); - // Log.AsyncM(y); + if (location is FarmHouse) { Point point = new Point(x / Game1.tileSize, y / Game1.tileSize); @@ -802,13 +446,13 @@ namespace Revitalize.Objects.Machines } } } - this.boundingBox = new Rectangle(x / Game1.tileSize, y / Game1.tileSize, this.boundingBox.Width, this.boundingBox.Height); + this.boundingBox = new Rectangle(x / Game1.tileSize * Game1.tileSize, y / Game1.tileSize * Game1.tileSize, this.boundingBox.Width, this.boundingBox.Height); foreach (KeyValuePair c in location.objects) { StardewValley.Object ehh = c.Value; - if (((ehh.GetType()).ToString()).Contains("Machine")) + if (((ehh.GetType()).ToString()).Contains("Spawner")) { - Machine current2 = (Machine)ehh; + Decoration current2 = (Decoration)ehh; if (current2.Decoration_type == 11 && current2.heldObject == null && current2.getBoundingBox(current2.tileLocation).Intersects(this.boundingBox)) { current2.performObjectDropInAction(this, false, (who == null) ? Game1.player : who); @@ -827,16 +471,16 @@ namespace Revitalize.Objects.Machines } } this.updateDrawPosition(); - // Log.AsyncO(this.boundingBox); - // Log.AsyncO(x); - // Log.AsyncY(y); + // Log.AsyncO(this.boundingBox); + // Log.AsyncO(x); + // Log.AsyncY(y); for (int i = 0; i <= this.boundingBox.X / Game1.tileSize; i++) { - base.placementAction(location, x + 1, y, who); + Util.placementAction(this, location, x + 1, y, who); } for (int i = 0; i <= this.boundingBox.Y / Game1.tileSize; i++) { - base.placementAction(location, x, y + 1, who); + Util.placementAction(this, location, x + 1, y, who); } return true; } @@ -850,16 +494,6 @@ namespace Revitalize.Objects.Machines { int num = (this.parentSheetIndex == 1293) ? 3 : 0; bool flag2 = false; - /* - foreach (Rectangle current in walls) - { - if ((this.Decoration_type == 6 || this.Decoration_type == 13 || num != 0) && current.Y + num == point.Y && current.Contains(point.X, point.Y - num)) - { - flag2 = true; - break; - } - } - */ if (!flag2) { Game1.showRedMessage("Must be placed on wall"); @@ -889,18 +523,8 @@ namespace Revitalize.Objects.Machines } } } - this.boundingBox = new Rectangle(x / Game1.tileSize, y / Game1.tileSize, this.boundingBox.Width, this.boundingBox.Height); - /* - foreach (Furniture current2 in (location as FarmHouse).furniture) - { - if (current2.furniture_type == 11 && current2.heldObject == null && current2.getBoundingBox(current2.tileLocation).Intersects(this.boundingBox)) - { - current2.performObjectDropInAction(this, false, (who == null) ? Game1.player : who); - bool result = true; - return result; - } - } - */ + this.boundingBox = new Rectangle(x / Game1.tileSize * Game1.tileSize, y / Game1.tileSize * Game1.tileSize, this.boundingBox.Width, this.boundingBox.Height); + foreach (StardewValley.Farmer current3 in location.getFarmers()) { if (current3.GetBoundingBox().Intersects(this.boundingBox)) @@ -911,8 +535,8 @@ namespace Revitalize.Objects.Machines } } this.updateDrawPosition(); - thisLocation = Game1.player.currentLocation; - return base.placementAction(location, x, y, who); + this.thisLocation = Game1.player.currentLocation; + return Util.placementAction(this, location, x, y, who); } } @@ -1057,40 +681,6 @@ namespace Revitalize.Objects.Machines return new Rectangle((int)this.tileLocation.X * Game1.tileSize, (int)this.tileLocation.Y * Game1.tileSize, num * Game1.tileSize, num2 * Game1.tileSize); } - private int getTypeNumberFromName(string typeName) - { - string key; - switch (key = typeName.ToLower()) - { - case "chair": - return 0; - case "bench": - return 1; - case "couch": - return 2; - case "armchair": - return 3; - case "dresser": - return 4; - case "long table": - return 5; - case "painting": - return 6; - case "lamp": - return 7; - case "decor": - return 8; - case "bookcase": - return 10; - case "table": - return 11; - case "rug": - return 12; - case "window": - return 13; - } - return 9; - } public override int salePrice() { @@ -1137,44 +727,95 @@ namespace Revitalize.Objects.Machines public override void drawWhenHeld(SpriteBatch spriteBatch, Vector2 objectPosition, StardewValley.Farmer f) { - base.drawWhenHeld(spriteBatch, objectPosition, f); + if (TextureSheet == null) + { + TextureSheet = Game1.content.Load(texturePath); + } + if (areLightAndDrawColorsDifferent == false) spriteBatch.Draw(this.TextureSheet, objectPosition, new Microsoft.Xna.Framework.Rectangle?(Game1.currentLocation.getSourceRectForObject(f.ActiveObject.ParentSheetIndex)), Util.invertColor(this.lightColor), 0f, Vector2.Zero, (float)Game1.pixelZoom, SpriteEffects.None, Math.Max(0f, (float)(f.getStandingY() + 2) / 10000f)); + else + { + spriteBatch.Draw(this.TextureSheet, objectPosition, new Microsoft.Xna.Framework.Rectangle?(Game1.currentLocation.getSourceRectForObject(f.ActiveObject.ParentSheetIndex)), Util.invertColor(this.drawColor), 0f, Vector2.Zero, (float)Game1.pixelZoom, SpriteEffects.None, Math.Max(0f, (float)(f.getStandingY() + 2) / 10000f)); + } + + /* + if (f.ActiveObject != null && f.ActiveObject.Name.Contains("=")) + { + spriteBatch.Draw(Game1.objectSpriteSheet, objectPosition + new Vector2((float)(Game1.tileSize / 2), (float)(Game1.tileSize / 2)), new Microsoft.Xna.Framework.Rectangle?(Game1.currentLocation.getSourceRectForObject(f.ActiveObject.ParentSheetIndex)), Color.White, 0f, new Vector2((float)(Game1.tileSize / 2), (float)(Game1.tileSize / 2)), (float)Game1.pixelZoom + Math.Abs(Game1.starCropShimmerPause) / 8f, SpriteEffects.None, Math.Max(0f, (float)(f.getStandingY() + 2) / 10000f)); + if (Math.Abs(Game1.starCropShimmerPause) <= 0.05f && Game1.random.NextDouble() < 0.97) + { + return; + } + Game1.starCropShimmerPause += 0.04f; + if (Game1.starCropShimmerPause >= 0.8f) + { + Game1.starCropShimmerPause = -0.8f; + } + } + */ } public override void drawInMenu(SpriteBatch spriteBatch, Vector2 location, float scaleSize, float transparency, float layerDepth, bool drawStackNumber) { - spriteBatch.Draw(TextureSheet, location + new Vector2((float)(Game1.tileSize / 2), (float)(Game1.tileSize / 2)), new Rectangle?(this.defaultSourceRect), Color.White * transparency, 0f, new Vector2((float)(this.defaultSourceRect.Width / 2), (float)(this.defaultSourceRect.Height / 2)), 1f * this.getScaleSize() * scaleSize, SpriteEffects.None, layerDepth); + if (TextureSheet == null) + { + TextureSheet = Game1.content.Load(texturePath); + } + if (areLightAndDrawColorsDifferent == false) spriteBatch.Draw(TextureSheet, location + new Vector2((float)(Game1.tileSize / 2), (float)(Game1.tileSize / 2)), new Rectangle?(this.defaultSourceRect), Util.invertColor(this.lightColor), 0f, new Vector2((float)(this.defaultSourceRect.Width / 2), (float)(this.defaultSourceRect.Height / 2)), 1f * this.getScaleSize() * scaleSize, SpriteEffects.None, layerDepth); + else + { + spriteBatch.Draw(TextureSheet, location + new Vector2((float)(Game1.tileSize / 2), (float)(Game1.tileSize / 2)), new Rectangle?(this.defaultSourceRect), Util.invertColor(this.drawColor), 0f, new Vector2((float)(this.defaultSourceRect.Width / 2), (float)(this.defaultSourceRect.Height / 2)), 1f * this.getScaleSize() * scaleSize, SpriteEffects.None, layerDepth); + } } public override void draw(SpriteBatch spriteBatch, int x, int y, float alpha = 1f) { + if (TextureSheet == null) + { + TextureSheet = Game1.content.Load(texturePath); + } if (x == -1) { - spriteBatch.Draw(TextureSheet, Game1.GlobalToLocal(Game1.viewport, this.drawPosition), new Rectangle?(this.sourceRect), Color.White * alpha, 0f, Vector2.Zero, (float)Game1.pixelZoom, this.flipped ? SpriteEffects.FlipHorizontally : SpriteEffects.None, (this.Decoration_type == 12) ? 0f : ((float)(this.boundingBox.Bottom - 8) / 10000f)); + if (areLightAndDrawColorsDifferent == false) spriteBatch.Draw(TextureSheet, Game1.GlobalToLocal(Game1.viewport, this.drawPosition), new Rectangle?(this.sourceRect), Util.invertColor(this.lightColor) * alpha, 0f, Vector2.Zero, (float)Game1.pixelZoom, this.flipped ? SpriteEffects.FlipHorizontally : SpriteEffects.None, (this.Decoration_type == 12) ? 0f : ((float)(this.boundingBox.Bottom - 8) / 10000f)); + else spriteBatch.Draw(TextureSheet, Game1.GlobalToLocal(Game1.viewport, this.drawPosition), new Rectangle?(this.sourceRect), Util.invertColor(this.drawColor) * alpha, 0f, Vector2.Zero, (float)Game1.pixelZoom, this.flipped ? SpriteEffects.FlipHorizontally : SpriteEffects.None, (this.Decoration_type == 12) ? 0f : ((float)(this.boundingBox.Bottom - 8) / 10000f)); } else { - spriteBatch.Draw(TextureSheet, Game1.GlobalToLocal(Game1.viewport, new Vector2((float)(x * Game1.tileSize), (float)(y * Game1.tileSize - (this.sourceRect.Height * Game1.pixelZoom - this.boundingBox.Height)))), new Rectangle?(this.sourceRect), Color.White * alpha, 0f, Vector2.Zero, (float)Game1.pixelZoom, this.flipped ? SpriteEffects.FlipHorizontally : SpriteEffects.None, (this.Decoration_type == 12) ? 0f : ((float)(this.boundingBox.Bottom - 8) / 10000f)); + if (areLightAndDrawColorsDifferent == false) spriteBatch.Draw(TextureSheet, Game1.GlobalToLocal(Game1.viewport, new Vector2((float)(x * Game1.tileSize), (float)(y * Game1.tileSize - (this.sourceRect.Height * Game1.pixelZoom - this.boundingBox.Height)))), new Rectangle?(this.sourceRect), Util.invertColor(this.lightColor) * alpha, 0f, Vector2.Zero, (float)Game1.pixelZoom, this.flipped ? SpriteEffects.FlipHorizontally : SpriteEffects.None, (this.Decoration_type == 12) ? 0f : ((float)(this.boundingBox.Bottom - 8) / 10000f)); + else spriteBatch.Draw(TextureSheet, Game1.GlobalToLocal(Game1.viewport, new Vector2((float)(x * Game1.tileSize), (float)(y * Game1.tileSize - (this.sourceRect.Height * Game1.pixelZoom - this.boundingBox.Height)))), new Rectangle?(this.sourceRect), Util.invertColor(this.drawColor) * alpha, 0f, Vector2.Zero, (float)Game1.pixelZoom, this.flipped ? SpriteEffects.FlipHorizontally : SpriteEffects.None, (this.Decoration_type == 12) ? 0f : ((float)(this.boundingBox.Bottom - 8) / 10000f)); } if (this.heldObject != null) { - if (this.heldObject is Machine) + if (this.heldObject is Light) { - (this.heldObject as Machine).drawAtNonTileSpot(spriteBatch, Game1.GlobalToLocal(Game1.viewport, new Vector2((float)(this.boundingBox.Center.X - Game1.tileSize / 2), (float)(this.boundingBox.Center.Y - (this.heldObject as Machine).sourceRect.Height * Game1.pixelZoom - Game1.tileSize / 4))), (float)(this.boundingBox.Bottom - 7) / 10000f, alpha); + (this.heldObject as Light).drawAtNonTileSpot(spriteBatch, Game1.GlobalToLocal(Game1.viewport, new Vector2((float)(this.boundingBox.Center.X - Game1.tileSize / 2), (float)(this.boundingBox.Center.Y - (this.heldObject as Spell).sourceRect.Height * Game1.pixelZoom - Game1.tileSize / 4))), (float)(this.boundingBox.Bottom - 7) / 10000f, alpha); return; } - spriteBatch.Draw(Game1.shadowTexture, Game1.GlobalToLocal(Game1.viewport, new Vector2((float)(this.boundingBox.Center.X - Game1.tileSize / 2), (float)(this.boundingBox.Center.Y - Game1.tileSize * 4 / 3))) + new Vector2((float)(Game1.tileSize / 2), (float)(Game1.tileSize * 5 / 6)), new Rectangle?(Game1.shadowTexture.Bounds), Color.White * alpha, 0f, new Vector2((float)Game1.shadowTexture.Bounds.Center.X, (float)Game1.shadowTexture.Bounds.Center.Y), 4f, SpriteEffects.None, (float)this.boundingBox.Bottom / 10000f); - spriteBatch.Draw(Game1.objectSpriteSheet, Game1.GlobalToLocal(Game1.viewport, new Vector2((float)(this.boundingBox.Center.X - Game1.tileSize / 2), (float)(this.boundingBox.Center.Y - Game1.tileSize * 4 / 3))), new Rectangle?(Game1.currentLocation.getSourceRectForObject(this.heldObject.ParentSheetIndex)), Color.White * alpha, 0f, Vector2.Zero, (float)Game1.pixelZoom, SpriteEffects.None, (float)(this.boundingBox.Bottom + 1) / 10000f); + if (areLightAndDrawColorsDifferent == false) + { + spriteBatch.Draw(Game1.shadowTexture, Game1.GlobalToLocal(Game1.viewport, new Vector2((float)(this.boundingBox.Center.X - Game1.tileSize / 2), (float)(this.boundingBox.Center.Y - Game1.tileSize * 4 / 3))) + new Vector2((float)(Game1.tileSize / 2), (float)(Game1.tileSize * 5 / 6)), new Rectangle?(Game1.shadowTexture.Bounds), Util.invertColor(this.lightColor) * alpha, 0f, new Vector2((float)Game1.shadowTexture.Bounds.Center.X, (float)Game1.shadowTexture.Bounds.Center.Y), 4f, SpriteEffects.None, (float)this.boundingBox.Bottom / 10000f); + spriteBatch.Draw(Game1.objectSpriteSheet, Game1.GlobalToLocal(Game1.viewport, new Vector2((float)(this.boundingBox.Center.X - Game1.tileSize / 2), (float)(this.boundingBox.Center.Y - Game1.tileSize * 4 / 3))), new Rectangle?(Game1.currentLocation.getSourceRectForObject(this.heldObject.ParentSheetIndex)), Util.invertColor(this.lightColor) * alpha, 0f, Vector2.Zero, (float)Game1.pixelZoom, SpriteEffects.None, (float)(this.boundingBox.Bottom + 1) / 10000f); + } + else + { + spriteBatch.Draw(Game1.shadowTexture, Game1.GlobalToLocal(Game1.viewport, new Vector2((float)(this.boundingBox.Center.X - Game1.tileSize / 2), (float)(this.boundingBox.Center.Y - Game1.tileSize * 4 / 3))) + new Vector2((float)(Game1.tileSize / 2), (float)(Game1.tileSize * 5 / 6)), new Rectangle?(Game1.shadowTexture.Bounds), Util.invertColor(this.drawColor) * alpha, 0f, new Vector2((float)Game1.shadowTexture.Bounds.Center.X, (float)Game1.shadowTexture.Bounds.Center.Y), 4f, SpriteEffects.None, (float)this.boundingBox.Bottom / 10000f); + spriteBatch.Draw(Game1.objectSpriteSheet, Game1.GlobalToLocal(Game1.viewport, new Vector2((float)(this.boundingBox.Center.X - Game1.tileSize / 2), (float)(this.boundingBox.Center.Y - Game1.tileSize * 4 / 3))), new Rectangle?(Game1.currentLocation.getSourceRectForObject(this.heldObject.ParentSheetIndex)), Util.invertColor(this.drawColor) * alpha, 0f, Vector2.Zero, (float)Game1.pixelZoom, SpriteEffects.None, (float)(this.boundingBox.Bottom + 1) / 10000f); + } + } } - public virtual void drawAtNonTileSpot(SpriteBatch spriteBatch, Vector2 location, float layerDepth, float alpha = 1f) + public override void drawAtNonTileSpot(SpriteBatch spriteBatch, Vector2 location, float layerDepth, float alpha = 1f) { - spriteBatch.Draw(TextureSheet, location, new Rectangle?(this.sourceRect), Color.White * alpha, 0f, Vector2.Zero, (float)Game1.pixelZoom, this.flipped ? SpriteEffects.FlipHorizontally : SpriteEffects.None, layerDepth); + if (TextureSheet == null) + { + TextureSheet = Game1.content.Load(texturePath); + } + spriteBatch.Draw(TextureSheet, location, new Rectangle?(this.sourceRect), Util.invertColor(this.drawColor) * alpha, 0f, Vector2.Zero, (float)Game1.pixelZoom, this.flipped ? SpriteEffects.FlipHorizontally : SpriteEffects.None, layerDepth); } public override Item getOne() { - Machine Machine = new Machine(this.parentSheetIndex, this.tileLocation, this.inventoryMaxSize); + Light Light = new Light(this.parentSheetIndex, this.tileLocation, this.lightColor, this.drawColor, this.areLightAndDrawColorsDifferent); /* drawPosition = this.drawPosition; defaultBoundingBox = this.defaultBoundingBox; @@ -1183,113 +824,7 @@ namespace Revitalize.Objects.Machines rotations = this.rotations; rotate(); */ - return Machine; - } - - public virtual bool isInventoryFull() - { - // Log.AsyncC("Count" + inventory.Count); - // Log.AsyncC("size" + inventoryMaxSize); - if (inventory.Count >= inventoryMaxSize) - { - - return true; - } - else - { - return false; - } - - } - - public virtual bool addItemToInventory(Item I) - { - if (isInventoryFull() == false) - { - inventory.Add(I.getOne()); - return true; - } - else return false; - } - - public virtual void showUI() - { - Game1.activeClickableMenu = new StorageContainer(this.inventory, this.inventoryMaxSize,3); - this.itemReadyForHarvest = false; - /* - Log.AsyncC("DROPPING INVENTORY!"); - - Random random = new Random(inventory.Count); - int i = random.Next(); - i = i % 4; - Vector2 v2 = new Vector2(this.tileLocation.X * Game1.tileSize, this.tileLocation.Y * Game1.tileSize); - foreach (var I in inventory) - { - Log.AsyncY(I.Name); - Log.AsyncO(I.getStack()); - Log.AsyncM(I.Stack); - Log.AsyncC("Dropping an item!"); - Game1.createItemDebris(I, v2, i); - } - inventory.Clear(); - */ - } - - public virtual bool addItemToInventoryElseDrop(Item I) - { - - if (isInventoryFull() == false) - { - foreach (Item C in inventory) - { - if (C == null) continue; - if (I.canStackWith(C) == true) - { - C.addToStack(I.Stack); - return true; - } - else - { - inventory.Add(I.getOne()); - return true; - } - } - inventory.Add(I.getOne()); - return true; - } - else { - Random random = new Random(inventory.Count); - int i = random.Next(); - i = i % 4; - Vector2 v2 = new Vector2(this.tileLocation.X * Game1.tileSize, this.tileLocation.Y * Game1.tileSize); - Game1.createItemDebris(I.getOne(), v2, i); - return false; - } - } - - public virtual void toggleLights() - { - - if (lightsOn == false) - { - - // Log.AsyncG("ADD LIGHTS"); - // this.Decoration_type = 7; - // this.type = "Lamp"; - - // this.lightSource.lightTexture = Game1.content.Load("LooseSprites\\Lighting\\Lantern"); - // this.lightSource.position = tileLocation; - - // this.addLights(thisLocation, lightColor); - this.addLights(thisLocation, lightColor); - lightsOn = true; - } - if (lightsOn == true) - { - this.removeLights(Game1.player.currentLocation); - lightsOn = false; - } - + return Light; } public override string getCategoryName() @@ -1303,6 +838,5 @@ namespace Revitalize.Objects.Machines return Util.invertColor(LightColors.Black); } - } } diff --git a/Revitalize/Revitalize/Revitalize/Objects/Machines/Quarry.cs b/Revitalize/Revitalize/Revitalize/Objects/Machines/Quarry.cs index 6a8951ce..b684a948 100644 --- a/Revitalize/Revitalize/Revitalize/Objects/Machines/Quarry.cs +++ b/Revitalize/Revitalize/Revitalize/Objects/Machines/Quarry.cs @@ -340,7 +340,7 @@ namespace Revitalize.Objects.Machines this.thisLocation = null; return true; } - this.showUI(); + // this.showUI(); return false; } diff --git a/Revitalize/Revitalize/Revitalize/Objects/Machines/TestMachine.cs b/Revitalize/Revitalize/Revitalize/Objects/Machines/TestMachine.cs new file mode 100644 index 00000000..8567fbdc --- /dev/null +++ b/Revitalize/Revitalize/Revitalize/Objects/Machines/TestMachine.cs @@ -0,0 +1,880 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Revitalize.Resources; +using StardewModdingAPI; +using StardewValley; +using StardewValley.Locations; +using StardewValley.Menus; +using System; +using System.Collections.Generic; +using System.IO; +using System.Xml.Serialization; + +namespace Revitalize.Objects.Machines +{ + /// + /// Machine Core class. Only extend off of this. + /// + /// + public class TestMachine : Revitalize.Objects.Machines.Machine + { + public List inputInventory; + public List outputInventory; + public bool areLightAndDrawColorsDifferent; + + + public override string Name + { + get + { + return this.name; + } + } + + public override void InitializeBasics(int InvMaxSize, Vector2 tile) + { + this.inventory = new List(); + this.inputInventory = new List(); + this.inventory = this.inputInventory; + this.outputInventory = new List(); + this.inventoryMaxSize = InvMaxSize; + this.tileLocation = tile; + lightsOn = false; + lightColor = Color.Black; + thisType = this.GetType().ToString(); + + + this.inventory.Capacity = inventoryMaxSize; + this.inputInventory.Capacity = inventoryMaxSize; + this.outputInventory.Capacity = inventoryMaxSize; + } + + + public TestMachine() + { + this.updateDrawPosition(); + } + + public TestMachine(bool f) + { + //does nothng + } + + public TestMachine(int which, Vector2 Tile, Color LightColor, Color DrawColor, bool differentColors = true, int InventoryMaxSize = 0, bool isRemovable = true) + { + this.useXML = true; + removable = isRemovable; + this.InitializeBasics(InventoryMaxSize, Tile); + this.lightColor = LightColor; + this.drawColor = DrawColor; + this.minutesUntilReady = 10; + areLightAndDrawColorsDifferent = differentColors; + TextureSheet = Game1.content.Load(Path.Combine("Revitalize", "Lights", "AdjustableLights", "Graphics", "AdjustableLights")); + texturePath = Path.Combine("Revitalize", "Lights", "AdjustableLights", "Graphics", "AdjustableLights"); + Dictionary dictionary = Game1.content.Load>(Path.Combine("Revitalize", "Lights", "AdjustableLights", "Data", "AdjustableLights")); + string[] array = dictionary[which].Split(new char[] + { + '/' + }); + this.name = array[0]; + this.Decoration_type = 1; + + try + { + this.description = array[6]; + } + catch (Exception err) + { + this.description = "A light thats color can be adjusted."; + } + + this.defaultSourceRect = new Rectangle(which * 16 % TextureSheet.Width, which * 16 / TextureSheet.Width * 16, 1, 1); + if (array[2].Equals("-1")) + { + this.sourceRect = this.getDefaultSourceRectForType(which, this.Decoration_type); + this.defaultSourceRect = this.sourceRect; + } + else + { + this.defaultSourceRect.Width = Convert.ToInt32(array[2].Split(new char[] + { + ' ' + })[0]); + this.defaultSourceRect.Height = Convert.ToInt32(array[2].Split(new char[] + { + ' ' + })[1]); + this.sourceRect = new Rectangle(which * 16 % TextureSheet.Width, which * 16 / TextureSheet.Width * 16, this.defaultSourceRect.Width * 16, this.defaultSourceRect.Height * 16); + this.defaultSourceRect = this.sourceRect; + } + this.defaultBoundingBox = new Rectangle((int)this.tileLocation.X, (int)this.tileLocation.Y, 1, 1); + if (array[3].Equals("-1")) + { + this.boundingBox = this.getDefaultBoundingBoxForType(this.Decoration_type); + this.defaultBoundingBox = this.boundingBox; + } + else + { + this.defaultBoundingBox.Width = Convert.ToInt32(array[3].Split(new char[] + { + ' ' + })[0]); + this.defaultBoundingBox.Height = Convert.ToInt32(array[3].Split(new char[] + { + ' ' + })[1]); + this.boundingBox = new Rectangle((int)this.tileLocation.X * Game1.tileSize, (int)this.tileLocation.Y * Game1.tileSize, this.defaultBoundingBox.Width * Game1.tileSize, this.defaultBoundingBox.Height * Game1.tileSize); + this.defaultBoundingBox = this.boundingBox; + } + this.updateDrawPosition(); + this.rotations = Convert.ToInt32(array[4]); + this.price = Convert.ToInt32(array[5]); + this.parentSheetIndex = which; + } + + public override string getDescription() + { + return this.description; + } + + public override bool performDropDownAction(StardewValley.Farmer who) + { + this.resetOnPlayerEntry((who == null) ? Game1.currentLocation : who.currentLocation); + return false; + } + + public override void resetOnPlayerEntry(GameLocation environment) + { + + if (Game1.isDarkOut() || Game1.timeOfDay <= 500) + { + this.addLights(thisLocation); + } + base.resetOnPlayerEntry(environment); + } + + public override void hoverAction() + { + base.hoverAction(); + if (!Game1.player.isInventoryFull()) + { + Game1.mouseCursor = 2; + } + } + + public override bool checkForAction(StardewValley.Farmer who, bool justCheckingForActivity = false) + { + var mState = Microsoft.Xna.Framework.Input.Mouse.GetState(); + if (mState.RightButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed) + { + return this.RightClicked(who); + + // Game1.showRedMessage("YOOO"); + //do some stuff when the right button is down + // rotate(); + if (this.heldObject != null) + { + // Game1.player.addItemByMenuIfNecessary(this.heldObject); + // this.heldObject = null; + } + else + { + // this.heldObject = Game1.player.ActiveObject; + // Game1.player.removeItemFromInventory(heldObject); + } + //this.minutesUntilReady = 30; + } + else + { + //Game1.showRedMessage("CRY"); + } + + if (justCheckingForActivity) + { + return true; + } + return this.clicked(who); + } + + //DONT USE THIS BASE IT IS TERRIBLE + public override bool clicked(StardewValley.Farmer who) + { + + // Game1.showRedMessage("THIS IS CLICKED!!!"); + //var mState = Microsoft.Xna.Framework.Input.Mouse.GetState(); + + + if (removable == false) return false; + + + Game1.haltAfterCheck = false; + if (this.Decoration_type == 11 && who.ActiveObject != null && who.ActiveObject != null && this.heldObject == null) + { + // Game1.showRedMessage("Why1?"); + return false; + } + if (this.heldObject == null && (who.ActiveObject == null || !(who.ActiveObject is Light))) + { + if (Game1.player.currentLocation is FarmHouse) + { + // + Util.addItemToInventoryAndCleanTrackedList(this); + removeLights(this.thisLocation); + this.lightsOn = false; + Game1.playSound("coin"); + // this.flaggedForPickUp = true; + thisLocation = null; + return true; + } + else + { + // return true; + // this.heldObject = new Light(parentSheetIndex, Vector2.Zero, this.lightColor, this.inventoryMaxSize); + Util.addItemToInventoryAndCleanTrackedList(this); + removeLights(this.thisLocation); + this.lightsOn = false; + Game1.playSound("coin"); + thisLocation = null; + return true; + + } + } + if (this.heldObject != null && who.addItemToInventoryBool(this.heldObject, false)) + { + // Game1.showRedMessage("Why3?"); + // if(this.heldObject!=null) Game1.player.addItemByMenuIfNecessary((Item)this.heldObject); + Util.addItemToInventoryAndCleanTrackedList(this); + this.heldObject.performRemoveAction(this.tileLocation, who.currentLocation); + this.heldObject = null; + Game1.playSound("coin"); + removeLights(this.thisLocation); + this.lightsOn = false; + thisLocation = null; + return true; + } + return false; + } + + public override bool RightClicked(StardewValley.Farmer who) + { + //Game1.activeClickableMenu = new Revitalize.Menus.LightCustomizer(this); + if (this.inputInventory == null) + { + Log.AsyncG(">>>>>>>>??????????????????>>>>>>>>>>>>>"); + } + if (this.outputInventory == null) + { + Log.AsyncC(">??????????????"); + } + Log.AsyncM(this.GetType()); + // this.outputInventory.Add(new Revitalize.Objects.Light(0, Vector2.Zero, LightColors.Azure, LightColors.Azure)); + Game1.activeClickableMenu = new Revitalize.Menus.Machines.MachineInventory(this, this.inputInventory, this.outputInventory, 3); + return false; + } + + public override void DayUpdate(GameLocation location) + { + base.DayUpdate(location); + this.lightGlowAdded = false; + if (!Game1.isDarkOut() || (Game1.newDay && !Game1.isRaining) || Game1.timeOfDay <= 500) + { + this.removeLights(location); + return; + } + // this.addLights(thisLocation, lightColor); + this.addLights(thisLocation, lightColor); + } + + public override bool performObjectDropInAction(StardewValley.Object dropIn, bool probe, StardewValley.Farmer who) + { + // Log.AsyncG("HEY!"); + if ((this.Decoration_type == 11 || this.Decoration_type == 5) && this.heldObject == null && !dropIn.bigCraftable && (!(dropIn is Light) || ((dropIn as Light).getTilesWide() == 1 && (dropIn as Light).getTilesHigh() == 1))) + { + this.heldObject = (StardewValley.Object)dropIn.getOne(); + this.heldObject.tileLocation = this.tileLocation; + this.heldObject.boundingBox.X = this.boundingBox.X; + this.heldObject.boundingBox.Y = this.boundingBox.Y; + // Log.AsyncO(getDefaultBoundingBoxForType((dropIn as Light).Decoration_type)); + this.heldObject.performDropDownAction(who); + if (!probe) + { + Game1.playSound("woodyStep"); + // Log.AsyncC("HUH?"); + if (who != null) + { + who.reduceActiveItemByOne(); + } + } + return true; + } + return false; + } + + + public override bool minutesElapsed(int minutes, GameLocation environment) + { + + this.minutesUntilReady = (this.minutesUntilReady - minutes); + + if (Game1.isDarkOut() || Game1.timeOfDay <= 500) + { + this.addLights(thisLocation); + } + + if (minutesUntilReady == 0) + { + minutesUntilReady = 10; + if(Util.isInventoryFull(this.outputInventory) == false) + { + Util.addItemToOtherInventory(this.outputInventory,(Item)(new StardewValley.Object(388, 1))); + } + } + + return false; + } + + public override void performRemoveAction(Vector2 tileLocation, GameLocation environment) + { + this.removeLights(environment); + if (this.Decoration_type == 13 && this.lightGlowAdded) + { + environment.lightGlows.Remove(new Vector2((float)(this.boundingBox.X + Game1.tileSize / 2), (float)(this.boundingBox.Y + Game1.tileSize))); + this.lightGlowAdded = false; + } + this.spillInventoryEverywhere(); + base.performRemoveAction(tileLocation, environment); + } + + + public override bool isGroundFurniture() + { + return this.Decoration_type != 13 && this.Decoration_type != 6 && this.Decoration_type != 13; + } + + public override bool canBeGivenAsGift() + { + return false; + } + + public override bool canBePlacedHere(GameLocation l, Vector2 tile) + { + if ((l is FarmHouse)) + { + for (int i = 0; i < this.boundingBox.Width / Game1.tileSize; i++) + { + for (int j = 0; j < this.boundingBox.Height / Game1.tileSize; j++) + { + Vector2 vector = tile * (float)Game1.tileSize + new Vector2((float)i, (float)j) * (float)Game1.tileSize; + vector.X += (float)(Game1.tileSize / 2); + vector.Y += (float)(Game1.tileSize / 2); + foreach (KeyValuePair something in l.objects) + { + StardewValley.Object obj = something.Value; + if ((obj.GetType()).ToString().Contains("Light")) + { + Light current = (Light)obj; + if (current.Decoration_type == 11 && current.getBoundingBox(current.tileLocation).Contains((int)vector.X, (int)vector.Y) && current.heldObject == null && this.getTilesWide() == 1) + { + bool result = true; + return result; + } + if ((current.Decoration_type != 12 || this.Decoration_type == 12) && current.getBoundingBox(current.tileLocation).Contains((int)vector.X, (int)vector.Y)) + { + bool result = false; + return result; + } + } + } + } + } + return base.canBePlacedHere(l, tile); + } + else + { + // Game1.showRedMessage("NOT FARMHOUSE"); + for (int i = 0; i < this.boundingBox.Width / Game1.tileSize; i++) + { + for (int j = 0; j < this.boundingBox.Height / Game1.tileSize; j++) + { + Vector2 vector = tile * (float)Game1.tileSize + new Vector2((float)i, (float)j) * (float)Game1.tileSize; + vector.X += (float)(Game1.tileSize / 2); + vector.Y += (float)(Game1.tileSize / 2); + + } + } + return Util.canBePlacedHere(this, l, tile); + } + } + + public override void updateDrawPosition() + { + this.drawPosition = new Vector2((float)this.boundingBox.X, (float)(this.boundingBox.Y - (this.sourceRect.Height * Game1.pixelZoom - this.boundingBox.Height))); + } + + public override int getTilesWide() + { + return this.boundingBox.Width / Game1.tileSize; + } + + public override int getTilesHigh() + { + return this.boundingBox.Height / Game1.tileSize; + } + + public override bool placementAction(GameLocation location, int x, int y, StardewValley.Farmer who = null) + { + + if (location is FarmHouse) + { + Point point = new Point(x / Game1.tileSize, y / Game1.tileSize); + List walls = FarmHouse.getWalls((location as FarmHouse).upgradeLevel); + this.tileLocation = new Vector2((float)point.X, (float)point.Y); + bool flag = false; + if (this.Decoration_type == 6 || this.Decoration_type == 13 || this.parentSheetIndex == 1293) + { + int num = (this.parentSheetIndex == 1293) ? 3 : 0; + bool flag2 = false; + foreach (Rectangle current in walls) + { + if ((this.Decoration_type == 6 || this.Decoration_type == 13 || num != 0) && current.Y + num == point.Y && current.Contains(point.X, point.Y - num)) + { + flag2 = true; + break; + } + } + if (!flag2) + { + Game1.showRedMessage("Must be placed on wall"); + return false; + } + flag = true; + } + for (int i = point.X; i < point.X + this.getTilesWide(); i++) + { + for (int j = point.Y; j < point.Y + this.getTilesHigh(); j++) + { + if (location.doesTileHaveProperty(i, j, "NoFurniture", "Back") != null) + { + Game1.showRedMessage("Furniture can't be placed here"); + return false; + } + if (!flag && Utility.pointInRectangles(walls, i, j)) + { + Game1.showRedMessage("Can't place on wall"); + return false; + } + if (location.getTileIndexAt(i, j, "Buildings") != -1) + { + return false; + } + } + } + this.boundingBox = new Rectangle(x / Game1.tileSize * Game1.tileSize, y / Game1.tileSize * Game1.tileSize, this.boundingBox.Width, this.boundingBox.Height); + foreach (KeyValuePair c in location.objects) + { + StardewValley.Object ehh = c.Value; + if (((ehh.GetType()).ToString()).Contains("Spawner")) + { + Decoration current2 = (Decoration)ehh; + if (current2.Decoration_type == 11 && current2.heldObject == null && current2.getBoundingBox(current2.tileLocation).Intersects(this.boundingBox)) + { + current2.performObjectDropInAction(this, false, (who == null) ? Game1.player : who); + bool result = true; + return result; + } + } + } + foreach (StardewValley.Farmer current3 in location.getFarmers()) + { + if (current3.GetBoundingBox().Intersects(this.boundingBox)) + { + Game1.showRedMessage("Can't place on top of a person."); + bool result = false; + return result; + } + } + this.updateDrawPosition(); + // Log.AsyncO(this.boundingBox); + // Log.AsyncO(x); + // Log.AsyncY(y); + for (int i = 0; i <= this.boundingBox.X / Game1.tileSize; i++) + { + Util.placementAction(this, location, x + 1, y, who); + } + for (int i = 0; i <= this.boundingBox.Y / Game1.tileSize; i++) + { + Util.placementAction(this, location, x + 1, y, who); + } + return true; + } + else + { + Point point = new Point(x / Game1.tileSize, y / Game1.tileSize); + // List walls = FarmHouse.getWalls((location as FarmHouse).upgradeLevel); + this.tileLocation = new Vector2((float)point.X, (float)point.Y); + bool flag = false; + if (this.Decoration_type == 6 || this.Decoration_type == 13 || this.parentSheetIndex == 1293) + { + int num = (this.parentSheetIndex == 1293) ? 3 : 0; + bool flag2 = false; + if (!flag2) + { + Game1.showRedMessage("Must be placed on wall"); + return false; + } + flag = true; + } + for (int i = point.X; i < point.X + this.getTilesWide(); i++) + { + for (int j = point.Y; j < point.Y + this.getTilesHigh(); j++) + { + if (location.doesTileHaveProperty(i, j, "NoFurniture", "Back") != null) + { + Game1.showRedMessage("Furniture can't be placed here"); + return false; + } + /* + if (!flag && Utility.pointInRectangles(walls, i, j)) + { + Game1.showRedMessage("Can't place on wall"); + return false; + } + */ + if (location.getTileIndexAt(i, j, "Buildings") != -1) + { + return false; + } + } + } + this.boundingBox = new Rectangle(x / Game1.tileSize * Game1.tileSize, y / Game1.tileSize * Game1.tileSize, this.boundingBox.Width, this.boundingBox.Height); + + foreach (StardewValley.Farmer current3 in location.getFarmers()) + { + if (current3.GetBoundingBox().Intersects(this.boundingBox)) + { + Game1.showRedMessage("Can't place on top of a person."); + bool result = false; + return result; + } + } + this.updateDrawPosition(); + this.thisLocation = Game1.player.currentLocation; + return Util.placementAction(this, location, x, y, who); + } + + } + + public override bool isPlaceable() + { + return true; + } + + public override Rectangle getBoundingBox(Vector2 tileLocation) + { + return this.boundingBox; + } + + private Rectangle getDefaultSourceRectForType(int tileIndex, int type) + { + int num; + int num2; + switch (type) + { + case 0: + num = 1; + num2 = 2; + goto IL_94; + case 1: + num = 2; + num2 = 2; + goto IL_94; + case 2: + num = 3; + num2 = 2; + goto IL_94; + case 3: + num = 2; + num2 = 2; + goto IL_94; + case 4: + num = 2; + num2 = 2; + goto IL_94; + case 5: + num = 5; + num2 = 3; + goto IL_94; + case 6: + num = 2; + num2 = 2; + goto IL_94; + case 7: + num = 1; + num2 = 3; + goto IL_94; + case 8: + num = 1; + num2 = 2; + goto IL_94; + case 10: + num = 2; + num2 = 3; + goto IL_94; + case 11: + num = 2; + num2 = 3; + goto IL_94; + case 12: + num = 3; + num2 = 2; + goto IL_94; + case 13: + num = 1; + num2 = 2; + goto IL_94; + } + num = 1; + num2 = 2; + IL_94: + return new Rectangle(tileIndex * 16 % TextureSheet.Width, tileIndex * 16 / TextureSheet.Width * 16, num * 16, num2 * 16); + } + + private Rectangle getDefaultBoundingBoxForType(int type) + { + int num; + int num2; + switch (type) + { + case 0: + num = 1; + num2 = 1; + goto IL_94; + case 1: + num = 2; + num2 = 1; + goto IL_94; + case 2: + num = 3; + num2 = 1; + goto IL_94; + case 3: + num = 2; + num2 = 1; + goto IL_94; + case 4: + num = 2; + num2 = 1; + goto IL_94; + case 5: + num = 5; + num2 = 2; + goto IL_94; + case 6: + num = 2; + num2 = 2; + goto IL_94; + case 7: + num = 1; + num2 = 1; + goto IL_94; + case 8: + num = 1; + num2 = 1; + goto IL_94; + case 10: + num = 2; + num2 = 1; + goto IL_94; + case 11: + num = 2; + num2 = 2; + goto IL_94; + case 12: + num = 3; + num2 = 2; + goto IL_94; + case 13: + num = 1; + num2 = 2; + goto IL_94; + } + num = 1; + num2 = 1; + IL_94: + return new Rectangle((int)this.tileLocation.X * Game1.tileSize, (int)this.tileLocation.Y * Game1.tileSize, num * Game1.tileSize, num2 * Game1.tileSize); + } + + + public override int salePrice() + { + return this.price; + } + + public override int maximumStackSize() + { + return 1; + } + + public override int getStack() + { + return this.stack; + } + + public override int addToStack(int amount) + { + return 1; + } + + private float getScaleSize() + { + int num = this.sourceRect.Width / 16; + int num2 = this.sourceRect.Height / 16; + if (num >= 5) + { + return 0.75f; + } + if (num2 >= 3) + { + return 1f; + } + if (num <= 2) + { + return 2f; + } + if (num <= 4) + { + return 1f; + } + return 0.1f; + } + + public override void drawWhenHeld(SpriteBatch spriteBatch, Vector2 objectPosition, StardewValley.Farmer f) + { + if (TextureSheet == null) + { + TextureSheet = Game1.content.Load(texturePath); + } + if (areLightAndDrawColorsDifferent == false) spriteBatch.Draw(this.TextureSheet, objectPosition, new Microsoft.Xna.Framework.Rectangle?(Game1.currentLocation.getSourceRectForObject(f.ActiveObject.ParentSheetIndex)), Util.invertColor(this.lightColor), 0f, Vector2.Zero, (float)Game1.pixelZoom, SpriteEffects.None, Math.Max(0f, (float)(f.getStandingY() + 2) / 10000f)); + else + { + spriteBatch.Draw(this.TextureSheet, objectPosition, new Microsoft.Xna.Framework.Rectangle?(Game1.currentLocation.getSourceRectForObject(f.ActiveObject.ParentSheetIndex)), Util.invertColor(this.drawColor), 0f, Vector2.Zero, (float)Game1.pixelZoom, SpriteEffects.None, Math.Max(0f, (float)(f.getStandingY() + 2) / 10000f)); + } + + /* + if (f.ActiveObject != null && f.ActiveObject.Name.Contains("=")) + { + spriteBatch.Draw(Game1.objectSpriteSheet, objectPosition + new Vector2((float)(Game1.tileSize / 2), (float)(Game1.tileSize / 2)), new Microsoft.Xna.Framework.Rectangle?(Game1.currentLocation.getSourceRectForObject(f.ActiveObject.ParentSheetIndex)), Color.White, 0f, new Vector2((float)(Game1.tileSize / 2), (float)(Game1.tileSize / 2)), (float)Game1.pixelZoom + Math.Abs(Game1.starCropShimmerPause) / 8f, SpriteEffects.None, Math.Max(0f, (float)(f.getStandingY() + 2) / 10000f)); + if (Math.Abs(Game1.starCropShimmerPause) <= 0.05f && Game1.random.NextDouble() < 0.97) + { + return; + } + Game1.starCropShimmerPause += 0.04f; + if (Game1.starCropShimmerPause >= 0.8f) + { + Game1.starCropShimmerPause = -0.8f; + } + } + */ + } + + public override void drawInMenu(SpriteBatch spriteBatch, Vector2 location, float scaleSize, float transparency, float layerDepth, bool drawStackNumber) + { + if (TextureSheet == null) + { + TextureSheet = Game1.content.Load(texturePath); + } + if (areLightAndDrawColorsDifferent == false) spriteBatch.Draw(TextureSheet, location + new Vector2((float)(Game1.tileSize / 2), (float)(Game1.tileSize / 2)), new Rectangle?(this.defaultSourceRect), Util.invertColor(this.lightColor), 0f, new Vector2((float)(this.defaultSourceRect.Width / 2), (float)(this.defaultSourceRect.Height / 2)), 1f * this.getScaleSize() * scaleSize, SpriteEffects.None, layerDepth); + else + { + spriteBatch.Draw(TextureSheet, location + new Vector2((float)(Game1.tileSize / 2), (float)(Game1.tileSize / 2)), new Rectangle?(this.defaultSourceRect), Util.invertColor(this.drawColor), 0f, new Vector2((float)(this.defaultSourceRect.Width / 2), (float)(this.defaultSourceRect.Height / 2)), 1f * this.getScaleSize() * scaleSize, SpriteEffects.None, layerDepth); + } + } + + public override void draw(SpriteBatch spriteBatch, int x, int y, float alpha = 1f) + { + if (TextureSheet == null) + { + TextureSheet = Game1.content.Load(texturePath); + } + if (x == -1) + { + if (areLightAndDrawColorsDifferent == false) spriteBatch.Draw(TextureSheet, Game1.GlobalToLocal(Game1.viewport, this.drawPosition), new Rectangle?(this.sourceRect), Util.invertColor(this.lightColor) * alpha, 0f, Vector2.Zero, (float)Game1.pixelZoom, this.flipped ? SpriteEffects.FlipHorizontally : SpriteEffects.None, (this.Decoration_type == 12) ? 0f : ((float)(this.boundingBox.Bottom - 8) / 10000f)); + else spriteBatch.Draw(TextureSheet, Game1.GlobalToLocal(Game1.viewport, this.drawPosition), new Rectangle?(this.sourceRect), Util.invertColor(this.drawColor) * alpha, 0f, Vector2.Zero, (float)Game1.pixelZoom, this.flipped ? SpriteEffects.FlipHorizontally : SpriteEffects.None, (this.Decoration_type == 12) ? 0f : ((float)(this.boundingBox.Bottom - 8) / 10000f)); + } + else + { + if (areLightAndDrawColorsDifferent == false) spriteBatch.Draw(TextureSheet, Game1.GlobalToLocal(Game1.viewport, new Vector2((float)(x * Game1.tileSize), (float)(y * Game1.tileSize - (this.sourceRect.Height * Game1.pixelZoom - this.boundingBox.Height)))), new Rectangle?(this.sourceRect), Util.invertColor(this.lightColor) * alpha, 0f, Vector2.Zero, (float)Game1.pixelZoom, this.flipped ? SpriteEffects.FlipHorizontally : SpriteEffects.None, (this.Decoration_type == 12) ? 0f : ((float)(this.boundingBox.Bottom - 8) / 10000f)); + else spriteBatch.Draw(TextureSheet, Game1.GlobalToLocal(Game1.viewport, new Vector2((float)(x * Game1.tileSize), (float)(y * Game1.tileSize - (this.sourceRect.Height * Game1.pixelZoom - this.boundingBox.Height)))), new Rectangle?(this.sourceRect), Util.invertColor(this.drawColor) * alpha, 0f, Vector2.Zero, (float)Game1.pixelZoom, this.flipped ? SpriteEffects.FlipHorizontally : SpriteEffects.None, (this.Decoration_type == 12) ? 0f : ((float)(this.boundingBox.Bottom - 8) / 10000f)); + } + if (this.heldObject != null) + { + if (this.heldObject is Light) + { + (this.heldObject as Light).drawAtNonTileSpot(spriteBatch, Game1.GlobalToLocal(Game1.viewport, new Vector2((float)(this.boundingBox.Center.X - Game1.tileSize / 2), (float)(this.boundingBox.Center.Y - (this.heldObject as Spell).sourceRect.Height * Game1.pixelZoom - Game1.tileSize / 4))), (float)(this.boundingBox.Bottom - 7) / 10000f, alpha); + return; + } + if (areLightAndDrawColorsDifferent == false) + { + spriteBatch.Draw(Game1.shadowTexture, Game1.GlobalToLocal(Game1.viewport, new Vector2((float)(this.boundingBox.Center.X - Game1.tileSize / 2), (float)(this.boundingBox.Center.Y - Game1.tileSize * 4 / 3))) + new Vector2((float)(Game1.tileSize / 2), (float)(Game1.tileSize * 5 / 6)), new Rectangle?(Game1.shadowTexture.Bounds), Util.invertColor(this.lightColor) * alpha, 0f, new Vector2((float)Game1.shadowTexture.Bounds.Center.X, (float)Game1.shadowTexture.Bounds.Center.Y), 4f, SpriteEffects.None, (float)this.boundingBox.Bottom / 10000f); + spriteBatch.Draw(Game1.objectSpriteSheet, Game1.GlobalToLocal(Game1.viewport, new Vector2((float)(this.boundingBox.Center.X - Game1.tileSize / 2), (float)(this.boundingBox.Center.Y - Game1.tileSize * 4 / 3))), new Rectangle?(Game1.currentLocation.getSourceRectForObject(this.heldObject.ParentSheetIndex)), Util.invertColor(this.lightColor) * alpha, 0f, Vector2.Zero, (float)Game1.pixelZoom, SpriteEffects.None, (float)(this.boundingBox.Bottom + 1) / 10000f); + } + else + { + spriteBatch.Draw(Game1.shadowTexture, Game1.GlobalToLocal(Game1.viewport, new Vector2((float)(this.boundingBox.Center.X - Game1.tileSize / 2), (float)(this.boundingBox.Center.Y - Game1.tileSize * 4 / 3))) + new Vector2((float)(Game1.tileSize / 2), (float)(Game1.tileSize * 5 / 6)), new Rectangle?(Game1.shadowTexture.Bounds), Util.invertColor(this.drawColor) * alpha, 0f, new Vector2((float)Game1.shadowTexture.Bounds.Center.X, (float)Game1.shadowTexture.Bounds.Center.Y), 4f, SpriteEffects.None, (float)this.boundingBox.Bottom / 10000f); + spriteBatch.Draw(Game1.objectSpriteSheet, Game1.GlobalToLocal(Game1.viewport, new Vector2((float)(this.boundingBox.Center.X - Game1.tileSize / 2), (float)(this.boundingBox.Center.Y - Game1.tileSize * 4 / 3))), new Rectangle?(Game1.currentLocation.getSourceRectForObject(this.heldObject.ParentSheetIndex)), Util.invertColor(this.drawColor) * alpha, 0f, Vector2.Zero, (float)Game1.pixelZoom, SpriteEffects.None, (float)(this.boundingBox.Bottom + 1) / 10000f); + } + + } + } + + public override void drawAtNonTileSpot(SpriteBatch spriteBatch, Vector2 location, float layerDepth, float alpha = 1f) + { + if (TextureSheet == null) + { + TextureSheet = Game1.content.Load(texturePath); + } + spriteBatch.Draw(TextureSheet, location, new Rectangle?(this.sourceRect), Util.invertColor(this.drawColor) * alpha, 0f, Vector2.Zero, (float)Game1.pixelZoom, this.flipped ? SpriteEffects.FlipHorizontally : SpriteEffects.None, layerDepth); + } + + public override Item getOne() + { + TestMachine Light = new TestMachine(this.parentSheetIndex, this.tileLocation, this.lightColor, this.drawColor, this.areLightAndDrawColorsDifferent); + /* + drawPosition = this.drawPosition; + defaultBoundingBox = this.defaultBoundingBox; + boundingBox = this.boundingBox; + currentRotation = this.currentRotation - 1; + rotations = this.rotations; + rotate(); + */ + return Light; + } + + public override string getCategoryName() + { + return "Machine"; + // return base.getCategoryName(); + } + + public override Color getCategoryColor() + { + return Util.invertColor(LightColors.Black); + } + + public static TestMachine ParseObject(string data) + { + TestMachine h = Serialize.ReadFromXMLFile(data); + return h; + } + public static void SerializeObject(Item d) + { + Serialize.WriteToXMLFile(Path.Combine(Serialize.InvPath, d.Name + ".xml"), (TestMachine)d); + // Serialize.WriteToJsonFile(Path.Combine(InvPath, d.Name + ".json"), (BagofHolding)d); + } + public static void SerializeObjectFromWorld(CoreObject d) + { + Serialize.WriteToXMLFile(Path.Combine(Serialize.objectsInWorldPath, d.thisLocation.name, d.Name + ".xml"), (TestMachine)d); + } + + } +} diff --git a/Revitalize/Revitalize/Revitalize/Resources/Dictionaries.cs b/Revitalize/Revitalize/Revitalize/Resources/Dictionaries.cs index 1798d2d9..e998f4f2 100644 --- a/Revitalize/Revitalize/Revitalize/Resources/Dictionaries.cs +++ b/Revitalize/Revitalize/Revitalize/Resources/Dictionaries.cs @@ -68,7 +68,8 @@ namespace Revitalize.Resources acceptedTypes.Add("Revitalize.Objects.ExtraSeeds", new SerializerDataNode(new ser(Serialize.serializeExtraSeeds), new par(Serialize.parseExtraSeeds),null)); acceptedTypes.Add("Revitalize.Objects.Spell", new SerializerDataNode(new ser(Serialize.serializeSpell), new par(Serialize.parseSpell), null)); acceptedTypes.Add("Revitalize.Magic.Alchemy.Objects.BagofHolding", new SerializerDataNode(new ser(Serialize.serializeBagOfHolding), new par(Serialize.parseBagOfHolding), null)); - } + acceptedTypes.Add("Revitalize.Objects.Machines.TestMachine", new SerializerDataNode(new ser(Revitalize.Objects.Machines.TestMachine.SerializeObject), new par(Objects.Machines.TestMachine.ParseObject), new world(Objects.Machines.TestMachine.SerializeObjectFromWorld))); + } public static void addAllInteractionTypes() { diff --git a/Revitalize/Revitalize/Revitalize/Revitalize.csproj b/Revitalize/Revitalize/Revitalize/Revitalize.csproj index eacaad2a..1f9ed68e 100644 --- a/Revitalize/Revitalize/Revitalize/Revitalize.csproj +++ b/Revitalize/Revitalize/Revitalize/Revitalize.csproj @@ -56,8 +56,10 @@ + + @@ -80,7 +82,6 @@ - diff --git a/Revitalize/Revitalize/Revitalize/Serialize.cs b/Revitalize/Revitalize/Revitalize/Serialize.cs index b01dfdf0..40695833 100644 --- a/Revitalize/Revitalize/Revitalize/Serialize.cs +++ b/Revitalize/Revitalize/Revitalize/Serialize.cs @@ -44,6 +44,7 @@ namespace Revitalize ProcessDirectoryForDeletion(objectsInWorldPath); List removalList = new List(); int countProcessed = 0; + List idk = new List(); foreach (CoreObject d in Lists.trackedObjectList) { try @@ -60,7 +61,7 @@ namespace Revitalize } string s = Convert.ToString((d.GetType())); - + if (Dictionaries.acceptedTypes.ContainsKey(s)) { SerializerDataNode t; @@ -69,7 +70,14 @@ namespace Revitalize if (works == true) { countProcessed++; - t.worldObj.Invoke(d); + if (d.useXML == false) + { + t.worldObj.Invoke(d); + } + else + { + idk.Add(d); + } Log.AsyncC("Progress on saving objects: " + countProcessed + "/" + Lists.trackedObjectList.Count); removalList.Add(d); } @@ -79,8 +87,29 @@ namespace Revitalize { i.thisLocation.removeObject(i.tileLocation, false); } - removalList.Clear(); + foreach(var v in idk) + { + string s = Convert.ToString((v.GetType())); + if (Dictionaries.acceptedTypes.ContainsKey(s)) + { + SerializerDataNode t; + + bool works = Dictionaries.acceptedTypes.TryGetValue(s, out t); + if (works == true) + { + countProcessed++; + if ((v as CoreObject).useXML == true) + { + t.worldObj.Invoke(v as CoreObject); + } + Log.AsyncG("Progress on saving objects: " + countProcessed + "/" + Lists.trackedObjectList.Count); + removalList.Add(v as CoreObject); + } + } + } + + removalList.Clear(); Log.AsyncM("Revitalize: Done cleaning world for saving."); } @@ -372,8 +401,8 @@ namespace Revitalize { // Create an instance of the XmlSerializer class; // specify the type of object to serialize. - XmlSerializer serializer = - new XmlSerializer(typeof(T)); + + XmlSerializer serializer = new XmlSerializer(typeof(T)); TextWriter writer = new StreamWriter(filePath); serializer.Serialize(writer, objectToWrite); @@ -1213,10 +1242,9 @@ namespace Revitalize public static void serializeBagOfHolding(Item d) { WriteToXMLFile(Path.Combine(InvPath, d.Name + ".xml"), (BagofHolding)d); - // Serialize.WriteToJsonFile(Path.Combine(InvPath, d.Name + ".json"), (BagofHolding)d); + // Serialize.WriteToJsonFile(Path.Combine(InvPath, d.Name + ".json"), (BagofHolding)d); } - public static Quarry parseQuarry(string data) { dynamic obj = JObject.Parse(data); diff --git a/Revitalize/Revitalize/Revitalize/Utilities/Util.cs b/Revitalize/Revitalize/Revitalize/Utilities/Util.cs index 6c1a143b..81ab1f39 100644 --- a/Revitalize/Revitalize/Revitalize/Utilities/Util.cs +++ b/Revitalize/Revitalize/Revitalize/Utilities/Util.cs @@ -96,10 +96,14 @@ namespace Revitalize return false; } } - public static bool isInventoryFull(List inventory) + public static bool isInventoryFull(List inventory, bool logInfo=false) { - // Log.AsyncG("size "+inventory.Count); - // Log.AsyncG("max "+inventory.Capacity); + if (logInfo) + { + Log.AsyncG("size " + inventory.Count); + Log.AsyncG("max " + inventory.Capacity); + } + if (inventory.Count == inventory.Capacity) return true; else return false; }