using Microsoft.Xna.Framework; using Sprint3_actual.ActiveItems; using Sprint3_actual.StateFiles; using System; using System.Collections.Generic; using System.Text; namespace Sprint3_actual { public class DrawableInventorySprites { private Inventory inventory; private ILink player; private KeyValuePair<object,object>[,] inventoryItems = new KeyValuePair<object, object>[2, 4]; private ISprite cursorColor; private IStageItem activeItem; private int timer; private int row; private int col; public DrawableInventorySprites(Inventory inventory, Vector2 topCoords) { cursorColor = InventorySpriteFactory.Instance.CreateRedCursor((int)topCoords.X + 384, (int)topCoords.Y + 144); activeItem = new NullItem(); this.inventory = inventory; timer = 12; row = 0; col = 0; } public void setSlot(int rowIndex, int columnIndex) { row += rowIndex; row = row < 0 ? 1 : row % 2; col += columnIndex; col = col < 0 ? 3 : col % 4; } public void setLink(ILink link) { player = link; } public void removeItems(Dictionary<object, object> items) { foreach(KeyValuePair<object, object> item in items) { if(item.Key.GetType() == typeof(BombItem) && inventory.BombCount == 0) { if (player.GetItem().GetType() == typeof(Bomb)) player.SetItem(new Null()); items.Remove(item.Key); } } } public void DrawHealth(Vector2 coords) { int health = ((Link)player).LinkHealth; int i; for (i = 0; i < health/2; i++) { if (i < 8) InventorySpriteFactory.Instance.CreateFullHeart((int)coords.X + 528 + (i*24), (int)coords.Y + 96).draw(); else InventorySpriteFactory.Instance.CreateFullHeart((int)coords.X + 528 + ((i-8)*24), (int)coords.Y + 120).draw(); } if (health % 2 != 0 && i < 8) InventorySpriteFactory.Instance.CreateHalfHeart((int)coords.X + 528 + (i * 24), (int)coords.Y + 96).draw(); else if (health % 2 != 0 && i >= 8) InventorySpriteFactory.Instance.CreateHalfHeart((int)coords.X + 528 + (i - 8) * 24, (int)coords.Y + 120).draw(); } public void DrawInventory(Dictionary<object, object> items, Vector2 topCoords) { if (Inventory.Instance.inInventory()) { cursorColor.draw(); activeItem.DrawItem(); int rowIndex = 0; int colIndex = 0; foreach (KeyValuePair<object, object> item in items) { if (colIndex > 3) { colIndex = 0; rowIndex++; } ((IStageItem)(item.Key)).setPos((int)topCoords.X + 400 + (colIndex * 72), (int)topCoords.Y + 149 + (rowIndex * 52)); ((IStageItem)(item.Key)).DrawItem(); colIndex++; } } else activeItem.DrawItem(); } public void UpdateInventory(Vector2 bottomCoords, Vector2 topCoords, Dictionary<object, object> items) { if (items.Count < col+1 || (row == 1 && items.Count - 4 < col+1)) { player.SetItem(new Null()); activeItem = new NullItem(); } int r = 0; int c = 0; foreach (KeyValuePair<object, object> item in items) { if (c > 3) r = 1; inventoryItems[r, c] = item; if (item.Value.GetType() != typeof(Null) && row == r && col == c) { player.SetItem((IActiveItem)item.Value); activeItem = (IStageItem)item.Key; } c++; } if (Inventory.Instance.inInventory()) { timer--; if (timer < 1) timer = 12; if (timer < 7) cursorColor = InventorySpriteFactory.Instance.CreateRedCursor((int)topCoords.X + 384 + (col * 72), (int)topCoords.Y + 144 + (row * 52)); else cursorColor = InventorySpriteFactory.Instance.CreateBlueCursor((int)topCoords.X + 384 + (col * 72), (int)topCoords.Y + 144 + (row * 52)); activeItem.setPos((int)topCoords.X + 204, (int)topCoords.Y + 144); } else activeItem.setPos((int)bottomCoords.X + 384, (int)bottomCoords.Y + 72); removeItems(items); } } }