Esempio n. 1
0
    public void Update_GUI()
    {
        list.Clear();
        Volyme_Text.text = string.Format("Volyme: {0}", !Inventory.Limited_Volyme ? "Unlimited" : string.Format("{0} / {1}", Helper.Float_To_String(Inventory.Current_Volyme, 1), Inventory.Max_Volyme));
        Weight_Text.text = string.Format("Weight: {0}", !Inventory.Limited_Weight ? "Unlimited" : string.Format("{0} / {1}", Helper.Float_To_String(Inventory.Current_Weight, 1), Inventory.Max_Weight));

        foreach (KeyValuePair <string, int> stacked_items in Inventory.Count_Dictionary_Internal_Names)
        {
            Item item = null;
            if (stacked_items.Value == 1)
            {
                item = Inventory.Get_Items(stacked_items.Key)[0];
            }
            else
            {
                item = ItemPrototypes.Instance.Get_Item_Prototype(stacked_items.Key);
            }
            list.Add_Row(item.Internal_Name,
                         new List <ScrollableList.TextData>()
            {
                new ScrollableList.TextData("CountText", string.Format("{0}x", stacked_items.Value), stacked_items.Value != 1),
                new ScrollableList.TextData("NameText", item.Name, true),
                new ScrollableList.TextData("DurabilityText", string.Format("{0}%", item.Unbreaking ? "inf" : Helper.Float_To_String(item.Relative_Durability * 100.0f, 0)), stacked_items.Value == 1)
            },
                         new List <ScrollableList.ImageData>()
            {
                new ScrollableList.ImageData("IconImage", item.UI_Sprite, item.UI_Sprite_Type, true)
            },
                         new List <ScrollableList.ButtonData>()
            {
                new ScrollableList.ButtonData("ExpandButton", ">", delegate() { Expand(item, stacked_items.Value); }, true, stacked_items.Value != 1),
                new ScrollableList.ButtonData("InvisibleButton", null, delegate() { Select_Item(item, stacked_items.Value != 1); }, true, true)
            });
        }
    }
Esempio n. 2
0
    public void Update_GUI()
    {
        foreach (KeyValuePair <TabType, Button> pair in tab_buttons)
        {
            GameObject.Destroy(pair.Value.gameObject);
        }
        tab_buttons.Clear();
        foreach (KeyValuePair <TabType, GameObject> pair in tab_panels)
        {
            GameObject.Destroy(pair.Value);
        }
        tab_panels.Clear();

        int index = 0;

        foreach (TabType tab in Enum.GetValues(typeof(TabType)))
        {
            //Button
            Button button = GameObject.Instantiate(
                Tab_Button_Prototype,
                new Vector3(
                    Tab_Button_Prototype.transform.position.x + (Tab_Button_Prototype.GetComponent <RectTransform>().rect.width *index),
                    Tab_Button_Prototype.transform.position.y,
                    Tab_Button_Prototype.transform.position.z
                    ),
                Quaternion.identity,
                Main_Panel.transform
                );
            button.name = string.Format("{0}_button", tab.ToString());
            button.gameObject.SetActive(true);
            button.GetComponentInChildren <Text>().text = tab.ToString();

            Button.ButtonClickedEvent click = new Button.ButtonClickedEvent();
            click.AddListener(new UnityAction(delegate() { Select_Tab(tab); }));
            button.onClick = click;
            tab_buttons.Add(tab, button);

            //Panel
            GameObject panel = GameObject.Instantiate(
                Tab_Panel_Prototype,
                new Vector3(
                    Tab_Panel_Prototype.transform.position.x,
                    Tab_Panel_Prototype.transform.position.y,
                    Tab_Panel_Prototype.transform.position.z
                    ),
                Quaternion.identity,
                Main_Panel.transform
                );
            panel.name = string.Format("{0}_panel", tab.ToString());
            panel.SetActive(true);
            tab_panels.Add(tab, panel);

            //Recipes
            string s;
            foreach (CraftingRecipe recipe in CraftingRecipePrototypes.Instance.Get_All_In(tab))
            {
                ScrollableList list = panel.GetComponentInChildren <ScrollableList>();
                list.Add_Row(recipe.Id.ToString(), new List <ScrollableList.TextData>()
                {
                    new ScrollableList.TextData("NameText", Player.Current.Can_Craft(recipe, out s) ? recipe.Name : string.Format("<i>{0}</i>", recipe.Name), true)
                },
                             new List <ScrollableList.ImageData>()
                {
                    new ScrollableList.ImageData("IconImage", recipe.Icon_Sprite, recipe.Icon_Sprite_Type, true)
                },
                             new List <ScrollableList.ButtonData>()
                {
                    new ScrollableList.ButtonData("SelectButton", null, delegate() { Select_Recipe(recipe); }, true, true)
                });
            }
            panel.SetActive(false);

            index++;
        }
    }