public void mouseHoverEnter(Image overlayObject) { Color c = goodColor; // c.a = 103.0f/255.0f; InventorySlot slot = overlayObject.GetComponent <InventoryItem>().slot; Debug.Log(slot); List <Image> otherImages = new List <Image>(); if (selectedItem == null) { if (UnitGUI.inventorySlots.Contains(slot)) { Debug.Log(slot); InventoryItemSlot iis = (selectedCharacter == null ? null : selectedCharacter.characterSheet.inventory.inventory[(int)slot - (int)InventorySlot.Zero]); if (iis != null && iis.hasItem()) { List <InventoryItemSlot> sllls = new List <InventoryItemSlot>(); if (iis.itemSlot != iis) { sllls.Add(iis.itemSlot); } foreach (InventoryItemSlot iis2 in iis.itemSlot.otherSlots) { if (iis2 == iis) { continue; } sllls.Add(iis2); } foreach (InventoryItemSlot iis2 in sllls) { int slotind = iis2.index; Image img = overlayObject.transform.parent.GetChild(slotind).GetComponent <Image>(); img.color = c; otherImages.Add(img); } } } } else { Item i = selectedItem.GetComponent <InventoryItem>().item; ActionType at = Inventory.getActionTypeForMovement(slot, originalSlot); Debug.Log(i.itemName); if (UnitGUI.inventorySlots.Contains(slot)) { Vector2 currentHighlightSlot = UnitGUI.getIndexOfSlot(slot); Vector2 originSlot = currentHighlightSlot - selectedCell; Item i2 = selectedCharacter.characterSheet.inventory.inventory[UnitGUI.getLinearIndexFromIndex(currentHighlightSlot)].getItem(); if (i2 != null) { if (!selectedCharacter.characterSheet.inventory.itemCanStackWith(i2, i) || !canUseActionType(at)) { c = badColor; } else { i = i2; originSlot = UnitGUI.getIndexFromLinearIndex(selectedCharacter.characterSheet.inventory.inventory[UnitGUI.getLinearIndexFromIndex(currentHighlightSlot)].itemSlot.index); } } else { if (!canUseActionType(at) || !(originSlot.y >= 0 && originSlot.x >= 0 && originSlot.x < 4 && originSlot.y < 4 && selectedCharacter.characterSheet.inventory.canInsertItemInSlot(i, originSlot))) { c = badColor; } } foreach (Vector2 cell in i.getShape()) { Vector2 cc = originSlot + cell; if (cc != currentHighlightSlot && cc.x >= 0 && cc.y >= 0 && cc.x < 4 && cc.y < 4) { int ind = UnitGUI.getLinearIndexFromIndex(cc); Image img = overlayObject.transform.parent.GetChild(ind).GetComponent <Image>(); img.color = c; otherImages.Add(img); } } } else if (UnitGUI.armorSlots.Contains(slot)) { if (!selectedCharacter.characterSheet.characterLoadout.canInsertItemInSlot(slot, i, originalSlot)) { c = badColor; } } else if (BaseManager.trapTurretInventorySlots.Contains(slot)) { if (!baseManager.canInsertItem(i, slot) || (i is Turret) || (i is Trap)) { c = badColor; } } else if (!canUseActionType(at)) { c = badColor; } else { // c = badColor; } } if (!overlayObjectList.ContainsKey(overlayObject)) { overlayObjectList.Add(overlayObject, otherImages); } overlayObject.color = c; if (!overlayObjects.Contains(overlayObject)) { overlayObjects.Add(overlayObject); } }
public void deselectItem(Image overlayObject) { if (selectedItem == null) { setLootInteractable(true); return; } CharacterSheet cs = selectedCharacter.characterSheet; Item i = selectedItem.GetComponent <InventoryItem>().item; InventorySlot insertSlot = (originalSlot == InventorySlot.Trap || originalSlot == InventorySlot.Turret ? InventorySlot.None : originalSlot); if (overlayObjects.Count > 0) { InventorySlot sl = overlayObjects[0].GetComponent <InventoryItem>().slot; if (sl == InventorySlot.None) { insertSlot = sl; } else if (BaseManager.trapTurretInventorySlots.Contains(sl)) { if (baseManager.canInsertItem(i, sl)) { insertSlot = sl; } } else if (UnitGUI.armorSlots.Contains(sl)) { if (cs.characterLoadout.canInsertItemInSlot(sl, i, originalSlot)) { insertSlot = sl; } } else if (UnitGUI.inventorySlots.Contains(sl)) { Vector2 vSlot = UnitGUI.getIndexOfSlot(sl); int oSlot = UnitGUI.getLinearIndexFromIndex(vSlot); vSlot -= selectedCell; int iSlot = UnitGUI.getLinearIndexFromIndex(vSlot); if (iSlot >= 0 && iSlot < 16 && cs.inventory.canInsertItemInSlot(i, vSlot)) { insertSlot = UnitGUI.getInventorySlotFromIndex(vSlot); } else if (oSlot >= 0 && oSlot < 16) { Item inSlot = cs.inventory.inventory[oSlot].getItem(); if (inSlot != null && cs.inventory.itemCanStackWith(inSlot, i)) { insertSlot = sl; } } } } ActionType at = Inventory.getActionTypeForMovement(originalSlot, insertSlot); if (!canUseActionType(at)) { insertSlot = originalSlot; } // if (selectedUnit != null) { // if ((at == ActionType.Minor && selectedUnit.minorsLeft <= 0) || (at == ActionType.Standard && selectedUnit.usedStandard) || (at == ActionType.Movement && selectedUnit.usedMovement)) return; // } if (UnitGUI.armorSlots.Contains(insertSlot)) { Item i2 = cs.characterLoadout.getItemInSlot(insertSlot); GameObject oldItem = null; if (i2 != null) { oldItem = getArmourParent(insertSlot).transform.FindChild("InventoryItem").gameObject; } cs.characterLoadout.setItemInSlot(insertSlot, i); Vector2 size = i.getSize() * 32.0f; GameObject armourParent = getArmourParent(insertSlot); selectedItem.transform.SetParent(armourParent.transform, false); Vector2 v = new Vector2(); v.x = 32.0f - size.x / 2.0f; if (size.y >= 64.0f) { v.y = -64.0f + size.y; } else { v.y = -32.0f + size.y / 2.0f; } selectedItem.GetComponent <RectTransform>().anchoredPosition = v; selectedItem.GetComponent <InventoryItem>().slot = originalSlot; GameObject canv = armourParent.transform.FindChild("Canvas").gameObject; //.FindChild("Overlay"); RectTransform rt = canv.GetComponent <RectTransform>(); rt.anchoredPosition = v; rt.sizeDelta = size; i = i2; if (i != null) { selectedItem = oldItem; InventorySlot sl = originalSlot; Vector2 vSlot = UnitGUI.getIndexOfSlot(sl); // vSlot -= selectedCell; sl = UnitGUI.getInventorySlotFromIndex(vSlot); int iSlot = UnitGUI.getLinearIndexFromIndex(vSlot); Debug.Log("Drop has item: " + sl + " " + vSlot + " " + iSlot + " " + selectedCell); Item inSlot = (iSlot < 0 || iSlot >= 16 ? null : cs.inventory.inventory[iSlot].getItem()); if (cs.inventory.canInsertItemInSlot(i, vSlot) || (inSlot != null && cs.inventory.itemCanStackWith(inSlot, i))) { insertSlot = sl; } else { foreach (InventorySlot sl2 in UnitGUI.inventorySlots) { sl = sl2; vSlot = UnitGUI.getIndexOfSlot(sl); iSlot = UnitGUI.getLinearIndexFromIndex(vSlot); inSlot = cs.inventory.inventory[iSlot].getItem(); if (cs.inventory.canInsertItemInSlot(i, vSlot) || (inSlot != null && cs.inventory.itemCanStackWith(inSlot, i))) { insertSlot = sl; break; } } } Debug.Log("Drop has item2: " + insertSlot + " " + vSlot + " " + iSlot + " " + selectedCell); selectedCell = new Vector2(0, 0); } if (selectedUnit != null) { selectedUnit.idleAnimation(false); selectedUnit.Invoke("beginIdle", 0.05f); } } else if (BaseManager.trapTurretInventorySlots.Contains(insertSlot) && !(i is Turret) && !(i is Trap)) { Debug.Log("Trap Turret"); Item i2 = baseManager.getTrapTurretInSlot(insertSlot); GameObject oldItem = null; if (i2 != null) { oldItem = getArmourParent(insertSlot).transform.FindChild("InventoryItem").gameObject; } baseManager.setItemInSlot(insertSlot, i); // cs.characterLoadout.setItemInSlot(insertSlot,i); Vector2 size = i.getSize() * 32.0f; GameObject armourParent = getArmourParent(insertSlot); selectedItem.transform.SetParent(armourParent.transform, false); Vector2 v = new Vector2(); v.x = 32.0f - size.x / 2.0f; if (size.y >= 64.0f) { v.y = -64.0f + size.y; } else { v.y = -32.0f + size.y / 2.0f; } selectedItem.GetComponent <RectTransform>().anchoredPosition = v; selectedItem.GetComponent <InventoryItem>().slot = originalSlot; GameObject canv = armourParent.transform.FindChild("Canvas").gameObject; //.FindChild("Overlay"); RectTransform rt = canv.GetComponent <RectTransform>(); rt.anchoredPosition = v; rt.sizeDelta = size; i = i2; if (i != null) { selectedItem = oldItem; InventorySlot sl = originalSlot; Vector2 vSlot = UnitGUI.getIndexOfSlot(sl); // vSlot -= selectedCell; sl = UnitGUI.getInventorySlotFromIndex(vSlot); int iSlot = UnitGUI.getLinearIndexFromIndex(vSlot); Debug.Log("Drop has item: " + sl + " " + vSlot + " " + iSlot + " " + selectedCell); Item inSlot = (iSlot < 0 || iSlot >= 16 ? null : cs.inventory.inventory[iSlot].getItem()); if (cs.inventory.canInsertItemInSlot(i, vSlot) || (inSlot != null && cs.inventory.itemCanStackWith(inSlot, i))) { insertSlot = sl; } else { foreach (InventorySlot sl2 in UnitGUI.inventorySlots) { sl = sl2; vSlot = UnitGUI.getIndexOfSlot(sl); iSlot = UnitGUI.getLinearIndexFromIndex(vSlot); inSlot = cs.inventory.inventory[iSlot].getItem(); if (cs.inventory.canInsertItemInSlot(i, vSlot) || (inSlot != null && cs.inventory.itemCanStackWith(inSlot, i))) { insertSlot = sl; break; } } } Debug.Log("Drop has item2: " + insertSlot + " " + vSlot + " " + iSlot + " " + selectedCell); selectedCell = new Vector2(0, 0); } if (!(baseManager.turretFrame == null || baseManager.turretApplicator == null || baseManager.turretGear == null || baseManager.energySource == null)) { createTurret(); } if (!(baseManager.trapFrame == null || baseManager.trapApplicator == null || baseManager.trapGear == null || baseManager.trigger == null)) { createTrap(); } if (selectedUnit != null) { selectedUnit.idleAnimation(false); selectedUnit.Invoke("beginIdle", 0.05f); } } else { Debug.Log("Insert Slot: " + insertSlot + " Original: " + originalSlot); } if (UnitGUI.inventorySlots.Contains(insertSlot)) { if (cs.inventory.canInsertItemInSlot(i, UnitGUI.getIndexOfSlot(insertSlot))) { cs.inventory.insertItemInSlot(i, UnitGUI.getIndexOfSlot(insertSlot)); selectedItem.transform.SetParent(inventorySlots.transform, false); Vector2 v = 32.0f * UnitGUI.getIndexOfSlot(insertSlot); v.y *= -1; selectedItem.GetComponent <RectTransform>().anchoredPosition = v; selectedItem.GetComponent <InventoryItem>().slot = insertSlot; } else { Vector2 vSlot = UnitGUI.getIndexOfSlot(insertSlot); int iSlot = UnitGUI.getLinearIndexFromIndex(vSlot); Item inSlot = cs.inventory.inventory[iSlot].getItem(); if (inSlot != null && cs.inventory.itemCanStackWith(inSlot, i)) { cs.inventory.stackItemWith(inSlot, i); GameObject[] obj = GameObject.FindGameObjectsWithTag("inventoryitem"); foreach (GameObject go in obj) { InventoryItem invP = go.GetComponent <InventoryItem>(); if (invP.item == inSlot) { invP.transform.FindChild("Text").GetComponent <Text>().text = (inSlot.stackSize() > 1 ? inSlot.stackSize() + "" : ""); } } } GameObject.Destroy(selectedItem); } } if (insertSlot == InventorySlot.None) { if (currentLootTile != null) { currentLootTile.addItem(i); selectedItem.transform.SetParent(lootContent, false); selectedItem.GetComponent <InventoryItem>().slot = insertSlot; selectedItem.GetComponent <LayoutElement>().ignoreLayout = false; selectedItem.GetComponent <CanvasGroup>().blocksRaycasts = true; selectedItem.transform.FindChild("Overlay").gameObject.SetActive(true); } else if (currentStash != null) { addLootItem(i, 1); foreach (Item s in i.stack) { addLootItem(s); } currentStash.addItem(i); GameObject.Destroy(selectedItem); } } selectedItem = null; List <Image> hoveredCopy = new List <Image>(overlayObjects); foreach (Image im in hoveredCopy) { mouseHoverLeave(im); mouseHoverEnter(im); } if (inventoryHead != null) { setACText(); } setLootInteractable(true); if (selectedUnit != null) { if (at == ActionType.Minor) { selectedUnit.useMinor(MinorType.Loot, false, false); } else if (at == ActionType.Standard) { selectedUnit.useStandard(); } if (!selectedUnit.usedStandard) { StandardType[] standards = selectedUnit.getStandardTypes(); if (!sameAsOldStandards(standards)) { BattleGUI.resetStandardButtons(); } } } else { selectedCharacter.saveCharacter(); } }