Exemplo n.º 1
0
        public FindBlock (DataNode searchRoot)
        {
            InitializeComponent();

            _searchRoot = searchRoot;

            _groupX = new CoordinateGroup() {
                RegionBox = _regionXTextBox,
                ChunkBox = _chunkXTextBox,
                BlockBox = _blockXTextBox,
                LocalChunkBox = _localChunkXTextBox,
                LocalBlockBox = _localBlockXTextBox,
            };

            _groupZ = new CoordinateGroup() {
                RegionBox = _regionZTextBox,
                ChunkBox = _chunkZTextBox,
                BlockBox = _blockZTextBox,
                LocalChunkBox = _localChunkZTextBox,
                LocalBlockBox = _localBlockZTextBox,
            };

            ApplyRegion(_groupX, "0", true);
            ApplyRegion(_groupZ, "0", true);

            Validate();
        }
Exemplo n.º 2
0
        public override bool Process(DataNode dataNode, ConsoleOptions options)
        {
            string value = options.Values[0];

            TagDataNode tagDataNode = dataNode as TagDataNode;
            return tagDataNode.Parse(value);
        }
Exemplo n.º 3
0
        public FindReplace (MainForm main, NodeTreeController controller, DataNode searchRoot)
        {
            InitializeComponent();

            _main = main;
            _mainController = controller;
            _mainSearchRoot = searchRoot;

            _findController = new RuleTreeController(treeView1);
            treeView1.NodeMouseDoubleClick += (s, e) => {
                _findController.EditSelection();
            };

            //_findController.VirtualRootDisplay = "Find Rules";

            _replaceController = new NodeTreeController(treeView2);
            treeView2.NodeMouseDoubleClick += (s, e) => {
                _replaceController.EditSelection();
            };

            _replaceController.VirtualRootDisplay = "Replacement Tags";

            _explorerStrip.Renderer = new ToolStripExplorerRenderer();
            _explorerStrip.ImageList = _mainController.IconList;

            _explorerManager = new ExplorerBarController(_explorerStrip, _mainController.IconRegistry, _mainController.IconList, searchRoot);
            _explorerManager.SearchRootChanged += (s, e) => {
                _mainSearchRoot = _explorerManager.SearchRoot;
                Reset();
            };
        }
Exemplo n.º 4
0
        public override bool Process (DataNode dataNode, ConsoleOptions options)
        {
            if (options.Values.Count == 0)
                return false;

            string jsonPath = options.Values[0];
            using (FileStream stream = File.OpenWrite(jsonPath)) {
                using (StreamWriter writer = new StreamWriter(stream)) {
                    if (dataNode is TagDataNode) {
                        TagDataNode tagNode = dataNode as TagDataNode;
                        WriteNbtTag(writer, tagNode.Tag);
                    }
                    else if (dataNode is NbtFileDataNode) {
                        dataNode.Expand();
                        TagNodeCompound root = new TagNodeCompound();

                        foreach (DataNode child in dataNode.Nodes) {
                            TagDataNode childTagNode = child as TagDataNode;
                            if (childTagNode == null)
                                continue;

                            if (childTagNode.Tag != null)
                                root.Add(childTagNode.NodeName, childTagNode.Tag);
                        }

                        WriteNbtTag(writer, root);
                    }
                }
            }

            return true;
        }
Exemplo n.º 5
0
        public override bool CanProcess (DataNode dataNode)
        {
            if (!(dataNode is TagListDataNode))
                return false;

            return true;
        }
Exemplo n.º 6
0
        private DataNode ExpandDataNode(DataNode dataNode, string tagPath)
        {
            string[] pathParts = tagPath.Split('/');

            DataNode curTag = dataNode;
            curTag.Expand();

            foreach (var part in pathParts) {
                TagDataNode.Container container = curTag as TagDataNode.Container;
                if (curTag == null)
                    throw new Exception("Invalid tag path");

                DataNode childTag = null;
                foreach (var child in curTag.Nodes) {
                    if (child.NodePathName == part)
                        childTag = child;
                }

                if (childTag == null)
                    throw new Exception("Invalid tag path");

                curTag.Expand();
            }

            return curTag;
        }
Exemplo n.º 7
0
        public override bool CanProcess(DataNode dataNode)
        {
            if (!(dataNode is TagDataNode) || !dataNode.CanEditNode)
                return false;
            if (dataNode is TagByteArrayDataNode || dataNode is TagIntArrayDataNode)
                return false;

            return true;
        }
        public ExplorerBarController (ToolStrip toolStrip, IconRegistry registry, ImageList iconList, DataNode rootNode)
        {
            _explorerStrip = toolStrip;
            _registry = registry;
            _iconList = iconList;
            _rootNode = rootNode;

            Initialize();
        }
Exemplo n.º 9
0
        public static string Print(DataNode node, bool showType)
        {
            if (!_key.ContainsKey(node.GetType()))
                return "";

            if (showType)
                return "<" + _key[node.GetType()] + "> " + node.NodeDisplay;
            else
                return node.NodeDisplay;
        }
Exemplo n.º 10
0
        public override bool Process (DataNode dataNode, ConsoleOptions options)
        {
            Console.WriteLine(TypePrinter.Print(dataNode, options.ShowTypes));

            if (dataNode.IsContainerType) {
                foreach (var child in dataNode.Nodes)
                    Console.WriteLine(" | " + TypePrinter.Print(child, options.ShowTypes));
            }

            return true;
        }
Exemplo n.º 11
0
        private void PrintSubTree (DataNode dataNode, ConsoleOptions options, string indent, bool last)
        {
            Console.WriteLine(indent + " + " + TypePrinter.Print(dataNode, options.ShowTypes));

            indent += last ? "  " : " |";
            int cnt = 0;

            dataNode.Expand();
            foreach (DataNode child in dataNode.Nodes) {
                cnt++;
                PrintSubTree(child, options, indent, cnt == dataNode.Nodes.Count);
            }
        }
Exemplo n.º 12
0
        public override bool Process (DataNode dataNode, ConsoleOptions options)
        {
            TagListDataNode listNode = dataNode as TagListDataNode;

            listNode.Clear();
            foreach (string value in options.Values) {
                TagNode tag = TagDataNode.DefaultTag(listNode.Tag.ValueType);
                TagDataNode tagData = TagDataNode.CreateFromTag(tag);
                if (!tagData.Parse(value))
                    return false;

                if (!listNode.AppendTag(tagData.Tag))
                    return false;
            }

            return true;
        }
Exemplo n.º 13
0
        private DataNode Search (DataNode node)
        {
            if (node is DirectoryDataNode) {
                DirectoryDataNode dirNode = node as DirectoryDataNode;
                if (!dirNode.IsExpanded)
                    dirNode.Expand();

                foreach (var subNode in dirNode.Nodes) {
                    DataNode resultNode = Search(subNode);
                    if (resultNode != null)
                        return resultNode;
                }

                return null;
            }
            else if (node is RegionFileDataNode) {
                RegionFileDataNode regionNode = node as RegionFileDataNode;

                int rx, rz;
                if (!RegionFileDataNode.RegionCoordinates(regionNode.NodePathName, out rx, out rz))
                    return null;
                if (rx != _groupX.Region.Value || rz != _groupZ.Region.Value)
                    return null;

                if (!regionNode.IsExpanded)
                    regionNode.Expand();

                foreach (var subNode in regionNode.Nodes) {
                    DataNode resultNode = Search(subNode);
                    if (resultNode != null)
                        return resultNode;
                }

                return null;
            }
            else if (node is RegionChunkDataNode) {
                RegionChunkDataNode chunkNode = node as RegionChunkDataNode;
                if (chunkNode.X != _groupX.LocalChunk.Value || chunkNode.Z != _groupZ.LocalChunk.Value)
                    return null;

                return chunkNode;
            }

            return null;
        }
Exemplo n.º 14
0
        private void RefreshChildNodes(TreeNode node, DataNode dataNode)
        {
            Dictionary<DataNode, TreeNode> currentNodes = new Dictionary<DataNode, TreeNode>();
            foreach (TreeNode child in node.Nodes) {
                if (child.Tag is DataNode)
                    currentNodes.Add(child.Tag as DataNode, child);
            }

            node.Nodes.Clear();
            foreach (DataNode child in dataNode.Nodes) {
                if (!currentNodes.ContainsKey(child))
                    node.Nodes.Add(CreateUnexpandedNode(child));
                else
                    node.Nodes.Add(currentNodes[child]);
            }

            foreach (TreeNode child in node.Nodes)
                child.ContextMenuStrip = BuildNodeContextMenu(child.Tag as DataNode);

            if (node.Nodes.Count == 0 && dataNode.HasUnexpandedChildren) {
                ExpandNode(node);
                node.Expand();
            }
        }
Exemplo n.º 15
0
 private bool PasteIntoNodePred(DataNode dataNode, out GroupCapabilities caps)
 {
     caps = dataNode.PasteIntoNodeCapabilities;
     return (dataNode != null) && dataNode.CanPasteIntoNode;
 }
Exemplo n.º 16
0
        private TreeNode GetRootFromDataNodePath(DataNode node, out Stack<DataNode> hierarchy)
        {
            hierarchy = new Stack<DataNode>();
            while (node != null) {
                hierarchy.Push(node);
                node = node.Parent;
            }

            DataNode rootDataNode = hierarchy.Pop();
            TreeNode frontNode = null;
            foreach (TreeNode child in _nodeTree.Nodes) {
                if (child.Tag == rootDataNode)
                    frontNode = child;
            }

            return frontNode;
        }
Exemplo n.º 17
0
        private TreeNode FindFrontNode(DataNode node)
        {
            Stack<DataNode> hierarchy;
            TreeNode frontNode = GetRootFromDataNodePath(node, out hierarchy);

            if (frontNode == null)
                return null;

            while (hierarchy.Count > 0) {
                if (!frontNode.IsExpanded) {
                    frontNode.Nodes.Add(new TreeNode());
                    frontNode.Expand();
                }

                DataNode childData = hierarchy.Pop();
                foreach (TreeNode childFront in frontNode.Nodes) {
                    if (childFront.Tag == childData) {
                        frontNode = childFront;
                        break;
                    }
                }
            }

            return frontNode;
        }
Exemplo n.º 18
0
 private bool EditNodePred(DataNode dataNode, out GroupCapabilities caps)
 {
     caps = dataNode.EditNodeCapabilities;
     return (dataNode != null) && dataNode.CanEditNode;
 }
Exemplo n.º 19
0
 private bool DeleteNodePred(DataNode dataNode, out GroupCapabilities caps)
 {
     caps = dataNode.DeleteNodeCapabilities;
     return (dataNode != null) && dataNode.CanDeleteNode;
 }
Exemplo n.º 20
0
        protected Dictionary<string, object> BuildExpandSet(DataNode node)
        {
            if (node == null || !node.IsExpanded)
                return null;

            Dictionary<string, object> dict = new Dictionary<string, object>();
            foreach (DataNode child in node.Nodes) {
                Dictionary<string, object> childDict = BuildExpandSet(child);
                if (childDict != null) {
                    if (!String.IsNullOrEmpty(child.NodeName))
                        dict[child.NodeName] = childDict;
                    else
                        dict[child.NodeDisplay] = childDict;
                }
            }

            return dict;
        }
Exemplo n.º 21
0
        private void SearchDiscoveryCallback(DataNode node)
        {
            _nodeTree.SelectedNode = FindFrontNode(node);

            if (_searchForm != null) {
                _searchForm.DialogResult = DialogResult.OK;
                _searchForm = null;
            }
        }
Exemplo n.º 22
0
 private bool ReorderNodePred(DataNode dataNode, out GroupCapabilities caps)
 {
     caps = dataNode.ReorderNodeCapabilities;
     return (dataNode != null) && dataNode.CanReoderNode;
 }
Exemplo n.º 23
0
 private void SearchCollapseCallback(DataNode node)
 {
     CollapseBelow(node);
 }
Exemplo n.º 24
0
 private bool CreateFloatNodePred(DataNode dataNode, out GroupCapabilities caps)
 {
     caps = GroupCapabilities.Single;
     return (dataNode != null) && dataNode.CanCreateTag(TagType.TAG_FLOAT);
 }
Exemplo n.º 25
0
        private void SearchEndCallback(DataNode node)
        {
            _searchForm.DialogResult = DialogResult.OK;
            _searchForm = null;

            MessageBox.Show("End of results");
        }
Exemplo n.º 26
0
 private bool CreateIntArrayNodePred(DataNode dataNode, out GroupCapabilities caps)
 {
     caps = GroupCapabilities.Single;
     return (dataNode != null) && dataNode.CanCreateTag(TagType.TAG_INT_ARRAY);
 }
Exemplo n.º 27
0
        protected void RestoreExpandSet(DataNode node, Dictionary<string, object> expandSet)
        {
            node.Expand();

            foreach (DataNode child in node.Nodes) {
                if (expandSet.ContainsKey(child.NodeName)) {
                    Dictionary<string, object> childDict = (Dictionary<string, object>)expandSet[child.NodeName];
                    if (childDict != null)
                        RestoreExpandSet(child, childDict);
                }
                else if (expandSet.ContainsKey(child.NodeDisplay)) {
                    Dictionary<string, object> childDict = (Dictionary<string, object>)expandSet[child.NodeDisplay];
                    if (childDict != null)
                        RestoreExpandSet(child, childDict);
                }
            }
        }
Exemplo n.º 28
0
 private bool CreateStringNodePred(DataNode dataNode, out GroupCapabilities caps)
 {
     caps = GroupCapabilities.Single;
     return (dataNode != null) && dataNode.CanCreateTag(TagType.TAG_STRING);
 }
Exemplo n.º 29
0
 public override bool CanProcess (DataNode dataNode)
 {
     return true;
 }
Exemplo n.º 30
0
        private TreeNode CreateUnexpandedNode(DataNode node)
        {
            TreeNode frontNode = new TreeNode(node.NodeDisplay);
            frontNode.ImageIndex = _iconRegistry.Lookup(node.GetType());
            frontNode.SelectedImageIndex = frontNode.ImageIndex;
            frontNode.Tag = node;
            frontNode.ContextMenuStrip = BuildNodeContextMenu(node);

            if (node.HasUnexpandedChildren || node.Nodes.Count > 0)
                frontNode.Nodes.Add(new TreeNode());

            return frontNode;
        }