/// <summary>
 /// Click gauche sur une ville
 /// </summary>
 /// <param name="posCell">position de la map clickée</param>
 /// <param name="clickV">la ville</param>
 /// <param name="released">si on a clické ou relaché</param>
 private void leftClickOnVille(Point posCell, VilleDescription clickV, bool released)
 {
     // Si aucune armée n'est sélectionnée et que c'est notre ville, ouvre le panneau de gestion
     if ((_jeu.selectedArmee == null) && (clickV.faction == _jeu.tourFaction))
     {
         _jeu.addOverlay(new PanneauVille(_jeu, clickV));
     }
     // Si une armée est sélectionnée, on calcul une nouvelle trajectoire si c'est une ville amie
     else if ((_jeu.selectedArmee != null) && (clickV.faction == _jeu.tourFaction))
     {
         setTarget(posCell);
     }
     // si c'est une ville ennemie, c'est une attaque
     else if ((_jeu.selectedArmee != null) && (clickV.faction != _jeu.tourFaction))
     {
         // raccourci d'écriture pour vérifier si on est à coté
         Point v = clickV.positionMap;
         Point a = _jeu.selectedArmee.positionCarte;
         if ((a.X >= (v.X - 1)) && (a.X <= (v.X + 2)) && (a.Y >= (v.Y - 1)) && (a.Y <= (v.Y + 2)))
         {
             // Oui ! A l'attaaaaaaaaaaaaaaaaaaaaaaaaque !
             attaqueVille(clickV);
         }
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Créer une pop up d'info sur click droit
        /// </summary>
        /// <param name="mouseX"></param>
        /// <param name="mouseY"></param>
        public void createInfoPopup(int mouseX, int mouseY)
        {
            // Détermine où on a cliqué : terrain, ville, armée...

            float            extraHeight = 0;
            int              extraWidth  = 0;
            Armee            armeeClick  = null;
            VilleDescription villeClick  = null;

            TerrainDescription.TerrainCell cellClick = getClicked(mouseX, mouseY, ref armeeClick, ref villeClick);
            string titre = "(bug)";

            // Priorité aux armées
            if (armeeClick != null)
            {
                titre       = armeeClick.proue.vraiNom + " (" + _jeu.factions.getFaction(armeeClick.faction).nom + ")";
                extraHeight = Creatures.CREATURE_SIZE + PopWindow.MARGE_TITRE;
                extraWidth  = Creatures.CREATURE_SIZE * Armee.MAX_TAILLE + PopWindow.MARGE_TITRE * 2;
            }
            // puis les villes
            else if (villeClick != null)
            {
                titre       = villeClick.nom + " (" + _jeu.factions.getFaction(villeClick.faction).nom + ")";
                extraHeight = -2.5f;
                extraWidth  = 300;
            }
            // Enfin le terrain
            else
            {
                // Ruines
                if (cellClick.ruine)
                {
                    int carteX = (mouseX + _jeu.terrain.offsetCarte.X) / _jeu.blockSize;
                    int carteY = (mouseY + _jeu.terrain.offsetCarte.Y) / _jeu.blockSize;
                    Ruines.RuineDescription desc = _jeu.ruines.ruines[new Point(carteX, carteY)];
                    titre = "Ruine de " + desc.nom + " (" + (desc.visite ? "déjà visité" : "non exploré") + ")";
                }
                else if (cellClick.route)
                {
                    titre = "Route - le chemin le plus rapide";
                }
                else
                {
                    switch (cellClick.type)
                    {
                    case TerrainDescription.TypeTerrain.COLLINE:
                        titre = "Collines - difficile de les traverser";
                        break;

                    case TerrainDescription.TypeTerrain.EAU:
                        titre = "Eau - il vous faut ou voler, nager ou prendre un bateau";
                        break;

                    case TerrainDescription.TypeTerrain.FORET:
                        titre = "Forêt - difficile de la traverser";
                        break;

                    case TerrainDescription.TypeTerrain.HERBE:
                        titre = "Plaine - le terrain le plus rapide après la route";
                        break;

                    case TerrainDescription.TypeTerrain.MARECAGE:
                        titre = "Marécages - difficile de les traverser";
                        break;

                    case TerrainDescription.TypeTerrain.MONTAGNE:
                        titre = "Montagnes - A moins de les survoler, on ne peut les traverser";
                        break;
                    }
                }
            }
            // Taille du texte
            Vector2 fontSize = _jeu.font.MeasureString(titre);

            Point taille = PopWindow.getPopWindowSize(_jeu, titre);

            // Ajoute un bord
            if (taille.X < extraWidth)
            {
                taille.X = extraWidth;
            }
            if (extraHeight < 0)
            {
                taille.Y = (int)((float)taille.Y * (-extraHeight));
            }
            else
            {
                taille.Y = (int)((float)taille.Y + extraHeight);
            }
            PopWindow info = new PopWindow(_jeu, Overlay.Position.SOURIS, taille.X, taille.Y, mouseX, mouseY, titre);

            // Custom Draw pour afficher l'armée s'il le faut
            if (armeeClick != null)
            {
                info.drawCallBack = delegate(SpriteBatch spriteBatch, GraphicsDevice GraphicsDevice, GameTime gameTime) {
                    int x = info.xoverlay + _jeu.terrain.offsetCarte.X + PopWindow.MARGE_TITRE / 2;
                    int y = info.yoverlay + info.height - Creatures.CREATURE_SIZE - PopWindow.MARGE_TITRE / 2 + _jeu.terrain.offsetCarte.Y;
                    for (int i = 0; i < armeeClick.getTaille(); i++)
                    {
                        Creature crea = armeeClick.getCreature(i);
                        _jeu.creatures.draw(spriteBatch, GraphicsDevice, gameTime, x, y, 0f, crea.typeCreature);
                        x += Creatures.CREATURE_SIZE;
                    }
                };
            }
            // Custom draw pour les villes
            else if (villeClick != null)
            {
                info.drawCallBack = delegate(SpriteBatch spriteBatch, GraphicsDevice GraphicsDevice, GameTime gameTime) {
                    float x = info.xoverlay + PopWindow.MARGE_TITRE / 2;
                    float y = info.yoverlay + PopWindow.MARGE_TITRE + fontSize.Y;
                    spriteBatch.DrawString(_jeu.font, "Défense :" + villeClick.niveauDefense, new Vector2(x, y), Color.BlanchedAlmond);
                    if (villeClick.capitaleFaction != 0)
                    {
                        y += fontSize.Y;
                        spriteBatch.DrawString(_jeu.font, "Capitale de : " + _jeu.factions.getFaction(villeClick.capitaleFaction).nom, new Vector2(x, y),
                                               _jeu.factions.getFaction(villeClick.capitaleFaction).couleur);
                    }
                };
            }

            _jeu.addOverlay(info);
            _jeu.curseur.forme = Cursor.FormeCurseur.INTERROGATION;
        }