public void Init(Tapestry_UI_InventoryDisplayTextElement displayPrefab, Tapestry_Inventory inv, string inventoryName, Tapestry_EquipmentProfile eq = null) { title.text = inventoryName; elements = new List <Tapestry_UI_InventoryDisplayTextElement>(); int y = -24; int height = 24; if (!ReferenceEquals(eq, null)) { if (eq.GetNumberOfEquippedItems() == 0) { Tapestry_UI_InventoryDisplayTextElement e = (Tapestry_UI_InventoryDisplayTextElement)Instantiate(displayPrefab, content); e.GetComponent <RectTransform>().localPosition = new Vector3(e.GetComponent <RectTransform>().localPosition.x, y, 0); e.title.text = "<i>Nothing equipped</i>"; e.title.color = new Color(1, 1, 1, 0.5f); e.quantity.text = ""; e.size.text = ""; elements.Add(e); y -= 24; height += 24; } else { Dictionary <Tapestry_EquipSlot, Tapestry_ItemStack> dict = eq.ToDict(); foreach (Tapestry_EquipSlot slot in dict.Keys) { Tapestry_UI_InventoryDisplayTextElement e = (Tapestry_UI_InventoryDisplayTextElement)Instantiate(displayPrefab, content); e.GetComponent <RectTransform>().localPosition = new Vector3(e.GetComponent <RectTransform>().localPosition.x, y, 0); e.SetData(dict[slot]); y -= 24; height += 24; e.equippedInSlot = slot; if (slot == Tapestry_EquipSlot.LeftHand) { e.SetEquippedState(1); } else if (slot == Tapestry_EquipSlot.RightHand) { e.SetEquippedState(2); } else if (slot == Tapestry_EquipSlot.BothHands) { e.SetEquippedState(3); } else { e.SetEquippedState(4); } elements.Add(e); } } } if (inv.items.Count == 0) { Tapestry_UI_InventoryDisplayTextElement e = (Tapestry_UI_InventoryDisplayTextElement)Instantiate(displayPrefab, content); e.GetComponent <RectTransform>().localPosition = new Vector3(e.GetComponent <RectTransform>().localPosition.x, y, 0); e.title.text = "<i>No items</i>"; e.title.color = new Color(1, 1, 1, 0.5f); e.quantity.text = ""; e.size.text = ""; elements.Add(e); y -= 24; height += 24; } else { foreach (Tapestry_ItemStack stack in inv.items) { Tapestry_UI_InventoryDisplayTextElement e = (Tapestry_UI_InventoryDisplayTextElement)Instantiate(displayPrefab, content); e.GetComponent <RectTransform>().localPosition = new Vector3(e.GetComponent <RectTransform>().localPosition.x, y, 0); e.SetData(stack); y -= 24; height += 24; elements.Add(e); } } height += 24; }
public void HandleInteract() { bool leftClick = Input.GetMouseButton(0); bool rightClick = Input.GetMouseButton(1); bool activate = Input.GetKey(Tapestry_Config.KeyboardInput_Activate) || leftClick || rightClick; if (activateLastFrame && !activate) { Tapestry_UI_InventoryDisplayTextElement active = null; sbyte side = 0; foreach (Tapestry_UI_InventoryDisplayTextElement e in left.elements) { if (e.Active) { active = e; side = -1; break; } } if (side != -1) { foreach (Tapestry_UI_InventoryDisplayTextElement e in right.elements) { if (e.Active) { active = e; side = 1; break; } } } if (active != null) { Debug.Log("Clicked on \"" + active.title.text + "\", side=" + side); if (side == 1) { leftInv.AddItem(active.GetData(), 1); rightInv.RemoveItem(active.GetData(), 1); Open(leftInv, equipment, rightInv, leftName, rightName); } else if (side == -1) { if (ReferenceEquals(rightInv, null)) { if (active.GetData().isHoldable) { if (active.isEquipment) { if (active.equippedInSlot == Tapestry_EquipSlot.LeftHand) { if (rightClickLastFrame) { Debug.Log("Right clicked item in left slot"); if (equipment.GetInSlot(Tapestry_EquipSlot.RightHand) != null) { Debug.Log("Thar be a thingus"); player.Unequip(Tapestry_EquipSlot.RightHand); player.Equip(equipment.GetInSlot(Tapestry_EquipSlot.LeftHand), Tapestry_EquipSlot.RightHand); player.Unequip(Tapestry_EquipSlot.LeftHand); Open(leftInv, equipment, rightInv, leftName, rightName); } else { Tapestry_ItemData swap = equipment.GetInSlot(Tapestry_EquipSlot.LeftHand); player.Unequip(Tapestry_EquipSlot.LeftHand); player.Equip(swap, Tapestry_EquipSlot.RightHand); Open(leftInv, equipment, rightInv, leftName, rightName); } } else if (activateLastFrame || leftClickLastFrame) { Debug.Log("Left clicked item in left slot"); player.Unequip(Tapestry_EquipSlot.LeftHand); Open(leftInv, equipment, rightInv, leftName, rightName); } } else if (active.equippedInSlot == Tapestry_EquipSlot.RightHand) { if (leftClickLastFrame) { if (equipment.GetInSlot(Tapestry_EquipSlot.LeftHand) != null) { player.Unequip(Tapestry_EquipSlot.LeftHand); player.Equip(equipment.GetInSlot(Tapestry_EquipSlot.RightHand), Tapestry_EquipSlot.LeftHand); player.Unequip(Tapestry_EquipSlot.RightHand); Open(leftInv, equipment, rightInv, leftName, rightName); } else { Tapestry_ItemData swap = equipment.GetInSlot(Tapestry_EquipSlot.RightHand); player.Unequip(Tapestry_EquipSlot.RightHand); player.Equip(swap, Tapestry_EquipSlot.LeftHand); Open(leftInv, equipment, rightInv, leftName, rightName); } } else if (activateLastFrame || rightClickLastFrame) { player.Unequip(Tapestry_EquipSlot.RightHand); Open(leftInv, equipment, rightInv, leftName, rightName); } } } else { if (active.GetData().slot == Tapestry_EquipSlot.EitherHand && leftClickLastFrame) { player.Equip(active.GetData(), Tapestry_EquipSlot.LeftHand); active.SetEquippedState(1); active.equippedInSlot = Tapestry_EquipSlot.LeftHand; Open(leftInv, equipment, rightInv, leftName, rightName); } else if (active.GetData().slot == Tapestry_EquipSlot.EitherHand && rightClickLastFrame) { player.Equip(active.GetData(), Tapestry_EquipSlot.RightHand); active.SetEquippedState(2); active.equippedInSlot = Tapestry_EquipSlot.RightHand; Open(leftInv, equipment, rightInv, leftName, rightName); } else if (active.GetData().slot == Tapestry_EquipSlot.BothHands && (leftClickLastFrame || rightClickLastFrame)) { player.Equip(active.GetData(), Tapestry_EquipSlot.BothHands); active.SetEquippedState(3); active.equippedInSlot = Tapestry_EquipSlot.BothHands; Open(leftInv, equipment, rightInv, leftName, rightName); } //foreach(Tapestry_UI_InventoryDisplayTextElement te in left.elements) //{ // if(te.GetData() != player.equippedLeft && te.GetData() != player.equippedRight) // te.SetEquippedState(0); //} } } else { if (active.GetData().useEffect) { player.AddEffect(active.GetData().effect); leftInv.RemoveItem(active.GetData(), 1); Open(leftInv, equipment, rightInv, leftName, rightName); } } } else { rightInv.AddItem(active.GetData(), 1); leftInv.RemoveItem(active.GetData(), 1); Open(leftInv, null, rightInv, leftName, rightName); } } } } //End of frame activateLastFrame = activate; leftClickLastFrame = leftClick; rightClickLastFrame = rightClick; }