public static void AddUnlockable(ResearchNode node, Def unlockable = null) { Def toAdd = unlockable; if (toAdd == null) { // get a new unlockable here } if (toAdd is ThingDef curthing) { if (curthing.plant?.sowResearchPrerequisites != null) { curthing.plant.sowResearchPrerequisites.Add(node.Research); ProfileManager.AddCommand("".Find(curthing).Get(new { curthing.plant }).Get(new { curthing.plant.sowResearchPrerequisites }).Add().Find(node.Research)); ResearchSelectPanel.unlockedDefs.Clear(); } else if (curthing.researchPrerequisites != null) { curthing.researchPrerequisites.Add(node.Research); ProfileManager.AddCommand("".Find(curthing).Get(new { curthing.researchPrerequisites }).Add().Find(node.Research)); } } else if (toAdd is TerrainDef curterrain && (curterrain.researchPrerequisites != null)) { curterrain.researchPrerequisites.Add(node.Research); ProfileManager.AddCommand("".Find(curterrain).Get(new { curterrain.researchPrerequisites }).Add().Find(node.Research)); }
public static void RemovePrereq(ResearchNode node, ResearchNode prereq) { node.RemovePrereq(prereq); node.Research.prerequisites.Remove(prereq.Research); ProfileManager.AddCommand("".Find(node.Research).Get(new { node.Research.prerequisites }).Remove().Find(prereq.Research)); //Research.ResearchViewWindow.Refresh(); }
public static void SetName(ResearchNode node, string newName) { node.Research.label = newName; var cachedLabelCap = AccessTools.Field(typeof(Def), "cachedLabelCap"); cachedLabelCap.SetValue(node.Research, null); ProfileManager.AddCommand("".Find(node.Research).Set(new { node.Research.label }).Find(newName)); }
public static void AddPrereq(ResearchNode node, ResearchNode prereq) { if (node.Research.prerequisites == null) { node.Research.prerequisites = new List <ResearchProjectDef>(); ProfileManager.AddCommand(Find(node.Research).Set(new { node.Research.prerequisites }).New(typeof(List <ResearchProjectDef>))); } node.Research.prerequisites.Add(prereq.Research); ProfileManager.AddCommand(Find(node.Research).Get(new { node.Research.prerequisites }).Add().Find(prereq.Research)); node.AddPrereq(prereq); //Research.ResearchViewWindow.Refresh(); }
public static void AddResearchProject(Vector2 location, string defName) { float x = (location.x + (NodeSize.x + NodeMargins.x)) / (NodeSize.x + NodeMargins.x); float y = (location.y + (NodeSize.y + NodeMargins.y)) / (NodeSize.y + NodeMargins.y); ResearchProjectDef newDef = new ResearchProjectDef(); newDef.defName = defName; newDef.label = defName; newDef.description = defName; newDef.baseCost = 600; newDef.techLevel = TechLevel.Industrial; newDef.researchViewX = Rand.Range(0, 500) / 100f; newDef.researchViewY = Rand.Range(0, 500) / 100f; newDef.tab = ResearchTabDefOf.Main; ProfileManager.AddCommand(Enqueue().New(typeof(ResearchProjectDef))); ProfileManager.AddCommand(Enqueue().Dequeue().Set(new { newDef.defName }).Find(defName)); ProfileManager.AddCommand(Enqueue().Dequeue().Set(new { newDef.label }).Find(defName)); ProfileManager.AddCommand(Enqueue().Dequeue().Set(new { newDef.description }).Find(defName)); ProfileManager.AddCommand(Enqueue().Dequeue().Set(new { newDef.baseCost }).Find(newDef.baseCost)); ProfileManager.AddCommand(Enqueue().Dequeue().Set(new { newDef.techLevel }).Find(TechLevel.Industrial)); ProfileManager.AddCommand(Enqueue().Dequeue().Set(new { newDef.researchViewX }).Find(newDef.researchViewX)); ProfileManager.AddCommand(Enqueue().Dequeue().Set(new { newDef.tab }).Find(newDef.tab)); ProfileManager.AddCommand(Add().Dequeue().Set(new { newDef.researchViewY }).Find(newDef.researchViewY)); DefDatabase <ResearchProjectDef> .Add(newDef); //we're refreshing now smilers //wait no we're not KEKWait ResearchNode node = new ResearchNode(newDef); node.X = Mathf.RoundToInt(x); node.Y = Mathf.RoundToInt(y); DRimEditor.Research.Tree._nodes.Add(node); //ResearchWindow.Refresh(); //ResearchNode sel = Research.Tree.Nodes.Find(n => n is ResearchNode rn && rn.Research == newDef) as ResearchNode; ResearchSelectPanel.Select(node); ResearchSelectPanel.newName = newDef.label; //DefExplorerWindow.Recache(); if (DefExplorerWindow.initialized) { //DetailCategory cat = DefDatabase<DetailCategory>.AllDefsListForReading.Find(c => c.defType == typeof(ResearchProjectDef)); DetailCategory cat = DefExplorerWindow.detailCategories[typeof(ResearchProjectDef)]; DefExplorerWindow.instance.AddNewDefToCat(newDef, cat); } }