public MainWindow() { InitializeComponent(); _treeData = TechTreeDiagram.TechTreeGrid.DataContext as TechTreeViewModel; if (_treeData == null) { return; } var workspaceViewModel = new WorkspaceViewModel(); _treeData.WorkspaceViewModel = workspaceViewModel; var sidebar = MainSideBar.DataContext as TechTreeViewModel; if (sidebar == null) { return; } sidebar.WorkspaceViewModel = workspaceViewModel; ContentGrid.DataContext = workspaceViewModel; DataContext = workspaceViewModel; }
public override void PopulateParts(PartCollectionViewModel pc, TechTreeViewModel ttvm) { // Add all part in node foreach (var node in ttvm.TechTree) { foreach (var part in pc.PartCollection) { if (part.TechRequired == node.Id) { node.TechNode.Parts.Add(part.PartName); } } } // Create and init part table with name => partviewmodel var partTable = new Dictionary <string, PartViewModel>(); foreach (PartViewModel part in pc.PartCollection) { try { if (!partTable.ContainsKey(part.PartName)) { partTable.Add(part.PartName, part); } else { var duplicate = partTable[part.PartName]; var existString = String.Format(" - Existing part: {0} ({1})", duplicate.PartName, duplicate.FileName); Logger.Error("PartLoader: Error while storing part \"{0}\" " + "({1}) into PartCollection - {2}{3}", part.PartName, part.FileName, "Part already exists", existString); } } catch (Exception e) { Logger.Error("StockTechTreeLoader.PopulateParts: " + "PartLoader: Error while storing part \"{0}\" " + "({1}) into PartCollection - {2}", part.PartName, part.FileName, e.Message); } } foreach (var node in ttvm.TechTree) { foreach (String part in node.TechNode.Parts) { if (partTable.ContainsKey(part)) { node.Parts.Add(partTable[part]); pc.PartCollection.Remove(partTable[part]); } else { var tmpPart = new Part(part) { Title = part, TechRequired = node.Id, Category = "(Unknown)" }; node.Parts.Add(new PartViewModel(tmpPart)); } } } }
public override TreeSaver StartTree(TechTreeViewModel techTree = null) { AddLine("TechTree"); AddLine("{"); IndentationLevel++; AddLine("id = TEDGeneratedTree"); AddLine("label = TED Generated Tree"); return(this); }
public override void Save(TechTreeViewModel techtreeviewmodel, string path) { this.StartTree(techtreeviewmodel); var totalCost = 0; foreach (TechNodeViewModel node in techtreeviewmodel.TechTree) { totalCost += node.Cost; var parts = new List <string>(); foreach (var part in node.Parts) { parts.Add(part.PartName); } var parents = new List <string>(); foreach (var parent in node.Parents) { String parentPos = FindParentPosition(node.Pos, parent.Pos); String parentIdPos = parent.Id + "|" + parentPos; parents.Add(parentIdPos); } this.StartNode(). SaveAttribute(new KeyValuePair <string, string>("id", node.Id)). SaveAttribute(new KeyValuePair <string, string>("nodepart", node.NodePart)). SaveAttribute(new KeyValuePair <string, string>("title", node.Title)). SaveAttribute(new KeyValuePair <string, string>("description", node.Description)). SaveAttribute(new KeyValuePair <string, string>("cost", node.Cost.ToString(CultureInfo.InvariantCulture))). SavePosition(node.Pos.X, node.Pos.Y, node.Zlayer). SaveAttribute(new KeyValuePair <string, string>("icon", IconStringConverter.IconString[(int)node.Icon])). SaveAttribute(new KeyValuePair <string, string>("anyParent", node.AnyToUnlock.ToString())). SaveAttribute(new KeyValuePair <string, string>("hideEmpty", node.HideEmpty.ToString())). SaveAttribute(new KeyValuePair <string, string>("hideIfNoBranchParts", node.HideIfNoBranchParts.ToString())). SaveAttribute(new KeyValuePair <string, string>("scale", node.Scale.ToString())); StartParents(). SaveParents(parents). EndParents(). StartParts(). SaveParts(node). EndParts(). EndNode(); } this.EndTree(); this.Save(path); Logger.Log("Tree saved succesfully to {0}. Total cost: {1} science. Total nodes: {2} nodes.", path, totalCost, techtreeviewmodel.TechTree.Count); }
public override void LoadTree(KerbalConfig config, TechTreeViewModel treeData) { var nameNodeHashtable = new Dictionary <string, TechNodeViewModel>(); var techNodes = config.First(child => child.Name == "TechTree").Children.Where(node => node.Name == "RDNode").ToArray(); foreach (KerbalNode node in techNodes.Where(kerbalNode => kerbalNode.Values.ContainsKey("nodeName"))) { var v = node.Values; var id = v["id"].First(); TechNodeViewModel techNodeViewModel; if (nameNodeHashtable.ContainsKey(id)) { techNodeViewModel = nameNodeHashtable[id]; } else { techNodeViewModel = new TechNodeViewModel(); nameNodeHashtable.Add(id, techNodeViewModel); } techNodeViewModel.TechNode = this.PopulateFromSource(node); // Find parent foreach (KerbalNode parentNode in node.Children.Where(child => child.Name == "Parent")) { var parentKeyValuePairs = parentNode.Values.Where(pair => pair.Key == "parentID"); var parents = new List <string>(); foreach (var parentKeyValuePair in parentKeyValuePairs) { parents.Add(parentKeyValuePair.Value.First()); } foreach (var parent in parents.Where(parent => !nameNodeHashtable.ContainsKey(parent))) { nameNodeHashtable.Add(parent, new TechNodeViewModel()); } foreach (var parent in parents.Where(parent => !String.IsNullOrEmpty(parent) && nameNodeHashtable.ContainsKey(parent))) { techNodeViewModel.Parents.Add(nameNodeHashtable[parent]); } } treeData.TechTree.Add(techNodeViewModel); } }
public abstract void PopulateParts(PartCollectionViewModel pc, TechTreeViewModel ttvm);
public abstract void LoadTree(KerbalConfig config, TechTreeViewModel treeData);
public TechTreeDiagram() { InitializeComponent(); _techTree = DataContext as TechTreeViewModel; }
public abstract void Save(TechTreeViewModel techTree, string path);
public abstract TreeSaver StartTree(TechTreeViewModel techTree = null);