Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
BevelledRectangleWidget.cs
浏览该文件的文档.
1using Engine;
3
4namespace Game {
7
9
11
13
15
17
19
21
23
25
27
29
31
33
35
37
39
41
43
45
46 public Vector2 Size { get; set; }
47
48 public float RoundingRadius {
49 get => m_roundingRadius;
50 set {
51 if (value != m_roundingRadius) {
52 m_roundingRadius = value;
54 }
55 }
56 }
57
58 public int RoundingCount {
59 get => m_roundingCount;
60 set {
61 if (value != m_roundingCount) {
62 m_roundingCount = value;
64 }
65 }
66 }
67
68 public float BevelSize {
69 get => m_bevelSize;
70 set {
71 if (value != m_bevelSize) {
72 m_bevelSize = value;
74 }
75 }
76 }
77
78 public float DirectionalLight {
79 get => m_directionalLight;
80 set {
81 if (value != m_directionalLight) {
82 m_directionalLight = value;
84 }
85 }
86 }
87
88 public float AmbientLight {
89 get => m_ambientLight;
90 set {
91 if (value != m_ambientLight) {
92 m_ambientLight = value;
94 }
95 }
96 }
97
99 get => m_texture;
100 set {
101 if (value != m_texture) {
102 m_texture = value;
103 m_cachedBatchesValid = false;
104 }
105 }
106 }
107
108 public float TextureScale { get; set; }
109
112 set {
113 if (value != m_textureLinearFilter) {
114 m_textureLinearFilter = value;
115 m_cachedBatchesValid = false;
116 }
117 }
118 }
119
121 get => m_centerColor;
122 set {
123 if (value != m_centerColor) {
124 m_centerColor = value;
125 m_cachedBatchesValid = false;
126 }
127 }
128 }
129
131 get => m_bevelColor;
132 set {
133 if (value != m_bevelColor) {
134 m_bevelColor = value;
135 m_cachedBatchesValid = false;
136 }
137 }
138 }
139
141 get => m_shadowColor;
142 set {
143 if (value != m_shadowColor) {
144 m_shadowColor = value;
145 m_cachedBatchesValid = false;
146 }
147 }
148 }
149
150 public float ShadowSize {
151 get => m_shadowSize;
152 set {
153 if (value != m_shadowSize) {
154 m_shadowSize = value;
155 m_cachedBatchesValid = false;
156 }
157 }
158 }
159
161
163 Size = new Vector2(float.PositiveInfinity);
164 TextureLinearFilter = false;
165 TextureScale = 1f;
166 RoundingRadius = 6f;
167 RoundingCount = 3;
168 BevelSize = 2f;
169 AmbientLight = 0.6f;
170 DirectionalLight = 0.4f;
171 CenterColor = new Color(181, 172, 154);
172 BevelColor = new Color(181, 172, 154);
173 ShadowColor = new Color(0, 0, 0, 32);
174 ShadowSize = 2f;
175 IsHitTestVisible = false;
176 }
177
178 public override void Draw(DrawContext dc) {
179 Color centerColor = CenterColor * new Vector4(0.6f, 0.6f, 0.6f, 1f);
180 Color bevelColor = BevelColor;
181 Color shadowColor = ShadowColor;
182 bool flag = shadowColor != Color.Transparent && BevelSize > 0f;
183 float globalScale = GlobalScale;
184 if (globalScale != m_cachedPixelsPerUnit) {
185 m_cachedPixelsPerUnit = globalScale;
186 m_cachedBatchesValid = false;
187 }
188 Vector2 vector = new Vector2(TextureScale) / RootWidget.GlobalScale;
189 if (vector != m_cachedTextureScale) {
190 m_cachedTextureScale = vector;
191 m_cachedBatchesValid = false;
192 }
193 float antialiasSize = 1f / globalScale;
194 if (Texture != null) {
196 bool flatShading = m_points.Any(p => p.RoundingCount == 0);
197 m_cachedShadowBatch.Clear();
198 m_cachedTexturedBatch.Clear();
199 m_cachedTexturedBatch.Texture = Texture;
200 if (flag) {
202 }
205 m_points,
206 vector,
208 globalScale,
209 antialiasSize,
210 BevelSize,
211 flatShading,
212 centerColor,
213 bevelColor,
216 );
218 }
219 if (flag) {
220 if (m_flatBatch == null) {
222 }
223 m_flatBatch.QueueBatch(
227 );
228 }
229 if (m_texturedBatch == null) {
231 Texture,
232 false,
233 1,
234 null,
235 null,
236 null,
238 );
239 }
241 return;
242 }
244 bool flatShading2 = m_points.Any(p => p.RoundingCount == 0);
245 m_cachedShadowBatch.Clear();
246 m_cachedFlatBatch.Clear();
247 if (flag) {
249 }
252 m_points,
253 globalScale,
254 antialiasSize,
255 BevelSize,
256 flatShading2,
257 centerColor,
258 bevelColor,
261 );
263 }
264 if (m_flatBatch == null) {
266 }
267 if (flag) {
268 m_flatBatch.QueueBatch(
272 );
273 }
275 }
276
277 public override void MeasureOverride(Vector2 parentAvailableSize) {
278 IsDrawRequired = BevelColor.A != 0 || CenterColor.A != 0;
280 }
281
282 public override void ArrangeOverride() {
283 Vector2 vector = new(0f, 0f);
284 Vector2 vector2 = new(ActualSize.X, 0f);
285 Vector2 vector3 = new(ActualSize.X, ActualSize.Y);
286 Vector2 vector4 = new(0f, ActualSize.Y);
287 if (vector != m_points[0].Position
288 || vector2 != m_points[1].Position
289 || vector3 != m_points[2].Position
290 || vector4 != m_points[3].Position) {
295 m_cachedBatchesValid = false;
296 }
297 }
298
299 public static void QueueBevelledRectangle(TexturedBatch2D texturedBatch,
300 FlatBatch2D flatBatch,
301 Vector2 c1,
302 Vector2 c2,
303 float depth,
304 float bevelSize,
305 Color color,
306 Color bevelColor,
307 Color shadowColor,
308 float ambientLight,
309 float directionalLight,
310 float textureScale) {
311 float num = MathF.Abs(bevelSize);
312 Vector2 vector = c1;
313 Vector2 vector2 = c1 + new Vector2(num);
314 Vector2 vector3 = c2 - new Vector2(num);
315 Vector2 vector4 = c2;
316 Vector2 vector5 = c2 + new Vector2(1.5f * num);
317 float x = vector.X;
318 float x2 = vector2.X;
319 float x3 = vector3.X;
320 float x4 = vector4.X;
321 float x5 = vector5.X;
322 float y = vector.Y;
323 float y2 = vector2.Y;
324 float y3 = vector3.Y;
325 float y4 = vector4.Y;
326 float y5 = vector5.Y;
327 float num2 = MathUtils.Saturate((bevelSize > 0f ? 1f : -0.75f) * directionalLight + ambientLight);
328 float num3 = MathUtils.Saturate((bevelSize > 0f ? -0.75f : 1f) * directionalLight + ambientLight);
329 float num4 = MathUtils.Saturate((bevelSize > 0f ? -0.375f : 0.5f) * directionalLight + ambientLight);
330 float num5 = MathUtils.Saturate((bevelSize > 0f ? 0.5f : -0.375f) * directionalLight + ambientLight);
331 float num6 = MathUtils.Saturate(0f * directionalLight + ambientLight);
332 Color color2 = new((byte)(num4 * bevelColor.R), (byte)(num4 * bevelColor.G), (byte)(num4 * bevelColor.B), bevelColor.A);
333 Color color3 = new((byte)(num5 * bevelColor.R), (byte)(num5 * bevelColor.G), (byte)(num5 * bevelColor.B), bevelColor.A);
334 Color color4 = new((byte)(num2 * bevelColor.R), (byte)(num2 * bevelColor.G), (byte)(num2 * bevelColor.B), bevelColor.A);
335 Color color5 = new((byte)(num3 * bevelColor.R), (byte)(num3 * bevelColor.G), (byte)(num3 * bevelColor.B), bevelColor.A);
336 Color color6 = new((byte)(num6 * color.R), (byte)(num6 * color.G), (byte)(num6 * color.B), color.A);
337 if (texturedBatch != null) {
338 float num7 = textureScale / texturedBatch.Texture.Width;
339 float num8 = textureScale / texturedBatch.Texture.Height;
340 float num9 = x * num7;
341 float num10 = y * num8;
342 float x6 = num9;
343 float x7 = (x2 - x) * num7 + num9;
344 float x8 = (x3 - x) * num7 + num9;
345 float x9 = (x4 - x) * num7 + num9;
346 float y6 = num10;
347 float y7 = (y2 - y) * num8 + num10;
348 float y8 = (y3 - y) * num8 + num10;
349 float y9 = (y4 - y) * num8 + num10;
350 if (bevelColor.A > 0) {
351 texturedBatch.QueueQuad(
352 new Vector2(x, y),
353 new Vector2(x2, y2),
354 new Vector2(x3, y2),
355 new Vector2(x4, y),
356 depth,
357 new Vector2(x6, y6),
358 new Vector2(x7, y7),
359 new Vector2(x8, y7),
360 new Vector2(x9, y6),
361 color4
362 );
363 texturedBatch.QueueQuad(
364 new Vector2(x3, y2),
365 new Vector2(x3, y3),
366 new Vector2(x4, y4),
367 new Vector2(x4, y),
368 depth,
369 new Vector2(x8, y7),
370 new Vector2(x8, y8),
371 new Vector2(x9, y9),
372 new Vector2(x9, y6),
373 color3
374 );
375 texturedBatch.QueueQuad(
376 new Vector2(x, y4),
377 new Vector2(x4, y4),
378 new Vector2(x3, y3),
379 new Vector2(x2, y3),
380 depth,
381 new Vector2(x6, y9),
382 new Vector2(x9, y9),
383 new Vector2(x8, y8),
384 new Vector2(x7, y8),
385 color5
386 );
387 texturedBatch.QueueQuad(
388 new Vector2(x, y),
389 new Vector2(x, y4),
390 new Vector2(x2, y3),
391 new Vector2(x2, y2),
392 depth,
393 new Vector2(x6, y6),
394 new Vector2(x6, y9),
395 new Vector2(x7, y8),
396 new Vector2(x7, y7),
397 color2
398 );
399 }
400 if (color6.A > 0) {
401 texturedBatch.QueueQuad(new Vector2(x2, y2), new Vector2(x3, y3), depth, new Vector2(x7, y7), new Vector2(x8, y8), color6);
402 }
403 }
404 else if (flatBatch != null) {
405 if (bevelColor.A > 0) {
406 flatBatch.QueueQuad(new Vector2(x, y), new Vector2(x2, y2), new Vector2(x3, y2), new Vector2(x4, y), depth, color4);
407 flatBatch.QueueQuad(new Vector2(x3, y2), new Vector2(x3, y3), new Vector2(x4, y4), new Vector2(x4, y), depth, color3);
408 flatBatch.QueueQuad(new Vector2(x, y4), new Vector2(x4, y4), new Vector2(x3, y3), new Vector2(x2, y3), depth, color5);
409 flatBatch.QueueQuad(new Vector2(x, y), new Vector2(x, y4), new Vector2(x2, y3), new Vector2(x2, y2), depth, color2);
410 }
411 if (color6.A > 0) {
412 flatBatch.QueueQuad(new Vector2(x2, y2), new Vector2(x3, y3), depth, color6);
413 }
414 }
415 if (bevelSize > 0f
416 && flatBatch != null
417 && shadowColor.A > 0) {
418 Color color7 = shadowColor;
419 Color color8 = new(0, 0, 0, 0);
420 flatBatch.QueueTriangle(
421 new Vector2(x, y4),
422 new Vector2(x2, y5),
423 new Vector2(x2, y4),
424 depth,
425 color8,
426 color8,
427 color7
428 );
429 flatBatch.QueueTriangle(
430 new Vector2(x4, y),
431 new Vector2(x4, y2),
432 new Vector2(x5, y2),
433 depth,
434 color8,
435 color7,
436 color8
437 );
438 flatBatch.QueueTriangle(
439 new Vector2(x4, y4),
440 new Vector2(x4, y5),
441 new Vector2(x5, y4),
442 depth,
443 color7,
444 color8,
445 color8
446 );
447 flatBatch.QueueQuad(
448 new Vector2(x2, y4),
449 new Vector2(x2, y5),
450 new Vector2(x4, y5),
451 new Vector2(x4, y4),
452 depth,
453 color7,
454 color8,
455 color8,
456 color7
457 );
458 flatBatch.QueueQuad(
459 new Vector2(x4, y2),
460 new Vector2(x4, y4),
461 new Vector2(x5, y4),
462 new Vector2(x5, y2),
463 depth,
464 color7,
465 color7,
466 color8,
467 color8
468 );
469 }
470 }
471 }
472}
Engine.Color Color
static readonly DepthStencilState None
void QueueQuad(Vector2 corner1, Vector2 corner2, float depth, Color color)
void QueueTriangle(Vector2 p1, Vector2 p2, Vector2 p3, float depth, Color color)
TexturedBatch2D TexturedBatch(Texture2D texture, bool useAlphaTest=false, int layer=0, DepthStencilState depthStencilState=null, RasterizerState rasterizerState=null, BlendState blendState=null, SamplerState samplerState=null)
FlatBatch2D FlatBatch(int layer=0, DepthStencilState depthStencilState=null, RasterizerState rasterizerState=null, BlendState blendState=null)
void QueueQuad(Vector2 corner1, Vector2 corner2, float depth, Vector2 texCoord1, Vector2 texCoord2, Color color)
static float Saturate(float x)
static void QueueBevelledRectangle(TexturedBatch2D texturedBatch, FlatBatch2D flatBatch, Vector2 c1, Vector2 c2, float depth, float bevelSize, Color color, Color bevelColor, Color shadowColor, float ambientLight, float directionalLight, float textureScale)
override void MeasureOverride(Vector2 parentAvailableSize)
BevelledShapeRenderer.Point[] m_points
static void QueueShapeShadow(FlatBatch2D batch, IEnumerable< Point > points, float pixelsPerUnit, float shadowSize, Color shadowColor)
static void QueueShape(FlatBatch2D batch, IEnumerable< Point > points, float pixelsPerUnit, float antialiasSize, float bevelSize, bool flatShading, Color centerColor, Color bevelColor, float directional, float ambient)
readonly PrimitivesRenderer2D PrimitivesRenderer2D
float GlobalScale
Widget RootWidget
Color GlobalColorTransform
Vector2 DesiredSize
bool IsDrawRequired
virtual bool IsHitTestVisible
Vector2 ActualSize
Matrix GlobalTransform
static Matrix CreateTranslation(float x, float y, float z)
static readonly Vector2 Zero