public void JumpTo(HelpDef helpDef) { Find.MainTabsRoot.SetCurrentTab(this.def); ResetFilter(); _jump = true; SelectedHelpDef = helpDef; HelpCategoryDef cat = DefDatabase <HelpCategoryDef> .AllDefsListForReading.First(hc => hc.HelpDefs.Contains(helpDef)); cat.Expanded = true; ModCategory mod = CachedHelpCategories.First(mc => mc.HelpCategories.Contains(cat)); mod.Expanded = true; }
public void DrawHelpEntry(ref Vector2 cur, int nestLevel, Rect view, HelpDef helpDef) { bool selected = SelectedHelpDef == helpDef; if (selected && _jump) { SelectionScrollPos.y = cur.y; _jump = false; } if (DrawEntry(ref cur, nestLevel, view, helpDef.LabelCap, State.Leaf, selected)) { SelectedHelpDef = helpDef; } }
public IHelpDefView SecondaryView(HelpDef def) { return(null); }
public bool Accept(HelpDef def) { return(true); }
void DrawSelectionArea(Rect rect) { entryCounter = 0; Widgets.DrawMenuSection(rect); FilterUpdate(); var filterRect = new Rect(rect.xMin + WindowMargin, rect.yMin + WindowMargin, rect.width - (3 * WindowMargin) - 30f, 30f); var clearRect = new Rect(filterRect.xMax + WindowMargin + 3f, rect.yMin + WindowMargin + 3f, 24f, 24f); _filterString = Widgets.TextField(filterRect, _filterString); if (_filterString != "") { if (Widgets.ButtonImage(clearRect, Widgets.CheckboxOffTex)) { _filterString = ""; Filter(); } } Rect outRect = rect; outRect.yMin += 40f; outRect.xMax -= 2f; // some spacing around the scrollbar var viewWidth = SelectionHeight > outRect.height ? outRect.width - 16f : outRect.width; var viewRect = new Rect(0f, 0f, viewWidth, SelectionHeight); GUI.BeginGroup(outRect); Widgets.BeginScrollView(outRect.AtZero(), ref SelectionScrollPos, viewRect); if (CachedHelpCategories.Count(mc => mc.ShouldDraw) < 1) { Rect messageRect = outRect.AtZero(); Widgets.Label(messageRect, "NoHelpDefs".Translate()); } else { Vector2 cur = Vector2.zero; // This works fine for the current artificial three levels of helpdefs. // Can easily be adapted by giving each category a list of subcategories, // and migrating the responsibility for drawing them and the helpdefs to DrawCatEntry(). // Would also require some minor adaptations to the filter methods, but nothing major. // - Fluffy. foreach (ModCategory mc in CachedHelpCategories.Where(mc => mc.ShouldDraw)) { DrawModEntry(ref cur, 0, viewRect, mc); cur.x += EntryIndent; if (!mc.Expanded) { continue; } foreach (HelpCategoryDef hc in mc.HelpCategories.Where(hc => hc.ShouldDraw)) { DrawCatEntry(ref cur, 1, viewRect, hc); if (!hc.Expanded) { continue; } foreach (HelpDef hd in hc.HelpDefs.Where(hd => hd.ShouldDraw)) { if (entryCounter >= MaxEntryCount) { var lastItem = new HelpDef { defName = hd.defName, label = "MaxAmountOfHits".Translate(), category = hd.category }; DrawHelpEntry(ref cur, 1, viewRect, lastItem); break; } DrawHelpEntry(ref cur, 1, viewRect, hd); } if (entryCounter >= MaxEntryCount) { break; } } if (entryCounter >= MaxEntryCount) { break; } } SelectionHeight = cur.y; } Widgets.EndScrollView(); GUI.EndGroup(); }
public void Draw(ref Vector2 cur, Vector3 colWidths, IHelpDefView window = null) { // calculate height of row, or fetch from cache if (!_heightSet) { List <float> heights = new List <float>(); if (!Prefix.NullOrEmpty()) { heights.Add(Text.CalcHeight(Prefix, colWidths.x)); } heights.Add(Text.CalcHeight(Def.LabelStyled(), colWidths.y)); if (!Suffix.NullOrEmpty()) { heights.Add(Text.CalcHeight(Suffix, colWidths.z)); } _height = heights.Max(); _heightSet = true; } // draw text if (!Prefix.NullOrEmpty()) { Rect prefixRect = new Rect(cur.x, cur.y, colWidths.x, _height); Widgets.Label(prefixRect, Prefix); } if (!Suffix.NullOrEmpty()) { Rect suffixRect = new Rect(cur.x + colWidths.x + colWidths.y + 2 * HelpDetailSection._columnMargin, cur.y, colWidths.z, _height); Widgets.Label(suffixRect, Suffix); } Rect labelRect; if (Def.IconTexture() != null) { Rect iconRect = new Rect(cur.x + colWidths.x + (Prefix.NullOrEmpty() ? 0 : 1) * HelpDetailSection._columnMargin, cur.y + 2f, 16f, 16f); labelRect = new Rect(cur.x + colWidths.x + 20f + (Prefix.NullOrEmpty() ? 0 : 1) * HelpDetailSection._columnMargin, cur.y, colWidths.y - 20f, _height); Def.DrawColouredIcon(iconRect); Widgets.Label(labelRect, Def.LabelStyled()); } else { labelRect = new Rect(cur.x + colWidths.x + (Prefix.NullOrEmpty() ? 0 : 1) * HelpDetailSection._columnMargin, cur.y, colWidths.y, _height); Widgets.Label(labelRect, Def.LabelStyled()); } // def interactions (if any) // if we have a window set up to catch jumps, and there is a helpdef available, draw a button on the def text. HelpDef helpDef = Def.GetHelpDef(); if ( (window != null) && (helpDef != null) ) { TooltipHandler.TipRegion(labelRect, Def.description + (Def.description.NullOrEmpty() ? "" : "\n\n") + ResourceBank.String.JumpToTopic); if (Widgets.ButtonInvisible(labelRect)) { if (window.Accept(helpDef)) { window.JumpTo(helpDef); } else { window.SecondaryView(helpDef).JumpTo(helpDef); } } } if ( (helpDef == null) && (!Def.description.NullOrEmpty()) ) { TooltipHandler.TipRegion(labelRect, Def.description); } cur.y += _height - MainTabWindow_ModHelp.LineHeigthOffset; }