Exemplo n.º 1
0
        public static void CreateConversations(Game gameRef)
        {
            Texture2D sceneTexture = gameRef.Content.Load <Texture2D>(@"Scenes\scenebackground");
            //SpriteFont sceneFont = gameRef.Content.Load<SpriteFont>(@"Fonts\scenefont");
            SpriteFont sceneFont = gameRef.Content.Load <SpriteFont>(@"Fonts\GameFont");

            Conversation c = new Conversation("MarissaHello", "Hello", sceneTexture, sceneFont);

            c.BackgroundName = "scenebackground";
            c.FontName       = "scenefont";

            List <SceneOption> options = new List <SceneOption>();
            SceneOption        option  = new SceneOption("Good bye.", "", new SceneAction()
            {
                Action = ActionType.End, Parameter = "none"
            });

            options.Add(option);

            GameScene scene = new GameScene(gameRef, "Hello, my name is Marissa. I'm still learning about summoning avatars.", options);

            c.AddScene("Hello", scene);

            ConversationList.Add("MarissaHello", c);

            c = new Conversation("LanceHello", "Hello", sceneTexture, sceneFont);
            c.BackgroundName = "scenebackground";
            c.FontName       = "scenefont";

            options = new List <SceneOption>();
            option  = new SceneOption("Yes", "ILikeFire", new SceneAction()
            {
                Action = ActionType.Talk, Parameter = "none"
            });
            options.Add(option);

            option = new SceneOption("No", "IDislikeFire", new SceneAction()
            {
                Action = ActionType.Talk, Parameter = "none"
            });
            options.Add(option);

            scene = new GameScene(gameRef, "Fire avatars are my favorites. Do you Like fire type avatars too?", options);
            c.AddScene("Hello", scene);

            options = new List <SceneOption>();
            option  = new SceneOption("Good bye.", "", new SceneAction()
            {
                Action = ActionType.End, Parameter = "none"
            });
            options.Add(option);

            scene = new GameScene(gameRef, "That's cool. I wouldn't want to hug one though.", options);

            c.AddScene("ILikeFire", scene);

            options = new List <SceneOption>();
            option  = new SceneOption("Good bye.", "", new SceneAction()
            {
                Action = ActionType.End, Parameter = "none"
            });
            options.Add(option);

            scene = new GameScene(gameRef, "Each to their own i guess.", options);

            c.AddScene("IDislikeFire", scene);

            conversationList.Add("LanceHello", c);
        }
Exemplo n.º 2
0
        public static void FromFile(string fileName, Game gameRef, bool editor = false)
        {
            XmlDocument xmlDoc = new XmlDocument();

            try
            {
                xmlDoc.Load(fileName);
                XmlNode root = xmlDoc.FirstChild;

                if (root.Name == "xml")
                {
                    root = root.NextSibling;
                }

                if (root.Name != "Conversations")
                {
                    throw new Exception("Invalid conversation file!");
                }

                foreach (XmlNode node in root.ChildNodes)
                {
                    if (node.Name == "#comment")
                    {
                        continue;
                    }

                    if (node.Name != "Conversation")
                    {
                        throw new Exception("Invalid conversation file!");
                    }

                    string conversationName = node.Attributes["Name"].Value;
                    string firstScene       = node.Attributes["FirstScene"].Value;
                    string backgroundName   = node.Attributes["BackgroundName"].Value;
                    string fontName         = node.Attributes["FontName"].Value;

                    Texture2D    background   = gameRef.Content.Load <Texture2D>(@"Backgrounds\" + backgroundName);
                    SpriteFont   font         = gameRef.Content.Load <SpriteFont>(@"Fonts\" + fontName);
                    Conversation conversation = new Conversation(conversationName, firstScene, background, font);
                    conversation.BackgroundName = backgroundName;
                    conversation.FontName       = fontName;

                    foreach (XmlNode sceneNode in node.ChildNodes)
                    {
                        string text         = "";
                        string optionText   = "";
                        string optionScene  = "";
                        string optionAction = "";
                        string optionParam  = "";
                        string sceneName    = "";

                        if (sceneNode.Name != "GameScene")
                        {
                            throw new Exception("Invalid conversation file!");
                        }

                        sceneName = sceneNode.Attributes["Name"].Value;

                        List <SceneOption> sceneOptions = new List <SceneOption>();

                        foreach (XmlNode innerNode in sceneNode.ChildNodes)
                        {
                            if (innerNode.Name == "Text")
                            {
                                text = innerNode.InnerText;
                            }

                            if (innerNode.Name == "GameSceneOption")
                            {
                                optionText   = innerNode.Attributes["Text"].Value;
                                optionScene  = innerNode.Attributes["Option"].Value;
                                optionAction = innerNode.Attributes["Action"].Value;
                                optionParam  = innerNode.Attributes["Parameter"].Value;

                                SceneAction action = new SceneAction();
                                action.Parameter = optionParam;
                                action.Action    = (ActionType)Enum.Parse(typeof(ActionType), optionAction);
                                SceneOption option = new SceneOption(optionText, optionScene, action);
                                sceneOptions.Add(option);
                            }
                        }

                        GameScene scene = null;

                        if (editor)
                        {
                            scene = new GameScene(text, sceneOptions);
                        }
                        else
                        {
                            scene = new GameScene(gameRef, text, sceneOptions);
                        }

                        conversation.AddScene(sceneName, scene);
                    }
                    conversationList.Add(conversationName, conversation);
                }
            }
            catch
            {
            }
            finally
            {
                xmlDoc = null;
            }
        }