private void DoDrives(Rect rect) { //Widgets.DrawBox(rect); Widgets.DrawBoxSolid(rect, this.drivesBackgroundColor); Text.Font = GameFont.Small; Text.Anchor = TextAnchor.MiddleLeft; float buttonHeight = 24; Rect rectView = new Rect(0, 0, rect.width - this.scrollBarWidth, buttonHeight * this.drives.Count()); Widgets.BeginScrollView(rect, ref this.drivesScrollPos, rectView); int index = 0; foreach (string drive in this.drives) { Rect rectButton = new Rect(rectView.x, rectView.y + index * buttonHeight, rectView.width + this.scrollBarWidth, buttonHeight); if (Widgets.ButtonText(rectButton, $" {drive}", false, false, true)) { this.currentPath = drive; this.dirInfoDirty = true; this.soundAmbient.PlayOneShotOnCamera(null); } if (drive == Path.GetPathRoot(this.currentPath)) { Widgets.DrawHighlightSelected(rectButton); } else { Widgets.DrawHighlightIfMouseover(rectButton); } index++; } Widgets.EndScrollView(); }
private void DrawListEntry(Rect entryRect, AIPackageDef p, ref AIPackageDef selPackage, ref AIPackageDef unselPackage, bool alternate) { if (IsSelected(p)) { Widgets.DrawHighlightSelected(entryRect); if (Mouse.IsOver(entryRect)) TooltipHandler.TipRegion(entryRect, p.Tooltip); } else if (Mouse.IsOver(entryRect)) { Widgets.DrawHighlight(entryRect); TooltipHandler.TipRegion(entryRect, p.Tooltip); } else if (alternate) Widgets.DrawAltRect(entryRect); Text.Anchor = TextAnchor.MiddleCenter; Widgets.Label(entryRect, $" {p.LabelCap}"); Text.Anchor = TextAnchor.UpperLeft; if (Widgets.ButtonInvisible(entryRect)) { selPackage = p; unselPackage = null; } }
public float Draw(float x, float y, float width, bool selected, Action clickedCallback) { float num = (float)(width * 0.44999998807907104); Rect rect = new Rect(8f, y, width, Text.CalcHeight(this.ValueString, num)); if (selected) { Widgets.DrawHighlightSelected(rect); } else if (Mouse.IsOver(rect)) { Widgets.DrawHighlight(rect); } Rect rect2 = rect; rect2.width -= num; Widgets.Label(rect2, this.LabelCap); Rect rect3 = rect; rect3.x = rect2.xMax; rect3.width = num; Widgets.Label(rect3, this.ValueString); if (this.stat != null) { StatDef localStat = this.stat; TooltipHandler.TipRegion(rect, new TipSignal(() => localStat.LabelCap + ": " + localStat.description, this.stat.GetHashCode())); } if (Widgets.ButtonInvisible(rect, false)) { clickedCallback(); } return(rect.height); }
public virtual void DoModButton(Rect canvas, bool alternate = false, Action clickAction = null, Action doubleClickAction = null, bool deemphasizeFiltered = false, string filter = null) { #if DEBUG clickAction += () => Debug.Log("clicked: " + Name); doubleClickAction += () => Debug.Log("doubleClicked: " + Name); #endif if (alternate) { Widgets.DrawBoxSolid(canvas, Resources.SlightlyDarkBackground); } if (Page_BetterModConfig.Instance.Selected == this) { if (Page_BetterModConfig.Instance.SelectedHasFocus) { Widgets.DrawHighlightSelected(canvas); } else { Widgets.DrawHighlight(canvas); } } if (!DraggingManager.Dragging) { HandleInteractions(canvas, clickAction, doubleClickAction); } }
private void DoGeneralRect(Rect rect) { string generalLabel = I18n.GeneralSettingsLabel; Widgets.Label(rect, generalLabel.Bolded()); Widgets.DrawLightHighlight(rect); if (Widgets.ButtonInvisible(rect)) { SoundDefOf.Click.PlayOneShotOnCamera(); if (selected == GeneralSettingsContent) { selected = Drawer.Empty; } else { selected = GeneralSettingsContent; } } if (selected == GeneralSettingsContent) { Widgets.DrawHighlightSelected(rect); } else if (Mouse.IsOver(rect)) { Widgets.DrawHighlight(rect); } }
/// <summary> /// Draw a lable which doubles as a button. /// </summary> /// <param name="rect"> Rect for drawing. </param> /// <param name="label"> Label to draw in <paramref name="rect"/>. </param> /// <param name="action"> Action to take when it is clicked. </param> /// <param name="toggleable"> Indicates if button can be toggled and uses a selected texture if true. </param> public static void DrawLabelButton(Rect rect, string label, Action action, bool toggleable) { Text.WordWrap = false; Text.Anchor = TextAnchor.MiddleLeft; Widgets.Label(rect, label); if (toggleable) { if (Mouse.IsOver(rect)) { Widgets.DrawHighlightSelected(rect); } } else { Widgets.DrawHighlightIfMouseover(rect); } if (Widgets.ButtonInvisible(rect)) { action?.Invoke(); } Text.Anchor = TextAnchor.UpperLeft; Text.WordWrap = true; }
public static void Draw(Rect canvas) { GUI.BeginGroup(canvas); var menuRect = new Rect(0f, 0f, canvas.width * 0.25f, canvas.height); var menuInnerRect = new Rect(0f, 0f, menuRect.width - 8f, menuRect.height - 8f); var menuView = new Rect(0f, 0f, menuInnerRect.width - 16f, Text.LineHeight * PageCount); var pageRect = new Rect( menuRect.x + menuRect.width + 5f, 0f, canvas.width - menuRect.width - 5f, canvas.height ); var pageInnerRect = new Rect(0f, 0f, pageRect.width, pageRect.height); var pageView = new Rect(0f, 0f, pageRect.width - 16f, Text.LineHeight * 13); var listing = new Listing_Standard(); Widgets.DrawMenuSection(menuRect); listing.Begin(menuRect.ContractedBy(4f)); Widgets.BeginScrollView(menuInnerRect, ref _menuScrollPos, menuView); foreach (string page in Pages) { Rect lineRect = listing.GetRect(Text.LineHeight); if (_lastPage == page) { Widgets.DrawHighlightSelected(lineRect); } Widgets.Label(lineRect, $"RDA.Settings.{page}".Translate()); if (Widgets.ButtonInvisible(lineRect)) { _lastPage = page; } } listing.End(); Widgets.EndScrollView(); listing.Begin(pageRect); Widgets.BeginScrollView(pageInnerRect, ref _pageScrollPos, pageView); switch (_lastPage) { case "General": DrawGeneralPage(listing); break; case "Experimental": DrawExperimentalPage(listing); break; } listing.End(); Widgets.EndScrollView(); GUI.EndGroup(); }
private void DrawDesignEntry(Rect rect, Blueprint bp, bool alternate) { try { GUI.BeginGroup(rect); Rect entryRect = new Rect(0f, 0f, rect.width, rect.height - DesignEntryMargin); if (Widgets.ButtonInvisible(entryRect)) { if (selBlueprint != null && selBlueprint == bp) { selBlueprint = null; } else { selBlueprint = bp; bpHandler = new BlueprintWindowHandler(selBlueprint, BlueprintHandlerState.Normal); bpHandler.CloseButtonVisible = false; bpHandler.EditButtonVisible = true; } } if (selBlueprint != null && selBlueprint == bp) { Widgets.DrawHighlightSelected(entryRect); } else if (Mouse.IsOver(entryRect)) { Widgets.DrawHighlight(entryRect); } else if (alternate) { Widgets.DrawAltRect(entryRect); } Rect textRect = new Rect(SectionMargin, 0, entryRect.width - SectionMargin, entryRect.height); Text.Anchor = TextAnchor.MiddleLeft; Widgets.Label(textRect, bp.Label); Text.Anchor = TextAnchor.UpperLeft; string text = bp.ChassisType == ChassisType.Small ? "SmallChassis".Translate() : bp.ChassisType == ChassisType.Medium ? "MediumChassis".Translate() : bp.ChassisType == ChassisType.Large ? "LargeChassis".Translate() : "Undefined droid chassis "; text += " "; Text.Anchor = TextAnchor.LowerRight; Text.Font = GameFont.Tiny; Widgets.Label(textRect, text); Text.Anchor = TextAnchor.UpperLeft; Text.Font = GameFont.Small; } finally { GUI.EndGroup(); Text.Anchor = TextAnchor.UpperLeft; } }
private static void AddHighlightToLabel_PostFix(Rect rect, Pawn pawn) { if (!Numbers_Settings.pawnTableHighlightSelected) { return; } if (Find.Selector.IsSelected(pawn)) { Widgets.DrawHighlightSelected(rect); } }
public static void Postfix(Rect rect, Pawn pawn) { if (!Settings.Get().pawnTableHighlightSelected) { return; } if (Find.Selector.IsSelected(pawn)) { Widgets.DrawHighlightSelected(rect); } }
/// <summary> /// Generic method for drawing the squares. /// </summary> /// <param name="cur">Current x,y vector</param> /// <param name="nestLevel">Level of nesting for indentation</param> /// <param name="view">Size of viewing area (assumed vertically scrollable)</param> /// <param name="label">Label to show</param> /// <param name="state">State of collapsing icon to show</param> /// <param name="selected">For leaf entries, is this entry selected?</param> /// <returns></returns> public bool DrawEntry(ref Vector2 cur, int nestLevel, Rect view, string label, State state, bool selected = false) { entryCounter++; cur.x = nestLevel * EntryIndent; var iconOffset = ArrowImageSize.x + (2 * WindowMargin); var width = view.width - cur.x - iconOffset - WindowMargin; var height = EntryHeight; if (Text.CalcHeight(label, width) > EntryHeight) { Text.Font = GameFont.Tiny; var height2 = Text.CalcHeight(label, width); height = Mathf.Max(height, height2); } if (state != State.Leaf) { var iconRect = new Rect(cur.x + WindowMargin, cur.y + (height / 2) - (ArrowImageSize.y / 2), ArrowImageSize.x, ArrowImageSize.y); GUI.DrawTexture(iconRect, state == State.Expanded ? ResourceBank.Icon.HelpMenuArrowDown : ResourceBank.Icon.HelpMenuArrowRight); } Text.Anchor = TextAnchor.MiddleLeft; var labelRect = new Rect(cur.x + iconOffset, cur.y, width, height); Widgets.Label(labelRect, label); Text.Anchor = TextAnchor.UpperLeft; Text.Font = GameFont.Small; // full viewRect width for overlay and button var buttonRect = view; buttonRect.yMin = cur.y; cur.y += height; buttonRect.yMax = cur.y; GUI.color = Color.grey; Widgets.DrawLineHorizontal(view.xMin, cur.y, view.width); GUI.color = Color.white; if (selected) { Widgets.DrawHighlightSelected(buttonRect); } else { Widgets.DrawHighlightIfMouseover(buttonRect); } return(Widgets.ButtonInvisible(buttonRect)); }
private void DrawLeftRectAsOptions(Rect rect, IEnumerable <RecipeSpec> options) { Widgets.DrawMenuSection(rect, false); GUI.BeginGroup(rect); float y = 0; int i = 0; Text.Anchor = TextAnchor.MiddleCenter; foreach (var s in options) { var row = new Rect(0f, y, rect.width, 50f); Widgets.DrawHighlightIfMouseover(row); var labelRec = new Rect(row.x, row.y, row.width, row.height); Widgets.Label(labelRec, s.ProductLabel); if (_selected == s.Label) { Widgets.DrawHighlightSelected(row); } if (i++ % 2 == 1) { Widgets.DrawAltRect(row); } y += 50f; if (Widgets.ButtonInvisible(row)) { _selected = s.Label; SoundDefOf.CheckboxTurnedOn.PlayOneShotOnCamera(); } } var buttonRect = new Rect(35f, rect.height - 80f, rect.width - 70f, 50f); Text.Anchor = TextAnchor.MiddleCenter; if (Widgets.ButtonText(buttonRect, "Choose")) { MateriaMod.Instance.SetChoice(_selected); SoundDefOf.Click.PlayOneShotOnCamera(); } Text.Anchor = TextAnchor.UpperLeft; GUI.EndGroup(); }
public void DoMainList(Rect canvas, float itemHeight) { int profileCount = ProfileManager.profiles.Count(); float viewHeight = (float)profileCount * itemHeight; Rect topLabel = new Rect(canvas.x, canvas.y, canvas.width, itemHeight); Widgets.Label(topLabel, "Profiles:"); Rect addNameRect = new Rect(topLabel.x, topLabel.yMax, canvas.width, Text.LineHeight); currentAddText = Widgets.TextField(addNameRect, currentAddText); Rect outRect = new Rect(addNameRect.x, addNameRect.yMax + 5f, addNameRect.width, canvas.height); Rect viewRect = new Rect(addNameRect.x, addNameRect.yMax + 5f, addNameRect.width - 16f, viewHeight); float curHeight = 0f; Widgets.BeginScrollView(outRect, ref fileScrollPosition, viewRect, true); using (var enumerator = ProfileManager.profiles.GetEnumerator()) { while (enumerator.MoveNext()) { Profile current = enumerator.Current; Rect rowRect = new Rect(outRect.x, outRect.y + curHeight, canvas.width, itemHeight); if (selectedProfile == current) { Widgets.DrawHighlightSelected(rowRect); } else if (Mouse.IsOver(rowRect)) { Widgets.DrawHighlight(rowRect); } else { Widgets.DrawLightHighlight(rowRect); } GUI.BeginGroup(rowRect); Rect labelRect = new Rect(0f, 0f, canvas.width, itemHeight); Widgets.Label(labelRect, current.ToString()); GUI.EndGroup(); if (Mouse.IsOver(rowRect) && Event.current.type == EventType.MouseDown && Event.current.button == 0) { SelectProfile(current); } curHeight += itemHeight; } } Widgets.EndScrollView(); }
public void Drow() { if (DataSource == null) { return; } ScrollPosition = GUI.BeginScrollView( Area , ScrollPosition , new Rect(0, 0, Area.width - WidthScrollLine, DataSource.Count * TextHeight)); var rect = new Rect(0, 0, Area.width - WidthScrollLine, TextHeight); for (int i = 0; i < DataSource.Count; i++) { var text = DataSource[i].ToString(); Widgets.Label(rect, text); if (i == SelectedIndex) { Widgets.DrawHighlightSelected(rect); //Widgets.DrawHighlight(rect); } if (Mouse.IsOver(rect)) { Widgets.DrawHighlight(rect); } if (Tooltip != null) { var tt = Tooltip(DataSource[i]); if (!string.IsNullOrEmpty(tt)) { TooltipHandler.TipRegion(rect, tt); } } if (Widgets.ButtonInvisible(rect)) { SelectedIndex = i; if (OnClick != null) { OnClick(i, DataSource[i]); } } rect.y += TextHeight; } GUI.EndScrollView(); }
private static void DrawTabs(Tab tab) { DubGUI.ResetFont(); yOffset += 40f; var row = listing.GetRect(30f); if (tab.category == Category.Settings) { if (GUIController.GetCurrentTab == tab) { Widgets.DrawHighlightSelected(row); } Widgets.DrawHighlightIfMouseover(row); if (Widgets.ButtonInvisible(row)) { tab.onClick(); } } else { Widgets.DrawHighlightIfMouseover(row); Widgets.DrawTextureFitted(row.RightPartPixels(row.height), tab.collapsed ? DubGUI.DropDown : DubGUI.FoldUp, 1f); if (Widgets.ButtonInvisible(row)) { tab.collapsed = !tab.collapsed; } } row.x += 5f; Widgets.Label(row, tab.Label); TooltipHandler.TipRegion(row, tab.Tip); Text.Anchor = TextAnchor.MiddleLeft; Text.Font = GameFont.Tiny; if (tab.collapsed) { return; } foreach (var entry in tab.entries) { DrawEntry(ref row, entry); } }
//Draw selection and mouseover highlights public static void Postfix(Rect rect, Pawn pawn) { //from DoCell: Rect rowRect = new Rect(rect.x, rect.y, rect.width, Mathf.Min(rect.height, 30f)); if (Mod.settings.pawnTableHighlightSelected) if (Find.Selector.IsSelected(pawn)) Widgets.DrawHighlightSelected(rowRect); if (Mod.settings.pawnTableArrowMouseover) if (Mouse.IsOver(rowRect)) { Vector3 center = UI.UIToMapPosition((float)(UI.screenWidth / 2), (float)(UI.screenHeight / 2)); bool arrow = (center - pawn.DrawPos).MagnitudeHorizontalSquared() >= 121f;//Normal arrow is 9^2, using 11^1 seems good too. TargetHighlighter.Highlight(pawn, arrow, true, true); } }
private void DrawAvailableJobList(Rect outRect, Rect viewRect) { // set sizes viewRect.height = _availablePawnKinds.Count * LargeListEntryHeight; if (viewRect.height > outRect.height) { viewRect.width -= ScrollbarWidth; } Widgets.BeginScrollView(outRect, ref _scrollPosition, viewRect); GUI.BeginGroup(viewRect); for (var i = 0; i < _availablePawnKinds.Count; i++) { // set up rect var row = new Rect(0f, LargeListEntryHeight * i, viewRect.width, LargeListEntryHeight); // highlights Widgets.DrawHighlightIfMouseover(row); if (i % 2 == 0) { Widgets.DrawAltRect(row); } if (_availablePawnKinds[i] == _selectedAvailable) { Widgets.DrawHighlightSelected(row); } // draw label string label = _availablePawnKinds[i].LabelCap + "\n<i>" + "FML.TameWildCount".Translate( _availablePawnKinds[i].GetTame(manager).Count, _availablePawnKinds[i].GetWild(manager).Count) + "</i>"; Label(row, label, TextAnchor.MiddleLeft, margin: Margin * 2); // button if (Widgets.ButtonInvisible(row)) { _selectedAvailable = _availablePawnKinds[i]; // for highlighting to work Selected = new ManagerJob_Livestock(_availablePawnKinds[i], manager); // for details } } GUI.EndGroup(); Widgets.EndScrollView(); }
public static void DrawSlot(PartCustomisePack slot, Rect rect, ChassisType ct, BlueprintHandlerState state) { try { GUI.BeginGroup(rect); Rect slotRect = new Rect(rect.width / 2 - SlotRectSize.x / 2, 0f, SlotRectSize.x, SlotRectSize.y); if (Mouse.IsOver(slotRect)) { Widgets.DrawHighlightSelected(slotRect); TooltipHandler.TipRegion(slotRect, slot.Part.GetTooltip()); } else { Widgets.DrawHighlight(slotRect); } Widgets.DrawBox(slotRect); Rect imageRect = new Rect(slotRect.center.x - IconRectSize.x / 2, slotRect.center.y - IconRectSize.y / 2, IconRectSize.x, IconRectSize.y); Widgets.DrawTextureFitted(imageRect, DefaultSlotIcon, 1f);//TODO:: show slot icon Rect labelRect = new Rect(0f, SlotRectSize.y, rect.width, SlotLabelHeight); Text.Anchor = TextAnchor.MiddleCenter; if (slot.Part.color != null) { GUI.color = slot.Part.color.GetColor(); } Widgets.Label(labelRect, slot.Part.LabelCap); GUI.color = Color.white; if (state == BlueprintHandlerState.New || state == BlueprintHandlerState.Edit) { if (Widgets.ButtonInvisible(slotRect)) { Dialog_SelectPart sp = new Dialog_SelectPart(slot, ct); Find.WindowStack.Add(sp); } } } finally { Text.Anchor = TextAnchor.UpperLeft; GUI.EndGroup(); } }
void DrawHelpRow(Rect hRect, HelpDef hCat) { if (hCat == SelectedHelpDef) { Widgets.DrawHighlightSelected(hRect); } else if (hRect.Contains(Event.current.mousePosition)) { Widgets.DrawHighlight(hRect); } Text.Anchor = TextAnchor.MiddleLeft; Widgets.Label(hRect, hCat.LabelCap); Text.Anchor = TextAnchor.UpperLeft; if (Widgets.InvisibleButton(hRect)) { SelectedHelpDef = hCat; } }
private void DrawCurrentJobList(Rect outRect, Rect viewRect) { // set sizes viewRect.height = _currentJobs.Count * LargeListEntryHeight; if (viewRect.height > outRect.height) { viewRect.width -= ScrollbarWidth; } Widgets.BeginScrollView(outRect, ref _scrollPosition, viewRect); GUI.BeginGroup(viewRect); for (var i = 0; i < _currentJobs.Count; i++) { // set up rect var row = new Rect(0f, LargeListEntryHeight * i, viewRect.width, LargeListEntryHeight); // highlights Widgets.DrawHighlightIfMouseover(row); if (i % 2 == 0) { Widgets.DrawAltRect(row); } if (_currentJobs[i] == _selectedCurrent) { Widgets.DrawHighlightSelected(row); } // draw label _currentJobs[i].DrawListEntry(row, false, true); // button if (Widgets.ButtonInvisible(row)) { Selected = _currentJobs[i]; } } GUI.EndGroup(); Widgets.EndScrollView(); }
public Rect DrawItem <T>(Rect inRect, T selectedObj, T obj, int ind, Action <Rect, T, int> drawFunc, Action <T> onClick) where T : class { Rect listItemRect = new Rect(inRect); listItemRect.height = 45f; if (ind % 2 == 0) { Widgets.DrawAltRect(listItemRect); } drawFunc(listItemRect, obj, ind); if (Event.current.type == EventType.MouseDown && Event.current.button == 0 && Mouse.IsOver(listItemRect)) { onClick(obj); SoundDefOf.Click.PlayOneShotOnCamera(); } Widgets.DrawHighlightIfMouseover(listItemRect); if (Mouse.IsOver(listItemRect) && lastMouseoverObj != obj) { SoundDefOf.Mouseover_Standard.PlayOneShotOnCamera(); lastMouseoverObj = obj; } if (!Mouse.IsOver(listItemRect) && lastMouseoverObj == obj) { lastMouseoverObj = null; } if (selectedObj == obj) { Widgets.DrawHighlightSelected(listItemRect); } return(listItemRect); }
private bool DrawHost(ref Vector2 cur, Rect view, MCMHost host) { float width = view.width - cur.x - Margin; float height = EntryHeight; string label = host.Label; if (Text.CalcHeight(label, width) > EntryHeight) { Text.Font = GameFont.Tiny; float height2 = Text.CalcHeight(label, width); height = Mathf.Max(height, height2); } Text.Anchor = TextAnchor.MiddleLeft; Rect labelRect = new Rect(cur.x + Margin, cur.y, width - Margin, height); Widgets.Label(labelRect, label); Text.Anchor = TextAnchor.UpperLeft; Text.Font = GameFont.Small; // full viewRect width for overlay and button Rect buttonRect = view; buttonRect.yMin = cur.y; cur.y += height; buttonRect.yMax = cur.y; GUI.color = Color.grey; Widgets.DrawLineHorizontal(view.xMin, cur.y, view.width); GUI.color = Color.white; if (SelectedHost == host) { Widgets.DrawHighlightSelected(buttonRect); } else { Widgets.DrawHighlightIfMouseover(buttonRect); } return(Widgets.InvisibleButton(buttonRect)); }
public static void BeginTabbedView(Rect rect, string[] tabs, ref int activeTabIndex) { GUI.BeginGroup(rect); float occupatedSpace = 0; for (int i = 0; i < tabs.Length; i++) { float width = HorizontalSpacing + Text.CalcSize(tabs[i]).x + HorizontalSpacing; var tabRect = new Rect(occupatedSpace, 0, width, TabHeight); occupatedSpace += width; if (Widgets.ButtonInvisible(tabRect, true)) { activeTabIndex = i; } if (activeTabIndex == i) { Widgets.DrawHighlightSelected(tabRect); } else { Widgets.DrawHighlightIfMouseover(tabRect); } tabRect.x += HorizontalSpacing; Widgets.Label(tabRect, tabs[i]); } var highlitedLine = new Rect(0, TabHeight, rect.width, 2); Widgets.DrawHighlightSelected(highlitedLine); var contentRect = new Rect(0, TabHeight + HLineHeight, rect.width, rect.height - TabHeight - HLineHeight); GUI.BeginGroup(contentRect); TabbedViewStackIndex.Push(activeTabIndex); }
public float Draw(float x, float y, float width, bool selected, Action clickedCallback, Action mousedOverCallback, Vector2 scrollPosition, Rect scrollOutRect) { float num = width * 0.45f; Rect rect = new Rect(8f, y, width, Text.CalcHeight(ValueString, num)); if (!(y - scrollPosition.y + rect.height < 0f) && !(y - scrollPosition.y > scrollOutRect.height)) { if (selected) { Widgets.DrawHighlightSelected(rect); } else if (Mouse.IsOver(rect)) { Widgets.DrawHighlight(rect); } Rect rect2 = rect; rect2.width -= num; Widgets.Label(rect2, LabelCap); Rect rect3 = rect; rect3.x = rect2.xMax; rect3.width = num; Widgets.Label(rect3, ValueString); if (stat != null && Mouse.IsOver(rect)) { StatDef localStat = stat; TooltipHandler.TipRegion(rect, new TipSignal(() => localStat.LabelCap + ": " + localStat.description, stat.GetHashCode())); } if (Widgets.ButtonInvisible(rect)) { clickedCallback(); } if (Mouse.IsOver(rect)) { mousedOverCallback(); } } return(rect.height); }
private void DrawEnableButton(Rect rect, MethodInfo method, string methodString) { var tooltip = $"Enable stack trace profiling"; var height = rect.height; if (height > 25f + Text.LineHeight) { DubGUI.CenterText(() => Widgets.Label(rect.TopPartPixels(Text.LineHeight), "Enable")); rect.AdjustVerticallyBy(Text.LineHeight); } if (currentlyTracking) { Widgets.DrawHighlightSelected(rect); } var centerRect = rect.CenterWithDimensions(25, 25); TooltipHandler.TipRegion(centerRect, tooltip); if (Widgets.ButtonImage(centerRect, Widgets.CheckboxOnTex)) { if (currentlyTracking is false) { StackTraceUtility.Reset(); currentTrace = 0; currentTrackedStacktraces = 0; Modbase.Harmony.Patch(method, postfix: new HarmonyMethod(postfix)); } else { ThreadSafeLogger.ErrorOnce($"Can not retrace {methodString} while currently tracing", method.GetHashCode()); } currentlyTracking = true; } }
public float Draw(float x, float y, float width, bool selected, Action clickedCallback, Action mousedOverCallback, Vector2 scrollPosition, Rect scrollOutRect) { float num = width * 0.45f; Rect rect = new Rect(8f, y, width, Text.CalcHeight(this.ValueString, num)); if (y - scrollPosition.y + rect.height >= 0f && y - scrollPosition.y <= scrollOutRect.height) { if (selected) { Widgets.DrawHighlightSelected(rect); } else if (Mouse.IsOver(rect)) { Widgets.DrawHighlight(rect); } Rect rect2 = rect; rect2.width -= num; Widgets.Label(rect2, this.LabelCap); Rect rect3 = rect; rect3.x = rect2.xMax; rect3.width = num; Widgets.Label(rect3, this.ValueString); if (this.data.Parent != null && Mouse.IsOver(rect)) { TooltipHandler.TipRegion(rect, new TipSignal(this.data.RecordID.Description, this.data.GetHashCode())); } if (Widgets.ButtonInvisible(rect, true)) { clickedCallback(); } if (Mouse.IsOver(rect)) { mousedOverCallback(); } } return(rect.height); }
private void DrawNameQueue(Listing listing) { for (var index = 0; index < _pawnComponent.ViewerNameQueue.Count; index++) { string name = _pawnComponent.ViewerNameQueue[index]; Rect line = listing.GetRect(Text.LineHeight); var buttonRect = new Rect(line.x + line.width - line.height * 3f, line.y, line.height * 3f, line.height); var nameRect = new Rect(line.x, line.y, line.width - buttonRect.width - 5f, line.height); if (index % 2 == 0) { Widgets.DrawLightHighlight(line); } if (name.EqualsIgnoreCase(_username)) { Widgets.DrawHighlightSelected(line); } Widgets.DrawHighlightIfMouseover(line); DrawNameFromQueue(nameRect, name, buttonRect, index); } }
private void DrawEntry(DroidChassisPartDef d, Rect rect, bool alternate, string label = "") { string labelToUse = label.NullOrEmpty() ? d.LabelCap : label; if (d == selPart) { Widgets.DrawHighlightSelected(rect); if (Mouse.IsOver(rect)) { TooltipHandler.TipRegion(rect, d.GetTooltip()); } } else if (Mouse.IsOver(rect)) { Widgets.DrawHighlight(rect); TooltipHandler.TipRegion(rect, d.GetTooltip()); } else if (alternate) { Widgets.DrawAltRect(rect); } if (Widgets.ButtonInvisible(rect)) { selPart = d; } Text.Anchor = TextAnchor.MiddleLeft; if (d.color != null) { GUI.color = d.color.GetColor(); } Widgets.Label(rect, labelToUse); Text.Anchor = TextAnchor.UpperLeft; GUI.color = Color.white; }
private void DoThingTab(Rect rect) { if (!Analyzer.SelectedMode.IsPatched) { Text.Font = GameFont.Medium; Text.Anchor = TextAnchor.MiddleCenter; Widgets.Label(rect, $"Loading{GenText.MarchingEllipsis(0f)}"); Text.Font = GameFont.Small; Text.Anchor = TextAnchor.UpperLeft; return; } var topslot = rect.TopPartPixels(20f); Rect rowby = topslot.LeftPartPixels(25f); if (Widgets.ButtonImage(rowby, TexButton.SpeedButtonTextures[Analyzer.running ? 0 : 1])) { Analyzer.running = !Analyzer.running; } TooltipHandler.TipRegion(rowby, "Start and stop logging"); bool save = false; if (Analyzer.Settings.AdvancedMode) { Rect searchbox = topslot.LeftPartPixels(topslot.width - 300f); searchbox.x += 25f; DubGUI.InputField(searchbox, "Search", ref TimesFilter, DubGUI.MintSearch); rowby.x = searchbox.xMax; rowby.width = 175f; if (Widgets.ButtonTextSubtle(rowby, stlank, Mathf.Clamp01(Mathf.InverseLerp(H_RootUpdate.LastMinGC, H_RootUpdate.LastMaxGC, totalBytesOfMemoryUsed)), 5)) { totalBytesOfMemoryUsed = GC.GetTotalMemory(true); } TooltipHandler.TipRegion(rowby, "Approximation of total bytes currently allocated in managed memory + rate of new allocation\n\nClick to force GC"); rowby.x = rowby.xMax; rowby.width = 100f; save = Widgets.ButtonTextSubtle(rowby, "Save .CSV"); TooltipHandler.TipRegion(rowby, $"Save the current list of times to a csv file in {GenFilePaths.FolderUnderSaveData("Profiling")}"); } else { Rect searchbox = topslot.RightPartPixels(topslot.width - 25f); DubGUI.InputField(searchbox, "Search", ref TimesFilter, DubGUI.MintSearch); } rowby.x = rowby.xMax; rowby.width = 25f; rect.y += 25f; rect.height -= 25f; var innyrek = rect.AtZero(); innyrek.width -= 16f; innyrek.height = groaner; GizmoListRect = rect.AtZero(); GizmoListRect.y += scrolpos.y; Widgets.BeginScrollView(rect, ref scrolpos, innyrek); GUI.BeginGroup(innyrek); listing.Begin(innyrek); float goat = 0; //List<ProfileLog> logs = null; //if (Analyzer.SortBy == "First") //{ // logs = Analyzer.Logs.ToList(); //} //else if (Analyzer.SortBy == "A-Z") //{ // logs = Analyzer.Logs.ToList().OrderBy(x => x.Key).ToList(); //} //else if (Analyzer.SortBy == "Usage") //{ // logs = Analyzer.Logs.ToList().OrderByDescending(x => x.Average).ToList(); //} Text.Anchor = TextAnchor.MiddleLeft; Text.Font = GameFont.Tiny; lock (Analyzer.sync) { foreach (var log in Analyzer.Logs) { if (!log.Label.Has(TimesFilter)) { continue; } var r = listing.GetRect(40f); if (r.Overlaps(GizmoListRect)) { var profile = Analyzer.Profiles[log.Key]; if (Input.GetKey(KeyCode.LeftControl)) { if (Widgets.ButtonInvisible(r)) { Analyzer.SelectedMode.Clicked?.Invoke(null, new object[] { profile, log }); Analyzer.Settings.Write(); } } bool on = true; if (Analyzer.SelectedMode.Selected != null) { on = (bool)Analyzer.SelectedMode.Selected.Invoke(null, new object[] { profile, log }); } if (Analyzer.SelectedMode.Checkbox != null) { var r2 = new Rect(r.x, r.y, 25f, r.height); r.x += 25f; if (DubGUI.Checkbox(r2, "", ref on)) { Analyzer.SelectedMode.Checkbox?.Invoke(null, new object[] { profile, log }); Analyzer.Settings.Write(); } } Widgets.DrawHighlightIfMouseover(r); if (Widgets.ButtonInvisible(r)) { Dialog_Graph.RunKey(log.Key); } if (Dialog_Graph.key == log.Key) { Widgets.DrawHighlightSelected(r); } var col = grey; if (log.Percent > 0.25f) { col = blue; } if (log.Percent > 0.75f) { col = red; } Widgets.FillableBar(r.BottomPartPixels(8f), log.Percent, col, clear, false); r = r.LeftPartPixels(50); if (!on) { GUI.color = Color.grey; } Widgets.Label(r, log.Average_s); if (Analyzer.Settings.AdvancedMode) { r.x = r.xMax; Widgets.Label(r, profile.memRiseStr); } r.x = r.xMax; r.width = 2000; Widgets.Label(r, log.Label); GUI.color = Color.white; if (save) { csv.Append($"{log.Label},{log.Average},{profile.BytesUsed}"); foreach (var historyTime in profile.History.times) { csv.Append($",{historyTime}"); } csv.AppendLine(); } } listing.GapLine(0f); goat += 4f; goat += r.height; } } if (save) { var path = GenFilePaths.FolderUnderSaveData("Profiling") + $"/{Analyzer.SelectedMode.name}_{DateTime.Now.ToFileTime()}.csv"; File.WriteAllText(path, csv.ToString()); csv.Clear(); Messages.Message($"Saved to {path}", MessageTypeDefOf.TaskCompletion, false); } listing.End(); groaner = goat; GUI.EndGroup(); Text.Font = GameFont.Small; Text.Anchor = TextAnchor.UpperLeft; Widgets.EndScrollView(); }
public void DoLeftRow(Rect rect) { Widgets.DrawMenuSection(rect); // content float height = _leftRowHeight; var scrollView = new Rect(0f, 0f, rect.width, height); if (height > rect.height) { scrollView.width -= 16f; } Widgets.BeginScrollView(rect, ref _scrollPosition, scrollView); Rect scrollContent = scrollView; GUI.BeginGroup(scrollContent); Vector2 cur = Vector2.zero; var i = 0; foreach (ManagerJob_Forestry job in _jobs) { var row = new Rect(0f, cur.y, scrollContent.width, Utilities.LargeListEntryHeight); Widgets.DrawHighlightIfMouseover(row); if (_selected == job) { Widgets.DrawHighlightSelected(row); } if (i++ % 2 == 1) { Widgets.DrawAltRect(row); } Rect jobRect = row; if (ManagerTab_Overview.DrawOrderButtons(new Rect(row.xMax - 50f, row.yMin, 50f, 50f), manager, job)) { Refresh(); } jobRect.width -= 50f; job.DrawListEntry(jobRect, false); if (Widgets.ButtonInvisible(jobRect)) { _selected = job; } cur.y += Utilities.LargeListEntryHeight; } // row for new job. var newRect = new Rect(0f, cur.y, scrollContent.width, Utilities.LargeListEntryHeight); Widgets.DrawHighlightIfMouseover(newRect); if (i % 2 == 1) { Widgets.DrawAltRect(newRect); } Text.Anchor = TextAnchor.MiddleCenter; Widgets.Label(newRect, "<" + "FMF.NewForestryJob".Translate() + ">"); Text.Anchor = TextAnchor.UpperLeft; if (Widgets.ButtonInvisible(newRect)) { Selected = new ManagerJob_Forestry(manager); } TooltipHandler.TipRegion(newRect, "FMF.NewForestryJobTooltip".Translate()); cur.y += Utilities.LargeListEntryHeight; _leftRowHeight = cur.y; GUI.EndGroup(); Widgets.EndScrollView(); }