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 static ResourceDropdown CreateResourceChoiceDropdown(Transform parent, Vector3 localPosition, ResourceQuantityQualityList choiceRqqList, string taskName, Domain domain, Sprite resultSprite) { ResourceDropdown rd = Create(parent, localPosition, choiceRqqList, taskName, domain, false); AddUiElements(rd, parent, resultSprite, false); return(rd); }
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"); }
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(); }); }
private static void AddUiElements(ResourceDropdown resourceDropdown, Transform parent, Sprite resultSprite, bool isStatic) { // Add stuff to the right of the resources // This fails when the resource count is 0!!!!! Vector3 localPosition = resourceDropdown.elements[resourceDropdown.elements.Count - 1].transform.localPosition; JustUiElements(resourceDropdown, parent, resultSprite, isStatic, localPosition); }
// Use this for initialization void Awake() { newConstructionDropdown.bbcb = new BuildingButtonCallback(BuildActionSelected); buildingActionDropdown.buildCallback = new BuildingButtonCallback(BuildActionSelected); buildingActionDropdown.demolishCallback = new BuildingButtonCallback(DemolishActionSelected); buildingActionDropdown.newJobCallback = new JobButtonCallback(NewJobActionSelected); resourceChoiceDropdown = null; activeJobDisplays = new List <ResourceDropdown>(); }
private static ResourceDropdown CreateNoResource(Transform parent, Vector3 localPosition, string taskName, Domain domain, Sprite resultSprite, bool isStatic) { GameObject newGo = new GameObject("Resource Dropdown"); ResourceDropdown resourceDropdown = newGo.AddComponent <ResourceDropdown>(); resourceDropdown.taskName = taskName; resourceDropdown.domain = domain; JustUiElements(resourceDropdown, parent, resultSprite, isStatic, localPosition); return(resourceDropdown); }
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); }); }
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); }
public static ResourceDropdown CreateNoResourceDropdown(Transform parent, Vector3 localPosition, string taskName, Domain domain, Sprite resultSprite) { ResourceDropdown rd = CreateNoResource(parent, localPosition, taskName, domain, resultSprite, false); return(rd); }