Example #1
0
        /// <summary>
        /// Load mission contents from saved state
        /// </summary>
        private void FromState(MissionSavedState state)
        {
            Dependencies.Invalidate();

            BeginUpdate();

            FromXml(state.Xml, true, true);

            ChangesPending = state.ChangesPending;
            FilePath = state.FilePath;
            CommentsBeforeRoot = state.CommentsBefore;
            CommentsAfterRoot = state.CommentsAfter;
            PlayerShipNames = state.PlayerShipNames;
            VersionNumber = state.VersionNumber;

            //Find selected node
            if (state.SelectedNode >= 0)
            {
                int curStep = -1;
                foreach (TreeNode node in TreeViewNodes.Nodes)
                    FromState_RecursiveSelectByStep(node, ref curStep, state.SelectedNode);
            }

            if (state.SelectedAction >= 0)
                foreach (TreeNode node in TreeViewStatements.Nodes)
                    FromState_RecursiveSelectByTag(node, ((MissionNode)TreeViewNodes.SelectedNode.Tag).Actions[state.SelectedAction]);

            if (state.SelectedCondition >= 0)
                foreach (TreeNode node in TreeViewStatements.Nodes)
                    FromState_RecursiveSelectByTag(node, ((MissionNode)TreeViewNodes.SelectedNode.Tag).Conditions[state.SelectedCondition]);

            if (state.SelectedLabel >= 0)
                FlowLayoutPanelMain.Controls[state.SelectedLabel].Focus();

            RecalculateNodeCount();

            EndUpdate();
        }
Example #2
0
        /// <summary>
        /// Save mission contents to a state
        /// </summary>
        /// <param name="shortDescription">Description of the state</param>
        private MissionSavedState ToState(string shortDescription)
        {
            MissionSavedState result = new MissionSavedState();
            result.Xml = ToXml(true);
            result.Description = shortDescription;
            result.ChangesPending = ChangesPending;
            result.FilePath = FilePath;
            result.CommentsBefore = CommentsBeforeRoot;
            result.CommentsAfter = CommentsAfterRoot;
            result.PlayerShipNames = PlayerShipNames;
            result.VersionNumber = VersionNumber;
            result.SelectedNode = -1;
            if (TreeViewNodes.SelectedNode!=null)
            {
                int curStep = -1;
                foreach (TreeNode node in TreeViewNodes.Nodes)
                    if (ToState_RecursivelyGetSelected(node, ref curStep))
                        break;
                result.SelectedNode = curStep;
            }

            result.SelectedAction = -1;
            result.SelectedCondition = -1;
            result.SelectedLabel = -1;
            if (TreeViewNodes.SelectedNode != null && TreeViewStatements.SelectedNode != null && TreeViewStatements.SelectedNode.Tag is MissionStatement)
            {
                MissionNode curNode = (MissionNode)TreeViewNodes.SelectedNode.Tag;
                MissionStatement curStatement = (MissionStatement)TreeViewStatements.SelectedNode.Tag;
                if (curNode.Actions.Contains(curStatement))
                    result.SelectedAction = curNode.Actions.IndexOf(curStatement);
                if (curNode.Conditions.Contains(curStatement))
                    result.SelectedCondition = curNode.Conditions.IndexOf(curStatement);
                foreach (Control c in FlowLayoutPanelMain.Controls)
                    if (c.Focused)
                        result.SelectedLabel = FlowLayoutPanelMain.Controls.IndexOf(c);
            }

            return result;
        }
Example #3
0
        /// <summary>
        /// Undo mission to a state
        /// </summary>
        /// <param name="state">If provided, undo until we reach the state, otherwise, undo to the last state</param>
        public void Undo(MissionSavedState state = null)
        {
            if (UndoStack.Count < 2)
                return;

            state = state ?? UndoStack.Peek();
            while (RedoStack.Count == 0 || RedoStack.Peek() != state)
                RedoStack.Push(UndoStack.Pop());
            FromState(UndoStack.Peek());

            UpdateObjectsText();
        }