Example #1
0
 //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;
 }
Example #2
0
 public void OnActionButtonExit(String description, ResourceValueDictionary resourceCost)
 {
     hud.OnActionButtonExit(description, resourceCost);
 }
Example #3
0
 public void updateResource(ResourceValueDictionary resourceCosts, String player)
 {
     foreach (KeyValuePair<Resource, int> kv in resourceCosts)
     {
         updateResource(kv.Key, kv.Value, player);
     }
 }
Example #4
0
 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);
     }
 }
Example #5
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;
    }
Example #6
0
 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);
     }
 }
Example #7
0
 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;
 }