public static void Draw(Rect inrect, GeneralInformation?currentInformation)
        {
            if (currentInformation == null || currentInformation.Value.patches.NullOrEmpty())
            {
                return;
            }

            Text.Font   = GameFont.Tiny;
            Text.Anchor = TextAnchor.MiddleLeft;

            foreach (var patch in currentInformation?.patches)
            {
                var left  = $" {patch.patchType}";
                var right = $" {patch.modName}";

                var textHeight = Mathf.Max(Text.CalcHeight(left, inrect.width / 2), Text.CalcHeight(right, inrect.width / 2 - 5f));

                var rect = inrect.TopPartPixels(textHeight);
                inrect.y += textHeight;

                var anchor = Text.Anchor;
                Text.Anchor = TextAnchor.MiddleCenter;

                var leftRect = rect.LeftPart(.5f);
                Widgets.Label(leftRect, left);
                var rightRect = rect.RightPart(.5f);
                rightRect.x += 5;
                Widgets.Label(rightRect, right);

                Text.Anchor = anchor;

                Widgets.DrawHighlightIfMouseover(rect);

                if (Mouse.IsOver(rect))
                {
                    // todo cache tip
                    TooltipHandler.TipRegion(rect, $"Mod Name: {patch.modName}\nPatch Type: {patch.patchType}\nPatch Method: {patch.typeName}:{patch.methodName}");
                }

                if (Input.GetMouseButtonDown(1) && rect.Contains(Event.current.mousePosition)) // mouse button right
                {
                    List <FloatMenuOption> options = new List <FloatMenuOption>()
                    {
                        new FloatMenuOption("Open In Github", () => Panel_BottomRow.OpenGithub($"{patch.typeName}.{patch.methodName}")),
                        new FloatMenuOption("Open In Dnspy (requires local path)", () => Panel_BottomRow.OpenDnspy(patch.method))
                    };

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

            DubGUI.ResetFont();
        }
        public static void Draw(Rect inrect, GeneralInformation?currentInformation)
        {
            inrect = inrect.ContractedBy(4);
            if (currentInformation == null || currentInformation.Value.patches.NullOrEmpty())
            {
                return;
            }

            Text.Font   = GameFont.Tiny;
            Text.Anchor = TextAnchor.MiddleLeft;

            x = 0;

            var viewrect = inrect;

            viewrect.x     += 10;
            viewrect.width -= 28;
            viewrect.height = y;

            var row = viewrect;

            row.height = 40;
            row.width  = Mathf.Max(x, viewrect.width);

            Widgets.BeginScrollView(inrect, ref scroller, viewrect);

            foreach (var patch in currentInformation?.patches)
            {
                var meth = $"{patch.typeName} : {patch.methodName}";
                row.width = meth.GetWidthCached();

                if (row.width > x)
                {
                    x = row.width;
                }

                Widgets.Label(row, meth);

                Widgets.DrawHighlightIfMouseover(row);

                if (Mouse.IsOver(row))
                {
                    TooltipHandler.TipRegion(row, $"Mod Name: {patch.modName}\nPatch Type: {patch.patchType}");
                }

                if (Input.GetMouseButtonDown(1) && row.Contains(Event.current.mousePosition)) // mouse button right
                {
                    List <FloatMenuOption> options = new List <FloatMenuOption>()
                    {
                        new FloatMenuOption("Open In Github", () => Panel_BottomRow.OpenGithub($"{patch.typeName}.{patch.methodName}")),
                        new FloatMenuOption("Open In Dnspy (requires local path)", () => Panel_BottomRow.OpenDnspy(patch.method))
                    };

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

                row.y = row.yMax;

                y = row.yMax;
            }

            Widgets.EndScrollView();

            DubGUI.ResetFont();
        }
Exemple #3
0
        public static void DrawStats(Rect inrect, GeneralInformation?currentInformation)
        {
            var stats = new LogStats();

            stats.GenerateStats();

            stats = null;

            lock (CurrentLogStats.sync)
            {
                stats = CurrentLogStats.stats;
            }

            if (stats == null)
            {
                return;
            }

            inrect = inrect.ContractedBy(4f);
            var r = inrect;

            r.height = listing.CurHeight;
            r.width  = 18;
            Widgets.BeginScrollView(inrect, ref scrolls, r);

            listing.Begin(inrect);
            Text.Font = GameFont.Tiny;

            var sb = new StringBuilder();

            if (currentInformation.HasValue)
            {
                sb.AppendLine(
                    $"Method: {currentInformation.Value.methodName}, Mod: {currentInformation.Value.modName}");
                sb.AppendLine(
                    $"Assembly: {currentInformation.Value.assname}, Patches: {currentInformation.Value.patches.Count}");

                var modLabel = sb.ToString().TrimEndNewlines();
                var rect     = listing.GetRect(Text.CalcHeight(modLabel, listing.ColumnWidth));

                Widgets.Label(rect, modLabel);
                Widgets.DrawHighlightIfMouseover(rect);

                if (Input.GetMouseButtonDown(1) && rect.Contains(Event.current.mousePosition)) // mouse button right
                {
                    var options = new List <FloatMenuOption>
                    {
                        new FloatMenuOption("Open In Github",
                                            () => Panel_BottomRow.OpenGithub(
                                                $"{currentInformation.Value.typeName}.{currentInformation.Value.methodName}")),
                        new FloatMenuOption("Open In Dnspy (requires local path)",
                                            () => Panel_BottomRow.OpenDnspy(currentInformation.Value.method))
                    };

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

                listing.GapLine(2f);

                sb.Clear();
            }

            sb.AppendLine($"Total Entries:".Colorize(Color.grey) + $" { stats.Entries}");
            sb.AppendLine($"Total Calls:".Colorize(Color.grey) + $" {stats.TotalCalls}");
            sb.AppendLine($"Total Time:".Colorize(Color.grey) + $" {stats.TotalTime:0.000}ms");

            sb.AppendLine($"Avg Time/Call:".Colorize(Color.grey) + $" {stats.MeanTimePerCall:0.000}ms");
            sb.AppendLine($"Avg Calls/Update:".Colorize(Color.grey) + $" {stats.MeanCallsPerUpdateCycle:0.00}");
            sb.AppendLine($"Avg Time/Update:".Colorize(Color.grey) + $" {stats.MeanTimePerUpdateCycle:0.000}ms");

            sb.AppendLine($"Median Calls:".Colorize(Color.grey) + $" {stats.MedianCalls}");
            sb.AppendLine($"Median Time:".Colorize(Color.grey) + $" {stats.MedianTime}");
            sb.AppendLine($"Max Time:".Colorize(Color.grey) + $" {stats.HighestTime:0.000}ms");
            sb.AppendLine($"Max Calls/Update:".Colorize(Color.grey) + $" {stats.HighestCalls}");

            listing.Label(sb.ToTaggedString().Trim());

            DubGUI.ResetFont();

            listing.End();

            Widgets.EndScrollView();
        }