Esempio n. 1
0
    private void GenererInventaireSlot(Tribu tribu)
    {
        NettoyerInventaire();

        float[] gains = tribu.stockRessources.RessourcesEnStock.gains;

        //Génère slots de ressource
        for (int i = 0; i < gains.Length; i++)
        {
            Ressource ressource = ListeRessources.Defaut.listeDesRessources[i];
            if (gains[i] >= 1 && !platoActuel.ressourcesEchangees.Contains(ressource.nom))
            {
                GameObject nvSlot = Instantiate(slotRessourceBase, fond);
                listeSlots.Add(nvSlot);
                nvSlot.SetActive(true);

                foreach (Image image in nvSlot.GetComponentsInChildren <Image>())
                {
                    if (image.name == "Icone")
                    {
                        image.sprite = ListeIcones.Defaut.TrouverIconeRessource(ressource);
                    }
                }
                nvSlot.GetComponentInChildren <TextMeshProUGUI>().text     = "" + gains[i];
                nvSlot.GetComponentInChildren <InfoBulle>().texteInfoBulle = ressource.texteInfobulle;

                Button nvBouton = nvSlot.GetComponentInChildren <Button>();

                nvBouton.onClick.AddListener(() =>
                                             platoActuel.AjouterSlotEchange(ressource));
                nvBouton.onClick.AddListener(() => Destroy(nvSlot));
                nvBouton.onClick.AddListener(CacherInventaire);
            }
        }

        List <Consommable>            consommables    = tribu.stockRessources.consommables;
        Dictionary <Consommable, int> inventaireConso = new Dictionary <Consommable, int>();

        //Génère slots de consommables
        for (int i = 0; i < consommables.Count; i++)
        {
            if (inventaireConso.ContainsKey(consommables[i]))
            {
                inventaireConso[consommables[i]]++;
            }
            else
            {
                inventaireConso.Add(consommables[i], 1);
            }
        }

        foreach (Consommable consommable in inventaireConso.Keys)
        {
            if (!platoActuel.ressourcesEchangees.Contains(consommable.nom))
            {
                GameObject nvSlot = Instantiate(slotRessourceBase, fond);
                listeSlots.Add(nvSlot);
                nvSlot.SetActive(true);

                foreach (Image image in nvSlot.GetComponentsInChildren <Image>())
                {
                    if (image.name == "Icone")
                    {
                        image.sprite = consommable.icone;
                    }
                }
                nvSlot.GetComponentInChildren <TextMeshProUGUI>().text     = "" + inventaireConso[consommable];
                nvSlot.GetComponentInChildren <InfoBulle>().texteInfoBulle = consommable.TexteInfobulle;

                Button nvBouton = nvSlot.GetComponentInChildren <Button>();

                nvBouton.onClick.AddListener(() =>
                                             platoActuel.AjouterSlotEchange(consommable));
                nvBouton.onClick.AddListener(() => Destroy(nvSlot));
                nvBouton.onClick.AddListener(CacherInventaire);
            }
        }
    }