public void CreateDropdown(Vector3 localPosition, float w, float h)
    {
        // Create the button
        buildingDropdown               = UIElementFunctions.Dropdown(panel, null, "Select Building", localPosition, new Vector2(w, h));
        buildingDropdown.thisGo.name   = "Building Dropdown Button";
        buildingDropdown.childHeight   = 30;
        buildingDropdown.childFontSize = 16;
        buildingDropdown.CloseButton();

        int ind = 0;

        foreach (string category in buildingManager.buildingCategories)
        {
            buildingDropdown.AddChild();
            buildingDropdown.children[ind].textGo.text           = category;
            buildingDropdown.children[ind].buttonGo.interactable = false;
            buildingDropdown.children[ind].CloseButton();
            int subInd = 0;
            IEnumerable <BuildingDef> theseBuildingDefs = BuildingQueries.ByCategoryNoParent(ManagerBase.buildingDefinitions, category);
            foreach (BuildingDef def in theseBuildingDefs)
            {
                buildingDropdown.children[ind].AddChild();
                buildingDropdown.children[ind].children[subInd].textGo.text = def.name + " (Tier " + def.tier + ")";
                buildingDropdown.children[ind].children[subInd].buttonGo.onClick.AddListener(() => bbcb(def.name));
                buildingDropdown.children[ind].children[subInd].CloseButton();
                subInd++;
            }
            ind++;
        }
    }
    public static DropdownUIElement Dropdown(Transform parent, Sprite img, string txt, Vector3 localPosition, Vector2 size)
    {
        // Rect
        RectTransform     rect = AddRect(parent, localPosition, size);
        DropdownUIElement duie = rect.gameObject.AddComponent <DropdownUIElement>();

        duie.rectGo = rect;
        // Component Image
        if (img == null)
        {
            duie.imageGo = AddImage(duie.rectGo.transform);
        }
        else
        {
            duie.imageGo = AddImage(duie.rectGo.transform, img);
        }
        // Button
        duie.buttonGo = AddButton(duie.rectGo.transform);
        // Child Rect
        RectTransform chRect = AddTextRect(duie.rectGo.transform);

        // Child Rect's Text
        duie.textGo = AddText(chRect.transform, txt);
        ScaleRect(chRect, 0, 0);
        chRect.offsetMin = new Vector2(0, 0);
        chRect.offsetMax = new Vector2(0, 0);
        duie.Init();
        return(duie);
    }
Exemple #3
0
    public void AddChild()
    {
        if (children == null)
        {
            children = new List <DropdownUIElement>();
        }

        DropdownUIChild duiChild = UIElementFunctions.DropdownChild(this.container.transform, null, "", new Vector3(0, 0, 0), new Vector2(64, 64));

        if (rootDropdown == null)
        {
            rootDropdown = this;
        }

        duiChild.rootDropdown = this.rootDropdown;
        children.Add(duiChild);

        // Anchor to lower right
        duiChild.container.anchorMin = new Vector2(1, 0);
        duiChild.container.anchorMax = new Vector2(1, 0);

        duiChild.thisGo.AddComponent <LayoutElement>();

        duiChild.element.minHeight = this.childHeight;

        // Set image sprite and type
        duiChild.imageGo.sprite = this.imageGo.sprite;
        duiChild.imageGo.type   = this.imageGo.type;

        // Set childText font, font color, and font size
        duiChild.textGo.font     = this.textGo.font;
        duiChild.textGo.color    = this.textGo.color;
        duiChild.textGo.fontSize = this.childFontSize;

        // Set button normal, highlighted, pressed colors
        duiChild.events = duiChild.buttonGo.onClick;

        ColorBlock b = buttonGo.colors;

        b.normalColor      = this.normal;
        b.highlightedColor = this.highlighted;
        b.pressedColor     = this.pressed;
        buttonGo.colors    = b;

        // Set button's onClick and childEvents
        duiChild.buttonGo.onClick = duiChild.events;
        duiChild.buttonGo.onClick.AddListener(delegate() { CloseButton(); });
        duiChild.buttonGo.onClick.AddListener(delegate() { ChangeMainButton(duiChild.textGo.text, duiChild.imageGo.sprite, duiChild.defName); });
    }
Exemple #4
0
    public void CreateDropdown(Vector3 localPosition, float w, float h, string surfaceType)
    {
        // Create the button
        actionDropdown               = UIElementFunctions.Dropdown(panel, null, "Surface Actions", localPosition, new Vector2(w, h));
        actionDropdown.childHeight   = 30;
        actionDropdown.childFontSize = 16;

        // Demolish
        actionDropdown.AddChild();
        actionDropdown.children[0].textGo.text = "Demolish";
        actionDropdown.children[0].buttonGo.onClick.AddListener(() => demolishCallback("Demolish"));
        actionDropdown.children[0].CloseButton();

        // Upgrades
        int menuInd = actionDropdown.children.Count;

        actionDropdown.AddChild();
        actionDropdown.children[menuInd].textGo.text = "Upgrade";
        //actionDropdown.children[upgradeInd].buttonGo.interactable = false;
        actionDropdown.children[menuInd].CloseButton();

        //Debug.Log(surfaceType);
        IEnumerable <BuildingDef> upgrades = BuildingQueries.ByParent(ManagerBase.buildingDefinitions, surfaceType);
        int ind = 0;

        foreach (BuildingDef def in upgrades)
        {
            actionDropdown.children[menuInd].AddChild();
            actionDropdown.children[menuInd].children[ind].textGo.text = def.name + " (Tier " + def.tier + ")";
            Debug.Log(actionDropdown.children[menuInd].children[ind].textGo.text);
            actionDropdown.children[menuInd].children[ind].buttonGo.onClick.AddListener(() => buildCallback(def.name));
            actionDropdown.children[menuInd].children[ind].CloseButton();
            ind++;
        }

        // Jobs
        if (ManagerBase.buildingIndexOf.ContainsKey(surfaceType))
        {
            menuInd++;

            BuildingDef bldgDef = ManagerBase.buildingDefinitions[ManagerBase.buildingIndexOf[surfaceType]];

            List <JobDef> jobs = new List <JobDef>();

            for (int jeInd = 0; jeInd < bldgDef.jobsEnabled.Count; jeInd++)
            {
                jobs.AddRange(JobQueries.ByNameAndMaxTier(ManagerBase.jobDefinitions, bldgDef.jobsEnabled[jeInd], bldgDef.jobMaxTier[bldgDef.jobsEnabled[jeInd]]));
            }

            Debug.Log(jobs.Count());

            if (jobs.Count() > 0)
            {
                actionDropdown.AddChild();
                actionDropdown.children[menuInd].textGo.text           = "Start Job";
                actionDropdown.children[menuInd].buttonGo.interactable = false;
                actionDropdown.children[menuInd].CloseButton();
                actionDropdown.children[menuInd].Init();

                ind = 0;
                foreach (JobDef job in jobs)
                {
                    string jobString = job.name + " (" + job.outputName[0] + ")";
                    actionDropdown.children[menuInd].AddChild();
                    actionDropdown.children[menuInd].children[ind].textGo.text = jobString;
                    actionDropdown.children[menuInd].children[ind].buttonGo.onClick.AddListener(() => newJobCallback(job.guid));
                    actionDropdown.children[menuInd].children[ind].CloseButton();
                    ind++;
                }
            }
        }
    }