Example #1
0
        public void UpdateSlotInfo(CIItemBase item)
        {
            this._itemHere = item;

            bool slotEmpty = item == null;

            if (this._quantityText != null)
            {
                if (item == null)
                {
                    this._quantityText.text = string.Empty;
                }
                else
                {
                    if (item is CWeaponData weaponData)
                    {
                        this._quantityText.text = weaponData.IsLoadedWithInfiniteAmmo() ? string.Empty : weaponData.GetAmmoCount().ToString();
                    }
                    else
                    {
                        this._quantityText.text = item.Count.ToString();
                    }
                }
            }
            if (this._thumbnailSprite)
            {
                this._thumbnailSprite.color  = slotEmpty ? Color.clear : this._thumbColor;
                this._thumbnailSprite.sprite = !slotEmpty && item.GetScriptableObject() ? item.GetScriptableObject().ItemThumbnail : null;
            }
            if (this._nameText != null)
            {
                this._nameText.text = !slotEmpty && item.GetScriptableObject() ? item.GetScriptableObject().ItemName : string.Empty;
                this._nameText.gameObject.SetActive(!slotEmpty);
            }
        }
Example #2
0
        /// <summary>
        /// Returns TRUE if item add to inventory.
        /// </summary>
        public bool AddItem(CIItemBase item, bool hideNotification = true)
        {
            if (item == null)
            {
                Debug.LogError($"Could not add item because item do add is null!");
                return(false);
            }

            if (!hideNotification)
            {
                Debug.Log("TODO show new item get notitifcation");
            }

            bool alreadyHasThisItem = false;

            // check if already has item to stack
            for (int i = 0; i < this.InventoryItems.Length; i++)
            {
                if (this.InventoryItems[i] == null)
                {
                    continue;
                }
                alreadyHasThisItem = this.InventoryItems[i].GetScriptableObject() == item.GetScriptableObject();
                if (alreadyHasThisItem)
                {
                    // item exists, increase it quantity
                    this.InventoryItems[i].Add(item.Count);
                    this.UpdateView();
                    return(true);
                }
            }

            // check for a null space to fill
            for (int i = 0; i < this.InventoryItems.Length; i++)
            {
                if (this.InventoryItems[i] != null)
                {
                    continue;
                }

                Debug.Log($"Collected null item o empty space.");
                this.InventoryItems[i] = item;

                if (item is CWeaponData weapon)
                {
                    // auto equip gun
                    Debug.Log($"Auto equipping collected weapon.");
                    this._equippedWeaponRx.Value = weapon;
                }

                this.UpdateView();
                return(true);
            }

            // inventory is full
            Debug.Log($"Inventory is full.");
            this.UpdateView();
            return(false);
        }
Example #3
0
        public void Open(CIItemBase itemBase, int itemIndex, Vector2 position)
        {
            this._viewItensParent.transform.position = position;

            this._item      = itemBase;
            this._itemIndex = itemIndex;
            Debug.Log($"Opening {itemBase.GetScriptableObject().name} options. Itemindex is {itemIndex}.");

            // set visible buttons
            this._useItemButton.gameObject.SetActive(itemBase.GetScriptableObject().IsConsumable());
            this._equipItemButton.gameObject.SetActive(itemBase.GetScriptableObject() is CWeaponScriptableObject);
            this._examineButton.gameObject.SetActive(false);            // TODO //this._examineButton.gameObject.SetActive(itemData.ItemMeshGameObject != null);
            this._discardItemButton.gameObject.SetActive(itemBase.GetScriptableObject().CanBeDropped);

            this.gameObject.SetActive(true);
        }
 public override void SetItemHere(CIItemBase itemData)
 {
     this.AmmoHere = itemData as CAmmoData;
 }
Example #5
0
 public override void SetItemHere(CIItemBase itemData)
 {
     this.WeaponHere = itemData as CWeaponData;
 }
Example #6
0
 public abstract void SetItemHere(CIItemBase itemData);