예제 #1
0
    private static void JustUiElements(ResourceDropdown resourceDropdown, Transform parent, Sprite resultSprite, bool isStatic, Vector3 localPosition)
    {
        if (rightArrow == null)
        {
            Texture2D rightArrowTex = Resources.Load("Textures/RightArrow") as Texture2D;
            rightArrow = Sprite.Create(rightArrowTex,
                                       new Rect(0, 0, rightArrowTex.width, rightArrowTex.height),
                                       new Vector2(0.5f, 0.5f), rightArrowTex.width);
        }
        // Arrow
        localPosition.x += ResourceDropdownCreator.imageSize * 4 / 2;
        resourceDropdown.uiElements.Add(UIElementFunctions.ImageOnly(parent, rightArrow, localPosition, new Vector2(imageSize, imageSize)));
        resourceDropdown.uiElements[resourceDropdown.uiElements.Count - 1].gameObject.name = "Job Arrow";
        // Result
        localPosition.x += ResourceDropdownCreator.imageSize * 3 / 2;
        resourceDropdown.uiElements.Add(UIElementFunctions.ImageOnly(parent, resultSprite, localPosition, new Vector2(imageSize, imageSize)));
        resourceDropdown.uiElements[resourceDropdown.uiElements.Count - 1].gameObject.name = "Job Result";

        if (!isStatic)
        {
            localPosition.x += ResourceDropdownCreator.imageSize * 3 / 2;
            resourceDropdown.jobStartButton = UIElementFunctions.ButtonTextColor(parent, "Go", Color.green, localPosition, new Vector2(imageSize, imageSize));
            resourceDropdown.jobStartButton.textGo.fontSize       = 22;
            resourceDropdown.jobStartButton.buttonGo.interactable = false;
            resourceDropdown.jobStartButton.gameObject.name       = "Job Start Button";
            Debug.Log("Draw Go Button");
        }
    }
    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++;
        }
    }
예제 #3
0
    public void DemolishActionSelected(string s)
    {
        //Debug.Log("DemolishActionSelected");
        // Delete buttons
        //Debug.Log("Clear UI");
        ClearUIObjects();

        string txt = "Demolition\nTears down the current structure\n";

        if (jobDescriptionText == null)
        {
            jobDescriptionText = UIElementFunctions.TextOnly(jobsPanel.transform, txt, new Vector3(180, -50), new Vector2(300, 100));
        }
        else
        {
            jobDescriptionText.textGo.text = txt;
        }
        // Add prerequisites, colored, here

        // Buttons to make it go
        //Debug.Log("ResourceDropdownCreator");
        resourceChoiceDropdown = ResourceDropdownCreator.CreateNoResourceDropdown(tileDetailUiPanel.transform, new Vector3(-200, -185), "Demolition", ManagerBase.domain, null);
        resourceChoiceDropdown.jobStartButton.buttonGo.onClick.AddListener(delegate() { StartDemolitionJobButton(); });
        //Debug.Log("Done DemolishActionSelected");
    }
예제 #4
0
    public void BuildActionSelected(string s)
    {
        // Delete buttons
        ClearUIObjects();

        BuildingDef buildingSelected = ManagerBase.buildingDefinitions[ManagerBase.buildingIndexOf[s]];

        if (buildingSelected == null)
        {
            Debug.LogError("Should not have an unbuildable building here: " + s);
        }

        string txt = buildingSelected.name + "\n" + buildingSelected.description + "\n";

        if (jobDescriptionText == null)
        {
            jobDescriptionText = UIElementFunctions.TextOnly(jobsPanel.transform, txt, new Vector3(180, -50), new Vector2(300, 100));
        }
        else
        {
            jobDescriptionText.textGo.text = txt;
        }
        // Add prerequisites, colored, here

        // Figure out what the building needs
        resourceChoiceDropdown = ResourceDropdownCreator.CreateResourceChoiceDropdown(tileDetailUiPanel.transform, new Vector3(-200, -185), buildingSelected.resourcesToBuild, buildingSelected.name, ManagerBase.domain, buildingSelected.sprite);

        resourceChoiceDropdown.jobStartButton.buttonGo.onClick.AddListener(delegate() { StartConstructionJobButton(); });
    }
예제 #5
0
    public void ProcessJobComplete(DomainEventArg de)
    {
        CustomUIElement newEvent = UIElementFunctions.ButtonImageText(eventVlgRect.transform, null, de.message, new Vector3(0, 0, 0), new Vector2(0, 0));
        LayoutElement   element  = newEvent.thisGo.AddComponent <LayoutElement>();

        element.minHeight = this.jobEventHeight;
        uiElements.Add(new EventPanelButton(newEvent, jobEventPersistWallClockSec));
    }
예제 #6
0
    }                                                                                          // For scaling the children


    void Awake()
    {
        isOpen = false;
        thisGo = this.gameObject;

        container      = UIElementFunctions.AddVLGRect(transform);
        container.name = "vlgRect";
        container.gameObject.AddComponent <VerticalLayoutGroup>();
        UIElementFunctions.ScaleRect(container, 0, 0);
        container.anchorMin = new Vector2(0, 0);
        container.anchorMax = new Vector2(1, 0);
    }
예제 #7
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); });
    }
예제 #8
0
    void Awake()
    {
        isOpen = false;
        thisGo = this.gameObject;

        container      = UIElementFunctions.AddTextRect(transform);
        container.name = "vlgRect";
        container.gameObject.AddComponent <VerticalLayoutGroup>();
        UIElementFunctions.ScaleRect(container, 0, 0);

        // Do I need to do this?
        container.anchorMin = new Vector2(1, 0);
        container.anchorMax = new Vector2(1, 0);
        container.pivot     = new Vector2(0, 0);
        container.sizeDelta = new Vector2(160, 32);
    }
예제 #9
0
    public void NewJobActionSelected(System.Guid jobGuid)
    {
        JobDef jobSelected = JobQueries.ByGuid(ManagerBase.jobDefinitions, jobGuid);

        if (jobSelected == null)
        {
            Debug.LogError("Should not have an empty job here");
        }

        string txt = jobSelected.name + "\n" + jobSelected.description + "\n";

        if (jobDescriptionText == null)
        {
            jobDescriptionText = UIElementFunctions.TextOnly(jobsPanel.transform, txt, new Vector3(180, -50), new Vector2(300, 100));
        }
        else
        {
            jobDescriptionText.textGo.text = txt;
        }
        // Add prerequisites, colored, here

        // Figure out what the building needs
        Sprite output1Sprite = ManagerBase.resourceDefinitions[ManagerBase.resourceIndexOf[jobSelected.outputName[0]]].image;

        if (jobSelected.inputResources.rqqList.Count > 0) // Has inputs
        {
            resourceChoiceDropdown = ResourceDropdownCreator.CreateResourceChoiceDropdown(tileDetailUiPanel.transform, new Vector3(-200, -185), jobSelected.inputResources, jobSelected.name, ManagerBase.domain, output1Sprite);
        }
        else
        {
            resourceChoiceDropdown = ResourceDropdownCreator.CreateNoResourceDropdown(tileDetailUiPanel.transform, new Vector3(-200, -185), jobSelected.name, ManagerBase.domain, output1Sprite);
        }


        resourceChoiceDropdown.jobStartButton.buttonGo.onClick.AddListener(delegate() { StartJobButton(jobSelected); });
    }
예제 #10
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++;
                }
            }
        }
    }
예제 #11
0
    private static ResourceDropdown Create(Transform parent, Vector3 localPosition, ResourceQuantityQualityList choiceRqqList, string taskName, Domain domain, bool isStatic)
    {
        GameObject       newGo            = new GameObject("Resource Dropdown");
        ResourceDropdown resourceDropdown = newGo.AddComponent <ResourceDropdown>();

        resourceDropdown.choiceRqqList = choiceRqqList;
        resourceDropdown.taskName      = taskName;
        resourceDropdown.domain        = domain;

        int resInd = 0;

        foreach (ResourceQuantityQuality rqq in choiceRqqList.rqqList)
        {
            Dictionary <string, Sprite> stringSprite = rqq.GetImageOptions(rqq.minTier);

            // Create the button
            resourceDropdown.elements.Add(UIElementFunctions.Dropdown(parent, null, "", localPosition, new Vector2(64, 64)));
            //resourceDropdown[resInd].transform.localPosition = localPosition;

            localPosition.x += imageSize * 3 / 2;
            resourceDropdown.elements[resInd].thisGo.name = "Resource Dropdown Item";
            resourceDropdown.elements[resInd].childHeight = imageSize;

            int ind = 0;
            foreach (KeyValuePair <string, Sprite> entry in stringSprite)
            {
                ResourceNameQuantityQuality nqq = new ResourceNameQuantityQuality(entry.Key, QualityEnum.any, rqq.quantity);

                if (ind == 0)
                {
                    resourceDropdown.elements[resInd].imageGo.sprite = entry.Value;
                    resourceDropdown.elements[resInd].textGo.text    = "";
                    resourceDropdown.elements[resInd].defName        = entry.Key;
                }
                if (!isStatic)
                {
                    resourceDropdown.elements[resInd].AddChild();
                    resourceDropdown.elements[resInd].children[ind].tooltipData    = entry.Key;
                    resourceDropdown.elements[resInd].children[ind].defName        = entry.Key;
                    resourceDropdown.elements[resInd].children[ind].imageGo.sprite = entry.Value;
                }

                if (!nqq.CheckResource(domain.stock))
                {
                    if (ind == 0)
                    {
                        resourceDropdown.elements[resInd].imageGo.color = Color.red;
                        resourceDropdown.elements[resInd].allowed       = false;
                    }
                    if (!isStatic)
                    {
                        resourceDropdown.elements[resInd].children[ind].imageGo.color         = Color.red;
                        resourceDropdown.elements[resInd].children[ind].buttonGo.interactable = false;
                        resourceDropdown.elements[resInd].children[ind].allowed = false;
                    }
                }
                if (!isStatic)
                {
                    resourceDropdown.elements[resInd].children[ind].textGo.text = "";
                }

                // Add a quantity text
                string          quantityString = rqq.quantity.ToString();
                CustomUIElement temp           = UIElementFunctions.TextOnly(resourceDropdown.elements[resInd].thisGo.transform, quantityString, new Vector3(0, imageSize - 20), new Vector2(imageSize, 20F));
                temp.textGo.alignment = TextAnchor.MiddleCenter;

                ind++;
            }
            resInd++;
        }
        return(resourceDropdown);
    }