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; } }
public SceneOption(string text, string scene, SceneAction action) { optionText = text; optionScene = scene; optionAction = action; }