public XElement Serialize(MessageAnswer messageAnswer, string elementName = "answer")
        {
            messageAnswer.ThrowIfNull("messageAnswer");
            elementName.ThrowIfNull("elementName");

            return new XElement(
                elementName,
                MessagePartSerializer.Instance.Serialize(messageAnswer.Parts),
                EventHandlerCollectionSerializer.Instance.Serialize(messageAnswer.EventHandlerCollection),
                new XAttribute("id", messageAnswer.Id),
                new XAttribute("text", messageAnswer.Text));
        }
        public MessageAnswerSelectionManager(IEnumerable<MessageAnswer> answers)
        {
            answers.ThrowIfNull("answers");

            _answers = answers.ToArray();

            if (!_answers.Any())
            {
                throw new ArgumentException("Must provide at least one answer.", "answers");
            }

            _selectedAnswer = _answers.First();
        }
        public void SelectNextAnswer()
        {
            int index = Array.IndexOf(_answers, _selectedAnswer);

            if (index == _answers.Length - 1)
            {
                index = 0;
            }
            else
            {
                index++;
            }

            _selectedAnswer = _answers[index];
        }
        public MessageTextAnswer(
			MessageAnswer answer,
			string text,
			Vector2 size,
			Color unselectedAnswerForegroundColor,
			Color selectedAnswerForegroundColor,
			Color selectedAnswerBackgroundColor)
            : base(text, size, false)
        {
            answer.ThrowIfNull("answer");

            _answer = answer;
            _unselectedAnswerForegroundColor = unselectedAnswerForegroundColor;
            _selectedAnswerForegroundColor = selectedAnswerForegroundColor;
            _selectedAnswerBackgroundColor = selectedAnswerBackgroundColor;
        }
        public byte[] Serialize(MessageAnswer messageAnswer)
        {
            messageAnswer.ThrowIfNull("messageAnswer");

            var serializer = new CompactSerializer();

            serializer[0] = messageAnswer.Id.ToByteArray();
            serializer[1] = Encoding.UTF8.GetBytes(messageAnswer.Text);

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

            foreach (IMessagePart part in messageAnswer.Parts)
            {
                partSerializer[index++] = MessagePartSerializer.Instance.Serialize(part);
            }

            serializer[2] = partSerializer.Serialize();
            serializer[3] = EventHandlerCollectionSerializer.Instance.Serialize(messageAnswer.EventHandlerCollection);

            return serializer.Serialize();
        }
        public MessageAnswerSelectedEvent(MessageAnswer messageAnswer)
        {
            messageAnswer.ThrowIfNull("messageAnswer");

            _messageAnswer = messageAnswer;
        }
 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);
 }
        public void SelectPreviousAnswer()
        {
            int index = Array.IndexOf(_answers, _selectedAnswer);

            if (index == 0)
            {
                index = _answers.Length - 1;
            }
            else
            {
                index--;
            }

            _selectedAnswer = _answers[index];
        }
        public void SelectAnswer(MessageAnswer answer)
        {
            answer.ThrowIfNull("answer");

            _worldInstance.RaiseEvent(answer.OnSelected, new MessageAnswerSelectedEvent(answer));
            if (answer.Parts.Any())
            {
                EnqueueMessage(answer, MessageQueuePosition.First);
            }
        }