public static bool Matches(this ResearchProjectDef tech, string query) { var culture = CultureInfo.CurrentUICulture; query = query.ToLower(culture); return (tech.LabelCap.RawText.ToLower(culture).Contains(query) || ResearchTree_Patches.GetUnlockDefsAndDescs(tech).Any(unlock => unlock.First.LabelCap.RawText.ToLower(culture).Contains(query)) || tech.description.ToLower(culture).Contains(query)); }
public static void InferSkillBias(this ResearchProjectDef tech) { //Log.Warning("InferSkillBias Starting for "+tech.LabelCap); //1. check what it unlocks List <Pair <Def, string> > unlocks = ResearchTree_Patches.GetUnlockDefsAndDescs(tech); IEnumerable <Def> defs = unlocks.Select(x => x.First).AsEnumerable(); IEnumerable <ThingDef> thingDefs = from d in defs where d is ThingDef select d as ThingDef; IEnumerable <RecipeDef> recipeDefs = from d in defs where d is RecipeDef select d as RecipeDef; IEnumerable <TerrainDef> terrainDefs = from d in defs where d is TerrainDef select d as TerrainDef; //2. look for skills based on unlocked stuff //a. checking by query on the research tree //int matches = 0; if (tech.Matches("scanner") > 0 | tech.Matches("terraform") > 0) { miningTag = true; /*matches++;*/ } ; if (tech.Matches("sterile") > 0 | tech.Matches("medical") > 0 | tech.Matches("medicine") > 0 | tech.Matches("cryptosleep") > 0 | tech.Matches("prostheses") > 0 | tech.Matches("implant") > 0 | tech.Matches("organs") > 0 | tech.Matches("surgery") > 0) { medicineTag = true; /*matches++;*/ } ; if (tech.Matches("irrigation") > 0 | tech.Matches("soil") > 0 | tech.Matches("hydroponic") > 0) { plantsTag = true; /*matches++;*/ } ; if (tech.Matches("tool") > 0) { craftingTag = true; } if (tech.Matches("manage") > 0) { intellectualTag = true; } //b. checking by unlocked things if (thingDefs.Count() > 0) { foreach (ThingDef t in thingDefs) { if (t != null) { InvestigateThingDef(t); } } } //c. checking by unlocked recipes if (recipeDefs.Count() > 0) { foreach (RecipeDef r in recipeDefs) { //Log.Message("trying recipe " + r.label); foreach (ThingDef t in r.products.Select(x => x.thingDef)) { InvestigateThingDef(t); } if (r.workSkill != null) { AccessTools.Field(typeof(Extension_Research), r.workSkill.defName.ToLower() + "Tag").SetValue(tech, true); } } } //d. checking by unlocked terrainDefs if (terrainDefs.Count() > 0) { foreach (TerrainDef t in terrainDefs) { if (!constructionTag && t.designationCategory != null && t.designationCategory.label.Contains("floor")) { constructionTag = true; } else if (!miningTag) { miningTag = true; } } } //e. special cases if (HarmonyPatches.RunSpecialCases) { if (tech.defName.StartsWith("ResearchProject_RotR")) { miningTag = true; constructionTag = true; } if (tech.defName.StartsWith("BackupPower") || tech.defName.StartsWith("FluffyBreakdowns")) { constructionTag = true; } } //3. Figure out Bias. //int ThingDefCount = thingDefs.Count(); //int RecipeDefCount = recipeDefs.Count(); //int TerrainDefCount = terrainDefs.Count(); List <SkillDef> relevantSkills = new List <SkillDef>(); if (shootingTag) { relevantSkills.Add(SkillDefOf.Shooting); shootingTag = false; } if (meleeTag) { relevantSkills.Add(SkillDefOf.Melee); meleeTag = false; } if (constructionTag) { relevantSkills.Add(SkillDefOf.Construction); constructionTag = false; } if (miningTag) { relevantSkills.Add(SkillDefOf.Mining); miningTag = false; } if (cookingTag) { relevantSkills.Add(SkillDefOf.Cooking); cookingTag = false; } if (plantsTag) { relevantSkills.Add(SkillDefOf.Plants); plantsTag = false; } if (animalsTag) { relevantSkills.Add(SkillDefOf.Animals); animalsTag = false; } if (craftingTag) { relevantSkills.Add(SkillDefOf.Crafting); craftingTag = false; } if (artisticTag) { relevantSkills.Add(SkillDefOf.Artistic); artisticTag = false; } if (medicineTag) { relevantSkills.Add(SkillDefOf.Medicine); medicineTag = false; } if (socialTag) { relevantSkills.Add(SkillDefOf.Social); socialTag = false; } if (intellectualTag) { relevantSkills.Add(SkillDefOf.Intellectual); intellectualTag = false; } if (!relevantSkills.NullOrEmpty()) { SkillsByTech.Add(tech, relevantSkills); foreach (SkillDef skill in relevantSkills) { if (!TechsBySkill.ContainsKey(skill)) { TechsBySkill.Add(skill, new List <ResearchProjectDef>() { tech }); } else { TechsBySkill[skill].Add(tech); } } } else { Log.Warning("[HumanResources] No relevant skills could be calculated for " + tech + ". It won't be known by anyone."); } }
public override void Draw(Rect visibleRect, bool forceDetailedMode = false) { if (!IsVisible(visibleRect)) { Highlighted = false; return; } var detailedMode = forceDetailedMode; //|| MainTabWindow_ResearchTree.Instance.ZoomLevel < DetailedModeZoomLevelCutoff; var mouseOver = Mouse.IsOver(Rect); if (Event.current.type == EventType.Repaint) { // researches that are completed or could be started immediately, and that have the required building(s) available GUI.color = mouseOver ? GenUI.MouseoverColor : Color; if (mouseOver || Highlighted) { GUI.DrawTexture(Rect, ResearchTree_Assets.ButtonActive); } else { GUI.DrawTexture(Rect, ResearchTree_Assets.Button); } // grey out center to create a progress bar effect, completely greying out research not started. //if (Available) //{ var progressBarRect = Rect.ContractedBy(3f); //GUI.color = Assets.ColorAvailable[Research.techLevel]; GUI.color = Widgets.WindowBGFillColor; if (techComp.expertise.ContainsKey(Research)) { progressBarRect.xMin += techComp.expertise[Research] * progressBarRect.width; } //else //{ // progressBarRect.xMin += Research.ProgressPercent * progressBarRect.width; //} GUI.DrawTexture(progressBarRect, BaseContent.WhiteTex); //} Highlighted = false; // draw the research label if (!Completed && !Available) { GUI.color = Color.grey; } else { GUI.color = Color.white; } if (detailedMode) { Text.Anchor = TextAnchor.UpperLeft; Text.WordWrap = false; Text.Font = _largeLabel ? GameFont.Tiny : GameFont.Small; Widgets.Label(LabelRect, Research.LabelCap); } else { Text.Anchor = TextAnchor.MiddleCenter; Text.WordWrap = false; Text.Font = GameFont.Small;//GameFont.Medium; Widgets.Label(Rect, Research.LabelCap); } // draw research cost and icon if (detailedMode) { Text.Anchor = TextAnchor.UpperRight; Text.Font = Research.CostApparent > 1000000 ? GameFont.Tiny : GameFont.Small; Widgets.Label(CostLabelRect, Research.CostApparent.ToStringByStyle(ToStringStyle.Integer)); GUI.DrawTexture(CostIconRect, !Completed && !Available ? ResearchTree_Assets.Lock : ResearchTree_Assets.ResearchIcon, ScaleMode.ScaleToFit); } Text.WordWrap = true; // attach description and further info to a tooltip TooltipHandler.TipRegion(Rect, GetResearchTooltipString, Research.GetHashCode()); if (!BuildingPresent()) { string root = HarmonyPatches.ResearchPal ? "ResearchPal" : "Fluffy.ResearchTree"; string languageKey = root + ".MissingFacilities"; TooltipHandler.TipRegion(Rect, languageKey.Translate(string.Join(", ", MissingFacilities().Select(td => td.LabelCap).ToArray()))); } // draw unlock icons if (detailedMode) { var unlocks = ResearchTree_Patches.GetUnlockDefsAndDescs(Research); for (var i = 0; i < unlocks.Count; i++) { var iconRect = new Rect( IconsRect.xMax - (i + 1) * (Constants.IconSize.x + 4f), IconsRect.yMin + (IconsRect.height - Constants.IconSize.y) / 2f, Constants.IconSize.x, Constants.IconSize.y); if (iconRect.xMin - Constants.IconSize.x < IconsRect.xMin && i + 1 < unlocks.Count) { // stop the loop if we're about to overflow and have 2 or more unlocks yet to print. iconRect.x = IconsRect.x + 4f; GUI.DrawTexture(iconRect, ResearchTree_Assets.MoreIcon, ScaleMode.ScaleToFit); var tip = string.Join("\n", unlocks.GetRange(i, unlocks.Count - i).Select(p => p.Second).ToArray()); TooltipHandler.TipRegion(iconRect, tip); // new TipSignal( tip, Settings.TipID, TooltipPriority.Pawn ) ); break; } // draw icon unlocks[i].First.DrawColouredIcon(iconRect); // tooltip TooltipHandler.TipRegion(iconRect, unlocks[i].Second); } } } if (Widgets.ButtonInvisible(Rect, true)) { MainButtonDefOf.Research.Worker.InterfaceTryActivate(); ResearchTree_Patches.subjectToShow = Research; } }