public XElement Serialize(MessageQuestion messageQuestion, string elementName = "question")
        {
            messageQuestion.ThrowIfNull("messageQuestion");
            elementName.ThrowIfNull("elementName");

            return new XElement(
                elementName,
                messageQuestion.Answers.Select(arg => MessageAnswerSerializer.Instance.Serialize(arg)),
                new XAttribute("prompt", messageQuestion.Prompt),
                new XAttribute("questionForegroundColor", ColorSerializer.Instance.Serialize(messageQuestion.QuestionForegroundColor)),
                new XAttribute("unselectedAnswerForegroundColor", ColorSerializer.Instance.Serialize(messageQuestion.UnselectedAnswerForegroundColor)),
                new XAttribute("selectedAnswerForegroundColor", ColorSerializer.Instance.Serialize(messageQuestion.SelectedAnswerForegroundColor)),
                new XAttribute("selectedAnswerBackgroundColor", ColorSerializer.Instance.Serialize(messageQuestion.SelectedAnswerBackgroundColor)));
        }
        public byte[] Serialize(MessageQuestion messageQuestion)
        {
            messageQuestion.ThrowIfNull("messageQuestion");

            var serializer = new CompactSerializer();

            serializer[0] = Encoding.UTF8.GetBytes(messageQuestion.Prompt);
            serializer[1] = ColorSerializer.Instance.Serialize(messageQuestion.QuestionForegroundColor);
            serializer[2] = ColorSerializer.Instance.Serialize(messageQuestion.UnselectedAnswerForegroundColor);
            serializer[3] = ColorSerializer.Instance.Serialize(messageQuestion.SelectedAnswerForegroundColor);
            serializer[4] = ColorSerializer.Instance.Serialize(messageQuestion.SelectedAnswerBackgroundColor);

            var answerSerializer = new CompactSerializer();
            int index = 0;

            foreach (MessageAnswer answer in messageQuestion.Answers)
            {
                answerSerializer[index++] = MessageAnswerSerializer.Instance.Serialize(answer);
            }

            serializer[5] = answerSerializer.Serialize();

            return serializer.Serialize();
        }
        private void ProcessQuestion(MessageQuestion question, ref int lineIndex)
        {
            if (!question.Answers.Any())
            {
                return;
            }
            if (_wordsByLine[lineIndex].Any())
            {
                ProcessLineBreak(ref lineIndex);
            }

            _answers = question.Answers;

            _colorsByWordCoordinate[new Coordinate(0, lineIndex)] = question.QuestionForegroundColor;

            ProcessText(question.Prompt, MessageTextAlignment.Center, ref lineIndex);
            ProcessLineBreak(ref lineIndex);

            MessageTextAnswer[] answers = question.Answers.Select(arg => GetMessageTextAnswer(question, arg)).ToArray();

            float lineWidth =
                (_selectedAnswerWindowTexture.SpriteWidth * 2 * answers.Length) +
                (TextAdventure.Xna.Constants.MessageRenderer.AnswerHorizontalPadding * (answers.Length - 1)) +
                (TextAdventure.Xna.Constants.MessageRenderer.AnswerHorizontalTextPadding * 2 * answers.Length) +
                answers.Sum(arg => arg.Size.X);
            float lineHeight = (_selectedAnswerWindowTexture.SpriteHeight * 2) + answers.Max(arg => arg.Size.Y);

            _lineSizesByLine[lineIndex] = new Vector2(lineWidth, lineHeight);
            _wordsByLine[lineIndex] = new List<MessageTextWord>(answers);
            _alignmentsByLine[lineIndex] = MessageTextAlignment.Center;
        }
 private MessageTextAnswer GetMessageTextAnswer(MessageQuestion question, MessageAnswer answer)
 {
     return new MessageTextAnswer(
         answer,
         answer.Text,
         _font.MeasureString(answer.Text) + TextAdventure.Xna.Constants.MessageRenderer.ShadowOffset,
         question.UnselectedAnswerForegroundColor,
         question.SelectedAnswerForegroundColor,
         question.SelectedAnswerBackgroundColor);
 }