Пример #1
0
        /// <summary>
        /// Reads a Dialog Scene from an XML document
        /// </summary>
        /// <param name="node">The node that represents this scene</param>
        /// <param name="context">The Lua context to use for this scene</param>
        /// <returns>A dialog Scene as read from the document</returns>
        public static DialogueScene ReadFromXML(XmlNode node, LuaContext context)
        {
            DialogueScene scene = new DialogueScene(context);

            if (node.Attributes["name"] != null)
            {
                scene.m_name = node.Attributes["name"].Value;
            }

            if (node["selector"] != null)
            {
                scene.m_initDialogSelector = node["selector"].InnerText;
            }

            XmlNode dialogs = node["dialogues"];

            foreach (XmlNode dialogNode in dialogs)
            {
                if (dialogNode.Name == "dialog")
                {
                    scene.m_dialogs.Add(DialogueOutput.ReadFromXML(dialogNode));
                }
            }

            XmlNode choices = node["choices"];

            foreach (XmlNode choiceNode in choices)
            {
                if (choiceNode.Name == "choice")
                {
                    scene.m_choices.Add(DialogueChoice.ReadFromXML(choiceNode));
                }
            }

            return(scene);
        }
Пример #2
0
        /// <summary>
        /// Reads a DialogOption from an XML node
        /// </summary>
        /// <param name="node">The node to read from</param>
        /// <returns>A DialogOption read from the node</returns>
        public static DialogueOutput ReadFromXML(XmlNode node)
        {
            // Throw an exception if the ID is not defined
            if (node.Attributes["id"] == null)
            {
                throw new XmlException("ID is not defined for this node!");
            }

            // Throw an exception if the ID is not defined
            if (node.Attributes["speaker"] == null)
            {
                throw new XmlException("Speaker is not defined for this node!");
            }

            // Define a new Dialog option to return the result in
            DialogueOutput option = new DialogueOutput();

            // Try parsing ID from XML, and throw an exception if it fails
            if (!int.TryParse(node.Attributes["id"].Value, out option.m_id))
            {
                throw new XmlException("Could not parse ID to integer");
            }

            // Try parsing ID from XML, and throw an exception if it fails
            if (!int.TryParse(node.Attributes["speaker"].Value, out option.m_activeSpeaker))
            {
                throw new XmlException("Could not parse Speaker to integer");
            }

            // Try parsing ID from XML, and throw an exception if it fails
            if (node.Attributes["nextId"] != null && !int.TryParse(node.Attributes["nextId"].Value, out option.m_nextId))
            {
                throw new XmlException("Could not parse NextID to integer");
            }

            // Get the choices subnode
            if (node.Attributes["choices"] != null)
            {
                XmlAttribute choices = node.Attributes["choices"];

                string value = choices.InnerText;

                string[] ints = value.Split(',');

                foreach (string val in ints.Where(s => s.Length > 0))
                {
                    option.m_choices.Add(int.Parse(val));
                }
            }

            // Get the script if there is one
            if (node["script"] != null)
            {
                option.m_script = node["script"].Value;
            }

            // As long as the message exists, we load it
            if (node["message"] != null)
            {
                option.m_message = node["message"].InnerText;
            }
            // Otherwise, set it's message to an error text and log the warning
            else
            {
                option.m_message = string.Format(MISSING_MESSAGE, option.m_id);
                Logger.LogMessage(LogMessageType.Warning, "Dialog Option #{0} is missing a message content", option.m_id);
            }


            foreach (XmlNode texNode in node.SelectNodes("TextureChange"))
            {
                TextureChangeTag tag = new TextureChangeTag();

                tag.Role = (TextureRole)Enum.Parse(typeof(TextureRole), texNode.Attributes["role"].Value);

                if (texNode.Attributes["texture"] != null)
                {
                    tag.TextureName = texNode.Attributes["texture"].Value;
                }

                option.m_textureChanges[tag.Role] = tag;
            }

            // return the result
            return(option);
        }
Пример #3
0
 /// <summary>
 /// Removes a dialog output from this scene
 /// </summary>
 /// <param name="dialogOut">The output to remove</param>
 public void DeleteDialogOption(DialogueOutput dialogOut)
 {
     m_dialogs.Remove(dialogOut);
 }
Пример #4
0
 /// <summary>
 /// Add a new dialog to this scene
 /// </summary>
 /// <param name="dialog">The dialog to add</param>
 public void AddDialogOption(DialogueOutput dialog)
 {
     m_dialogs.Add(dialog);
 }