private List <Pair <Def, string> > Unlocks() { if (_unlocks == null) { _unlocks = Research.GetUnlockDefsAndDescs(); } return(_unlocks); }
public int Matches(string query) { var culture = CultureInfo.CurrentUICulture; query = query.ToLower(culture); if (Research.LabelCap.ToLower(culture).Contains(query)) { return(1); } if (Research.GetUnlockDefsAndDescs().Any(unlock => unlock.First.LabelCap.ToLower(culture).Contains(query))) { return(2); } if (Research.description.ToLower(culture).Contains(query)) { return(3); } return(0); }
/// <summary> /// Draw the node, including interactions. /// </summary> public bool Draw() { // cop out if off-screen Rect screen = new Rect(MainTabWindow_ResearchTree._scrollPosition.x, MainTabWindow_ResearchTree._scrollPosition.y, Screen.width, Screen.height - 35); if (Rect.xMin > screen.xMax || Rect.xMax < screen.xMin || Rect.yMin > screen.yMax || Rect.yMax < screen.yMin) { return(false); } // set color GUI.color = !Research.PrerequisitesCompleted ? AdjustFilterAlpha(Tree.GreyedColor) : AdjustFilterAlpha(Tree.MediumColor); // mouseover highlights if (Mouse.IsOver(Rect)) { // active button GUI.DrawTexture(Rect, ResearchTree.ButtonActive); // highlight this and all prerequisites if research not completed if (!Research.IsFinished) { HighlightWithPrereqs(); } else // highlight followups { foreach (Node child in Children) { MainTabWindow_ResearchTree.highlightedConnections.Add(new Pair <Node, Node>(this, child)); child.Highlight(GenUI.MouseoverColor, false, false); } } } // filter highlights else if (_matchType.IsValidMatch()) { GUI.DrawTexture(Rect, ResearchTree.ButtonActive); if (Settings.showFilteredLinks) { HighlightWithPrereqs(); } else { Highlight(GenUI.MouseoverColor, false, false); } } // if not moused over, just draw the default button state else { GUI.DrawTexture(Rect, ResearchTree.Button); } // grey out center to create a progress bar effect, completely greying out research not started. bool warnLocked = false, warnPenalty = false; if (!Research.IsFinished) { Rect progressBarRect = Rect.ContractedBy(2f); GUI.color = AdjustFilterAlpha(Tree.GreyedColor); progressBarRect.xMin += Research.ProgressPercent * progressBarRect.width; GUI.DrawTexture(progressBarRect, BaseContent.WhiteTex); warnLocked = IsLocked(Research); warnPenalty = Research.techLevel > Faction.OfPlayer.def.techLevel; } // draw the research label GUI.color = AdjustFilterAlpha(Color.white); Text.Anchor = TextAnchor.UpperLeft; Text.WordWrap = true; Text.Font = _largeLabel ? GameFont.Tiny : GameFont.Small; Widgets.Label(LabelRect, StringExtensions.TitleCase(Research.LabelCap)); // draw research cost and icon Text.Anchor = TextAnchor.UpperRight; Text.Font = GameFont.Small; if (warnPenalty) { GUI.color = AdjustFilterAlpha(Color.yellow); } Widgets.Label(CostLabelRect, Research.CostApparent.ToStringByStyle(ToStringStyle.Integer)); GUI.color = AdjustFilterAlpha(Color.white); if (warnLocked) { GUI.DrawTexture(CostIconRect, WarningIcon); } else { GUI.DrawTexture(CostIconRect, ResearchIcon); } Text.WordWrap = true; // attach description and further info to a tooltip TooltipHandler.TipRegion(Rect, GetResearchTooltipString()); // new TipSignal( GetResearchTooltipString(), Settings.TipID ) ); // draw unlock icons List <Pair <Def, string> > unlocks = Research.GetUnlockDefsAndDescs(); for (int i = 0; i < unlocks.Count; i++) { Rect iconRect = new Rect(IconsRect.xMax - (i + 1) * (Settings.IconSize.x + 4f), IconsRect.yMin + (IconsRect.height - Settings.IconSize.y) / 2f, Settings.IconSize.x, Settings.IconSize.y); if (iconRect.xMin - Settings.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; ResearchTree.MoreIcon.DrawFittedIn(iconRect, NodeAlpha()); string 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, NodeAlpha()); // tooltip TooltipHandler.TipRegion(iconRect, unlocks[i].Second); // new TipSignal( unlocks[i].Second, Settings.TipID, TooltipPriority.Pawn ) ); // reset the color GUI.color = Color.white; } // if clicked and not yet finished, queue up this research and all prereqs. if (Widgets.ButtonInvisible(Rect)) { // LMB is queue operations, RMB is info if (Event.current.button == 0 && !Research.IsFinished) { if (Settings.debugResearch && Prefs.DevMode && Event.current.control) { List <Node> nodesToResearch = GetMissingRequiredRecursive().Concat(new List <Node>(new[] { this })).ToList(); foreach (Node n in nodesToResearch) { if (Queue.IsQueued(n)) { Queue.Dequeue(n); } if (!n.Research.IsFinished) { Find.ResearchManager.InstantFinish(n.Research, false); } } Verse.Sound.SoundStarter.PlayOneShotOnCamera(MessageTypeDefOf.PositiveEvent.sound); } else { if (!Queue.IsQueued(this)) { if (warnLocked) { Messages.Message(ResourceBank.String.RequireMissing, MessageTypeDefOf.RejectInput); } // if shift is held, add to queue, otherwise replace queue Queue.EnqueueRange(GetMissingRequiredRecursive().Concat(new List <Node> (new [] { this })), Event.current.shift); } else { Queue.Dequeue(this); } } } else if (Event.current.button == 1) { ResearchPalMod.JumpToHelp(Research); } } return(true); }
/// <summary> /// Draw the node, including interactions. /// </summary> public override void Draw() { // cop out if off-screen var screen = new Rect(MainTabWindow_ResearchTree._scrollPosition.x, MainTabWindow_ResearchTree._scrollPosition.y, Screen.width, Screen.height - 35); if (Rect.xMin > screen.xMax || Rect.xMax < screen.xMin || Rect.yMin > screen.yMax || Rect.yMax < screen.yMin) { return; } // researches that are completed or could be started immediately, and that have the required building(s) available GUI.color = DrawColor; // mouseover highlights if (Mouse.IsOver(Rect)) // TODO: commented out for debug && BuildingPresent() ) { // active button GUI.DrawTexture(Rect, Assets.ButtonActive); // highlight this and all prerequisites if research not completed if (!Research.IsFinished) { List <ResearchNode> prereqs = GetMissingRequiredRecursive(); Highlight(GenUI.MouseoverColor, true, false); foreach (ResearchNode prerequisite in prereqs) { prerequisite.Highlight(GenUI.MouseoverColor, true, false); } } else // highlight followups { foreach (ResearchNode child in Children) { MainTabWindow_ResearchTree.highlightedConnections.Add(new Pair <ResearchNode, ResearchNode>(this, child)); child.Highlight(GenUI.MouseoverColor, false, false); } } } // if not moused over, just draw the default button state else { GUI.DrawTexture(Rect, Assets.Button); } // grey out center to create a progress bar effect, completely greying out research not started. if (!Research.IsFinished) { Rect progressBarRect = Rect.ContractedBy(2f); GUI.color = DrawColor / 2f; progressBarRect.xMin += Research.ProgressPercent * progressBarRect.width; GUI.DrawTexture(progressBarRect, BaseContent.WhiteTex); } // draw the research label GUI.color = Color.white; Text.Anchor = TextAnchor.UpperLeft; Text.WordWrap = false; Text.Font = _largeLabel ? GameFont.Tiny : GameFont.Small; Widgets.Label(LabelRect, Research.LabelCap); // draw research cost and icon Text.Anchor = TextAnchor.UpperRight; Text.Font = GameFont.Small; Widgets.Label(CostLabelRect, Research.CostApparent.ToStringByStyle(ToStringStyle.Integer)); GUI.DrawTexture(CostIconRect, Assets.ResearchIcon); Text.WordWrap = true; // attach description and further info to a tooltip TooltipHandler.TipRegion(Rect, GetResearchTooltipString()); if (!BuildingPresent()) { TooltipHandler .TipRegion(Rect, "Fluffy.ResearchTree.MissingFacilities".Translate(string.Join(", ", MissingFacilities().Select(td => td.LabelCap).ToArray()))); } // new TipSignal( GetResearchTooltipString(), Settings.TipID ) ); // draw unlock icons List <Pair <Def, string> > unlocks = Research.GetUnlockDefsAndDescs(); for (var i = 0; i < unlocks.Count; i++) { var iconRect = new Rect(IconsRect.xMax - (i + 1) * (Settings.IconSize.x + 4f), IconsRect.yMin + (IconsRect.height - Settings.IconSize.y) / 2f, Settings.IconSize.x, Settings.IconSize.y); if (iconRect.xMin - Settings.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, Assets.MoreIcon, ScaleMode.ScaleToFit); string 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); // new TipSignal( unlocks[i].Second, Settings.TipID, TooltipPriority.Pawn ) ); } // if clicked and not yet finished, queue up this research and all prereqs. if (Widgets.ButtonInvisible(Rect) && BuildingPresent()) { // LMB is queue operations, RMB is info if (Event.current.button == 0 && !Research.IsFinished) { if (!Queue.IsQueued(this)) { // if shift is held, add to queue, otherwise replace queue Queue.EnqueueRange(GetMissingRequiredRecursive().Concat(new List <ResearchNode>(new[] { this })), Event.current.shift); } else { Queue.Dequeue(this); } } } }