Ejemplo 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; });
            }
        }
Ejemplo 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;
        }
Ejemplo n.º 3
0
        public static Speech LoadSpeechFromXmlNode(XmlNode node, Speech root)
        {
            Speech speech = new Speech();

            if (root == null)
                root = speech;

            speech.Name = XmlExtensions.GetAttributeValue(node, "name", "SpeechNode");

            if (node["Text"] != null)
                speech.Text = node.SelectSingleNode("Text").InnerText;

            if (node["Prompt"] != null)
                speech.Prompt = node.SelectSingleNode("Prompt").InnerText;

            if (node["PromptLink"] != null)
                speech.PromptLink = node.SelectSingleNode("PromptLink").InnerText;

            // Load children
            foreach (XmlNode childNode in node.SelectNodes("Children/Speech"))
            {

                Speech child = LoadSpeechFromXmlNode(childNode, root);
                child.Root = root;

                speech.AddChild(child);
            }

            return speech;
        }
Ejemplo n.º 4
0
 public void AddChild(Speech child)
 {
     _children.Add(child);
 }