//Buttons actions
    void initButtonsActions()
    {
        miliciaPop.setUpAction(addFirstFoundHabitant_miliciaPop);
        miliciaPop.setDownAction(removeFirstFoundHabitant_miliciaPop);
        miliciaPop.enableUpAction();
        miliciaPop.enableDownAction();

        foodPop.setUpAction(addFirstFoundHabitant_foodPop);
        foodPop.setDownAction(removeFirstFoundHabitant_foodPop);
        foodPop.enableUpAction();
        foodPop.enableDownAction();

        woodPop.setUpAction(addFirstFoundHabitant_woodPop);
        woodPop.setDownAction(removeFirstFoundHabitant_woodPop);
        woodPop.enableUpAction();
        woodPop.enableDownAction();

        ironPop.setUpAction(addFirstFoundHabitant_ironPop);
        ironPop.setDownAction(removeFirstFoundHabitant_ironPop);
        ironPop.enableUpAction();
        ironPop.enableDownAction();

        goldPop.setUpAction(addFirstFoundHabitant_goldPop);
        goldPop.setDownAction(removeFirstFoundHabitant_goldPop);
        goldPop.enableUpAction();
        goldPop.enableDownAction();

        manaPop.setUpAction(addFirstFoundHabitant_manaPop);
        manaPop.setDownAction(removeFirstFoundHabitant_manaPop);
        manaPop.enableUpAction();
        manaPop.enableDownAction();
    }
Ejemplo n.º 2
0
    //Private Functions
    private void initUI()
    {
        //Set Title Text
        titleText.text = GameVariables.batimentSelectionne.nomBatiment;
        //Set Desc Text
        descText.text = GameVariables.batimentSelectionne.description;

        //Check Effectifs UI Needed + Set Pop Manager Actions
        if (GameVariables.batimentSelectionne.nbrMaxHab != 0)
        {
            buildingPopulationManager.gameObject.SetActive(true);
            buildingPopulationManager.gameObject.GetComponent <RectTransform>().localScale = new Vector3(1, 1, 1);
            secondSeparator.gameObject.SetActive(true);
            secondSeparator.gameObject.GetComponent <RectTransform>().localScale = new Vector3(1, 1, 1);

            buildingPopulationManager.setUpAction(() => {
                if (GameVariables.listHabitant.Count == 0)
                {
                    return;
                }

                Batiment batiment = GameVariables.batimentSelectionne;
                if (batiment == null || batiment.isEnDeplacement() || batiment.ListHabitants.Count >= batiment.nbrMaxHab)
                {
                    return;
                }

                List <Habitant> listMetierBat = GameVariables.getListMetier(batiment.typeHabitant);
                if (listMetierBat == null)
                {
                    return;
                }

                Habitant villager = GameVariables.listHabitant[0];
                GameVariables.listHabitant.Remove(villager);

                villager.Spawn = batiment;
                GameObject o   = villager.GetComponent <Role>().changementRole(batiment.typeHabitant.ToString());
                GameVariables.listHabitantAffecte.Add(villager);
                listMetierBat.Add(villager);
                batiment.ListHabitants.Add(o);
            });

            buildingPopulationManager.setDownAction(() => {
                Batiment batiment = GameVariables.batimentSelectionne;
                if (batiment == null || batiment.isEnDeplacement())
                {
                    return;
                }
                if (batiment.ListHabitants.Count == 0)
                {
                    return;
                }

                GameObject o = batiment.ListHabitants[0];

                if (o.GetComponent <Habitant>() == null)
                {
                    return;
                }

                List <Habitant> listMetierBat = GameVariables.getListMetier(batiment.typeHabitant);
                if (listMetierBat == null)
                {
                    return;
                }

                Habitant villager = o.GetComponent <Habitant>();
                batiment.ListHabitants.Remove(o);
                listMetierBat.Remove(villager);
                GameVariables.listHabitantAffecte.Remove(villager);

                villager.GetComponent <Role>().changementRole(Batiment.role.Habitant.ToString());
                GameVariables.listHabitant.Add(villager);
            });
        }
        else
        {
            buildingPopulationManager.gameObject.SetActive(false);
            buildingPopulationManager.gameObject.GetComponent <RectTransform>().localScale = new Vector3(0, 0, 0);
            secondSeparator.gameObject.SetActive(false);
            secondSeparator.gameObject.GetComponent <RectTransform>().localScale = new Vector3(0, 0, 0);
        }

        //Check Prod UI Needed
        if (GameVariables.batimentSelectionne is BatimentRessource)
        {
            buildingProdUI.gameObject.SetActive(true);
            buildingProdUI.gameObject.GetComponent <RectTransform>().localScale = new Vector3(1, 1, 1);
            thirdSeparator.gameObject.SetActive(true);
            thirdSeparator.gameObject.GetComponent <RectTransform>().localScale = new Vector3(1, 1, 1);
        }
        else
        {
            buildingProdUI.gameObject.SetActive(false);
            buildingProdUI.gameObject.GetComponent <RectTransform>().localScale = new Vector3(0, 0, 0);
            thirdSeparator.gameObject.SetActive(false);
            thirdSeparator.gameObject.GetComponent <RectTransform>().localScale = new Vector3(0, 0, 0);
        }

        //Check Upgrade UI Needed + Set Upgrade Action
        if (GameVariables.batimentSelectionne.batUpgrade != null)
        {
            buildingUpgradeUI.gameObject.SetActive(true);
            buildingUpgradeUI.gameObject.GetComponent <RectTransform>().localScale = new Vector3(1, 1, 1);

            buildingUpgradeUI.setUpgradeAction(() => {
                GameVariables.batimentSelectionne.upgradeStructure();
            });
        }
        else
        {
            buildingUpgradeUI.gameObject.SetActive(false);
            buildingUpgradeUI.gameObject.GetComponent <RectTransform>().localScale = new Vector3(0, 0, 0);
        }
    }