Esempio n. 1
0
 public void ShowConfirmWindow(Sprite itemSprite, ShopItem item, ItemSlotUI slotUI)
 {
     this.item   = item;
     this.slotUI = slotUI;
     confirmWindow.GetComponent <Dialog>().OpenDialog();
     confirmImage.GetComponent <Image>().sprite = itemSprite;
 }
    // 인벤토리 UI 새로고침
    public void RefreshInventory()
    {
        // 인벤토리 키순으로 정렬
        battleInventory  = battleInventory.OrderBy(_itemSlotData => _itemSlotData.itemData.key).ToList();  // 키순으로 정렬
        collectInventory = collectInventory.OrderBy(_itemSlotData => _itemSlotData.itemData.key).ToList(); // 키순으로 정렬

        // 인벤토리 데이터 설정
        int i = 0;

        foreach (ItemSlotData itemSlotData in battleInventory)
        {
            itemSlotData.fromSlotType = SlotType.battleSlot;
            itemSlotData.index        = i;
            i++;
        }
        i = 0;
        foreach (ItemSlotData itemSlotData in collectInventory)
        {
            itemSlotData.fromSlotType = SlotType.collectSlot;
            itemSlotData.index        = i;
            i++;
        }

        // 인벤토리 정보 가져오기
        List <ItemSlotData> inventory = new List <ItemSlotData>();
        SlotType            slotType;

        if (invetoryCategory == InventoryCategory.battle)
        {
            inventory = battleInventory;
            slotType  = SlotType.battleSlot;
        }
        else
        {
            inventory = collectInventory;
            slotType  = SlotType.collectSlot;
        }

        // itemSlotUI 전부 없애기
        foreach (Transform child in content.transform)
        {
            Destroy(child.gameObject);
        }

        // itemSlotUI 재생성
        foreach (ItemSlotData itemSlotData in inventory)
        {
            ItemSlotUI _itemSlotUI = Instantiate(itemSlotUI, content.transform).GetComponent <ItemSlotUI>();
            _itemSlotUI.ItemSlotData              = itemSlotData;
            _itemSlotUI.ItemSlotData.itemSlotUI   = _itemSlotUI;
            _itemSlotUI.ItemSlotData.fromSlotType = slotType;
            _itemSlotUI.slotType = slotType;
            _itemSlotUI.RefreshSlot();
            i++;
        }
    }
    private void RemoveItemSlots(int amount)
    {
        for (int i = 0; i < amount; i++)
        {
            ItemSlotUI empty = _itemSlots[i];
            empty.UpdateSlot(null);

            _itemSlots.RemoveAt(i);
            _poolManager.Store(empty.gameObject);
        }
    }
        public void ShowTooltip(ItemSlotUI itemSlotUI)
        {
            if (itemSlotUI == null || itemSlotUI.ReferencedSlotItem == null)
            {
                return;
            }

            UpdateTooltipText(itemSlotUI.ReferencedSlotItem);

            prevObj = (RectTransform)itemSlotUI.transform;
            ShowTooltip();
        }
Esempio n. 5
0
 //Gets called when the character updates an item amount
 public void OnUpdateItemAmount(InventoryItem item)
 {
     //loop through all the item slot UI components in the grid and update the quantity of an item
     for (int i = 0; i < Grid.childCount; i++)
     {
         ItemSlotUI slotUI = Grid.GetChild(i).GetComponent <ItemSlotUI>();
         if (item == slotUI.slot)
         {
             slotUI.slot.Amount = item.Amount;
         }
     }
 }
Esempio n. 6
0
 //Gets called when the character removes an item
 public void OnItemRemove(InventoryItem item)
 {
     for (int i = 0; i < Grid.childCount; i++)
     {
         //loop through all the item slot UI components in the grid and removes the item from the inventory view
         ItemSlotUI slotUI = Grid.GetChild(i).GetComponent <ItemSlotUI>();
         if (item == slotUI.slot)
         {
             slotUI.slot = null;
         }
     }
 }
Esempio n. 7
0
 //Gets called when the character picks up an item
 public void OnItemPickup(InventoryItem item)
 {
     //loop through all the item slot UI components in the grid and checks if one of them is empty to add a new item
     for (int i = 0; i < Grid.childCount; i++)
     {
         ItemSlotUI slotUI = Grid.GetChild(i).GetComponent <ItemSlotUI>();
         if (slotUI.slot == null)
         {
             slotUI.slot = item;
             break;
         }
     }
 }
    void CheckDraggingSlotEnd()
    {
        // 슬롯 드래깅 종료
        if (Input.GetMouseButtonUp(0))
        {
            // 마우스 포인터 정보 생성 및 저장
            pointer          = new PointerEventData(eventSystem);
            pointer.position = Input.mousePosition;

            // 마우스 포인터 밑에 있는 객체 가져오기 (UI)
            List <RaycastResult> results = new List <RaycastResult>();
            raycaster.Raycast(pointer, results);
            foreach (RaycastResult raycastResult in results)
            {
                // 아이템 슬롯에 드래그
                if (raycastResult.gameObject.tag == "ItemSlot")
                {
                    if (dragSlotUI.ItemSlotData == null)
                    {
                        continue;
                    }
                    ItemSlotUI itemSlot = raycastResult.gameObject.GetComponent <ItemSlotUI>();
                    if (itemSlot.slotType == SlotType.upgradeSlot)
                    {
                        Debug.Log("아이템 등록");
                        upgradeItemPanel.UpgradeItemSlotData = dragSlotUI.ItemSlotData;
                    }
                }
                // 유닛 인벤토리에 넣기
                else if (raycastResult.gameObject.tag == "Inventory")
                {
                    if (!draggingUnit)
                    {
                        continue;
                    }
                    int index = FindSlot(draggingUnit.GetComponent <Unit>()).index;

                    // 비용 회수
                    CurrentCost += battleInventory[index].deltaCost + battleInventory[index].itemData.cost;

                    // 유닛 인벤토리에 넣기
                    battleInventory[index].SpawnUnit = null;
                    battleInventory[index].IsActive  = true;
                    Destroy(draggingUnit.gameObject);
                    draggingUnit      = null;
                    dragStartPosition = new Vector3();
                    AdventureModeManager.Instance.SaveSpawnData();
                }
            }
        }
    }
Esempio n. 9
0
 public void RefreshInventory()
 {
     // 재료 슬롯 리스트 출력
     foreach (Transform child in materialItemSlotPanel.transform)
     {
         Destroy(child.gameObject);
     }
     foreach (ItemSlotData itemSlotData in materialInventory)
     {
         ItemSlotUI _itemSlotUI = Instantiate(itemSlotUI, materialItemSlotPanel.transform).GetComponent <ItemSlotUI>();
         _itemSlotUI.ItemSlotData            = itemSlotData;
         _itemSlotUI.ItemSlotData.itemSlotUI = _itemSlotUI;
         _itemSlotUI.slotType = SlotType.materialSlot;
         _itemSlotUI.RefreshSlot();
     }
 }
Esempio n. 10
0
    void SetCurrentItem(ItemSlotUI selectedItemSlot)
    {
        if (selectedItemSlot == null)
        {
            this._currentItem = null;
        }
        else if (!selectedItemSlot.IsEmpty())
        {
            this._currentItem = selectedItemSlot;
            selectedItemSlot.SetColor(ItemSlotUI.ItemSlotColor.Selected);
        }

        foreach (var itemSlot in inventoryItemSlots)
        {
            if (itemSlot != _currentItem)
            {
                itemSlot.SetColor(ItemSlotUI.ItemSlotColor.Default);
            }
        }
    }
Esempio n. 11
0
 public void Refresh()
 {
     //Remove all items from ui
     for (int i = 0; i < Grid.childCount; i++)
     {
         ItemSlotUI slotUI = Grid.GetChild(i).GetComponent <ItemSlotUI>();
         slotUI.slot = null;
     }
     //go through all the items in the inventory and add them back to the UI
     foreach (var item in inventory.inventoryData.items)
     {
         for (int i = 0; i < Grid.childCount; i++)
         {
             ItemSlotUI slotUI = Grid.GetChild(i).GetComponent <ItemSlotUI>();
             if (slotUI.slot == null)
             {
                 slotUI.slot = item;
                 break;
             }
         }
     }
 }
Esempio n. 12
0
    // Update is called once per frame
    void Update()
    {
        //set the tooltip item to null
        toolTip.item = null;

        //loop through all the item slots in the inventory grid
        for (int i = 0; i < Grid.childCount; i++)
        {
            //Get the item slot UI of the current child game object
            ItemSlotUI slotUI = Grid.GetChild(i).GetComponent <ItemSlotUI>();
            //check if the slot is null and if so continue to the next item slot in the grid
            if (slotUI.slot == null)
            {
                continue;
            }

            //check if the player is hovering over a item and the inventory is visable
            if (slotUI.IsHovering && Visable)
            {
                //set the tooltip item to the hovering itemslot
                toolTip.item = slotUI.slot.Item;

                //Drop the item
                if (Input.GetKeyDown(KeyCode.Q))
                {
                    inventory.DropItem(slotUI.slot);
                    continue;
                }
                //Check if the item is a Weapon
                if (slotUI.slot.Item.GetType() == typeof(Weapon))
                {
                    //Cast the item to a weapon
                    Weapon weapon = slotUI.slot.Item as Weapon;
                    //Equip the weapon to the left hand
                    if (Input.GetMouseButtonDown(0))
                    {
                        inventory.EquipWeapon(weapon, 1);
                    }
                    //Equip the weapon to the right hand
                    else if (Input.GetMouseButtonDown(1))
                    {
                        inventory.EquipWeapon(weapon, 2);
                    }
                }
            }
        }

        //check if the player is hovering of the left equiped item and left clicks
        if (Input.GetMouseButtonDown(0) && LeftItemSlot.IsHovering && Visable)
        {
            //Unequip left weapon
            inventory.EquipWeapon(null, 1);
            LeftItemSlot.slot = null;
        }
        //check if the player is hovering of the right equiped item and left clicks
        else if (Input.GetMouseButtonDown(0) && RightItemSlot.IsHovering && Visable)
        {
            //Unequip right weapon
            inventory.EquipWeapon(null, 2);
            RightItemSlot.slot = null;
        }
    }
    /// ------------------------------------------------------------- 마우스 조작 관련 ------------------------------------------------------------- ///
    // 슬롯 드래깅
    void CheckDraggingSlotStart()
    {
        if (Input.GetMouseButtonDown(0))
        {
            // 가져올 데이터 정보
            ItemSlotUI itemSlotUI = null;

            // 마우스 포인터 정보 생성 및 저장
            pointer          = new PointerEventData(eventSystem);
            pointer.position = Input.mousePosition;

            // 마우스 포인터 밑에 있는 객체 가져오기
            List <RaycastResult> results = new List <RaycastResult>();
            raycaster.Raycast(pointer, results);
            foreach (RaycastResult raycastResult in results)
            {
                if (raycastResult.gameObject.tag != "ItemSlot")
                {
                    continue;
                }
                itemSlotUI = raycastResult.gameObject.GetComponent <ItemSlotUI>();
                //Debug.Log(string.Format("{0} {1}번 슬롯 클릭 (Key: {2})", filter, itemSlotData.index, itemSlotData.itemData.key));
            }

            // 데이터 없으면 스킵
            if (itemSlotUI == null)
            {
                return;
            }
            if (itemSlotUI.ItemSlotData == null)
            {
                return;
            }

            // 유닛 활성화 비활성화
            if (itemSlotUI.slotType == SlotType.battleSlot)
            {
                if (!SelectMode)
                {
                    // 드래깅 시작
                    dragSlotUI.ItemSlotData = itemSlotUI.ItemSlotData;

                    // 유닛 드래깅 시작시 배치 가능 지역 미리보기 보이기
                    if (dragSlotUI.ItemSlotData.itemData.filter == Filter.unit && AdventureModeManager.Instance.Stat == AdventureGameModeStat.battlePlanPhase)
                    {
                        currentRoom.GetComponent <Room>().spawnArea.SetActive(true);
                    }
                }
                else
                {
                    // 슬롯 선택
                    itemSlotUI.Select = !itemSlotUI.Select;
                }
            }
            else if (itemSlotUI.slotType == SlotType.collectSlot)
            {
                if (SelectMode)
                {
                    itemSlotUI.Select = !itemSlotUI.Select;
                }
            }
            else if (itemSlotUI.slotType == SlotType.materialSlot)
            {
                // 슬롯 선택
                itemSlotUI.Select = !itemSlotUI.Select;
            }
            else if (itemSlotUI.slotType == SlotType.upgradeSlot)
            {
            }
        }
    }