Exemple #1
0
    public void selectItem(Image overlayObject)
    {
        beforeItemStandards = (selectedUnit != null ? selectedUnit.getStandardTypes() : new StandardType[0]);
        InventoryItem ii = overlayObject.GetComponent <InventoryItem>();
        InventorySlot sl = ii.slot;
        Item          i  = null;

        Debug.Log(sl + ": " + overlayObjects.Count);
        if (sl == InventorySlot.None)
        {
            Debug.Log(overlayObjects.Count);
            InventoryItem iii = overlayObject.transform.parent.GetComponent <InventoryItem>();
            if (iii != null)
            {
                i = iii.item;
                if (currentLootTile != null)
                {
                    currentLootTile.removeItem(i, 0);
                }
                else if (currentStash != null)
                {
                    currentStash.removeItem(i);
                }
                originalSlot = sl;
                overlayObject.gameObject.SetActive(false);
                overlayObject.transform.parent.GetComponent <LayoutElement>().ignoreLayout = true;
                overlayObject.transform.parent.GetComponent <CanvasGroup>().blocksRaycasts = false;
                mouseHoverLeave(overlayObject);
                Invoke("resetLootScrollPos", 0.05f);
            }
        }
        else if (UnitGUI.armorSlots.Contains(sl))
        {
            i = selectedCharacter.characterSheet.characterLoadout.removeItemFromSlot(sl);
            getArmourParent(sl).transform.FindChild("Canvas").GetComponent <RectTransform>().sizeDelta        = new Vector2(64.0f, 64.0f);
            getArmourParent(sl).transform.FindChild("Canvas").GetComponent <RectTransform>().anchoredPosition = new Vector2(0.0f, 0.0f);
            originalSlot = sl;
        }
        else if (UnitGUI.inventorySlots.Contains(sl))
        {
            ItemReturn i2 = selectedCharacter.characterSheet.inventory.removeItemFromSlot(sl);
            i            = i2.item;
            originalSlot = UnitGUI.getInventorySlotFromIndex(UnitGUI.getIndexOfSlot(sl) - i2.slot);
        }
        else if (BaseManager.trapTurretInventorySlots.Contains(sl))
        {
            i = baseManager.removeTrapTurretInSlot(sl);            // selectedCharacter.characterSheet.characterLoadout.removeItemFromSlot(sl);
            getArmourParent(sl).transform.FindChild("Canvas").GetComponent <RectTransform>().sizeDelta        = new Vector2(64.0f, 64.0f);
            getArmourParent(sl).transform.FindChild("Canvas").GetComponent <RectTransform>().anchoredPosition = new Vector2(0.0f, 0.0f);
            originalSlot = sl;
            if (baseManager.turretFrame == null || baseManager.turretApplicator == null || baseManager.turretGear == null || baseManager.energySource == null)
            {
                removeTurret();
            }
            if (baseManager.trapFrame == null || baseManager.trapApplicator == null || baseManager.trapGear == null || baseManager.trigger == null)
            {
                removeTrap();
            }
            if (sl == InventorySlot.Turret)
            {
                //	originalSlot = InventorySlot.None;
                removeTurretSupplies();
                //	hideLoot = false;
            }
            else if (sl == InventorySlot.Trap)
            {
                //	originalSlot = InventorySlot.None;
                removeTrapSupplies();
                //	hideLoot = false;
            }
        }
        if (i == null)
        {
            return;
        }
        GameObject[] items = GameObject.FindGameObjectsWithTag("inventoryitem");
        foreach (GameObject item in items)
        {
            if (item.GetComponent <InventoryItem>().item == i)
            {
                selectedItem = item;
                item.transform.SetParent(inventoryBackground.transform);
                Vector3 pos = item.transform.position;
                pos.y = Screen.height - pos.y;
                Vector3 mousePos = Input.mousePosition;
                mousePos.y   = Screen.height - mousePos.y;
                selectedCell = new Vector2((int)((mousePos.x - pos.x) / 32.0f), (int)((mousePos.y - pos.y) / 32.0f));
                Vector2 closest     = selectedCell;
                float   closestDist = float.MaxValue;
                foreach (Vector2 v in i.getShape())
                {
                    float dist = Mathf.Abs(v.x - selectedCell.x) + Mathf.Abs(v.y - selectedCell.y);
                    if (dist < closestDist)
                    {
                        closestDist = dist;
                        closest     = v;
                    }
                    if (dist <= Mathf.Epsilon)
                    {
                        break;
                    }
                }
                mouseSelectPos.x += (selectedCell.x - closest.x) * 32.0f;
                mouseSelectPos.y += (selectedCell.y - closest.y) * 32.0f;
                selectedCell      = closest;
                break;
            }
        }
        setACText();
        setLootInteractable(false);
    }
Exemple #2
0
    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();
        }
    }