Beispiel #1
0
    public override void OnDrop(GameObject Slot)
    {
        if (Visible == Visiblility.Hidden)
        {
            return;
        }

        UI_InventorySlot InventoryComponent = Slot.GetComponent <UI_InventorySlot> ();

        if (Inventory && InventoryComponent)
        {
            UI_Item    Item        = (Remove == RemoveType.RemoveOnDrag) ? TempDrag : this.Item;
            Vector2Int NewPosition = ParentInventory.AddItem(Item, InventoryComponent.Position);
            if (NewPosition != UI_Inventory.InvalidIndex)
            {
                if (Remove == RemoveType.RemoveOnDrop && RemoveEvent)
                {
                    ParentInventory.RemoveItem(Position);
                }
            }
            else
            {
                if (Remove == RemoveType.RemoveOnDrag)
                {
                    ParentInventory.AddItem(Item, Position);
                }
            }
        }

        UI_EquipSlot EquipComponent = Slot.GetComponent <UI_EquipSlot>();

        if (EquipComponent && EquipComponent.Inventory)
        {
            UI_Item    Item  = (Remove == RemoveType.RemoveOnDrag) ? TempDrag : this.Item;
            Vector2Int NewId = EquipComponent.Inventory.AddItem(Item, Slot);
            if (NewId != UI_Inventory.InvalidIndex)
            {
                if (Remove == RemoveType.RemoveOnDrop && RemoveEvent)
                {
                    ParentInventory.RemoveItem(Position);
                }
            }
            else
            {
                if (Remove == RemoveType.RemoveOnDrag)
                {
                    ParentInventory.AddItem(Item, Position);
                }
            }

            print("Cast To Equip slot");
        }
    }
Beispiel #2
0
    private UI_InventorySlot CreateUI_InventorySlot(int index)
    {
        Transform uI_InventorySlotTransform = Instantiate(uI_InventorySlotTemplate, transform);

        uI_InventorySlotTransform.GetComponent <RectTransform>().anchoredPosition = UI_InventorySlotPositionInInvnetory(index);
        uI_InventorySlotTransform.gameObject.SetActive(true);

        UI_InventorySlot uI_InventorySlot = uI_InventorySlotTransform.GetComponent <UI_InventorySlot>();

        uI_InventorySlot.SetIndex(index);

        return(uI_InventorySlot);
    }
Beispiel #3
0
    private void CreateDisplay()
    {
        for (int i = 0; i < Inventory.MAX_ITEM_COUNT; i++)
        {
            UI_InventorySlot uI_InventorySlot = CreateUI_InventorySlot(i);
            uI_InventorySlotList.Add(uI_InventorySlot);

            if (null != inventory.GetItem(i))
            {
                CreateUI_Item(i);
            }
        }
    }
Beispiel #4
0
    private UI_Item CreateUI_Item(int index)
    {
        UI_InventorySlot uI_InventorySlot = uI_InventorySlotList[index];
        Transform        uI_ItemTransform = Instantiate(uI_ItemTemplate, uI_InventorySlot.transform);

        uI_ItemTransform.GetComponent <RectTransform>().anchoredPosition = Vector2.zero;
        uI_ItemTransform.gameObject.SetActive(true);

        UI_Item uI_Item = uI_ItemTransform.GetComponent <UI_Item>();

        uI_Item.SetIndex(index);
        uI_Item.SetItem(inventory.GetItem(index));
        uI_Item.UpdateUI();

        return(uI_Item);
    }
Beispiel #5
0
    public bool RemoveItem(Vector2Int Position)
    {
        UI_InventorySlot Slot = GridCells [Position.x, Position.y].GetComponent <UI_InventorySlot> ();

        if (Slot.Item == UI_Item.invalid)
        {
            return(false);
        }

        bool Success      = false;
        int  OffsetWidth  = Position.x + Slot.Item.Size.x;
        int  OffsetHeight = Position.y + Slot.Item.Size.y;

        Slot = GridCells [Position.x, Position.y].GetComponent <UI_InventorySlot> ();
        if (Slot && Slot.Item != UI_Item.invalid)
        {
            Slot.SetIcon(null);
            Slot.SetScale(new Vector2Int(1, 1));
            Slot.Item = new UI_Item();
            Slot.SetVisibility(Visiblility.Visible);
            Success = true;
        }

        for (int x = Position.x; x < OffsetWidth; x++)
        {
            for (int y = Position.y; y < OffsetHeight; y++)
            {
                Slot = GridCells [x, y].GetComponent <UI_InventorySlot> ();
                if (Slot)
                {
                    Slot.SetIcon(null);
                    Slot.SetScale(new Vector2Int(1, 1));
                    Slot.Item = new UI_Item();
                    Slot.SetVisibility(Visiblility.Visible);
                    Slot.RaycastMode = UI_Slot.RaycastFilter.Active;
                    Success         &= true;
                }
            }
        }

        if (Success)
        {
            DebugLog("Item Removed Successfully");
        }

        return(Success);
    }
Beispiel #6
0
    protected virtual void HighLightUpdate()
    {
        if (Highlight && MouseOver && HoveredSlot != null && UI_Slot.DragObject != null)
        {
            UI_Drag    DragObject = UI_Slot.DragObject.GetComponent <UI_Drag>();
            Vector2Int Position   = (DragObject) ? DragObject.DragPosition : new Vector2Int(-1, -1);

            if (Position.x >= 0 && Position.y >= 0 && Position.x < GridCells.GetLength(0) && Position.y < GridCells.GetLength(1))
            {
                UI_InventorySlot SlotObject = GridCells[Position.x, Position.y].GetComponent <UI_InventorySlot>();
                if (SlotObject)
                {
                    print("H:" + HoveredSlot.name);
                }
            }
        }
    }
 // Update is called once per frame
 void Update()
 {
     if (playerMain == null)
     {
         playerMain = Network.getPlayer(NetworkManager.clientID);
         return;
     }
     for (int i = 0; i < inventorySlots.Count; i++)
     {
         UI_InventorySlot slot = inventorySlots[i];
         slot.SetItem(playerMain.inventory.GetItemFromSlot(i));
     }
     if (Input.GetKeyDown("space"))
     {
         display.SetActive(!display.activeSelf);
     }
 }
Beispiel #8
0
    public void UpdateItem(Item item)
    {
        this.item = item;
        UI_InventorySlot uI_InventorySlot = transform.parent.GetComponent <UI_InventorySlot>();

        if (null != uI_InventorySlot)
        {
            index = uI_InventorySlot.GetIndex();
        }
        else
        {
            Debug.LogError("Error: uI_Item parent is not UI_InventorySlot");
            Debug.Break();
        }

        UpdateUI();
    }
Beispiel #9
0
    public override void OnDrop(GameObject Slot)
    {
        if (Visible == Visiblility.Hidden)
        {
            return;
        }

        UI_EquipSlot EquipComponent = Slot.GetComponent <UI_EquipSlot>();

        if (EquipComponent && Inventory)
        {
            print("Drop Cast Equip");
        }

        UI_InventorySlot InventoryComponent = Slot.GetComponent <UI_InventorySlot>();

        if (InventoryComponent && Inventory)
        {
            UI_Item    Item  = (Remove == UI_InventorySlot.RemoveType.RemoveOnDrag) ? TempDrag : this.Item;
            Vector2Int Index = Inventory.AddItem(Item, InventoryComponent.Position);
            if (Index != UI_Inventory.InvalidIndex)
            {
                if (Remove == UI_InventorySlot.RemoveType.RemoveOnDrop)
                {
                    Inventory.RemoveItem(gameObject);
                }
            }
            else
            {
                if (Remove == UI_InventorySlot.RemoveType.RemoveOnDrag)
                {
                    Inventory.AddItem(Item, gameObject);
                }
            }
        }
    }