//Called to check whether there are enough resources to perform an action. //Params: resource type, amount (to subtract). //Returns true if there are enough, and updates the resource type. //Returns false if there aren't enough, and displays warnings. public bool checkResources(ResourceValueDictionary resourceCosts, String player) { ResourceValueDictionary resDict; if (player == "Ally") resDict = playerResources; else resDict = cpuResources; bool check = true; foreach (KeyValuePair<Resource, int> kv in resourceCosts) { if (resDict[kv.Key] - kv.Value < 0) { //Here goes stuff that happens when there aren't enough resources to perform the action. //i.e. text pop-up, sound warning. check = false; } } return check; }
public void OnActionButtonExit(String description, ResourceValueDictionary resourceCost) { hud.OnActionButtonExit(description, resourceCost); }
public void updateResource(ResourceValueDictionary resourceCosts, String player) { foreach (KeyValuePair<Resource, int> kv in resourceCosts) { updateResource(kv.Key, kv.Value, player); } }
void Awake() { goingToCollect = false; unitMovement = GetComponent<UnitMovement>(); animator = GetComponent<Animator>(); resourceBank = new ResourceValueDictionary(); foreach( Resource resource in Enum.GetValues(typeof(Resource))) { resourceBank.Add(resource, 0); } }
private GameObject addBlock( Transform parent, Sprite image, String description, ResourceValueDictionary resourceCost, UnityAction callback) { GameObject block = Instantiate(data.blockPrefab) as GameObject; Image background = block.GetComponent<Image>(); background.sprite = panelSprite; Image foreground = block.transform.GetChild(0).GetComponent<Image>(); foreground.sprite = image; block.AddComponent<ShowRightPanel>(); block.GetComponent<ShowRightPanel>().description = description; block.GetComponent<ShowRightPanel>().resourceCost = resourceCost == null ? ShowRightPanel.zeroResources : resourceCost; block.transform.SetParent(parent); // Add listener when clicked Button button = block.GetComponent<Button>(); button.onClick.AddListener(callback); return block; }
public void OnActionButtonExit(String description, ResourceValueDictionary resourceCost) { foreach (KeyValuePair<Resource, Text> kv in resourceCosts) { Resource resource = kv.Key; kv.Value.text = resourceCost[resource].ToString(); Text text = resourceTexts[resource]; text.text = (Int32.Parse(text.text) + resourceCost[resource]).ToString(); text.color = new Color(0f, 0f, 0f, 1f); } }
public void OnActionButtonEnter( String description, ResourceValueDictionary resourceCost ) { rightPanel.gameObject.SetActive(true); rightPanel.GetChild(1).gameObject.SetActive(! (resourceCost == ShowRightPanel.zeroResources)); foreach(KeyValuePair<Resource,Text> kv in resourceCosts) { Resource resource = kv.Key; kv.Value.text = resourceCost[resource].ToString(); Text text = resourceTexts[resource]; int newvalue = (Int32.Parse(text.text) - resourceCost[resource]); text.text = newvalue.ToString(); if(resourceCost[resource] != 0) text.color = newvalue > 0 ? new Color(.3f, .3f, .3f, 1f) : new Color(.5f, 0f, 0f, 1f); } descriptionText.text = description; }