Exemple #1
0
        /// <summary>
        /// Récupère les dimensions d'une image
        /// </summary>
        /// <param name="url">Url de l'image</param>
        /// <returns>Size</returns>
        private static VO_Size GetDimensionsOfAPicture(string url)
        {
            Texture2D pic  = FromFileThenClose(url);
            VO_Size   size = new VO_Size((int)pic.Width, (int)pic.Height);

            pic.Dispose();
            return(size);
        }
        /// <summary>
        /// Format Text
        /// </summary>
        /// <param name="message">VO_message du message</param>
        /// <returns>Sprite de texte</returns>
        public List <VO_String2D> FormatText(VO_Message message, VO_Size container, Point camera)
        {
            List <VO_String2D> sprite = null;

            RunServiceTask(delegate
            {
                sprite = _Business.FormatText(message, container, camera);
            }, ViewerErrors.STAGE_LOAD_MENU, false, message.ToString(), container.ToString(), camera.ToString());

            return(sprite);
        }
Exemple #3
0
        /// <summary>
        /// Format Text
        /// </summary>
        /// <param name="message">VO_message du message</param>
        /// <returns>Sprite de texte</returns>
        public List <VO_String2D> FormatText(VO_Message message, VO_Size container, Point camera)
        {
            int cameraLeft = (int)camera.X;
            int cameraTop  = (int)camera.Y;
            VO_CharacterSprite character = null;
            List <VO_String2D> textes    = new List <VO_String2D>();

            if (message.Character == new Guid(GlobalConstants.CURRENT_PLAYER_ID))
            {
                character = PlayableCharactersManager.CurrentPlayerCharacter.CharacterSprite;
            }
            else
            {
                character = GetCharacterSprite(message.Character);
            }
            if (character != null && character.IsTalking)
            {
                //Calcul du Width idéal
                // Valeur idéale = ViewerConstants.MESS_MAXIMUM_WIDTH / en 640
                int idealValue = ViewerConstants.MESS_MAXIMUM_WIDTH * container.Width / 640;
                int miniValue  = ViewerConstants.MESS_MINIMUM_WIDTH * container.Width / 640;
                int xLeft      = character.Location.X - cameraLeft - idealValue / 2;
                int xRight     = character.Location.X - cameraLeft + idealValue / 2;

                //Cas où le texte mord sur la gauche
                if (xLeft < ViewerConstants.MESS_PADDING_BORDER)
                {
                    xLeft = ViewerConstants.MESS_PADDING_BORDER;
                    if (xRight - xLeft < miniValue)
                    {
                        xRight = miniValue;
                    }
                }
                //Cas où le texte mord sur la droite
                else if (xRight > container.Width - ViewerConstants.MESS_PADDING_BORDER)
                {
                    xRight = container.Width - 1 - ViewerConstants.MESS_PADDING_BORDER;
                    if (xRight - xLeft < miniValue)
                    {
                        xLeft = container.Width - miniValue - ViewerConstants.MESS_PADDING_BORDER;
                    }
                }

                //1 - On détermine la hauteur que devra prendre le texte
                int         lineWidth = xRight - xLeft;
                string[]    words     = message.Text.Split(" ".ToCharArray());
                string      finalMess = string.Empty;
                string      tempMess  = string.Empty;
                int         height    = ViewerConstants.MESS_PADDING_CHARACTER;
                VO_String2D text      = AddText(message.FontSize, character.DialogColor);
                foreach (string word in words)
                {
                    //On test si le texte ne dépasse pas le width
                    if (string.IsNullOrEmpty(tempMess))
                    {
                        tempMess = word;
                    }
                    else
                    {
                        tempMess = finalMess + " " + word;
                    }
                    text.Text = tempMess;

                    if ((int)text.Destination.Width > lineWidth)
                    {
                        text.Text = finalMess;
                        height   += (int)text.Destination.Height + ViewerConstants.MESS_PADDING_LINES;
                        textes.Add(text);

                        //New message
                        text      = AddText(message.FontSize, character.DialogColor);
                        finalMess = word;
                    }
                    else
                    {
                        finalMess = tempMess;
                    }
                }
                text.Text = finalMess;
                height   += (int)text.Destination.Height;
                textes.Add(text);

                int finalY = character.GetAnimPosition().Y - cameraTop - height;
                if (finalY < ViewerConstants.MESS_PADDING_BORDER)
                {
                    finalY = ViewerConstants.MESS_PADDING_BORDER;
                }
                Point pos = new Point(character.Location.X - cameraLeft, finalY);

                for (int i = 0; i < textes.Count; i++)
                {
                    int newX  = character.Location.X - cameraLeft - ((int)textes[i].Destination.Width / 2);
                    int newX2 = newX + (int)textes[i].Destination.Width;
                    if (newX < ViewerConstants.MESS_PADDING_BORDER)
                    {
                        newX = ViewerConstants.MESS_PADDING_BORDER;
                    }
                    else if (newX2 > container.Width - ViewerConstants.MESS_PADDING_BORDER)
                    {
                        newX -= newX2 - container.Width + ViewerConstants.MESS_PADDING_BORDER;
                    }
                    textes[i].Position = new Vector2(newX, finalY + i * ((int)text.Destination.Height + ViewerConstants.MESS_PADDING_LINES));
                }
            }

            return(textes);
        }