@@ -248,16 +248,66 @@ inline glm::vec2 Scalable::GetUnfitScale() {
248
248
return scale;
249
249
}
250
250
251
- GenericElement *DeserializeUIElement (EngineSharedContext &sharedContext, rapidxml::xml_node<char > *node) {
251
+ GenericElement *DeserializeUIElement (EngineSharedContext &sharedContext, rapidxml::xml_node<char > *node, UI::GenericElement *parent = nullptr ) {
252
252
using namespace rapidxml ;
253
253
std::string nodeName = node->name ();
254
254
255
255
GenericElement *element;
256
256
257
- if (nodeName == " Panel" ) {
258
- xml_node<char > *fitTypeNode = node->first_node (" FitType" );
257
+ if (nodeName == " Group" ) {
258
+ xml_node<char > *propertiesNode = node->first_node (" Properties" );
259
+ UTILASSERT (propertiesNode);
260
+
261
+ xml_node<char > *fitTypeNode = propertiesNode->first_node (" FitType" );
262
+
263
+ xml_node<char > *positionNode = propertiesNode->first_node (" Position" );
264
+ UTILASSERT (positionNode);
265
+
266
+ xml_node<char > *positionXNode = positionNode->first_node (" X" );
267
+ UTILASSERT (positionXNode);
268
+ float positionX = std::stof (positionXNode->value ());
269
+
270
+ xml_node<char > *positionYNode = positionNode->first_node (" Y" );
271
+ UTILASSERT (positionYNode);
272
+ float positionY = std::stof (positionYNode->value ());
273
+
274
+
275
+ xml_node<char > *scaleNode = propertiesNode->first_node (" Scale" );
276
+ UTILASSERT (scaleNode);
277
+
278
+ xml_node<char > *scaleXNode = scaleNode->first_node (" X" );
279
+ UTILASSERT (scaleXNode);
280
+ float scaleX = std::stof (scaleXNode->value ());
281
+
282
+ xml_node<char > *scaleYNode = scaleNode->first_node (" Y" );
283
+ UTILASSERT (scaleYNode);
284
+ float scaleY = std::stof (scaleYNode->value ());
285
+
286
+ xml_node<char > *zDepthNode = propertiesNode->first_node (" ZDepth" );
287
+ float zDepth = 1 .0f ;
288
+
289
+ if (zDepthNode) {
290
+ zDepth = std::stof (zDepthNode->value ());
291
+ }
292
+
293
+ element = new UI::Scalable ();
294
+ element->SetPosition (glm::vec2 (positionX, positionY));
295
+ element->SetDepth (zDepth);
296
+
297
+ reinterpret_cast <UI::Scalable *>(element)->SetScale (glm::vec2 (scaleX, scaleY));
298
+
299
+ if (fitTypeNode && std::string (fitTypeNode->value ()) == " FIT_CHILDREN" ) {
300
+ reinterpret_cast <UI::Scalable *>(element)->fitType = UI::FIT_CHILDREN;
301
+ } else if (fitTypeNode && std::string (fitTypeNode->value ()) == " NONE" ) {
302
+ reinterpret_cast <UI::Scalable *>(element)->fitType = UI::NONE;
303
+ }
304
+ } else if (nodeName == " Panel" ) {
305
+ xml_node<char > *propertiesNode = node->first_node (" Properties" );
306
+ UTILASSERT (propertiesNode);
307
+
308
+ xml_node<char > *fitTypeNode = propertiesNode->first_node (" FitType" );
259
309
260
- xml_node<char > *colorNode = node ->first_node (" Color" );
310
+ xml_node<char > *colorNode = propertiesNode ->first_node (" Color" );
261
311
UTILASSERT (colorNode);
262
312
263
313
xml_node<char > *colorRNode = colorNode->first_node (" R" );
@@ -273,7 +323,7 @@ GenericElement *DeserializeUIElement(EngineSharedContext &sharedContext, rapidxm
273
323
float colorB = std::stof (colorBNode->value ());
274
324
275
325
276
- xml_node<char > *positionNode = node ->first_node (" Position" );
326
+ xml_node<char > *positionNode = propertiesNode ->first_node (" Position" );
277
327
UTILASSERT (positionNode);
278
328
279
329
xml_node<char > *positionXNode = positionNode->first_node (" X" );
@@ -285,7 +335,7 @@ GenericElement *DeserializeUIElement(EngineSharedContext &sharedContext, rapidxm
285
335
float positionY = std::stof (positionYNode->value ());
286
336
287
337
288
- xml_node<char > *scaleNode = node ->first_node (" Scale" );
338
+ xml_node<char > *scaleNode = propertiesNode ->first_node (" Scale" );
289
339
UTILASSERT (scaleNode);
290
340
291
341
xml_node<char > *scaleXNode = scaleNode->first_node (" X" );
@@ -296,7 +346,7 @@ GenericElement *DeserializeUIElement(EngineSharedContext &sharedContext, rapidxm
296
346
UTILASSERT (scaleYNode);
297
347
float scaleY = std::stof (scaleYNode->value ());
298
348
299
- xml_node<char > *zDepthNode = node ->first_node (" ZDepth" );
349
+ xml_node<char > *zDepthNode = propertiesNode ->first_node (" ZDepth" );
300
350
float zDepth = 1 .0f ;
301
351
302
352
if (zDepthNode) {
@@ -311,11 +361,14 @@ GenericElement *DeserializeUIElement(EngineSharedContext &sharedContext, rapidxm
311
361
reinterpret_cast <UI::Scalable *>(element)->fitType = UI::NONE;
312
362
}
313
363
} else if (nodeName == " Label" ) {
314
- xml_node<char > *textNode = node->first_node (" Text" );
364
+ xml_node<char > *propertiesNode = node->first_node (" Properties" );
365
+ UTILASSERT (propertiesNode);
366
+
367
+ xml_node<char > *textNode = propertiesNode->first_node (" Text" );
315
368
UTILASSERT (textNode);
316
369
std::string text = textNode->value ();
317
370
318
- xml_node<char > *positionNode = node ->first_node (" Position" );
371
+ xml_node<char > *positionNode = propertiesNode ->first_node (" Position" );
319
372
UTILASSERT (positionNode);
320
373
321
374
xml_node<char > *positionXNode = positionNode->first_node (" X" );
@@ -327,11 +380,11 @@ GenericElement *DeserializeUIElement(EngineSharedContext &sharedContext, rapidxm
327
380
float positionY = std::stof (positionYNode->value ());
328
381
329
382
330
- xml_node<char > *fontNode = node ->first_node (" Font" );
383
+ xml_node<char > *fontNode = propertiesNode ->first_node (" Font" );
331
384
UTILASSERT (fontNode);
332
385
std::string fontPath = fontNode->value ();
333
386
334
- xml_node<char > *zDepthNode = node ->first_node (" ZDepth" );
387
+ xml_node<char > *zDepthNode = propertiesNode ->first_node (" ZDepth" );
335
388
float zDepth = 1 .0f ;
336
389
337
390
if (zDepthNode) {
@@ -340,9 +393,12 @@ GenericElement *DeserializeUIElement(EngineSharedContext &sharedContext, rapidxm
340
393
341
394
element = new UI::Label (sharedContext, text, fontPath, glm::vec2 (positionX, positionY), zDepth);
342
395
} else if (nodeName == " Button" ) {
343
- xml_node<char > *fitTypeNode = node->first_node (" FitType" );
396
+ xml_node<char > *propertiesNode = node->first_node (" Properties" );
397
+ UTILASSERT (propertiesNode);
344
398
345
- xml_node<char > *positionNode = node->first_node (" Position" );
399
+ xml_node<char > *fitTypeNode = propertiesNode->first_node (" FitType" );
400
+
401
+ xml_node<char > *positionNode = propertiesNode->first_node (" Position" );
346
402
UTILASSERT (positionNode);
347
403
348
404
xml_node<char > *positionXNode = positionNode->first_node (" X" );
@@ -354,7 +410,7 @@ GenericElement *DeserializeUIElement(EngineSharedContext &sharedContext, rapidxm
354
410
float positionY = std::stof (positionYNode->value ());
355
411
356
412
357
- xml_node<char > *scaleNode = node ->first_node (" Scale" );
413
+ xml_node<char > *scaleNode = propertiesNode ->first_node (" Scale" );
358
414
UTILASSERT (scaleNode);
359
415
360
416
xml_node<char > *scaleXNode = scaleNode->first_node (" X" );
@@ -366,15 +422,15 @@ GenericElement *DeserializeUIElement(EngineSharedContext &sharedContext, rapidxm
366
422
float scaleY = std::stof (scaleYNode->value ());
367
423
368
424
/* bgPanel and fgLabel */
369
- xml_node<char > *bgPanelNode = node ->first_node (" BgPanel" );
425
+ xml_node<char > *bgPanelNode = propertiesNode ->first_node (" BgPanel" );
370
426
UTILASSERT (bgPanelNode);
371
427
xml_node<char > *panelNode = bgPanelNode->first_node (" Panel" );
372
428
373
429
GenericElement *bgPanel = DeserializeUIElement (sharedContext, panelNode);
374
430
UTILASSERT (bgPanel->type == UI::PANEL);
375
431
376
432
377
- xml_node<char > *fgLabelNode = node ->first_node (" FgLabel" );
433
+ xml_node<char > *fgLabelNode = propertiesNode ->first_node (" FgLabel" );
378
434
UTILASSERT (fgLabelNode);
379
435
xml_node<char > *labelNode = fgLabelNode->first_node (" Label" );
380
436
@@ -390,9 +446,17 @@ GenericElement *DeserializeUIElement(EngineSharedContext &sharedContext, rapidxm
390
446
reinterpret_cast <UI::Scalable *>(element)->fitType = UI::NONE;
391
447
}
392
448
} else {
393
- throw std::runtime_error (fmt::format (" Unknown UI Serialized Object Type: {}" , nodeName));
449
+ fmt::println (" WARN: Unknown UI Serialized Object Type: {}" , nodeName);
450
+
451
+ return nullptr ;
394
452
}
395
453
454
+ for (xml_node<char > *childElement = node->first_node (" Properties" )->next_sibling (); childElement; childElement = childElement->next_sibling ()) {
455
+ DeserializeUIElement (sharedContext, childElement, element);
456
+ }
457
+
458
+ element->SetParent (parent);
459
+
396
460
return element;
397
461
}
398
462
@@ -417,7 +481,12 @@ std::vector<GenericElement *> UI::LoadUIFile(EngineSharedContext &sharedContext,
417
481
418
482
xml_node<char > *uiSceneNode = uiSceneXML.first_node (" UIScene" );
419
483
for (xml_node<char > *uiElement = uiSceneNode->first_node (); uiElement; uiElement = uiElement->next_sibling ()) {
420
- elements.push_back (DeserializeUIElement (sharedContext, uiElement));
484
+ GenericElement *element = DeserializeUIElement (sharedContext, uiElement);
485
+
486
+ if (!element)
487
+ continue ;
488
+
489
+ elements.push_back (element);
421
490
}
422
491
423
492
return elements;
0 commit comments