Ejemplo n.º 1
0
 void Update()
 {
     if (_onHoovering)
     {
         InventoryPopupInfos.ChangePosition();
     }
 }
Ejemplo n.º 2
0
 public void OnPointerExit()
 {
     if (_onHoovering)
     {
         InventoryPopupInfos.Hide();
         _onHoovering = false;
     }
 }
Ejemplo n.º 3
0
 public void OnPointerEnter(int index)
 {
     if (Inventory.Items[index] == null)
     {
         return;
     }
     InventoryPopupInfos.Show(Inventory.Items[index].Name, Inventory.Items[index].Count);
     OnHoovering = true;
 }
Ejemplo n.º 4
0
 void Update()
 {
     if (OnHoovering)
     {
         InventoryPopupInfos.ChangePosition();
     }
     if (OnHooveringRecipe)
     {
         RecipePopupInfos.ChangePosition();
     }
 }
Ejemplo n.º 5
0
    public void OnPointerEnter(int index)
    {
        int contentIndex = _buttons.Length * _actualPage + index;

        if (contentIndex >= _itemContainer.Content.Length)
        {
            return;
        }
        if (_itemContainer.Content[contentIndex] == null)
        {
            return;
        }
        if (_itemContainer.Content[contentIndex].Type == ItemType.Money)
        {
            InventoryPopupInfos.Show(_itemContainer.Content[contentIndex].Name, (int)_itemContainer.Content[contentIndex].Value);
        }
        else
        {
            InventoryPopupInfos.Show(_itemContainer.Content[contentIndex].Name, _itemContainer.Content[contentIndex].Count);
        }
        _onHoovering = true;
    }
Ejemplo n.º 6
0
    public void SelectedItem(int index)
    {
        int contentIndex = _buttons.Length * _actualPage + index;

        if (_itemContainer.Content[contentIndex].Name != "Money")
        {
            Inventory.AddItemToInventory(_itemContainer.Content[contentIndex]);
        }
        else
        {
            Inventory.Money += _itemContainer.Content[contentIndex].Value;
            GlobalEventText.AddMessage(string.Format("You get {0} gold !", _itemContainer.Content[contentIndex].Value));
            Inventory.RefreshUI();
        }
        _itemContainer.Content[contentIndex] = null;

        _images[index].sprite = null;
        _buttons[index].SetActive(false);

        //Check if all the content of this page is gone
        for (int i = 0; i < _buttons.Length; i++)
        {
            if (_buttons[i].activeInHierarchy)
            {
                return;
            }
        }
        //Actual page empty !
        //If we aren't at the page 0
        if (_actualPage > 0)
        {
            do
            {
                _actualPage--;
                int start = _actualPage * _buttons.Length;
                int end   = start + _buttons.Length;
                //Check if the page -1 contains items:
                for (int i = start; i < end; i++)
                {
                    if (_itemContainer.Content[i] != null)
                    {
                        UpdateButtonAtPage(_actualPage);
                        if (_actualPage == 0)
                        {
                            _previousButton.SetActive(false);
                        }
                        return;
                    }
                }
            } while (_actualPage > 0);
        }
        //If we are at the page 0 => check if the content list is empty:
        //Looking for a page with some content
        for (int i = 0; i < _itemContainer.Content.Length; i++)
        {
            if (_itemContainer.Content[i] != null)
            {
                _actualPage = (int)(i / Buttons.Length);
                UpdateButtonAtPage(_actualPage);
                _previousButton.SetActive(false);
                //Checking if we can keep the next button on:
                if ((_actualPage + 1) * _buttons.Length >= _itemContainer.Content.Length)
                {
                    _nextButton.SetActive(false);
                }
                return;
            }
        }

        //Nothing left, we can destroy the object:
        Inventory.RemoveItemFromInventory(_itemContainer);
        InventoryUI.OnHoovering = false;
        InventoryPopupInfos.Hide();
        Exit();
    }
Ejemplo n.º 7
0
    public void InventoryItemClick(int index)
    {
        if (Inventory.Items[index] == null)
        {
            ClearText();
            _lastSelectedItem = -1;
            UseButton.gameObject.SetActive(false);
            return;
        }

        //Removing item:
        if (Input.GetMouseButton(1))
        {
            GameObject item = null;
            if (Input.GetKey(KeyCode.LeftShift))
            {
                GlobalEventText.AddMessage(string.Format("You just throw away \"{0}\" (x1)", Inventory.Items[index].Name));
                item = MonoItem.CreateGameObjectFromItem(Inventory.Items[index]);
                item.GetComponent <MonoItem>().thisItem.Count = 1;
                Inventory.DecreaseCount(Inventory.Items[index], 1);
            }
            else
            {
                GlobalEventText.AddMessage(string.Format("You just throw away \"{0}\" (x{1})", Inventory.Items[index].Name, Inventory.Items[index].Count));
                item = MonoItem.CreateGameObjectFromItem(Inventory.Items[index]);
                Inventory.RemoveItemFromInventory(Inventory.Items[index]);
                //Hide the infos popup
                OnHoovering = false;
                InventoryPopupInfos.Hide();
            }


            //Check if the playe tile contains items
            if (Scene._grid[Player.CurrentIndexPosition].TileItem != null)
            {
                //Check if the existing item is not a container
                Item[] items;
                Item   existing = Scene._grid[Player.CurrentIndexPosition].TileItem.GetComponent <MonoItem>().thisItem;
                if (existing.GType != GlobalType.Container)
                {
                    Debug.Log("Wrap items");
                    //Wrap all items in a bag:
                    Bag01 bag = new Bag01(Scene._grid[Player.CurrentIndexPosition].TileItem);
                    items    = new Item[2];
                    items[0] = existing;
                    items[1] = item.GetComponent <MonoItem>().thisItem;
                    bag.SetContent(items);
                    Scene._grid[Player.CurrentIndexPosition].TileItem.GetComponent <MonoItem>().thisItem = bag;

                    Scene._grid[Player.CurrentIndexPosition].ItemValue = bag.ItemValue;

                    Scene._grid[Player.CurrentIndexPosition].TileItem.GetComponent <SpriteRenderer>().sprite = bag.InGameSprite;

                    Destroy(item);
                }
                else
                {
                    Debug.Log("Add content");
                    ItemContainer container = (ItemContainer)existing;
                    items = new Item[container.Content.Length + 1];
                    //Get the existing items
                    for (int i = 0; i < container.Content.Length; i++)
                    {
                        items[i] = container.Content[i];
                    }
                    items[container.Content.Length] = (Item)item.GetComponent <MonoItem>().thisItem.Clone(); //Add the new item
                    container.SetContent(items);                                                             //Set the new content

                    Destroy(item);
                }
            }
            else
            {
                //Create the object in the player tile
                item.transform.position = Scene._grid[Player.CurrentIndexPosition].position;
                item.transform.SetParent(Scene._grid[Player.CurrentIndexPosition].TileObject.transform);
                Scene._grid[Player.CurrentIndexPosition].TileItem  = item;
                Scene._grid[Player.CurrentIndexPosition].ItemValue = item.GetComponent <MonoItem>().thisItem.ItemValue;
            }
            return;
        }
        _lastSelectedItem    = index;
        NameText.text        = string.Format("Name: {0}", Inventory.Items[index].Name);
        MassText.text        = string.Format("Mass: {0}", Inventory.Items[index].Mass);
        CountText.text       = string.Format("Quantity: {0}", Inventory.Items[index].Count);
        DescriptionText.text = string.Format("Description: {0}", Inventory.Items[index].Description);

        if (Inventory.Items[index].isUsable)
        {
            switch (Inventory.Items[index].GType)
            {
            case GlobalType.Fruits:
            case GlobalType.Vegetables:
                UseButton.transform.GetChild(0).GetComponent <Text>().text = "Eat";
                break;

            case GlobalType.Container:
                UseButton.transform.GetChild(0).GetComponent <Text>().text = "Open";
                break;

            default:
                UseButton.transform.GetChild(0).GetComponent <Text>().text = "Use";
                break;
            }
            UseButton.gameObject.SetActive(true);
        }
        else
        {
            UseButton.gameObject.SetActive(false);
        }
    }