/* * item: The item to remove * numberOfItems: The number of this item to remove * returns true if it successfully removed a item * */ public bool removeItem(ItemHud item, int numberOfItems) { foreach (InventorySlotHud slotHud in slots) { if (slotHud.getContainsItem() && slotHud.getItemHud().Equals(item)) { int id = -1; if (slotHud.getNumberOfItems() == 1) { slotHud.setItemHud(null); slotHud.setContainsItem(false); } slotHud.setNumberOfItems(slotHud.getNumberOfItems() - numberOfItems); //Checks what type of item we are adding to the inventory if (item.getItemType() == EItemType.SCREW) { id = 0; } else if (item.getItemType() == EItemType.OILCAN) { id = 1; } else if (item.getItemType() == EItemType.CEMENT) { id = 2; } else if (item.getItemType() == EItemType.APPLE) { id = 3; } else if (item.getItemType() == EItemType.CORN) { id = 4; } else if (item.getItemType() == EItemType.TREEGUN) { id = 5; } else if (item.getItemType() == EItemType.SHOVEL) { id = 6; } else if (item.getItemType() == EItemType.PICKAXE) { id = 7; } //Adds the font associated with this item SceneManager.getInstance.getFontManager().addFont(new Font(EFontType.STATIC, id, "FontInventory", ResourceManager.getInstance.Font2, slotHud.getNumberOfItems() + "", new Vector2(slotHud.Properties.getProperty <Vector2>("Position").X + 4.0f, slotHud.Properties.getProperty <Vector2>("Position").Y - 35.0f), Color.Red, -1.0f)); return(true); } } return(false); }
/* * item: The item to remove * numberOfItems: The number of this item to remove * returns true if it successfully removed a item * */ public bool removeItem(ItemHud item, int numberOfItems) { foreach (InventorySlotHud slotHud in slots) { if (slotHud.getContainsItem() && slotHud.getItemHud().Equals(item)) { int id = -1; if (slotHud.getNumberOfItems() == 1) { slotHud.setItemHud(null); slotHud.setContainsItem(false); } slotHud.setNumberOfItems(slotHud.getNumberOfItems() - numberOfItems); //Checks what type of item we are adding to the inventory if (item.getItemType() == EItemType.SCREW) { id = 0; } else if (item.getItemType() == EItemType.OILCAN) { id = 1; } else if (item.getItemType() == EItemType.CEMENT) { id = 2; } else if (item.getItemType() == EItemType.APPLE) { id = 3; } else if (item.getItemType() == EItemType.CORN) { id = 4; } else if (item.getItemType() == EItemType.TREEGUN) { id = 5; } else if (item.getItemType() == EItemType.SHOVEL) { id = 6; } else if (item.getItemType() == EItemType.PICKAXE) { id = 7; } //Adds the font associated with this item SceneManager.getInstance.getFontManager().addFont(new Font(EFontType.STATIC, id, "FontInventory", ResourceManager.getInstance.Font2, slotHud.getNumberOfItems() + "", new Vector2(slotHud.Properties.getProperty<Vector2>("Position").X + 4.0f, slotHud.Properties.getProperty<Vector2>("Position").Y - 35.0f), Color.Red, -1.0f)); return true; } } return false; }
/* * item: The item to add if its not already in the list. If it is in the list we only increase the number of this item * numberOfItems: How many of this item we add. Invalid to send in a value that is less than 1 * slotType: The slot which we want to insert this item into * returns true if it was successfully inserted * */ public bool insertItem(ItemHud item, int numberOfItems, ESlotType slotType) { if (numberOfItems > 0) { foreach (InventorySlotHud slotHud in slots) { if (slotHud.getSlotType() == slotType) { int id = -1; if (!slotHud.getContainsItem()) { //Console.WriteLine("Insert"); Vector2 position = slotHud.Properties.getProperty<Vector2>("Position"); Texture2D texture = item.Properties.getProperty<Texture2D>("Texture2D"); float rotation = item.Properties.getProperty<float>("Rotation"); Vector2 origin = item.Properties.getProperty<Vector2>("Origin"); Vector2 scale = item.Properties.getProperty<Vector2>("Scale"); ItemHud newItem = new ItemHud(item.getItemType(), texture, position, rotation, origin, scale); slotHud.setItemHud(newItem); slotHud.setContainsItem(true); if (slotType == ESlotType.OTHER) { slotHud.setNumberOfItems(slotHud.getNumberOfItems() + numberOfItems); //Checks what type of item we are adding to the inventory if (newItem.getItemType() == EItemType.SCREW) { id = 0; } else if (newItem.getItemType() == EItemType.OILCAN) { id = 1; } else if (newItem.getItemType() == EItemType.CEMENT) { id = 2; } else if (newItem.getItemType() == EItemType.APPLE) { id = 3; } else if (newItem.getItemType() == EItemType.CORN) { id = 4; } else if (newItem.getItemType() == EItemType.TREEGUN) { id = 5; } else if (newItem.getItemType() == EItemType.SHOVEL) { id = 6; } else if (newItem.getItemType() == EItemType.PICKAXE) { id = 7; } //Adds the font associated with this item SceneManager.getInstance.getFontManager().addFont(new Font(EFontType.STATIC, id, "FontInventory", ResourceManager.getInstance.Font2, slotHud.getNumberOfItems() + "", new Vector2(position.X + 4.0f, position.Y - 35.0f), Color.Red, -1.0f)); } return true; } else if (slotHud.getContainsItem() && slotHud.getItemHud().Equals(item)) { //Console.WriteLine("Count up"); if (slotType == ESlotType.OTHER) { slotHud.setNumberOfItems(slotHud.getNumberOfItems() + numberOfItems); //Checks what type of item we are adding to the inventory if (item.getItemType() == EItemType.SCREW) { id = 0; } else if (item.getItemType() == EItemType.OILCAN) { id = 1; } else if (item.getItemType() == EItemType.CEMENT) { id = 2; } else if (item.getItemType() == EItemType.APPLE) { id = 3; } else if (item.getItemType() == EItemType.CORN) { id = 4; } else if (item.getItemType() == EItemType.TREEGUN) { id = 5; } else if (item.getItemType() == EItemType.SHOVEL) { id = 6; } else if (item.getItemType() == EItemType.PICKAXE) { id = 7; } //Adds the font associated with this item SceneManager.getInstance.getFontManager().addFont(new Font(EFontType.STATIC, id, "FontInventory", ResourceManager.getInstance.Font2, slotHud.getNumberOfItems() + "", new Vector2(slotHud.Properties.getProperty<Vector2>("Position").X + 4.0f, slotHud.Properties.getProperty<Vector2>("Position").Y - 35.0f), Color.Red, -1.0f)); } return true; } } } } return false; }
/* * item: The item to add if its not already in the list. If it is in the list we only increase the number of this item * numberOfItems: How many of this item we add. Invalid to send in a value that is less than 1 * slotType: The slot which we want to insert this item into * returns true if it was successfully inserted * */ public bool insertItem(ItemHud item, int numberOfItems, ESlotType slotType) { if (numberOfItems > 0) { foreach (InventorySlotHud slotHud in slots) { if (slotHud.getSlotType() == slotType) { int id = -1; if (!slotHud.getContainsItem()) { //Console.WriteLine("Insert"); Vector2 position = slotHud.Properties.getProperty <Vector2>("Position"); Texture2D texture = item.Properties.getProperty <Texture2D>("Texture2D"); float rotation = item.Properties.getProperty <float>("Rotation"); Vector2 origin = item.Properties.getProperty <Vector2>("Origin"); Vector2 scale = item.Properties.getProperty <Vector2>("Scale"); ItemHud newItem = new ItemHud(item.getItemType(), texture, position, rotation, origin, scale); slotHud.setItemHud(newItem); slotHud.setContainsItem(true); if (slotType == ESlotType.OTHER) { slotHud.setNumberOfItems(slotHud.getNumberOfItems() + numberOfItems); //Checks what type of item we are adding to the inventory if (newItem.getItemType() == EItemType.SCREW) { id = 0; } else if (newItem.getItemType() == EItemType.OILCAN) { id = 1; } else if (newItem.getItemType() == EItemType.CEMENT) { id = 2; } else if (newItem.getItemType() == EItemType.APPLE) { id = 3; } else if (newItem.getItemType() == EItemType.CORN) { id = 4; } else if (newItem.getItemType() == EItemType.TREEGUN) { id = 5; } else if (newItem.getItemType() == EItemType.SHOVEL) { id = 6; } else if (newItem.getItemType() == EItemType.PICKAXE) { id = 7; } //Adds the font associated with this item SceneManager.getInstance.getFontManager().addFont(new Font(EFontType.STATIC, id, "FontInventory", ResourceManager.getInstance.Font2, slotHud.getNumberOfItems() + "", new Vector2(position.X + 4.0f, position.Y - 35.0f), Color.Red, -1.0f)); } return(true); } else if (slotHud.getContainsItem() && slotHud.getItemHud().Equals(item)) { //Console.WriteLine("Count up"); if (slotType == ESlotType.OTHER) { slotHud.setNumberOfItems(slotHud.getNumberOfItems() + numberOfItems); //Checks what type of item we are adding to the inventory if (item.getItemType() == EItemType.SCREW) { id = 0; } else if (item.getItemType() == EItemType.OILCAN) { id = 1; } else if (item.getItemType() == EItemType.CEMENT) { id = 2; } else if (item.getItemType() == EItemType.APPLE) { id = 3; } else if (item.getItemType() == EItemType.CORN) { id = 4; } else if (item.getItemType() == EItemType.TREEGUN) { id = 5; } else if (item.getItemType() == EItemType.SHOVEL) { id = 6; } else if (item.getItemType() == EItemType.PICKAXE) { id = 7; } //Adds the font associated with this item SceneManager.getInstance.getFontManager().addFont(new Font(EFontType.STATIC, id, "FontInventory", ResourceManager.getInstance.Font2, slotHud.getNumberOfItems() + "", new Vector2(slotHud.Properties.getProperty <Vector2>("Position").X + 4.0f, slotHud.Properties.getProperty <Vector2>("Position").Y - 35.0f), Color.Red, -1.0f)); } return(true); } } } } return(false); }