public void RehashFrom(PartTag tag) { if (EnabledTags.Contains(tag)) { Rehash(); } }
public void ToggleFilter(PartTag toToggle) { if (Input.GetKey(KeyCode.LeftControl)) { if (EnabledTags.Contains(toToggle)) { RemoveFilter(toToggle); } else { AddFilter(toToggle); } } else { bool add = !EnabledTags.Contains(toToggle); EnabledTags.Clear(); if (add) { EnabledTags.Add(toToggle); } Rehash(); } EditorPartList.Instance.Refresh(); }
internal void AddAfter(PartTag newTag) { if (Parent != null) { Parent.AddChild(newTag, this); } }
public void AddChild(PartTag toAdd, PartTag addAfter = null) { if (!ContainsChild(toAdd)) { if (toAdd.Parent != null) { toAdd.Parent.RemoveChild(toAdd); } toAdd.Parent = this; if (addAfter == null) { ChildTags.AddLast(toAdd); } else { LinkedListNode <PartTag> node = ChildTags.Find(addAfter); if (node != null) { ChildTags.AddAfter(node, toAdd); } else { ChildTags.AddLast(toAdd); } } Rehash(); } }
private void CreateAllPartTag() { List <PartTag> toDelete = new List <PartTag>(); foreach (PartTag tag in RootTag.ChildTags) { if (tag.Name == "All") { toDelete.Add(tag); } } toDelete.ForEach(tag => tag.Delete()); PartTag allTag = new PartTag(); allTag.Name = "All"; allTag.IconName = "All"; HashSet <AvailablePart> allParts = new HashSet <AvailablePart>(); SortedPartList.ForEach(part => { if (part.category != PartCategories.none) { allParts.Add(part); } }); allTag.AddParts(allParts); RootTag.AddChild(allTag); RootTag.ChildTags.Remove(allTag); RootTag.ChildTags.AddFirst(allTag); AutoGroupTag(allTag); }
public Texture2D GetTagIcon(PartTag tag) { if (string.IsNullOrEmpty(tag.IconName)) { return(GetIconTexture(GUIConstants.DefaultIconName, tag.Enabled)); } return(GetIconTexture(tag.IconName, tag.Enabled)); }
public void RemoveFilter(PartTag toRemove) { if (EnabledTags.Contains(toRemove)) { EnabledTags.Remove(toRemove); Rehash(); } }
public void AddFilter(PartTag toAdd) { if (!EnabledTags.Contains(toAdd)) { EnabledTags.Add(toAdd); Rehash(); } }
public void RemoveChild(PartTag toRemove) { if (ChildTags.Contains(toRemove)) { ChildTags.Remove(toRemove); toRemove.Parent = null; Rehash(); } }
public void Unindent() { PartTag partent = Parent; if (partent != null) { PartTag parent2 = Parent.Parent; if (parent2 != null) { partent.RemoveChild(this); parent2.AddChild(this, partent); } } }
public void MoveUp() { if (Parent != null) { LinkedListNode <PartTag> thisNode = Parent.ChildTags.Find(this); LinkedListNode <PartTag> prevNode = thisNode.Previous; if (prevNode != null) { PartTag temp = thisNode.Value; thisNode.Value = prevNode.Value; prevNode.Value = temp; UpdateTagList(); } } }
public bool ContainsChild(PartTag toCheck) { foreach (PartTag child in ChildTags) { if (child == toCheck) { return(true); } if (child.ContainsChild(toCheck)) { return(true); } } return(false); }
public void MoveDown() { if (Parent != null) { LinkedListNode <PartTag> thisNode = Parent.ChildTags.Find(this); LinkedListNode <PartTag> nextNode = thisNode.Next; if (nextNode != null) { PartTag temp = thisNode.Value; thisNode.Value = nextNode.Value; nextNode.Value = temp; UpdateTagList(); } } }
internal void AutoTagByMod() { CreateAllPartTag(); HashSet<PartTag> smallTags = new HashSet<PartTag>(); foreach (KeyValuePair<string, HashSet<AvailablePart>> kv in HashedModCatalog) { if (kv.Key != "") { HashSet<AvailablePart> toAdd = new HashSet<AvailablePart>(); foreach (AvailablePart modPart in kv.Value) { if (!ConfigHandler.Instance.AutotagOnlyUntagged || !RootTag.VisibleParts.Contains(modPart.title)) { toAdd.Add(modPart); } } if (toAdd.Count > 0) { PartTag existingTag = RootTag.ChildTags.FirstOrDefault(stag => stag.Name == kv.Key); LinkedListNode<PartTag> node = null; if (existingTag != null) { node = RootTag.ChildTags.Find(existingTag); } PartTag tag = new PartTag(); tag.Name = kv.Key; if (ResourceProxy.Instance.IconExists(kv.Key)) { tag.IconName = kv.Key; } tag.AddParts(toAdd); if (tag.VisibleParts.Count < ConfigHandler.Instance.SmallModTagPartCount) { smallTags.Add(tag); } RootTag.AddChild(tag); AutoGroupTag(tag); if (existingTag != null && node != null) { RootTag.ChildTags.Remove(tag); node.Value.Parent = null; node.Value = tag; if (tag.IconName == "") { tag.IconName = existingTag.IconName; } } } } } List<PartTag> toDelete = new List<PartTag>(); foreach (PartTag tag in RootTag.ChildTags) { if (tag.Name == "Small Mods") { toDelete.Add(tag); } } toDelete.ForEach(tag => tag.Delete()); if (smallTags.Count > 1) { PartTag smallTag = new PartTag(); smallTag.Name = "Small Mods"; smallTag.IconName = "SmallMods"; foreach (var tag in smallTags) { smallTag.AddChild(tag); } RootTag.AddChild(smallTag); } RootTag.Rehash(); }
internal void AutoGroupTag(PartTag tag) { Dictionary<string, HashSet<AvailablePart>> categories = PartCategorizer.GetCategories(tag.IncludedParts); if (categories.Count > 0) { if (categories.ContainsKey("Pod")) { PartTag pod = new PartTag(); pod.Name = "Pods"; if (categories.ContainsKey("MannedPod")) { PartTag mpod = new PartTag(); mpod.Name = "Manned"; mpod.AddParts(categories["MannedPod"]); tag.RemoveParts(categories["MannedPod"]); pod.AddChild(mpod); } if (categories.ContainsKey("UnmannedPod")) { PartTag upod = new PartTag(); upod.Name = "Unmanned"; upod.AddParts(categories["UnmannedPod"]); tag.RemoveParts(categories["UnmannedPod"]); pod.AddChild(upod); } if (categories.ContainsKey("Seat")) { PartTag seat = new PartTag(); seat.Name = "Seats"; seat.AddParts(categories["Seat"]); tag.RemoveParts(categories["Seat"]); pod.AddChild(seat); } tag.AddChild(pod); } if (categories.ContainsKey("Engine")) { PartTag engines = new PartTag(); engines.Name = "Propulsion"; engines.AddParts(categories["Engine"]); tag.RemoveParts(categories["Engine"]); foreach (string cat in categories.Keys) { if (cat.StartsWith("EngineProp_")) { PartTag catEngine = new PartTag(); catEngine.Name = cat.Substring("EngineProp_".Length); catEngine.AddParts(categories[cat]); engines.RemoveParts(categories[cat]); engines.AddChild(catEngine); } } if (categories.ContainsKey("RCS")) { PartTag rcs = new PartTag(); rcs.Name = "RCS"; rcs.AddParts(categories["RCS"]); tag.RemoveParts(categories["RCS"]); engines.AddChild(rcs); } if (engines.IncludedParts.Count > 0) { PartTag other = new PartTag(); other.Name = "Other"; other.AddParts(engines.IncludedParts); engines.RemoveParts(other.IncludedParts); engines.AddChild(other); } tag.AddChild(engines); engines.ChildTags = new LinkedList<PartTag>(engines.ChildTags.OrderBy(sorttag => sorttag.Name)); } if (categories.ContainsKey("Storage")) { PartTag storage = new PartTag(); storage.Name = "Storage"; storage.AddParts(categories["Storage"]); tag.RemoveParts(categories["Storage"]); foreach (string cat in categories.Keys) { if (cat.StartsWith("Storage_")) { PartTag catStore = new PartTag(); catStore.Name = cat.Substring("Storage_".Length); catStore.AddParts(categories[cat]); storage.RemoveParts(categories[cat]); storage.AddChild(catStore); } } storage.ChildTags = new LinkedList<PartTag>(storage.ChildTags.OrderBy(sorttag => sorttag.Name)); if (categories.ContainsKey("Transfer")) { PartTag transfer = new PartTag(); transfer.Name = "Transfer"; transfer.AddParts(categories["Transfer"]); storage.RemoveParts(categories["Transfer"]); storage.AddChild(transfer); } tag.AddChild(storage); if (storage.IncludedParts.Count > 0) { PartTag other = new PartTag(); other.Name = "Other"; other.AddParts(storage.IncludedParts); storage.RemoveParts(other.IncludedParts); storage.AddChild(other); } } if (categories.ContainsKey("Structural")) { PartTag structural = new PartTag(); structural.Name = "Structural"; structural.AddParts(categories["Structural"]); tag.RemoveParts(categories["Structural"]); tag.AddChild(structural); if (categories.ContainsKey("Structure")) { PartTag structure = new PartTag(); structure.Name = "Main"; structure.AddParts(categories["Structure"]); structural.RemoveParts(categories["Structure"]); structural.AddChild(structure); } if (categories.ContainsKey("Decoupler")) { PartTag decoupler = new PartTag(); decoupler.Name = "Decoupler"; decoupler.AddParts(categories["Decoupler"]); structural.RemoveParts(categories["Decoupler"]); structural.AddChild(decoupler); } if (structural.IncludedParts.Count > 0) { PartTag other = new PartTag(); other.Name = "Other"; other.AddParts(structural.IncludedParts); structural.RemoveParts(other.IncludedParts); structural.AddChild(other); } } if (categories.ContainsKey("Aero")) { PartTag aero = new PartTag(); aero.Name = "Aero"; aero.AddParts(categories["Aero"]); tag.RemoveParts(categories["Aero"]); if (categories.ContainsKey("ControlSurface")) { PartTag controlsurface = new PartTag(); controlsurface.Name = "Control Surfaces"; controlsurface.AddParts(categories["ControlSurface"]); aero.RemoveParts(categories["ControlSurface"]); aero.AddChild(controlsurface); } if (categories.ContainsKey("Winglet")) { PartTag winglet = new PartTag(); winglet.Name = "Winglets"; winglet.AddParts(categories["Winglet"]); aero.RemoveParts(categories["Winglet"]); aero.AddChild(winglet); } if (categories.ContainsKey("Intake")) { PartTag intake = new PartTag(); intake.Name = "Intakes"; intake.AddParts(categories["Intake"]); aero.RemoveParts(categories["Intake"]); aero.AddChild(intake); } if (aero.IncludedParts.Count > 0) { PartTag other = new PartTag(); other.Name = "Other"; other.AddParts(aero.IncludedParts); aero.RemoveParts(other.IncludedParts); aero.AddChild(other); } tag.AddChild(aero); } if (categories.ContainsKey("Utility")) { PartTag utils = new PartTag(); utils.Name = "Utility"; utils.AddParts(categories["Utility"]); tag.RemoveParts(categories["Utility"]); if (categories.ContainsKey("Docking")) { PartTag docking = new PartTag(); docking.Name = "Docking"; docking.AddParts(categories["Docking"]); utils.RemoveParts(categories["Docking"]); utils.AddChild(docking); } if (categories.ContainsKey("Generator")) { PartTag generator = new PartTag(); generator.Name = "Generators"; generator.AddParts(categories["Generator"]); utils.RemoveParts(categories["Generator"]); if (categories.ContainsKey("Solar Panel")) { PartTag solarpanels = new PartTag(); solarpanels.Name = "Solar Panels"; solarpanels.AddParts(categories["Solar Panel"]); generator.RemoveParts(categories["Solar Panel"]); generator.AddChild(solarpanels); } if (generator.IncludedParts.Count > 0) { PartTag other = new PartTag(); other.Name = "Other"; other.AddParts(generator.IncludedParts); generator.RemoveParts(other.IncludedParts); generator.AddChild(other); } utils.AddChild(generator); } if (categories.ContainsKey("LandingAparatus")) { PartTag landing = new PartTag(); landing.Name = "Landing"; landing.AddParts(categories["LandingAparatus"]); utils.RemoveParts(categories["LandingAparatus"]); if (categories.ContainsKey("Parachute")) { PartTag parachutes = new PartTag(); parachutes.Name = "Parachutes"; parachutes.AddParts(categories["Parachute"]); landing.RemoveParts(categories["Parachute"]); landing.AddChild(parachutes); } if (categories.ContainsKey("Wheel")) { PartTag wheels = new PartTag(); wheels.Name = "Wheels"; wheels.AddParts(categories["Wheel"]); landing.RemoveParts(categories["Wheel"]); landing.AddChild(wheels); } if (categories.ContainsKey("Landing Gear")) { PartTag gear = new PartTag(); gear.Name = "Landing Gears"; gear.AddParts(categories["Landing Gear"]); landing.RemoveParts(categories["Landing Gear"]); landing.AddChild(gear); } if (categories.ContainsKey("Landing Leg")) { PartTag leg = new PartTag(); leg.Name = "Landing Legs"; leg.AddParts(categories["Landing Leg"]); landing.RemoveParts(categories["Landing Leg"]); landing.AddChild(leg); } utils.AddChild(landing); } if (categories.ContainsKey("Light")) { PartTag light = new PartTag(); light.Name = "Light"; light.AddParts(categories["Light"]); utils.RemoveParts(categories["Light"]); utils.AddChild(light); } if (categories.ContainsKey("SAS")) { PartTag sas = new PartTag(); sas.Name = "SAS"; sas.AddParts(categories["SAS"]); utils.RemoveParts(categories["SAS"]); utils.AddChild(sas); } if (categories.ContainsKey("Control")) { PartTag control = new PartTag(); control.Name = "Control"; control.AddParts(categories["Control"]); utils.RemoveParts(categories["Control"]); utils.AddChild(control); } if (categories.ContainsKey("Ladder")) { PartTag ladders = new PartTag(); ladders.Name = "Ladders"; ladders.AddParts(categories["Ladder"]); utils.RemoveParts(categories["Ladder"]); utils.AddChild(ladders); } if (utils.IncludedParts.Count > 0) { PartTag other = new PartTag(); other.Name = "Other"; other.AddParts(utils.IncludedParts); utils.RemoveParts(other.IncludedParts); utils.AddChild(other); } tag.AddChild(utils); } if (categories.ContainsKey("Science")) { PartTag science = new PartTag(); science.Name = "Science"; science.AddParts(categories["Science"]); tag.RemoveParts(categories["Science"]); if (categories.ContainsKey("Sensor")) { PartTag sensors = new PartTag(); sensors.Name = "Sensors"; sensors.AddParts(categories["Sensor"]); science.RemoveParts(categories["Sensor"]); science.AddChild(sensors); } if (categories.ContainsKey("Antenna")) { PartTag antenna = new PartTag(); antenna.Name = "Antennas"; antenna.AddParts(categories["Antenna"]); science.RemoveParts(categories["Antenna"]); science.AddChild(antenna); } if (science.IncludedParts.Count > 0) { PartTag other = new PartTag(); other.Name = "Other"; other.AddParts(science.IncludedParts); science.RemoveParts(other.IncludedParts); science.AddChild(other); } tag.AddChild(science); } if (tag.IncludedParts.Count > 0) { PartTag ungrouped = new PartTag(); ungrouped.Name = "Other"; ungrouped.AddParts(tag.IncludedParts); tag.RemoveParts(ungrouped.IncludedParts); tag.AddChild(ungrouped); } } }
public void LoadPartTags() { if (File.Exists<PartCatalog>("catalog.txt")) { RootTag = new PartTag(); string[] lines = File.ReadAllLines<PartCatalog>("catalog.txt"); uint lineNum = 0; PartTag curTag = RootTag; bool tagError = false; foreach (string line in lines) { lineNum++; string trimmed = line.Trim(); if (trimmed.Length > 0) { if (trimmed.StartsWith("TAG", StringComparison.OrdinalIgnoreCase)) { string trimmedName = trimmed.Substring("TAG".Length).Trim(); if (trimmedName.Length > 0) { PartTag newTag = new PartTag(); newTag.Parent = curTag; curTag = newTag; curTag.Name = trimmedName; if (curTag.Parent == null) { RootTag.AddChild(curTag); } else { curTag.Parent.AddChild(curTag); } tagError = false; } else { Debug.LogWarning(String.Format("PartCatalog WARNING Line {0}: TAG without proper name", lineNum)); } } else { if (curTag == null) { if (!tagError) { tagError = true; Debug.LogError(String.Format("PartCatalog ERROR Line {0} parameters without started TAG", lineNum)); } } else { if (trimmed.StartsWith("NEW PAGE", StringComparison.OrdinalIgnoreCase)) { curTag.StartNewPage = true; } else if (trimmed.StartsWith("ICON", StringComparison.OrdinalIgnoreCase)) { string toParse = trimmed.Substring("ICON".Length).Trim(); curTag.IconName = toParse; if (curTag.IconName.Length == 0) { Debug.LogError(String.Format("PartCatalog Error Line {0} malformed Icon Name \"{1}\"", lineNum, toParse)); } } else if (trimmed.StartsWith("SHOW SPH", StringComparison.OrdinalIgnoreCase)) { string toParse = trimmed.Substring("SHOW SPH".Length).Trim(); bool newState = false; if (!bool.TryParse(toParse, out newState)) { Debug.LogError(String.Format("PartCatalog Error Line {0} malformed boolean \"{1}\"", lineNum, toParse)); } else { curTag.VisibleInSPH = newState; } } else if (trimmed.StartsWith("SHOW VAB", StringComparison.OrdinalIgnoreCase)) { string toParse = trimmed.Substring("SHOW VAB".Length).Trim(); bool newState = false; if (!bool.TryParse(toParse, out newState)) { Debug.LogError(String.Format("PartCatalog Error Line {0} malformed boolean \"{1}\"", lineNum, toParse)); } else { curTag.VisibleInVAB = newState; } } else if (trimmed.StartsWith("ADD PART", StringComparison.OrdinalIgnoreCase)) { string partName = trimmed.Substring("ADD PART".Length).Trim(); AvailablePart part = PartLoader.getPartInfoByName(partName); if (part == null) { Debug.LogError(String.Format("PartCatalog ERROR Line {0} Unknown Part {1}", lineNum, partName)); } else { curTag.AddPart(part); } } else if (trimmed.StartsWith("END TAG", StringComparison.OrdinalIgnoreCase)) { curTag = curTag.Parent; } else { Debug.LogError(string.Format("PartCatalog ERROR: Malformed Line {0}: {1}", lineNum, trimmed)); } } } } } } Debug.Log("****Finished Loading Parts****"); }
private void HandleKeyBindings() { HandleMouseScroll(); if (ConfigHandler.Instance.EnableShortcuts) { for (int i = 0; i < shortCutsKeyCodes.Length; i++) { int index = i; if (Input.GetKey(KeyCode.LeftShift)) { index += 10; } if (index < currentPageTags.Count) { if (Input.GetKeyUp(shortCutsKeyCodes[i])) { PartTag tag = currentPageTags.ElementAt(index); PartFilterManager.Instance.ToggleFilter(tag); } } } } Vector2 MousePos = new Vector2(Input.mousePosition.x, Screen.height - Input.mousePosition.y); if (GetToolbarRectRaw().Contains(MousePos)) { if (CurMouseScroll < 0.0f) { if (nextPageAvailable) { ConfigHandler.Instance.DisplayedPage++; UpdateDisplayedTags(); } } else if (CurMouseScroll > 0.0f && ConfigHandler.Instance.DisplayedPage > 0) { ConfigHandler.Instance.DisplayedPage--; UpdateDisplayedTags(); } } else if (GUIConstants.EditorScrollRegion.Contains(MousePos)) { if (CurMouseScroll < 0.0f) { if (ConfigHandler.Instance.EnableCategoryScrolling && Input.GetKey(KeyCode.LeftControl)) { MoveCategory(1); } else if (ConfigHandler.Instance.EnablePartListScrolling) { EditorPartList.Instance.NextPage(); } } else if (CurMouseScroll > 0.0f) { if (ConfigHandler.Instance.EnableCategoryScrolling && Input.GetKey(KeyCode.LeftControl)) { MoveCategory(-1); } else if (ConfigHandler.Instance.EnablePartListScrolling) { EditorPartList.Instance.PrevPage(); } } } }
public MouseOverStackEntry(PartTag tag, Vector2 pos) { Tag = tag; position = GUIUtility.GUIToScreenPoint(pos); }
public void AddChild(PartTag toAdd, PartTag addAfter = null) { if (!ContainsChild(toAdd)) { if (toAdd.Parent != null) { toAdd.Parent.RemoveChild(toAdd); } toAdd.Parent = this; if (addAfter == null) { ChildTags.AddLast(toAdd); } else { LinkedListNode<PartTag> node = ChildTags.Find(addAfter); if (node != null) { ChildTags.AddAfter(node, toAdd); } else { ChildTags.AddLast(toAdd); } } Rehash(); } }
internal void AutoTagByMod() { CreateAllPartTag(); HashSet <PartTag> smallTags = new HashSet <PartTag>(); foreach (KeyValuePair <string, HashSet <AvailablePart> > kv in HashedModCatalog) { if (kv.Key != "") { HashSet <AvailablePart> toAdd = new HashSet <AvailablePart>(); foreach (AvailablePart modPart in kv.Value) { if (!ConfigHandler.Instance.AutotagOnlyUntagged || !RootTag.VisibleParts.Contains(modPart.title)) { toAdd.Add(modPart); } } if (toAdd.Count > 0) { PartTag existingTag = RootTag.ChildTags.FirstOrDefault(stag => stag.Name == kv.Key); LinkedListNode <PartTag> node = null; if (existingTag != null) { node = RootTag.ChildTags.Find(existingTag); } PartTag tag = new PartTag(); tag.Name = kv.Key; if (ResourceProxy.Instance.IconExists(kv.Key)) { tag.IconName = kv.Key; } tag.AddParts(toAdd); if (tag.VisibleParts.Count < ConfigHandler.Instance.SmallModTagPartCount) { smallTags.Add(tag); } RootTag.AddChild(tag); AutoGroupTag(tag); if (existingTag != null && node != null) { RootTag.ChildTags.Remove(tag); node.Value.Parent = null; node.Value = tag; if (tag.IconName == "") { tag.IconName = existingTag.IconName; } } } } } List <PartTag> toDelete = new List <PartTag>(); foreach (PartTag tag in RootTag.ChildTags) { if (tag.Name == "Small Mods") { toDelete.Add(tag); } } toDelete.ForEach(tag => tag.Delete()); if (smallTags.Count > 1) { PartTag smallTag = new PartTag(); smallTag.Name = "Small Mods"; smallTag.IconName = "SmallMods"; foreach (var tag in smallTags) { smallTag.AddChild(tag); } RootTag.AddChild(smallTag); } RootTag.Rehash(); }
private void CreateAllPartTag() { List<PartTag> toDelete = new List<PartTag>(); foreach (PartTag tag in RootTag.ChildTags) { if (tag.Name == "All") { toDelete.Add(tag); } } toDelete.ForEach(tag => tag.Delete()); PartTag allTag = new PartTag(); allTag.Name = "All"; allTag.IconName = "All"; HashSet<AvailablePart> allParts = new HashSet<AvailablePart>(); SortedPartList.ForEach(part => { if (part.category != PartCategories.none) allParts.Add(part); }); allTag.AddParts(allParts); RootTag.AddChild(allTag); RootTag.ChildTags.Remove(allTag); RootTag.ChildTags.AddFirst(allTag); AutoGroupTag(allTag); }
internal void AutoGroupTag(PartTag tag) { Dictionary <string, HashSet <AvailablePart> > categories = PartCategorizer.GetCategories(tag.IncludedParts); if (categories.Count > 0) { if (categories.ContainsKey("Pod")) { PartTag pod = new PartTag(); pod.Name = "Pods"; if (categories.ContainsKey("MannedPod")) { PartTag mpod = new PartTag(); mpod.Name = "Manned"; mpod.AddParts(categories["MannedPod"]); tag.RemoveParts(categories["MannedPod"]); pod.AddChild(mpod); } if (categories.ContainsKey("UnmannedPod")) { PartTag upod = new PartTag(); upod.Name = "Unmanned"; upod.AddParts(categories["UnmannedPod"]); tag.RemoveParts(categories["UnmannedPod"]); pod.AddChild(upod); } if (categories.ContainsKey("Seat")) { PartTag seat = new PartTag(); seat.Name = "Seats"; seat.AddParts(categories["Seat"]); tag.RemoveParts(categories["Seat"]); pod.AddChild(seat); } tag.AddChild(pod); } if (categories.ContainsKey("Engine")) { PartTag engines = new PartTag(); engines.Name = "Propulsion"; engines.AddParts(categories["Engine"]); tag.RemoveParts(categories["Engine"]); foreach (string cat in categories.Keys) { if (cat.StartsWith("EngineProp_")) { PartTag catEngine = new PartTag(); catEngine.Name = cat.Substring("EngineProp_".Length); catEngine.AddParts(categories[cat]); engines.RemoveParts(categories[cat]); engines.AddChild(catEngine); } } if (categories.ContainsKey("RCS")) { PartTag rcs = new PartTag(); rcs.Name = "RCS"; rcs.AddParts(categories["RCS"]); tag.RemoveParts(categories["RCS"]); engines.AddChild(rcs); } if (engines.IncludedParts.Count > 0) { PartTag other = new PartTag(); other.Name = "Other"; other.AddParts(engines.IncludedParts); engines.RemoveParts(other.IncludedParts); engines.AddChild(other); } tag.AddChild(engines); engines.ChildTags = new LinkedList <PartTag>(engines.ChildTags.OrderBy(sorttag => sorttag.Name)); } if (categories.ContainsKey("Storage")) { PartTag storage = new PartTag(); storage.Name = "Storage"; storage.AddParts(categories["Storage"]); tag.RemoveParts(categories["Storage"]); foreach (string cat in categories.Keys) { if (cat.StartsWith("Storage_")) { PartTag catStore = new PartTag(); catStore.Name = cat.Substring("Storage_".Length); catStore.AddParts(categories[cat]); storage.RemoveParts(categories[cat]); storage.AddChild(catStore); } } storage.ChildTags = new LinkedList <PartTag>(storage.ChildTags.OrderBy(sorttag => sorttag.Name)); if (categories.ContainsKey("Transfer")) { PartTag transfer = new PartTag(); transfer.Name = "Transfer"; transfer.AddParts(categories["Transfer"]); storage.RemoveParts(categories["Transfer"]); storage.AddChild(transfer); } tag.AddChild(storage); if (storage.IncludedParts.Count > 0) { PartTag other = new PartTag(); other.Name = "Other"; other.AddParts(storage.IncludedParts); storage.RemoveParts(other.IncludedParts); storage.AddChild(other); } } if (categories.ContainsKey("Structural")) { PartTag structural = new PartTag(); structural.Name = "Structural"; structural.AddParts(categories["Structural"]); tag.RemoveParts(categories["Structural"]); tag.AddChild(structural); if (categories.ContainsKey("Structure")) { PartTag structure = new PartTag(); structure.Name = "Main"; structure.AddParts(categories["Structure"]); structural.RemoveParts(categories["Structure"]); structural.AddChild(structure); } if (categories.ContainsKey("Decoupler")) { PartTag decoupler = new PartTag(); decoupler.Name = "Decoupler"; decoupler.AddParts(categories["Decoupler"]); structural.RemoveParts(categories["Decoupler"]); structural.AddChild(decoupler); } if (structural.IncludedParts.Count > 0) { PartTag other = new PartTag(); other.Name = "Other"; other.AddParts(structural.IncludedParts); structural.RemoveParts(other.IncludedParts); structural.AddChild(other); } } if (categories.ContainsKey("Aero")) { PartTag aero = new PartTag(); aero.Name = "Aero"; aero.AddParts(categories["Aero"]); tag.RemoveParts(categories["Aero"]); if (categories.ContainsKey("ControlSurface")) { PartTag controlsurface = new PartTag(); controlsurface.Name = "Control Surfaces"; controlsurface.AddParts(categories["ControlSurface"]); aero.RemoveParts(categories["ControlSurface"]); aero.AddChild(controlsurface); } if (categories.ContainsKey("Winglet")) { PartTag winglet = new PartTag(); winglet.Name = "Winglets"; winglet.AddParts(categories["Winglet"]); aero.RemoveParts(categories["Winglet"]); aero.AddChild(winglet); } if (categories.ContainsKey("Intake")) { PartTag intake = new PartTag(); intake.Name = "Intakes"; intake.AddParts(categories["Intake"]); aero.RemoveParts(categories["Intake"]); aero.AddChild(intake); } if (aero.IncludedParts.Count > 0) { PartTag other = new PartTag(); other.Name = "Other"; other.AddParts(aero.IncludedParts); aero.RemoveParts(other.IncludedParts); aero.AddChild(other); } tag.AddChild(aero); } if (categories.ContainsKey("Utility")) { PartTag utils = new PartTag(); utils.Name = "Utility"; utils.AddParts(categories["Utility"]); tag.RemoveParts(categories["Utility"]); if (categories.ContainsKey("Docking")) { PartTag docking = new PartTag(); docking.Name = "Docking"; docking.AddParts(categories["Docking"]); utils.RemoveParts(categories["Docking"]); utils.AddChild(docking); } if (categories.ContainsKey("Generator")) { PartTag generator = new PartTag(); generator.Name = "Generators"; generator.AddParts(categories["Generator"]); utils.RemoveParts(categories["Generator"]); if (categories.ContainsKey("Solar Panel")) { PartTag solarpanels = new PartTag(); solarpanels.Name = "Solar Panels"; solarpanels.AddParts(categories["Solar Panel"]); generator.RemoveParts(categories["Solar Panel"]); generator.AddChild(solarpanels); } if (generator.IncludedParts.Count > 0) { PartTag other = new PartTag(); other.Name = "Other"; other.AddParts(generator.IncludedParts); generator.RemoveParts(other.IncludedParts); generator.AddChild(other); } utils.AddChild(generator); } if (categories.ContainsKey("LandingAparatus")) { PartTag landing = new PartTag(); landing.Name = "Landing"; landing.AddParts(categories["LandingAparatus"]); utils.RemoveParts(categories["LandingAparatus"]); if (categories.ContainsKey("Parachute")) { PartTag parachutes = new PartTag(); parachutes.Name = "Parachutes"; parachutes.AddParts(categories["Parachute"]); landing.RemoveParts(categories["Parachute"]); landing.AddChild(parachutes); } if (categories.ContainsKey("Wheel")) { PartTag wheels = new PartTag(); wheels.Name = "Wheels"; wheels.AddParts(categories["Wheel"]); landing.RemoveParts(categories["Wheel"]); landing.AddChild(wheels); } if (categories.ContainsKey("Landing Gear")) { PartTag gear = new PartTag(); gear.Name = "Landing Gears"; gear.AddParts(categories["Landing Gear"]); landing.RemoveParts(categories["Landing Gear"]); landing.AddChild(gear); } if (categories.ContainsKey("Landing Leg")) { PartTag leg = new PartTag(); leg.Name = "Landing Legs"; leg.AddParts(categories["Landing Leg"]); landing.RemoveParts(categories["Landing Leg"]); landing.AddChild(leg); } utils.AddChild(landing); } if (categories.ContainsKey("Light")) { PartTag light = new PartTag(); light.Name = "Light"; light.AddParts(categories["Light"]); utils.RemoveParts(categories["Light"]); utils.AddChild(light); } if (categories.ContainsKey("SAS")) { PartTag sas = new PartTag(); sas.Name = "SAS"; sas.AddParts(categories["SAS"]); utils.RemoveParts(categories["SAS"]); utils.AddChild(sas); } if (categories.ContainsKey("Control")) { PartTag control = new PartTag(); control.Name = "Control"; control.AddParts(categories["Control"]); utils.RemoveParts(categories["Control"]); utils.AddChild(control); } if (categories.ContainsKey("Ladder")) { PartTag ladders = new PartTag(); ladders.Name = "Ladders"; ladders.AddParts(categories["Ladder"]); utils.RemoveParts(categories["Ladder"]); utils.AddChild(ladders); } if (utils.IncludedParts.Count > 0) { PartTag other = new PartTag(); other.Name = "Other"; other.AddParts(utils.IncludedParts); utils.RemoveParts(other.IncludedParts); utils.AddChild(other); } tag.AddChild(utils); } if (categories.ContainsKey("Science")) { PartTag science = new PartTag(); science.Name = "Science"; science.AddParts(categories["Science"]); tag.RemoveParts(categories["Science"]); if (categories.ContainsKey("Sensor")) { PartTag sensors = new PartTag(); sensors.Name = "Sensors"; sensors.AddParts(categories["Sensor"]); science.RemoveParts(categories["Sensor"]); science.AddChild(sensors); } if (categories.ContainsKey("Antenna")) { PartTag antenna = new PartTag(); antenna.Name = "Antennas"; antenna.AddParts(categories["Antenna"]); science.RemoveParts(categories["Antenna"]); science.AddChild(antenna); } if (science.IncludedParts.Count > 0) { PartTag other = new PartTag(); other.Name = "Other"; other.AddParts(science.IncludedParts); science.RemoveParts(other.IncludedParts); science.AddChild(other); } tag.AddChild(science); } if (tag.IncludedParts.Count > 0) { PartTag ungrouped = new PartTag(); ungrouped.Name = "Other"; ungrouped.AddParts(tag.IncludedParts); tag.RemoveParts(ungrouped.IncludedParts); tag.AddChild(ungrouped); } } }
private void DrawTagButton(int ListPageNum, int TagIndentation, PartTag tag) { int count = tag.VisibleParts.Count; string title = tag.Name; if (selectedPartTagTransfer == null) { if (selectedPartTag == tag) { title = string.Format(">{0}<", title); } } else { if (selectedPartTag == tag) { title = string.Format("←{0}", title); } if (selectedPartTagTransfer == tag) { title = string.Format("→{0}", title); } } GUILayout.BeginHorizontal(); if (ListPageNum != -1) { GUILayout.Label(tag.StartNewPage || ListPageNum == 1 ? String.Format("{0}", ListPageNum) : String.Format("*{0}", ListPageNum), GUILayout.Width(17)); } else { GUILayout.Space(20); } RegisterHelp("PageNumber"); for (int i = 0; i < TagIndentation; i++) { GUILayout.Space(24); } if (tag.ChildTags.Count > 0) { if (tag.Collapsed) { if (GUILayout.Button("+", GUILayout.Width(20))) { if (Input.GetKey(KeyCode.LeftControl)) { tag.setCollapsedRecursive(false); } else { tag.Collapsed = false; } } RegisterHelp("ExpandTag"); } else { if (GUILayout.Button("-", GUILayout.Width(20))) { if (Input.GetKey(KeyCode.LeftControl)) { tag.setCollapsedRecursive(true); } else { tag.Collapsed = true; } } RegisterHelp("CollapseTag"); } } bool buttonPress = false; if (tag.IconName != "") { buttonPress |= GUILayout.Button(ResourceProxy.Instance.GetIconTexture(tag.IconName, true), iconStyle, GUILayout.Width(ConfigHandler.Instance.ButtonSize.x), GUILayout.Height(ConfigHandler.Instance.ButtonSize.y)); } TextAnchor oldAlignment = GUI.skin.button.alignment; GUI.skin.button.alignment = ConfigHandler.Instance.TagButtonTextAlignment; buttonPress |= GUILayout.Button(title); if (buttonPress) { if (Input.GetKey(KeyCode.LeftAlt)) { if (selectedPartTag != null && selectedPartTag != tag) { selectedPartTagTransfer = tag; } } else { if (selectedPartTag == tag) { inputText = selectedPartTag.Name; } else { selectedPartTag = tag; } selectedPartTagTransfer = null; } } RegisterHelp("SelectTag"); GUI.skin.button.alignment = oldAlignment; GUILayout.EndHorizontal(); if (!tag.Collapsed) { foreach (PartTag subtag in tag.ChildTags) { DrawTagButton(-1, TagIndentation + 1, subtag); } } }
private bool PartInclusionFilter(PartTag tag, AvailablePart part) { if (ConfigHandler.Instance.SearchPartInSubtags) { return !tag.VisibleParts.Contains(part.name); } else { return !tag.IncludedParts.Contains(part); } }
private void DrawTagTransferColumn(PartTag tagToList, PartTag tagMoveTo) { if (tagToList == selectedPartTag) { GUILayout.BeginVertical(GUILayout.Width((float)(windowPosition.width / 4 * 3 / 2))); } else { GUILayout.BeginVertical(GUILayout.Width((float)(windowPosition.width / 6 * 5 / 2))); } //DrawAddAllButton(selected); //DrawRemoveAllButton(selected); if (tagMoveTo == selectedPartTag) { DrawSortButton(); } else { DrawFilterButton(); } GUILayout.BeginHorizontal(); GUILayout.Label(String.Format("{0} {1}", tagToList.Name, GetCategoryString()), GUILayout.ExpandWidth(true)); RegisterHelp("TransferPartList"); if (tagToList == selectedPartTag) { if (ConfigHandler.Instance.SynchronizePartCategories) { if (GUILayout.Button("S", GUILayout.Width(30))) { ConfigHandler.Instance.SynchronizePartCategories = false; } RegisterHelp("SyncCategoriesOn"); } else { if (GUILayout.Button("A", GUILayout.Width(30))) { ConfigHandler.Instance.SynchronizePartCategories = true; } RegisterHelp("SyncCategoriesOff"); } if (GUILayout.Button("+", GUILayout.Width(30))) { collapsedFilter.Clear(); } RegisterHelp("ExpandAll"); if (GUILayout.Button("-", GUILayout.Width(30))) { foreach (AvailablePart part in PartCatalog.Instance.SortedPartList) { string category = GetPartCategory(part); if (category != null) { collapsedFilter.Add(category); } } } RegisterHelp("CollapseAll"); } GUILayout.EndHorizontal(); ScrollPositions[2] = GUILayout.BeginScrollView(ScrollPositions[2]); AvailablePart toMove = null; string lastCategory = null; foreach (AvailablePart part in PartCatalog.Instance.SortedPartList) { if (tagToList.IncludedParts.Contains(part)) { if (FilterPart(part)) { bool draw = true; string caption = part.title; if (ConfigHandler.Instance.SortNumber == 0) { caption = part.name; } else { DrawPartCategory(ref lastCategory, part, ref draw, tagToList == selectedPartTag); } if (draw && GUILayout.Button(part.title)) { toMove = part; } RegisterHelp("TransferPart"); } } } if (toMove != null) { if (!Input.GetKey(KeyCode.LeftControl)) { tagToList.RemovePart(toMove); } tagMoveTo.AddPart(toMove); } GUILayout.EndScrollView(); RegisterHelp("TransferPartList"); GUILayout.EndVertical(); }
public void LoadPartTags() { if (File.Exists <PartCatalog>("catalog.txt")) { RootTag = new PartTag(); string[] lines = File.ReadAllLines <PartCatalog>("catalog.txt"); uint lineNum = 0; PartTag curTag = RootTag; bool tagError = false; foreach (string line in lines) { lineNum++; string trimmed = line.Trim(); if (trimmed.Length > 0) { if (trimmed.StartsWith("TAG", StringComparison.OrdinalIgnoreCase)) { string trimmedName = trimmed.Substring("TAG".Length).Trim(); if (trimmedName.Length > 0) { PartTag newTag = new PartTag(); newTag.Parent = curTag; curTag = newTag; curTag.Name = trimmedName; if (curTag.Parent == null) { RootTag.AddChild(curTag); } else { curTag.Parent.AddChild(curTag); } tagError = false; } else { Debug.LogWarning(String.Format("PartCatalog WARNING Line {0}: TAG without proper name", lineNum)); } } else { if (curTag == null) { if (!tagError) { tagError = true; Debug.LogError(String.Format("PartCatalog ERROR Line {0} parameters without started TAG", lineNum)); } } else { if (trimmed.StartsWith("NEW PAGE", StringComparison.OrdinalIgnoreCase)) { curTag.StartNewPage = true; } else if (trimmed.StartsWith("ICON", StringComparison.OrdinalIgnoreCase)) { string toParse = trimmed.Substring("ICON".Length).Trim(); curTag.IconName = toParse; if (curTag.IconName.Length == 0) { Debug.LogError(String.Format("PartCatalog Error Line {0} malformed Icon Name \"{1}\"", lineNum, toParse)); } } else if (trimmed.StartsWith("SHOW SPH", StringComparison.OrdinalIgnoreCase)) { string toParse = trimmed.Substring("SHOW SPH".Length).Trim(); bool newState = false; if (!bool.TryParse(toParse, out newState)) { Debug.LogError(String.Format("PartCatalog Error Line {0} malformed boolean \"{1}\"", lineNum, toParse)); } else { curTag.VisibleInSPH = newState; } } else if (trimmed.StartsWith("SHOW VAB", StringComparison.OrdinalIgnoreCase)) { string toParse = trimmed.Substring("SHOW VAB".Length).Trim(); bool newState = false; if (!bool.TryParse(toParse, out newState)) { Debug.LogError(String.Format("PartCatalog Error Line {0} malformed boolean \"{1}\"", lineNum, toParse)); } else { curTag.VisibleInVAB = newState; } } else if (trimmed.StartsWith("ADD PART", StringComparison.OrdinalIgnoreCase)) { string partName = trimmed.Substring("ADD PART".Length).Trim(); AvailablePart part = PartLoader.getPartInfoByName(partName); if (part == null) { Debug.LogError(String.Format("PartCatalog ERROR Line {0} Unknown Part {1}", lineNum, partName)); } else { curTag.AddPart(part); } } else if (trimmed.StartsWith("END TAG", StringComparison.OrdinalIgnoreCase)) { curTag = curTag.Parent; } else { Debug.LogError(string.Format("PartCatalog ERROR: Malformed Line {0}: {1}", lineNum, trimmed)); } } } } } } Debug.Log("****Finished Loading Parts****"); }
public bool ContainsChild(PartTag toCheck) { foreach (PartTag child in ChildTags) { if (child == toCheck) { return true; } if (child.ContainsChild(toCheck)) { return true; } } return false; }
private void DrawTagColumn() { GUILayout.BeginVertical(GUILayout.ExpandHeight(true), GUILayout.Width(windowPosition.width / 6)); DrawCategoryButton(); GUILayout.BeginHorizontal(); if (GUILayout.Button("Autotag")) { PartCatalog.Instance.BuildCatalogs(); PartCatalog.Instance.AutoTagByMod(); } RegisterHelp("AutoTag"); if (GUILayout.Button("Autogroup")) { if (selectedPartTag != null) { PartCatalog.Instance.AutoGroupTag(selectedPartTag); } } RegisterHelp("AutoGroup"); GUILayout.EndHorizontal(); /* INDEV if (GUILayout.Button("Test")) { PartCategoryRuleHandler.Instance.ParseRulesFile("Default_rule.txt"); if (selectedPartTag != null) { foreach (var part in selectedPartTag.IncludedParts) { PartCategoryRuleHandler.Instance.GetCategoriesForPart(part); } } } */ if (GUILayout.Button("New Tag")) { inputText = inputText.Trim(); if (inputText != "") { PartTag newTag = new PartTag(); newTag.Name = inputText; newTag.VisibleInSPH = true; newTag.VisibleInVAB = true; if (selectedPartTag != null) { selectedPartTag.AddAfter(newTag); } else { PartCatalog.Instance.PartTags.AddLast(newTag); } selectedPartTag = newTag; inputText = ""; } } RegisterHelp("NewTag"); if (GUILayout.Button("Delete Tag")) { if (selectedPartTag != null) { PartTag nextTag = null; LinkedListNode<PartTag> node = selectedPartTag.Parent.ChildTags.Find(selectedPartTag); if (node != null) { if (node.Next != null) { nextTag = node.Next.Value; } else if (node.Previous != null) { nextTag = node.Previous.Value; } } selectedPartTag.Delete(); selectedPartTag = nextTag; } } RegisterHelp("DeleteTag"); if (GUILayout.Button("Rename Tag")) { if (selectedPartTag != null && inputText != "") { selectedPartTag.Name = inputText; } } RegisterHelp("RenameTag"); inputText = GUILayout.TextField(inputText); RegisterHelp("InputText"); GUILayout.BeginHorizontal(); GUILayout.Label("Available Tags", GUILayout.ExpandWidth(true)); if (GUILayout.Button("+", GUILayout.Width(20))) { PartCatalog.Instance.RootTag.setCollapsedRecursive(false); } RegisterHelp("ExpandAllTags"); if (GUILayout.Button("-", GUILayout.Width(20))) { PartCatalog.Instance.RootTag.setCollapsedRecursive(true); } RegisterHelp("CollapseAllTags"); GUILayout.EndHorizontal(); int ListPageNum = 0; int ListPageTags = 0; ScrollPositions[0] = GUILayout.BeginScrollView(ScrollPositions[0]); //List of Tags foreach (PartTag tag in PartCatalog.Instance.PartTags) { if (ListPageNum == 0 || tag.StartNewPage || ListPageTags == GUIEditorControls.Instance.MaxTagCount) { ListPageNum++; ListPageTags = 0; } if (ListPageTags == 0) { DrawTagButton(ListPageNum, 0, tag); } else { DrawTagButton(-1, 0, tag); } ListPageTags++; } GUILayout.FlexibleSpace(); GUILayout.EndScrollView(); RegisterHelp("TagList"); if (selectedPartTag != null) { GUILayout.BeginHorizontal(); if (GUILayout.Button("←")) { selectedPartTag.Unindent(); } RegisterHelp("UnindentTag"); if (GUILayout.Button("↑")) { int num = 1; if (Input.GetKey(KeyCode.LeftShift)) { num = ConfigHandler.Instance.TagMoveMultiplier; } for (int i = 0; i < num; i++) { selectedPartTag.MoveUp(); } } RegisterHelp("MoveTagUp"); if (GUILayout.Button("↓")) { int num = 1; if (Input.GetKey(KeyCode.LeftShift)) { num = ConfigHandler.Instance.TagMoveMultiplier; } for (int i = 0; i < num; i++) { selectedPartTag.MoveDown(); } } RegisterHelp("MoveTagDown"); if (GUILayout.Button("→")) { selectedPartTag.Indent(); selectedPartTag.Parent.Collapsed = false; } RegisterHelp("IndentTag"); GUILayout.EndHorizontal(); editIcon = GUILayout.Toggle(editIcon, "Edit Icon", HighLogic.Skin.button); if (selectedPartTag.Parent == PartCatalog.Instance.RootTag) { if (selectedPartTag.StartNewPage) { if (GUILayout.Button("Disable New Page")) { selectedPartTag.StartNewPage = false; } RegisterHelp("DisableNewPage"); } else { if (GUILayout.Button("Enable New Page")) { selectedPartTag.StartNewPage = true; } RegisterHelp("EnableNewPage"); } } if (selectedPartTag.VisibleInSPH && selectedPartTag.VisibleInVAB) { if (GUILayout.Button("Visibility: VAB&SPH")) { selectedPartTag.VisibleInSPH = false; } RegisterHelp("VisibilityVS"); } else if (selectedPartTag.VisibleInVAB) { if (GUILayout.Button("Visibility: VAB")) { selectedPartTag.VisibleInSPH = true; selectedPartTag.VisibleInVAB = false; } RegisterHelp("VisibilityV"); } else if (selectedPartTag.VisibleInSPH) { if (GUILayout.Button("Visibility: SPH")) { selectedPartTag.VisibleInSPH = false; } RegisterHelp("VisibilityS"); } else { if (GUILayout.Button("Visibility: None")) { selectedPartTag.VisibleInSPH = true; selectedPartTag.VisibleInVAB = true; } RegisterHelp("VisibilityNone"); } } GUILayout.BeginHorizontal(); DisplaySettingsPanel = GUILayout.Toggle(DisplaySettingsPanel, "Settings", HighLogic.Skin.button); RegisterHelp("Settings"); ConfigHandler.Instance.HelpActive = GUILayout.Toggle(ConfigHandler.Instance.HelpActive, "?", HighLogic.Skin.button, GUILayout.Width(30)); RegisterHelp("Help"); GUILayout.EndHorizontal(); GUILayout.EndVertical(); }
public Texture2D GetTagIcon(PartTag tag) { if (string.IsNullOrEmpty(tag.IconName)) { return GetIconTexture(GUIConstants.DefaultIconName, tag.Enabled); } return GetIconTexture(tag.IconName, tag.Enabled); }