Exemplo n.º 1
0
        public void LoadSpeech(Speech speech, ContentManager content)
        {
            if(speech == null)
                return;

            this.Speech = speech;
            _content = content;

            _currentText = StringExtensions.WrapText(Speech.Text, ContentPane.Width, ContentPane.Height, Font);
            _promptStartPosition = new Vector2(35, 15 + _currentText.Count * Font.MeasureString("W").Y + _currentText.Count * 2);

            // Clear any children (get rid of the labels)
            Children.Clear();

            if (speech.GetChildren().Count > 0)
            {
                foreach (Speech child in Speech.GetChildren())
                {
                    SpeechLabel lbl = new SpeechLabel();
                    lbl.Speech = child;
                    lbl.Name = "ConversationPrompt";
                    lbl.SetAllPadding(0);
                    lbl.Font = content.Load<SpriteFont>("Fonts/DefaultBold");
                    lbl.Text = child.Prompt;
                    lbl.Position = GetPromptPosition(lbl.Font, child.Prompt);
                    lbl.onMouseOver += new MouseEventHandler(delegate(Component sender, MouseState mouse)
                    {
                        lbl.Color = Color.Yellow;
                    });

                    lbl.onMouseOut += new MouseEventHandler(delegate(Component sender, MouseState mouse)
                    {
                        lbl.Color = Color.White;
                    });

                    lbl.onMouseClick += new MouseEventHandler(delegate(Component sender, MouseState mouse)
                    {
                        if (lbl.Speech.PromptLink.Equals("Child"))
                            this.LoadSpeech(lbl.Speech, _content);
                        else if (lbl.Speech.PromptLink.Equals("Exit"))
                            this.Visible = false;
                        else if (lbl.Speech.PromptLink.Contains(".speech"))
                            this.LoadSpeech(lbl.Speech.PromptLink, _content);
                        else
                            this.LoadSpeech(lbl.Speech.FindNodeFromRoot(child.PromptLink), _content);
                    });

                    Children.Add(lbl);
                }
            }
            else
            {
                this.onMouseClick += new MouseEventHandler(delegate(Component sender, MouseState mouse) { this.Visible = false; });
            }
        }
Exemplo n.º 2
0
        private Speech FindNode(Speech node, string name)
        {
            if (node.Name.Equals(name))
                return node;

            foreach (Speech child in node.GetChildren())
                if (child.Name.Equals(name))
                    return child;
                else
                    FindNode(child, name);

            return null;
        }