public static void Draw(Listing_Standard listing, float winHeight)
        {
            DubGUI.CenterText(() => listing.Label("devoptions.heading".TranslateSimple()));

            listing.GapLine(6f);

            DrawButtons(listing);
            var inputBarOffset = DisplayInputField(listing, winHeight);

            DisplaySelectionOptions(listing);

            var x = listing.curX + inputBarOffset;
            var y = listing.curY - Text.LineHeight;

            var width  = listing.ColumnWidth - inputBarOffset;
            var height = (winHeight - listing.curY) - 18f;

            var uiPoint = GUIUtility.GUIToScreenPoint(new Vector2(x, y));
            var rect    = new Rect(uiPoint, new Vector2(width, height));


            Window_SearchBar.SetCurrentInput(input);
            Window_SearchBar.UpdateSearchString(currentInput);

            bool shouldExit;

            lock (Window_SearchBar.sync)
            {
                shouldExit = Window_SearchBar.CheckShouldClose(new Rect(x, y, width, height)) || Window_SearchBar.cachedEntries.Count == 1 && Window_SearchBar.cachedEntries.First() == currentInput;
            }

            if (shouldExit)
            {
                return;
            }

            // 0x7FFFFFFF is 011111 ... in binary, in effect takes only the positive component of the hash
            Find.WindowStack.ImmediateWindow(currentInput.GetHashCode() & 0x7FFFFFFF, rect, WindowLayer.Super, () =>
            {
                GUI.color = Window_SearchBar.windowTransparency;
                Window_SearchBar.DoWindowContents(rect.AtZero());
                GUI.color = Color.white;
            }, false);
        }
Example #2
0
        private void DrawChangeTraceButton(Rect rect)
        {
            var height = rect.height;

            if (height > 25f + Text.LineHeight)
            {
                DubGUI.CenterText(() => Widgets.Label(rect.TopPartPixels(Text.LineHeight), "Change"));
                rect.AdjustVerticallyBy(Text.LineHeight);
            }

            var tooltip = $"Change the currently viewed stacktrace";

            if (currentTrackedStacktraces == 0)
            {
                GUI.color = Color.gray;
            }

            var centerRect = rect.CenterWithDimensions(25, 25);

            TooltipHandler.TipRegion(centerRect, tooltip);

            if (Widgets.ButtonImage(centerRect, Textures.Burger))
            {
                if (currentTrackedStacktraces != 0)
                {
                    var traces = StackTraceUtility.traces.Values.ToList();
                    CalculateHeaders(traces, traces.MaxBy(t => t.Depth).Depth);

                    var options = StackTraceUtility.traces
                                  .OrderBy(p => p.Value.Count)
                                  .Reverse()
                                  .Select(st => new FloatMenuOption($"{st.Value.Header} : {st.Value.Count}", () => { currentTrace = st.Key; }))
                                  .ToList();

                    Find.WindowStack.Add(new FloatMenu(options));
                }
            }

            if (currentTrackedStacktraces == 0)
            {
                GUI.color = Color.white;
            }
        }
Example #3
0
        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;
            }
        }
Example #4
0
        private void DrawDisableButton(Rect rect, MethodInfo method)
        {
            var height = rect.height;

            if (height > 25f + Text.LineHeight)
            {
                DubGUI.CenterText(() => Widgets.Label(rect.TopPartPixels(Text.LineHeight), "Disable"));
                rect.AdjustVerticallyBy(Text.LineHeight);
            }

            var tooltip = $"Disable stack trace profiling";

            if (currentlyTracking is false)
            {
                GUI.color = Color.gray;
            }

            var centerRect = rect.CenterWithDimensions(25, 25);

            TooltipHandler.TipRegion(centerRect, tooltip);

            if (Widgets.ButtonImage(centerRect, Widgets.CheckboxOffTex))
            {
                if (currentlyTracking)
                {
                    Modbase.Harmony.CreateProcessor(method).Unpatch(postfix);
                }

                currentlyTracking = false;
            }

            if (currentlyTracking is false)
            {
                GUI.color = Color.white;
            }
        }
Example #5
0
        public static void Draw(Listing_Standard listing, Rect win)
        {
            listing.Label(Strings.settings_dnspy);
            Settings.PathToDnspy = listing.TextEntry(Settings.PathToDnspy);
            listing.Gap();
            DubGUI.LabeledSliderFloat(listing, Strings.settings_updates_per_second, ref Settings.updatesPerSecond, 1.0f, 20.0f);
            DubGUI.Checkbox(Strings.settings_logging, listing, ref Settings.verboseLogging);
            DubGUI.Checkbox(Strings.settings_disable_tps_counter, listing, ref Settings.disableTPSCounter);
            DubGUI.Checkbox("settings.debuglog".Tr(), listing, ref Settings.enableLog);

            var s    = Strings.settings_disable_cleanup;
            var rect = listing.GetRect(Text.LineHeight);

            DubGUI.Checkbox(rect, s, ref Settings.disableCleanup);
            TooltipHandler.TipRegion(rect, Strings.settings_disable_cleanup_desc);

            listing.GapLine();

            DubGUI.CenterText(() => listing.Label("devoptions.heading".Tr()));
            listing.GapLine();

            var tabs = listing.GetRect(tabRect.height);

            tabs.width = tabRect.width;

            Drawtab(tabs, 0, "Patch Tools");
            tabs.x = tabs.xMax;
            Drawtab(tabs, 1, $"Saved Patches ({Settings.SavedPatches_Tick.Count + Settings.SavedPatches_Update.Count})");
            listing.Gap(4);
            if (PatchTab == 0)
            {
                if (listing.ButtonTextLabeled("Logging cycle", patchType.ToString()))
                {
                    if (patchType == Category.Tick)
                    {
                        patchType = Category.Update;
                    }
                    else
                    {
                        patchType = Category.Tick;
                    }
                    //For if onGui gets added
                    //var list = new List<FloatMenuOption>
                    //{
                    //    new FloatMenuOption("devoptions.patchtype.tick".Tr(), () => patchType = Category.Tick),
                    //    new FloatMenuOption("devoptions.patchtype.update".Tr(), () => patchType = Category.Update)
                    //    new FloatMenuOption("devoptions.patchtype.ongui".Tr(), () => patchType = Category.OnGui)
                    //};
                    //Find.WindowStack.Add(new FloatMenu(list));
                }

                if (showSearchbox)
                {
                    Window_SearchBar.Control();
                }
                var inputR = DisplayInputField(listing);

                Window_SearchBar.SetCurrentInput(input);
                Window_SearchBar.UpdateSearchString(currentInput);

                var searchRect = listing.GetRect(Mathf.Min(listing.curY, win.height - listing.curY));

                lock (Window_SearchBar.sync)
                {
                    if (showSearchbox && !Mouse.IsOver(searchRect) && Event.current.type != EventType.MouseDown)
                    {
                        showSearchbox = false;
                    }
                    if (GUI.GetNameOfFocusedControl() == "profileinput")
                    {
                        showSearchbox = true;
                    }
                    else
                    if (Mouse.IsOver(inputR))
                    {
                        showSearchbox = true;
                    }
                }

                if (showSearchbox)
                {
                    Window_SearchBar.DoWindowContents(searchRect);
                }
            }
            else
            {
                foreach (var patch in Settings.SavedPatches_Tick.ToList())
                {
                    var row = listing.GetRect(Text.LineHeight);
                    if (Widgets.CloseButtonFor(row.LeftPartPixels(30f)))
                    {
                        Settings.SavedPatches_Tick.Remove(patch);
                    }
                    Widgets.Label(row.RightPartPixels(row.width - 30f), patch + " Tick");
                    listing.GapLine();
                }
                foreach (var patch in Settings.SavedPatches_Update.ToList())
                {
                    var row = listing.GetRect(Text.LineHeight);
                    if (Widgets.CloseButtonFor(row.LeftPartPixels(30f)))
                    {
                        Settings.SavedPatches_Update.Remove(patch);
                    }
                    Widgets.Label(row.RightPartPixels(row.width - 30f), patch + " Update");
                    listing.GapLine();
                }
            }
        }