2using System.Collections.Generic;
4using System.Reflection;
5using System.Diagnostics;
8using Microsoft.Xna.Framework;
9using Microsoft.Xna.Framework.Input;
10using Microsoft.Xna.Framework.Graphics;
15 public static class CUIStylePrefab
17 public static CUIStyle FrameCaption =>
new CUIStyle()
19 {
"BackgroundColor",
"CUIPalette.Frame.Border"},
20 {
"Border",
"CUIPalette.Frame.Border"},
21 {
"TextColor",
"CUIPalette.Frame.Text"},
24 public static CUIStyle Header =>
new CUIStyle()
26 {
"BackgroundColor",
"CUIPalette.Header.Background"},
27 {
"Border",
"CUIPalette.Header.Border"},
28 {
"TextColor",
"CUIPalette.Header.Text"},
31 public static CUIStyle Nav =>
new CUIStyle()
33 {
"BackgroundColor",
"CUIPalette.Nav.Background"},
34 {
"Border",
"CUIPalette.Nav.Border"},
35 {
"TextColor",
"CUIPalette.Nav.Text"},
38 public static CUIStyle Main =>
new CUIStyle()
40 {
"BackgroundColor",
"CUIPalette.Main.Background"},
41 {
"Border",
"CUIPalette.Main.Border"},
42 {
"TextColor",
"CUIPalette.Main.Text"},
47 public static class CUIPrefab
49 public static CUIFrame ListFrame()
51 CUIFrame frame =
new CUIFrame();
52 frame[
"list"] =
new CUIVerticalList() { Relative =
new CUINullRect(0, 0, 1, 1), };
57 public static CUIComponent WrapInGroup(
string name, CUIComponent content)
59 CUIVerticalList group =
new CUIVerticalList() { FitContent =
new CUIBool2(
false,
true), };
60 group[
"header"] =
new CUITextBlock(name)
63 TextAlign = CUIAnchor.Center,
65 group[
"content"] = content;
69 public static CUIComponent Group(
string name)
71 CUIVerticalList group =
new CUIVerticalList()
73 FitContent =
new CUIBool2(
false,
true),
76 group[
"header"] =
new CUITextBlock(name)
79 TextAlign = CUIAnchor.Center,
82 group[
"content"] =
new CUIVerticalList()
84 FitContent =
new CUIBool2(
false,
true),
90 public static CUIComponent TextAndSliderWithLabel(
string name,
string command, FloatRange? range =
null)
92 CUIComponent wrapper =
new CUIVerticalList()
94 FitContent =
new CUIBool2(
false,
true),
95 Style = CUIStylePrefab.Main,
98 wrapper[
"label"] =
new CUITextBlock(name);
99 wrapper[
"controls"] = TextAndSlider(command, range);
104 public static CUIComponent TextAndSlider(
string command, FloatRange? range =
null)
106 CUIHorizontalList controls =
new CUIHorizontalList()
108 FitContent =
new CUIBool2(
false,
true),
109 RetranslateCommands =
true,
110 ReflectCommands =
true,
113 controls[
"text"] =
new CUITextInput()
115 Absolute =
new CUINullRect(w: 20.0f),
119 controls[
"slider"] =
new CUISlider()
121 Relative =
new CUINullRect(h: 1.0f),
122 FillEmptySpace =
new CUIBool2(
true,
false),
125 Range = range ??
new FloatRange(0, 1),
131 public static CUIFrame NewFrame()
133 CUIFrame frame =
new CUIFrame();
139 public static CUIVerticalList ListLayout() =>
new CUIVerticalList() { Relative =
new CUINullRect(0, 0, 1, 1) };
141 public static CUIHorizontalList FormHandle(
string caption =
"Caption")
143 CUIHorizontalList handle =
new CUIHorizontalList()
145 FitContent =
new CUIBool2(
false,
true),
146 Direction = CUIDirection.Reverse,
147 Style = CUIStylePrefab.FrameCaption,
150 handle[
"close"] =
new CUICloseButton();
152 handle[
"caption"] =
new CUITextBlock(caption) { FillEmptySpace =
new CUIBool2(
true,
false) };
157 public static void Frame(CUIFrame frame)
159 frame[
"layout"] =
new CUIVerticalList() { Relative =
new CUINullRect(0, 0, 1, 1), };
160 frame[
"layout"][
"handle"] =
new CUIHorizontalList()
162 FitContent =
new CUIBool2(
false,
true),
163 Direction = CUIDirection.Reverse,
164 Style = CUIStylePrefab.FrameCaption,
167 frame[
"layout"][
"handle"][
"close"] =
new CUICloseButton();
169 frame[
"layout"][
"handle"][
"caption"] =
new CUITextBlock(
"Caption") { FillEmptySpace =
new CUIBool2(
true,
false) };
171 frame[
"layout"][
"main"] =
new CUIComponent()
173 FillEmptySpace =
new CUIBool2(
false,
true),
174 Style = CUIStylePrefab.Main,
175 ConsumeDragAndDrop =
true,
178 frame[
"main"] = frame[
"layout"][
"main"];
179 frame[
"caption"] = frame[
"layout"][
"handle"][
"caption"];
184 public static CUIHorizontalList TickboxWithLabel(
string text,
string command,
float tickboxSize = 22.0f)
186 CUIHorizontalList list =
new CUIHorizontalList()
188 FitContent =
new CUIBool2(
true,
true),
191 list[
"tickbox"] =
new CUITickBox()
193 Absolute =
new CUINullRect(w: tickboxSize, h: tickboxSize),
198 list[
"text"] =
new CUITextBlock()
201 TextAlign = CUIAnchor.CenterLeft,
208 public static CUIHorizontalList InputWithValidation(PropertyInfo pi,
string command)
210 string ToUserFriendly(Type T)
212 if (T == typeof(
bool))
return "Boolean";
213 if (T == typeof(
int))
return "Integer";
214 if (T == typeof(
float))
return "Float";
218 CUIHorizontalList list =
new CUIHorizontalList()
220 FitContent =
new CUIBool2(
true,
true),
221 Border =
new CUIBorder(),
224 list[
"input"] =
new CUITextInput()
226 AbsoluteMin =
new CUINullRect(w: 100),
227 Relative =
new CUINullRect(w: 0.3f),
230 VatidationType = pi.PropertyType,
233 list[
"label"] =
new CUITextBlock()
235 FillEmptySpace =
new CUIBool2(
true,
false),
236 Text = $
"{ToUserFriendly(pi.PropertyType)} {pi.Name}",
237 TextAlign = CUIAnchor.CenterLeft,
238 BackgroundSprite =
new CUISprite(
"gradient.png"),
240 Style =
new CUIStyle(){
241 {
"BackgroundColor",
"CUIPalette.Text3.Background"},
242 {
"Border",
"CUIPalette.Text3.Border"},
243 {
"TextColor",
"CUIPalette.Text3.Text"},