4using System.Collections.Generic;
6using System.Reflection;
7using System.Diagnostics;
8using System.Runtime.CompilerServices;
12using Microsoft.Xna.Framework;
13using Microsoft.Xna.Framework.Input;
14using Microsoft.Xna.Framework.Graphics;
19 public class CUIDebugWindow : CUIFrame
21 public static CUIDebugWindow Main;
23 public CUIVerticalList EventsComponent;
24 public CUIVerticalList DebugIDsComponent;
25 public CUIPages Pages;
26 public CUIMultiButton PickIDButton;
28 public List<CUIDebugEventComponent> Events =
new List<CUIDebugEventComponent>();
30 public bool Loop {
get;
set; } =
true;
34 public void Capture(CUIDebugEvent e)
36 if (EventsComponent ==
null)
return;
38 if (target > 200)
return;
40 if (Events.Count < target + 1)
42 CUIDebugEventComponent ec =
new CUIDebugEventComponent(e);
44 EventsComponent.Append(ec);
46 ec.OnMouseEnter += (m) => ec.Value.Target.DebugHighlight =
true;
47 ec.OnMouseLeave += (m) => ec.Value.Target.DebugHighlight =
false;
51 Events[target].Value = e;
63 public void MakeIDList()
65 DebugIDsComponent.Visible =
false;
66 DebugIDsComponent.RemoveAllChildren();
68 List<CUIComponent> l =
new List<CUIComponent>();
70 if (CUI.Main is not
null)
74 if (!component.IgnoreDebug) l.Add(component);
78 foreach (CUIComponent c
in l)
80 CUIToggleButton b =
new CUIToggleButton(c.ToString())
84 Style =
new CUIStyle(){
85 {
"TextAlign",
"[0,0]"}
87 AddOnMouseDown = (m) =>
92 AddOnMouseEnter = (m) => c.DebugHighlight =
true,
93 AddOnMouseLeave = (m) => c.DebugHighlight =
false,
96 DebugIDsComponent.Append(b);
98 DebugIDsComponent.Visible =
true;
102 public CUIDebugWindow() : base()
105 this.Layout =
new CUILayoutVerticalList();
107 this[
"handle"] =
new CUIComponent()
109 Absolute =
new CUINullRect(
null,
null,
null, 20),
112 this[
"handle"][
"closebutton"] =
new CUIButton(
"X")
114 Anchor =
new Vector2(1, 0.5f),
115 Style =
new CUIStyle(){
116 {
"MasterColor",
"Red"}
118 AddOnMouseDown = (e) =>
120 CUIDebugWindow.Close();
124 this[
"controls"] =
new CUIComponent()
129 this[
"controls"][
"loop"] =
new CUIToggleButton(
"loop")
131 Relative =
new CUINullRect(0, 0, 0.5f,
null),
132 AddOnStateChange = (state) =>
136 EventsComponent?.RemoveAllChildren();
142 this[
"controls"].Append(PickIDButton =
new CUIMultiButton()
144 Relative =
new CUINullRect(0.5f, 0, 0.5f,
null),
145 Style =
new CUIStyle(){
146 {
"InactiveColor",
"0,0,0,128"},
147 {
"MousePressedColor",
"0,255,255,64"}
149 ConsumeDragAndDrop =
false,
151 Options =
new string[]{
152 "Debug events",
"Debugged components"
156 Append(Pages =
new CUIPages()
159 Style =
new CUIStyle(){
160 {
"BackgroundColor",
"0,0,32,128"}
165 EventsComponent =
new CUIVerticalList()
167 Relative =
new CUINullRect(0, 0, 1, 1),
172 DebugIDsComponent =
new CUIVerticalList()
174 Relative =
new CUINullRect(0, 0, 1, 1),
179 PickIDButton.OnSelect += (s) =>
181 if (PickIDButton.SelectedIndex == 0)
184 Pages.Open(EventsComponent);
186 else Pages.Open(DebugIDsComponent);
188 PickIDButton.Select(0);
190 this[
"controls"].Get<CUIToggleButton>(
"loop").State =
true;
195 public static CUIDebugWindow Open()
197 if (CUI.Main ==
null)
return null;
199 CUIDebugWindow w =
new CUIDebugWindow()
201 Absolute =
new CUINullRect(10, 370, 500, 370),
204 CUIDebugWindow.Main = w;
205 CUI.Main.OnTreeChanged += () => w.MakeIDList();
209 public static void Close()
211 if (CUIDebugWindow.Main ==
null)
return;
213 CUIDebugWindow.Main.RemoveSelf();
214 CUIDebugWindow.Main.Revealed =
false;
215 CUIDebugWindow.Main =
null;
218 public CUIDebugWindow(
float? x =
null,
float? y =
null,
float? w =
null,
float? h =
null) : this()
220 Relative =
new CUINullRect(x, y, w, h);
CUIBool2 FillEmptySpace
Will be resized to fill empty space in list components.
CUINullRect Relative
Relative to parent size and position, [0..1].
virtual CUIComponent Append(CUIComponent child, string name=null, [CallerMemberName] string memberName="")
Adds children to the end of the list.
CUIStyle Style
Allows you to assing parsable string or link to CUIPalette to any prop It's indexable,...
Vector2 Anchor
this point of this component
CUIBool2 FitContent
Will resize itself to fit components with absolute size, e.g. text.
CUINullRect Absolute
Absolute size and position in pixels.
static void RunRecursiveOn(CUIComponent component, Action< CUIComponent > action)
designed to be versatile, in fact never used