Beispiel #1
0
        //R. Judge: store item on MissionNode with Missionstatement  <-- WTF?
        /// <summary>
        /// Create and return new MissionNode from an XmlNode. Will set type appropriately.
        /// </summary>
        public static MissionNode NewFromXML(XmlNode item)
        {
            MissionNode mn = null;

            switch (item.Name)
            {
            case "event":
                mn = new MissionNode_Event();
                break;

            case "disabled_event":
                mn = new MissionNode_Event();
                break;

            case "start":
                mn = new MissionNode_Start();
                break;

            case "#comment":
                mn = new MissionNode_Comment();
                break;

            case "folder_arme":
                mn = new MissionNode_Folder();
                break;

            default:
                mn = new MissionNode_Unknown();
                break;
            }

            mn.FromXml(item);
            return(mn);
        }
        /// <summary>
        /// Converts selected nodes to comments. Will ask for confirmation via a dialog box for converting non-empty events and non-empty folders.
        /// </summary>
        public void ConvertSelectedNodesToComments()
        {
            bool convertEvents = false;
            bool convertFolders = false;
            int convertedCount = 0;

            foreach (TreeNode node in TreeViewNodes.SelectedNodes)
            {
                if (node.Parent != null)
                    continue;

                convertEvents = convertEvents || (node.Tag is MissionNode_Event && (((MissionNode_Event)node.Tag).Actions.Count > 0 || ((MissionNode_Event)node.Tag).Conditions.Count > 0));
                convertFolders = convertFolders || (node.Nodes.Count > 0);
            }

            convertEvents = convertEvents && MessageBox.Show("Selection contains non-empty events.\r\nDo you want them to be converted as well?\r\n(This will clear their contents)", "Artemis Mission Editor", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes;
            convertFolders = convertFolders && MessageBox.Show("Selection contains non-empty folders.\r\nDo you want them to be converted as well?\r\n(This will clear their contents)", "Artemis Mission Editor", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes;

            foreach (TreeNode node in TreeViewNodes.SelectedNodes.ToList())
            {
                //Node was already removed since a folder with it was converted to comment earlier in this loop
                if (TreeViewNodes.FindNode((TreeNode x) => x == node) == null)
                    continue;
                //Cant touch start node
                if (node.Tag is MissionNode_Start)
                    continue;
                //Skip nodes of already correct type
                if (node.Tag is MissionNode_Comment)
                    continue;
                //Cannot convert node inside a folder to comment
                if (node.Parent != null)
                    continue;
                //Skip nodes user decided not to convert
                if (!convertEvents && (node.Tag is MissionNode_Event && (((MissionNode_Event)node.Tag).Actions.Count > 0 || ((MissionNode_Event)node.Tag).Conditions.Count > 0)))
                    continue;
                if (!convertFolders && node.Nodes.Count > 0)
                    continue;

                MissionNode_Comment mnc = new MissionNode_Comment();
                mnc.Name = node.Text;
                node.Nodes.Clear();
                node.Tag = mnc;
                node.ImageIndex = mnc.ImageIndex;
                node.SelectedImageIndex = mnc.ImageIndex;

                if (node == TreeViewNodes.SelectedNode)
                    OutputMissionNodeContentsToStatementTree();

                convertedCount++;
            }

            if (convertedCount > 0)
                RegisterChange("Converted node(s) type to comment");
        }
        /// <summary>
        /// Add new comment to the mission
        /// </summary>
        /// <param name="nodeUnderCursor">Specified when inserting via dropdown menu, unspecified when inserting via hotkey</param>
        public void NodeAddCommentary(TreeNode nodeUnderCursor = null)
        {
            TreeNode newTNode = new TreeNode();
            MissionNode_Comment newMNode = new MissionNode_Comment();

            newTNode.Text = newMNode.Name;
            newTNode.ImageIndex = newMNode.ImageIndex;
            newTNode.SelectedImageIndex = newMNode.ImageIndex;
            newTNode.Tag = newMNode;

            NodeInsertUnderNode(newTNode, nodeUnderCursor ?? TreeViewNodes.SelectedNode);
            TreeViewNodes.SelectedNode = newTNode;

            RegisterChange("New commentary node");
        }
        //R. Judge: store item on MissionNode with Missionstatement  <-- WTF?
        /// <summary>
        /// Create and return new MissionNode from an XmlNode. Will set type appropriately.
        /// </summary>
        public static MissionNode NewFromXML(XmlNode item)
        {
            MissionNode mn = null;

            switch (item.Name)
            {
                case "event":
                    mn = new MissionNode_Event();
                    break;
                case "disabled_event":
                    mn = new MissionNode_Event();
                    break;
                case "start":
                    mn = new MissionNode_Start();
                    break;
                case "#comment":
                    mn = new MissionNode_Comment();
                    break;
                case "folder_arme":
                    mn = new MissionNode_Folder();
                    break;
                default:
                    mn = new MissionNode_Unknown();
                    break;
            }

            mn.FromXml(item);
            return mn;
        }