Esempio n. 1
0
    void SpawnItems(Fighter f, Transform parent)
    {
        foreach (Item i in f.Unit.inventory.GetOrderedArray(f))
        {
            GameObject go  = Instantiate(itemButtonPrefab, parent);
            ItemButton btn = go.GetComponent <ItemButton>();

            if (i.IsUseable(f))
            {
                btn.label.color = Color.white;
            }
            else
            {
                btn.label.color = Color.gray;
            }

            btn.SetItem(i);
            SetMethods(btn);
        }

        if (f.Unit.inventory.Items.Count < Inventory.Size)
        {
            GameObject go  = Instantiate(itemButtonPrefab, parent);
            ItemButton btn = go.GetComponent <ItemButton>();

            btn.SetItem(Item.Blank());

            SetMethods(btn);
        }
    }
Esempio n. 2
0
    public void InventoryClicked()
    {
        /*inventoryButton.gameObject.SetActive(false);
         * statusButton.gameObject.SetActive(false);
         * equipmentButton.gameObject.SetActive(false);
         * saveButton.gameObject.SetActive(false);
         * optionsButton.gameObject.SetActive(false);
         */
        if (currentTab == 1)
        {
            return;
        }
        Debug.Log(inventory.items.Count);

        //int x_offset = 0;
        //int y_offset = 0;
        int i = 0;

        foreach (KeyValuePair <string, Item> entry in inventory.items)
        {
            Item       item   = entry.Value;
            ItemButton button = Instantiate(itemButton, Vector3.zero, Quaternion.identity);
            button.SetItem(item);
            button.SetPlayer(player);
            button.panel = window;
            //button.SetDropdownParent(dropdownLayer.transform);
            //Button itemButton;
            button.transform.SetParent(scrollContent.transform, false);

            /*RectTransform buttonRT = (RectTransform)button.transform;
             * RectTransform itemPanelRT = (RectTransform)itemPanel.transform;
             * float w = buttonRT.rect.width;
             * float h = buttonRT.rect.height;
             * float left = itemPanelRT.rect.xMin + x_offset * w;
             * float top = itemPanelRT.rect.yMax - y_offset * h;
             * Debug.Log(left);
             * Debug.Log(top);
             * buttonRT.offsetMin = new Vector2(left, top-h);
             * buttonRT.offsetMax = new Vector2(left+w, top);*/
            button.itemName.text = entry.Key + " x" + item.count;

            /*if(x_offset == 0){
             *      x_offset = 1;
             * }
             * else{
             *      x_offset = 0;
             ++y_offset;
             * }*/
            //itemButtons[i].gameObject.SetActive(true);
            itemButton.menu  = this;
            itemButton.index = i;
            itemButtons.Add(button);
            ++i;
        }
        itemPanel.gameObject.SetActive(true);
        backButton.gameObject.SetActive(true);
        itemButtons[0].button.Select();
        currentTab = 1;
    }
Esempio n. 3
0
    private void AddItemToSpace(Item item, int count = 1)
    {
        GameObject but = Instantiate(Parent.ItemButtonPrefab.gameObject);
        ItemButton itb = but.GetComponent <ItemButton>();

        itb.SetItem(item);
        but.transform.SetParent(InventorySpace.transform, false);
        itb.SetDisplayInventory(this);
    }
Esempio n. 4
0
 // Use this for initialization
 void Start()
 {
     numeroItems = itemList.itemList.Count;
     for (int i = 0; i < numeroItems; i++)
     {
         ItemButton button = Instantiate(prefab).GetComponent <ItemButton>();
         button.transform.SetParent(transform);
         button.SetItem(itemList.itemList[i]);
     }
 }
Esempio n. 5
0
    public void CreateInventory(PlayerResources newPlayerResources)
    {
        items = new ItemButton[ItemModel.instance.itemData.Count];
        for (int i = 0; i < ItemModel.instance.itemData.Count; ++i)
        {
            GameObject newButton  = Instantiate(itemButtonPrefab, content);
            ItemButton itemButton = newButton.GetComponent <ItemButton>();

            itemButton.SetItem(i);
            itemButton.button.onClick.AddListener(() => SelectItem(itemButton.Id));
            items[i] = itemButton;
        }
        playerResources = newPlayerResources;
        IsActive        = true;
    }
Esempio n. 6
0
 private void _init()
 {
     _lastUpdated = DateTime.Now;
     // events
     clickerButton.onClick.AddListener(() => Click());
     // init player
     player = Player.GetInstance();
     player.Init();
     // init UI
     dropController.Init();
     UnityEngine.Object buttonPrefab = Resources.Load("ItemButton");
     buttons  = new ItemButton[player.items.Count];
     _itemIds = new int[player.items.Count];
     for (int i = 0; i < player.items.Count; ++i)
     {
         hardwares[i].SetActive(false);
         GameObject    obj  = Instantiate(buttonPrefab) as GameObject;
         RectTransform rect = obj.GetComponent <RectTransform>();
         rect.SetParent(buttonContainer);
         rect.anchoredPosition = new Vector2(0, i * -58);
         int index = i;
         _itemIds[i] = player.items[i].id;
         ItemButton button = obj.GetComponent <ItemButton>();
         button.SetOnMouseCallback(() => ShowTip(index));
         button.SetItem(player.items[i]);
         button.SetSprite(player.items[i].id);
         buttons[i] = button;
         obj.GetComponent <Button>().onClick.AddListener(() => BuyItem(index));
     }
     // load data & refresh
     player.Load();
     for (int i = 0; i < player.items.Count; ++i)
     {
         buttons[i].SetItem(player.items[i]);
         if (player.items[i].unlocked)
         {
             buttons[i].Unlock();
         }
         if (player.items[i].level > 0)
         {
             hardwares[i].SetActive(true);
         }
         dropController.SetMaxUnlockedNum(player.unlockedItem);
         dropController.SetSpeed(player.autoValue);
     }
     RefreshScore();
 }
    private void PopulateListItem(Node node, int nodeIndex)
    {
        listItens = node.GetListItens();

        for (int i = 0; i < listItens.Count; i++)
        {
            GameObject newObject = Instantiate(buttonsPrefabs[1], panelInteraction.transform);
            ItemButton pointer   = newObject.GetComponent <ItemButton>();

            pointer.SetController(this);
            pointer.SetParentNode(listNodes[i]);
            pointer.SetParentIndex(nodeIndex);
            pointer.SetItem(listItens[i]);
            pointer.SetIndex(i);

            itenButtonList.Add(newObject);
        }
    }
Esempio n. 8
0
    void SpawnButton(Item i, Fighter f)
    {
        GameObject go  = Instantiate(itemButtonPrefab, itemList.transform);
        ItemButton btn = go.GetComponent <ItemButton>();

        go.GetComponent <UIHighlight>().OnSelectAction += () => { hovered = btn.GetItem(); };
        go.GetComponent <Button>().onClick.AddListener(() => { OpenActionMenu(); });

        if (i.IsUseable(f))
        {
            btn.label.color = Color.white;
        }
        else
        {
            btn.label.color = Color.gray;
        }

        btn.SetItem(i);
    }