CrabUI
Loading...
Searching...
No Matches
CUIProps.cs
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Reflection;
5using System.Diagnostics;
6using System.Runtime.CompilerServices;
7using System.IO;
8
9using Barotrauma;
10using Microsoft.Xna.Framework;
11using Microsoft.Xna.Framework.Input;
12using Microsoft.Xna.Framework.Graphics;
13
14using System.Xml;
15using System.Xml.Linq;
16using HarmonyLib;
17
18namespace CrabUI
19{
20 public partial class CUIComponent
21 {
22 /// <summary>
23 /// Just a wrapper for CUIProps
24 /// idk how to separate them better
25 /// </summary>
26 //TODO this should be a dict, and cuiprop should have hash
27 public CUIComponentProps CUIProps { get; set; } = new();
28
29
30 public class CUIComponentProps
31 {
32 public CUIProp<int?> ZIndex = new CUIProp<int?>()
33 {
34 LayoutProp = true,
35 OnSet = (v, host) =>
36 {
37 foreach (var child in host.Children)
38 {
39 //HACK think, should i propagate null?
40 if (v.HasValue && !child.IgnoreParentZIndex)
41 {
42 child.ZIndex = v.Value + 1;
43 }
44 }
45 },
46 };
47
48 public CUIProp<bool> IgnoreEvents = new CUIProp<bool>()
49 {
50 OnSet = (v, host) =>
51 {
52 foreach (var child in host.Children)
53 {
54 if (!child.IgnoreParentEventIgnorance) child.IgnoreEvents = v;
55 }
56 },
57 };
58
59 public CUIProp<bool> Visible = new CUIProp<bool>()
60 {
61 Value = true,
62 OnSet = (v, host) =>
63 {
64 foreach (var child in host.Children)
65 {
66 if (!child.IgnoreParentVisibility) child.Visible = v;
67 }
68 },
69 };
70
71 public CUIProp<bool> Revealed = new CUIProp<bool>()
72 {
73 Value = true,
74 OnSet = (v, host) =>
75 {
76 // host.TreeChanged = true;
77 host.Visible = v;
78 host.IgnoreEvents = !v;
79 },
80 };
81
82 public CUIProp<CUIBool2> Ghost = new CUIProp<CUIBool2>()
83 {
84 LayoutProp = true,
85 AbsoluteProp = true,
86 };
87
88 public CUIProp<bool> CullChildren = new CUIProp<bool>()
89 {
90 OnSet = (v, host) =>
91 {
92 host.HideChildrenOutsideFrame = v;
93 },
94 };
95
96 public CUIProp<CUI3DOffset> ChildrenOffset = new CUIProp<CUI3DOffset>()
97 {
98 ChildProp = true,
99 Value = new CUI3DOffset(0, 0, 1), // uuuuuuuuu suka blyat!
100 Validate = (v, host) => host.ChildOffsetBounds.Check(v),
101 OnSet = (v, host) =>
102 {
103 foreach (var child in host.Children)
104 {
105 if (!child.Fixed) child.Scale = v.Z;
106 }
107 },
108 };
109
110 public CUIProp<bool> ResizeToSprite = new CUIProp<bool>()
111 {
112 LayoutProp = true,
113 OnSet = (v, host) =>
114 {
115 if (v)
116 {
117 host.Absolute = host.Absolute with
118 {
119 Width = host.BackgroundSprite.SourceRect.Width,
120 Height = host.BackgroundSprite.SourceRect.Height,
121 };
122 }
123 },
124 };
125
126
127 public CUIProp<CUIBool2> FillEmptySpace = new CUIProp<CUIBool2>()
128 {
129 LayoutProp = true,
130 };
131
132 public CUIProp<CUIBool2> FitContent = new CUIProp<CUIBool2>()
133 {
134 LayoutProp = true,
135 AbsoluteProp = true,
136 };
137
138 public CUIProp<CUINullRect> Absolute = new CUIProp<CUINullRect>()
139 {
140 LayoutProp = true,
141 AbsoluteProp = true,
142 };
143
144 public CUIProp<CUINullRect> AbsoluteMin = new CUIProp<CUINullRect>()
145 {
146 LayoutProp = true,
147 AbsoluteProp = true,
148 };
149
150 public CUIProp<CUINullRect> AbsoluteMax = new CUIProp<CUINullRect>()
151 {
152 LayoutProp = true,
153 AbsoluteProp = true,
154 };
155
156 public CUIProp<CUINullRect> Relative = new CUIProp<CUINullRect>()
157 {
158 LayoutProp = true,
159 };
160 public CUIProp<CUINullRect> RelativeMin = new CUIProp<CUINullRect>()
161 {
162 LayoutProp = true,
163 };
164 public CUIProp<CUINullRect> RelativeMax = new CUIProp<CUINullRect>()
165 {
166 LayoutProp = true,
167 };
168 public CUIProp<CUINullRect> CrossRelative = new CUIProp<CUINullRect>()
169 {
170 LayoutProp = true,
171 };
172
173 #region Graphic Props --------------------------------------------------------
174 #endregion
175
176
177 public CUIProp<PaletteOrder> Palette = new CUIProp<PaletteOrder>()
178 {
179 ShowInDebug = false,
180 OnSet = (v, host) =>
181 {
182 //TODO should this be called in deserialize?
183 CUIGlobalStyleResolver.OnComponentStyleChanged(host);
184 // foreach (var child in host.Children)
185 // {
186 // child.Palette = v;
187 // }
188 },
189 };
190
191 public CUIProp<CUISprite> BackgroundSprite = new CUIProp<CUISprite>()
192 {
193 Value = CUISprite.Default,
194 ShowInDebug = false,
195 Validate = (v, host) => v ?? CUISprite.Default,
196 OnSet = (v, host) =>
197 {
198 if (host.ResizeToSprite)
199 {
200 host.Absolute = host.Absolute with
201 {
202 Width = v.SourceRect.Width,
203 Height = v.SourceRect.Height,
204 };
205 }
206
207 if (host.IgnoreTransparent)
208 {
209 Rectangle bounds = host.BackgroundSprite.Texture.Bounds;
210 host.TextureData = new Color[bounds.Width * bounds.Height];
211 host.BackgroundSprite.Texture.GetData<Color>(host.TextureData);
212 }
213 },
214 };
215
216 public CUIProp<bool> IgnoreTransparent = new CUIProp<bool>()
217 {
218 OnSet = (v, host) =>
219 {
220 if (v)
221 {
222 Rectangle bounds = host.BackgroundSprite.Texture.Bounds;
223 host.TextureData = new Color[bounds.Width * bounds.Height];
224 host.BackgroundSprite.Texture.GetData<Color>(host.TextureData);
225 }
226 else
227 {
228 host.TextureData = null;
229 }
230 },
231 };
232
233 public CUIProp<Color> BackgroundColor = new CUIProp<Color>()
234 {
235 ShowInDebug = false,
236 OnSet = (v, host) =>
237 {
238 host.BackgroundVisible = v != Color.Transparent;
239 },
240 };
241
242 public CUIProp<Color> OutlineColor = new CUIProp<Color>()
243 {
244 ShowInDebug = false,
245 OnSet = (v, host) =>
246 {
247 host.OutlineVisible = v != Color.Transparent;
248 },
249 };
250
251 public CUIProp<Vector2> Padding = new CUIProp<Vector2>()
252 {
253 Value = new Vector2(2, 2),
254 DecorProp = true,
255 };
256 }
257
258
259 }
260}
CUIComponentProps CUIProps
Just a wrapper for CUIProps idk how to separate them better.
Definition CUIProps.cs:27
Wrapper object for prop value, setters, side effects, metadata etc.
Definition CUIProp.cs:24