private void HandleTooltips() { if (PainterIs(Painter.Drag)) { return; } Text.WordWrap = true; // attach description and further info to a tooltip if (!TechprintAvailable()) { TooltipHandler.TipRegion(Rect, ResourceBank.String.MissingTechprints(Research.TechprintsApplied, Research.techprintCount)); } if (!BuildingPresent()) { TooltipHandler.TipRegion(Rect, ResourceBank.String.MissingFacilities( string.Join(", ", MissingFacilities().Select(td => td.LabelCap) .ToArray()))); } TooltipHandler.TipRegion(Rect, GetResearchTooltipString, Research.GetHashCode()); if (Settings.progressTooltip && ProgressWorthDisplaying() && !Research.IsFinished) { TooltipHandler.TipRegion(Rect, string.Format("Progress: {0}", ProgressString())); } }
/// <summary> /// Draw the node, including interactions. /// </summary> 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, Assets.ButtonActive); } else { GUI.DrawTexture(Rect, 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]; 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.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 ? Assets.Lock : Assets.ResearchIcon, ScaleMode.ScaleToFit); } Text.WordWrap = true; // attach description and further info to a tooltip TooltipHandler.TipRegion(Rect, GetResearchTooltipString, Research.GetHashCode()); if (!BuildingPresent()) { TooltipHandler.TipRegion(Rect, ResourceBank.String.MissingFacilities(string.Join(", ", MissingFacilities().Select(td => td.LabelCap).ToArray()))); } else if (!TechprintAvailable()) { TooltipHandler.TipRegion(Rect, ResourceBank.String.MissingTechprints(Research.TechprintsApplied, Research.techprintCount)); } // draw unlock icons if (detailedMode) { var unlocks = Research.GetUnlockDefsAndDescs(); for (var i = 0; i < unlocks.Count; i++) { var iconRect = new Rect( IconsRect.xMax - (i + 1) * (IconSize.x + 4f), IconsRect.yMin + (IconsRect.height - IconSize.y) / 2f, IconSize.x, IconSize.y); if (iconRect.xMin - 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); 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 (mouseOver) { // highlight prerequisites if research available if (Available) { Highlighted = true; foreach (var prerequisite in GetMissingRequiredRecursive()) { prerequisite.Highlighted = true; } } // highlight children if completed else if (Completed) { foreach (var child in Children) { child.Highlighted = true; } } } } // if clicked and not yet finished, queue up this research and all prereqs. if (Widgets.ButtonInvisible(Rect) && Available) { // LMB is queue operations, RMB is info if (Event.current.button == 0 && !Research.IsFinished) { if (DebugSettings.godMode && Event.current.control) { var nodes = GetMissingRequiredRecursive() .Concat(new List <ResearchNode>(new[] { this })) .Distinct().Reverse(); foreach (ResearchNode n in nodes) { if (Queue.IsQueued(n)) { Queue.Dequeue(n); } if (!n.Research.IsFinished) { Find.ResearchManager.FinishProject(n.Research, false); } } if (nodes.Any()) { Messages.Message(ResourceBank.String.FinishedResearch(Research.LabelCap), MessageTypeDefOf.SilentInput, false); Queue.Notify_InstantFinished(); } } else if (!Queue.IsQueued(this)) { // if shift is held, add to queue, otherwise replace queue var queue = GetMissingRequiredRecursive() .Concat(new List <ResearchNode>(new[] { this })) .Distinct(); Queue.EnqueueRange(queue, Event.current.shift); } else { Queue.Dequeue(this); } } else if (Event.current.button == 1) { ResearchTree.JumpToHelp(Research); } } }
public static bool ResearchNode_Draw_Prefix(object __instance, Rect visibleRect, bool forceDetailedMode = false) { //Reflected objects Rect rect = (Rect)RectInfo.GetValue(__instance); ResearchProjectDef Research = (ResearchProjectDef)ResearchInfo.GetValue(__instance); bool available = (bool)AvailableInfo.GetValue(__instance); bool completed = Research.IsFinished; //simplified // if (!(bool)IsVisibleInfo.Invoke(__instance, new object[] { visibleRect })) { HighlightedProxy(__instance, false); return(false); } bool detailedMode = forceDetailedMode || (float)ZoomLevelInfo.GetValue(InstanceInfo.GetValue(__instance)) < DetailedModeZoomLevelCutoff; bool mouseOver = Mouse.IsOver(rect); bool highlighted = HighlightedProxy(__instance); 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 ? BrightColor : (Color)ColorInfo.GetValue(__instance); 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 = ResearchTree_Assets.ColorAvailable[Research.techLevel]; progressBarRect.xMin += Research.ProgressPercent * progressBarRect.width; GUI.DrawTexture(progressBarRect, BaseContent.WhiteTex); } HighlightedProxy(__instance, interest == Research); //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 = (bool)largeLabelInfo.GetValue(__instance) ? GameFont.Tiny : GameFont.Small; Widgets.Label((Rect)LabelRectInfo.GetValue(__instance), Research.LabelCap); } else { Text.Anchor = TextAnchor.MiddleCenter; Text.WordWrap = false; Text.Font = 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((Rect)CostLabelRectInfo.GetValue(__instance), Research.CostApparent.ToStringByStyle(ToStringStyle.Integer)); GUI.DrawTexture((Rect)CostIconRectInfo.GetValue(__instance), !completed && !available ? ResearchTree_Assets.Lock : ResearchTree_Assets.ResearchIcon, ScaleMode.ScaleToFit); } Text.WordWrap = true; //attach description and further info to a tooltip string root = HarmonyPatches.ResearchPal ? "ResearchPal" : "Fluffy.ResearchTree"; TooltipHandler.TipRegion(rect, new Func <string>(() => (string)GetResearchTooltipStringInfo.Invoke(__instance, new object[] { })), Research.GetHashCode()); if (!BuildingPresentProxy(Research)) { string languageKey = root + ".MissingFacilities"; TooltipHandler.TipRegion(rect, languageKey.Translate(string.Join(", ", MissingFacilities(Research).Select(td => td.LabelCap).ToArray()))); } else if (!TechprintAvailable(Research)) { string languageKey = root + ".MissingTechprints"; TooltipHandler.TipRegion(rect, languageKey.Translate(Research.TechprintsApplied, Research.techprintCount)); } //draw unlock icons if (detailedMode) { Rect IconsRect = (Rect)IconsRectInfo.GetValue(__instance); var unlocks = GetUnlockDefsAndDescs(Research); for (var i = 0; i < unlocks.Count; i++) { var iconRect = new Rect( IconsRect.xMax - (i + 1) * (IconSize.x + 4f), IconsRect.yMin + (IconsRect.height - IconSize.y) / 2f, IconSize.x, IconSize.y); if (iconRect.xMin - 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 (mouseOver) { if (interest != null && interest != Research) { DeInterest(); } //highlight prerequisites if research available if (available) { HighlightedProxy(__instance, true); foreach (var prerequisite in (IEnumerable <object>)GetMissingRequiredRecursiveInfo.Invoke(__instance, new object[] { })) { HighlightedProxy(Convert.ChangeType(prerequisite, ResearchNodeType()), true); } } //highlight children if completed else if (completed) { foreach (var child in (IEnumerable <object>)ChildrenInfo.GetValue(__instance)) { HighlightedProxy(Convert.ChangeType(child, ResearchNodeType()), true); } } } } //CUSTOM: a bunch of things on top Research.DrawExtras(rect, mouseOver || highlighted); if (Widgets.ButtonInvisible(rect)) { //CUSTOM: replaced queue operations for assignment menu if (Event.current.button == 0) { Research.SelectMenu(completed); } if (DebugSettings.godMode && Prefs.DevMode && Event.current.button == 1 && !Research.IsFinished) { Find.ResearchManager.FinishProject(Research); Research.WipeAssignments(); } } return(false); }
public void DoDraw(Rect visibleRect, bool forceDetailedMode = false, bool notDrawingSelected = true) { if (!IsVisible(visibleRect)) { Highlighted = false; DarkHighlighted = false; return; } var detailedMode = forceDetailedMode || ResearchWindow.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 && ResearchSelectPanel.selected != this ? GenUI.MouseoverColor : Color; GUI.color = Color; if (notDrawingSelected && (mouseOver || Highlighted)) { GUI.DrawTexture(Rect, Assets.ButtonActive); } else { GUI.DrawTexture(Rect, Assets.Button); } // grey out center to create a progress bar effect, completely greying out research not started. var progressBarRect = Rect.ContractedBy(3f); GUI.color = Assets.ColorAvailable[Research.techLevel]; progressBarRect.xMin += progressBarRect.width; GUI.DrawTexture(progressBarRect, BaseContent.WhiteTex); Highlighted = false; DarkHighlighted = false; GUI.color = Color.white; if (detailedMode) { Text.Anchor = TextAnchor.UpperLeft; Text.WordWrap = false; Text.Font = _largeLabel && notDrawingSelected ? GameFont.Tiny : GameFont.Small; Widgets.Label(LabelRect, Research.LabelCap); } else { Text.Anchor = TextAnchor.MiddleCenter; Text.WordWrap = false; Text.Font = GameFont.Medium; Widgets.Label(Rect, Research.LabelCap); } // draw research cost and icon if (detailedMode) { Text.Anchor = TextAnchor.UpperRight; Text.Font = Research.baseCost > 1000000 ? GameFont.Tiny : GameFont.Small; if (Research.techprintCount == 0) { Widgets.Label(CostLabelRect, Research.baseCost.ToStringByStyle(ToStringStyle.Integer)); GUI.DrawTexture(CostIconRect, Assets.ResearchIcon, ScaleMode.ScaleToFit); } else { int printsNeeded = Research.techprintCount; string label = printsNeeded.ToString(); Text.Font = GameFont.Tiny; Widgets.Label(CostLabelRect, label); GUI.DrawTexture(CostIconRect, shardTex, ScaleMode.ScaleToFit); if (!notDrawingSelected) { Rect selectedCostIconRect = new Rect(CostIconRect.x, CostIconRect.yMax + 2f, CostIconRect.width, CostIconRect.height); GUI.DrawTexture(selectedCostIconRect, Assets.ResearchIcon, ScaleMode.ScaleToFit); Rect selectedCostLabelRect = new Rect(CostLabelRect.x, selectedCostIconRect.y, CostLabelRect.width, CostLabelRect.height); Widgets.Label(selectedCostLabelRect, Research.baseCost.ToStringByStyle(ToStringStyle.Integer)); } } } Text.WordWrap = true; // attach description and further info to a tooltip TooltipHandler.TipRegion(Rect, GetResearchTooltipString, Research.GetHashCode()); /* if ( !BuildingPresent() ) * { * TooltipHandler.TipRegion( Rect, * ResourceBank.String.MissingFacilities( string.Join( ", ", * MissingFacilities().Select( td => td.LabelCap ).ToArray() ) ) ); * } else if (!TechprintAvailable()) { * TooltipHandler.TipRegion(Rect, * ResourceBank.String.MissingTechprints(Research.TechprintsApplied, Research.techprintCount)); * } */ // draw unlock icons if (detailedMode && notDrawingSelected) { var unlocks = Research.GetUnlockDefsAndDescs(); for (var i = 0; i < unlocks.Count; i++) { var iconRect = new Rect( IconsRect.xMax - (i + 1) * (IconSize.x + 4f), IconsRect.yMin + (IconsRect.height - IconSize.y) / 2f, IconSize.x, IconSize.y); if (iconRect.xMin - 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); 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); } } } else if (mouseOver) { if (Event.current.button == 0 && Event.current.type == EventType.MouseUp && ResearchSelectPanel._instance.draggingDef != null && ResearchSelectPanel.selected != this) { ResearchProjectEditor.SwapUnlockable(ResearchSelectPanel.selected, this, ResearchSelectPanel._instance.draggingDef.def); } } // if clicked and not yet finished, queue up this research and all prereqs. if (Widgets.ButtonInvisible(Rect)) { DoClick(); } }
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; } }
private static void DrawPawnAssignments(ResearchProjectDef tech, float height, Vector2 frameOffset, float startPos) { Vector2 position; Vector2 size = new Vector2(height, height); using (IEnumerator <Pawn> enumerator = currentPawns.Where(p => HasBeenAssigned(p, tech)).GetEnumerator()) { while (enumerator.MoveNext()) { position = new Vector2(startPos, frameOffset.y); Rect box = new Rect(position, size); Rect clickBox = new Rect(position.x + frameOffset.x, position.y, size.x - (2 * frameOffset.x), size.y); Pawn pawn = enumerator.Current; GUI.DrawTexture(box, PortraitsCache.Get(pawn, size, Rot4.South, cameraZoom: 1.2f)); if (Widgets.ButtonInvisible(clickBox)) { pawn.TryGetComp <CompKnowledge>().CancelBranch(tech); } TooltipHandler.TipRegion(clickBox, new Func <string>(() => AssignmentStatus(pawn, tech)), tech.GetHashCode()); startPos += height / 2; } } }