private void AddTreeNode(CategoryTreeNode parent, TreeNode parentNode) { foreach (var category in parent.SubCategories) { var node = new TreeNode(category.Name); if (category.SubCategories != null) { AddTreeNode(category, node); } if (category.Items != null) { foreach (var uid in category.Items) { var block = this.BlockDefinitions[uid]; block.Category = category.Name; node.Nodes.Add(block.Name).Tag = block; } } if (parentNode == null) { this.treeBlocks.Nodes.Add(node); } else { parentNode.Nodes.Add(node); } } }
private void FillCategoryItems(CategoryTreeNode node) { foreach (var category in node.SubCategories) { var list = this.BlockIdList.Where(item => item.Value.Category == category.Name); category.Items = list.Select(item => item.Value.Uid).ToList(); if (category.SubCategories != null) { this.FillCategoryItems(category); } } }
private void FormBlockErase_Load(object sender, EventArgs e) { try { this.Tree = CategoryTree.Load(CategoryTree.CATEGORY_TREE_FILE); this.Blueprint.LoadBlocks(); this.BlockDefinitions = this.Blueprint.BlockDefinitions; // BlockDefinitionStore.LoadBlockDefinitions(); this.treeBlocks.Nodes.Clear(); this.AddTreeNode(this.Tree, null); { var node = new TreeNode("unknown"); var list = this.BlockDefinitions.Where(w => string.IsNullOrEmpty(w.Value.Category)).ToList(); foreach (var item in list) { var block = this.BlockDefinitions[item.Key]; node.Nodes.Add(block.Name).Tag = block; } this.treeBlocks.Nodes.Add(node); } { var node = new TreeNode("undefined"); this.treeBlocks.Nodes.Add(node); } this.cmbColor.Items.Clear(); for (int i = 0; i < 32; i++) { var index = this.cmbColor.Items.Add(i); } this.cmbColor.SelectedIndex = 0; this.chkObjects.Items.Clear(); this.chkObjects.Items.Add("main object", true); this.chkObjects.Items.Add("sub object", true); this.lblName.Text = this.Blueprint.Name; this.FillCondition(); this.pictureBox1.Image = this.Blueprint.GetBmp(this.BlockDefinitions, this.TargetCondition, this.inputZoom.Value); } catch (Exception ex) { Console.WriteLine(ex.ToString()); MessageBox.Show(ex.Message, "error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public static void Save(string path, CategoryTreeNode tree) { using (var sr = new System.IO.StreamWriter(path)) { try { string json = Newtonsoft.Json.JsonConvert.SerializeObject(tree, Formatting.Indented); sr.Write(json); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } } }
public static CategoryTreeNode Load(string path) { var ret = new CategoryTreeNode(); using (var sr = new System.IO.StreamReader(path)) { var json = sr.ReadToEnd(); try { ret = Newtonsoft.Json.JsonConvert.DeserializeObject <CategoryTreeNode>(json); return(ret); } catch (Exception ex) { Console.WriteLine(ex.ToString()); return(null); } } }