CrabUI
Loading...
Searching...
No Matches
CUIDebug.cs
1#define CUIDEBUG
2// #define SHOWPERF
3
4using System;
5using System.Collections.Generic;
6using System.Linq;
7using System.Reflection;
8using System.Diagnostics;
9using System.Runtime.CompilerServices;
10using System.IO;
11
12using Barotrauma;
13using Microsoft.Xna.Framework;
14using Microsoft.Xna.Framework.Input;
15using Microsoft.Xna.Framework.Graphics;
16
17
18namespace CrabUI
19{
20 public static class CUIDebug
21 {
22 public static bool PrintKeys;
23
24#if !CUIDEBUG
25 [Conditional("DONT")]
26#endif
27 public static void Log(object msg, Color? cl = null)
28 {
29 if (!CUI.Debug) return;
30 cl ??= new Color(255, 64, 255);
31 LuaCsLogger.LogMessage($"{msg ?? "null"}", cl * 0.8f, cl);
32 }
33
34
35#if !CUIDEBUG
36 [Conditional("DONT")]
37#endif
38 public static void Info(object msg, Color? cl = null, [CallerFilePath] string source = "", [CallerLineNumber] int lineNumber = 0)
39 {
40 if (!CUI.Debug) return;
41 cl ??= Color.Cyan;
42 var fi = new FileInfo(source);
43
44 CUI.Log($"{fi.Directory.Name}/{fi.Name}:{lineNumber}", cl * 0.5f);
45 CUI.Log(msg, cl);
46 }
47
48#if !CUIDEBUG
49 [Conditional("DONT")]
50#endif
51 public static void Error(object msg, Color? cl = null, [CallerFilePath] string source = "", [CallerLineNumber] int lineNumber = 0)
52 {
53 if (!CUI.Debug) return;
54 cl ??= Color.Orange;
55 var fi = new FileInfo(source);
56
57 CUI.Log($"{fi.Directory.Name}/{fi.Name}:{lineNumber}", cl * 0.5f);
58 CUI.Log(msg, cl);
59 }
60
61#if !CUIDEBUG
62 [Conditional("DONT")]
63#endif
64 public static void Capture(CUIComponent host, CUIComponent target, string method, string sprop, string tprop, string value)
65 {
66 if (target == null || target.IgnoreDebug || !target.Debug) return;
67
68 //CUI.Log($"{host} {target} {method} {sprop} {tprop} {value}");
69
70 CUIDebugWindow.Main?.Capture(new CUIDebugEvent(host, target, method, sprop, tprop, value));
71 }
72
73#if !CUIDEBUG
74 [Conditional("DONT")]
75#endif
76 public static void Flush() => CUIDebugWindow.Main?.Flush();
77
78
79 // public static int CUIShowperfCategory = 1000;
80 // #if (!SHOWPERF || !CUIDEBUG)
81 // [Conditional("DONT")]
82 // #endif
83 // public static void CaptureTicks(double ticks, string name, int hash) => ShowPerfExtensions.Plugin.CaptureTicks(ticks, CUIShowperfCategory, name, hash);
84
85 // #if (!SHOWPERF || !CUIDEBUG)
86 // [Conditional("DONT")]
87 // #endif
88 // public static void CaptureTicks(double ticks, string name) => ShowPerfExtensions.Plugin.CaptureTicks(ticks, CUIShowperfCategory, name);
89
90 // #if (!SHOWPERF || !CUIDEBUG)
91 // [Conditional("DONT")]
92 // #endif
93 // public static void EnsureCategory() => ShowPerfExtensions.Plugin.EnsureCategory(CUIShowperfCategory);
94 }
95}