Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 21 additions & 20 deletions Source/Client/UI/DebugPanel/SyncDebugPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,29 @@
using System.Linq;
using Multiplayer.Client.Desyncs;
using Multiplayer.Client.Util;
using Multiplayer.Client.Patches;
using Multiplayer.Common;
using RimWorld;
using UnityEngine;
using Verse;
using System.Collections.Generic; // Added for List
using System.Collections.Generic;

namespace Multiplayer.Client.DebugUi
{
/// <summary>
/// Enhanced expandable debug panel that organizes existing comprehensive debug information
/// with modern UI/UX while preserving all developer functionality
/// </summary>
public static partial class SyncDebugPanel
public static class SyncDebugPanel
{
// Panel state
private static bool isExpanded = false;
private static bool isExpanded;
private static Vector2 scrollPosition = Vector2.zero;

// Panel dimensions
private const float HeaderHeight = 40f;
private const float VisibleExpandedHeight = 400f;
private const float ContentHeight = 1500f;
private const float PanelWidth = 275f;
private static float contentHeight;

// Visual constants
private const float Margin = 8f;
Expand Down Expand Up @@ -175,7 +174,7 @@ private static void DrawExpandedPanel(Rect rect)
Rect contentRect = new(rect.x, rect.y + 30f, rect.width, rect.height - 30f);

DrawHeader(headerRect);
Rect viewRect = new(0f, 0f, contentRect.width - 16f, ContentHeight);
Rect viewRect = new(0f, 0f, contentRect.width - 16f, contentHeight);
Widgets.BeginScrollView(contentRect, ref scrollPosition, viewRect);

float currentY = 0f;
Expand All @@ -194,6 +193,8 @@ private static void DrawExpandedPanel(Rect rect)
currentY += DrawMemoryPerformanceSection(viewRect.x + Margin, currentY, viewRect.width - Margin);
currentY += DrawMapManagementSection(viewRect.x + Margin, currentY, viewRect.width - Margin);

if (Event.current.type == EventType.Layout) contentHeight = currentY;

Widgets.EndScrollView();
}

Expand Down Expand Up @@ -241,7 +242,7 @@ private static float DrawStatusSummarySection(float x, float y, float width)
private static float DrawPerformanceRecorderSection(float x, float y, float width)
{
StatusBadge recordingStatus = PerformanceRecorder.GetRecordingStatus();

var lines = new List<DebugLine>
{
new("Status:", recordingStatus.text, recordingStatus.color),
Expand All @@ -254,7 +255,7 @@ private static float DrawPerformanceRecorderSection(float x, float y, float widt
lines.Add(new("Duration:", $"{duration.TotalSeconds:F1}s", Color.white));
lines.Add(new("Avg FPS:", PerformanceRecorder.AverageFPS > 0 ? $"{PerformanceRecorder.AverageFPS:F1}" : "N/A", Color.white));
lines.Add(new("Avg TPS:", PerformanceRecorder.AverageTPS > 0 ? $"{PerformanceRecorder.AverageTPS:F1}" : "N/A", Color.white));

if (PerformanceCalculator.IsInStabilizationPeriod())
{
lines.Add(new("TPS Perf:", "STABILIZING", Color.yellow));
Expand All @@ -267,11 +268,11 @@ private static float DrawPerformanceRecorderSection(float x, float y, float widt

var section = new DebugSection("PERFORMANCE RECORDER", lines.ToArray());
float sectionHeight = DrawSection(x, y, width, section);

// Add control buttons below the section
float buttonY = y + sectionHeight - SectionSpacing + 4f;
float buttonHeight = DrawRecorderControls(x, buttonY, width);

return sectionHeight + buttonHeight;
}

Expand Down Expand Up @@ -314,21 +315,21 @@ private static float DrawRecorderControls(float x, float y, float width)

var startRect = new Rect(x, currentY, buttonWidth, buttonHeight);
var stopRect = new Rect(x + buttonWidth + spacing, currentY, buttonWidth, buttonHeight);

GUI.color = PerformanceRecorder.IsRecording ? Color.gray : Color.white;

if (Widgets.ButtonText(startRect, "Start") && !PerformanceRecorder.IsRecording)
{
PerformanceRecorder.StartRecording();
}

GUI.color = !PerformanceRecorder.IsRecording ? Color.gray : Color.white;

if (Widgets.ButtonText(stopRect, "Stop") && PerformanceRecorder.IsRecording)
{
PerformanceRecorder.StopRecording();
}

GUI.color = Color.white;
currentY += buttonHeight + spacing;
return currentY - y;
Expand Down Expand Up @@ -379,7 +380,7 @@ private static float DrawPerformanceSection(float x, float y, float width)
float targetTps = PerformanceCalculator.GetTargetTPS();
string tpsPerformanceText;
Color tpsColor;

if (PerformanceCalculator.IsInStabilizationPeriod())
{
tpsPerformanceText = "STABILIZING";
Expand Down Expand Up @@ -477,7 +478,7 @@ private static float DrawTimingSyncSection(float x, float y, float width)
{
int timerLag = TickPatch.tickUntil - TickPatch.Timer;
Color lagColor = PerformanceCalculator.GetPerformanceColor(timerLag, 15, 30);

DebugLine[] timingLines = [
new("Timer Lag:", $"{timerLag}", lagColor),
new("Timer:", $"{TickPatch.Timer}", Color.white),
Expand All @@ -503,7 +504,7 @@ private static float DrawGameStateSection(float x, float y, float width)
try
{
AsyncTimeComp async = Find.CurrentMap?.AsyncTime();

DebugLine[] gameStateLines = [
new("Classic Mode:", $"{Find.IdeoManager?.classicMode ?? false}", Color.white),
new("Client Opinions:", $"{Multiplayer.game?.sync?.knownClientOpinions?.Count ?? 0}", Color.white),
Expand Down Expand Up @@ -544,7 +545,7 @@ private static float DrawCommandSyncSection(float x, float y, float width)
try
{
AsyncTimeComp async = Find.CurrentMap?.AsyncTime();

DebugLine[] commandLines = [
new("Async Commands:", $"{async?.cmds?.Count ?? 0}", Color.white),
new("World Commands:", $"{Multiplayer.AsyncWorldTime?.cmds?.Count ?? 0}", Color.white),
Expand All @@ -570,7 +571,7 @@ private static float DrawMemoryPerformanceSection(float x, float y, float width)
float serverTpt = TickPatch.tickUntil - TickPatch.Timer <= 3 ? TickPatch.serverTimePerTick * 1.2f :
TickPatch.tickUntil - TickPatch.Timer >= 7 ? TickPatch.serverTimePerTick * 0.8f :
TickPatch.serverTimePerTick;

DebugLine[] memoryLines = [
new("World Pawns:", $"{Find.WorldPawns.AllPawnsAliveOrDead.Count}", Color.white),
new("Pool Free Items:", $"{SimplePool<StackTraceLogItemRaw>.FreeItemsCount}", Color.white),
Expand Down Expand Up @@ -639,4 +640,4 @@ private static float DrawStatusLine(float x, float y, float width, string label,
return y + LineHeight + 1f; // Small padding between lines
}
}
}
}
Loading