MCPcopy Create free account
hub / github.com/WolfireGames/overgrowth / PrefabSelected

Method PrefabSelected

Source/Editors/map_editor.cpp:1447–1522  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1445}
1446
1447int MapEditor::PrefabSelected() {
1448 RibbonFlash(gui, "prefab");
1449 ReturnSelected(&selected);
1450
1451 if (selected.size() == 1 && selected[0]->GetType() == _prefab) {
1452 return 1;
1453 } else if (ContainsPrefabsRecursively(selected)) {
1454 return 2;
1455 } else if (selected.size() == 1 && selected[0]->GetType() == _group) {
1456 Group* f_group = static_cast<Group*>(selected[0]);
1457 if (f_group->HasParent()) {
1458 return 3;
1459 } else {
1460 Prefab* prefab = new Prefab();
1461 if (ActorsEditor_AddEntity(scenegraph_, prefab)) {
1462 DeselectAll(scenegraph_);
1463
1464 size_t c_count = f_group->children.size();
1465 prefab->children.resize(c_count);
1466 for (unsigned i = 0; i < c_count; i++) {
1467 prefab->children[i].direct_ptr = f_group->children[i].direct_ptr;
1468 }
1469 for (unsigned i = 0; i < c_count; i++) {
1470 prefab->children[i].direct_ptr->SetParent(prefab);
1471 }
1472
1473 f_group->children.clear();
1474 scenegraph_->UnlinkObject(f_group);
1475 delete f_group;
1476
1477 prefab->InitShape();
1478 prefab->InitRelMats();
1479 prefab->Select(true);
1480 QueueSaveHistoryState();
1481 return 0;
1482 } else {
1483 LOGE << "Failed at adding prefab to scenegraph" << std::endl;
1484 delete prefab;
1485 return 6;
1486 }
1487 }
1488 } else if (selected.size() > 0) {
1489 std::vector<int> child_ids;
1490 for (auto& i : selected) {
1491 if (!i->parent) {
1492 child_ids.push_back(i->GetID());
1493 }
1494 }
1495 if (child_ids.size() > 0) {
1496 Prefab* prefab = new Prefab();
1497 if (ActorsEditor_AddEntity(scenegraph_, prefab)) {
1498 prefab->children.resize(child_ids.size());
1499 for (size_t i = 0, len = child_ids.size(); i < len; ++i) {
1500 prefab->children[i].direct_ptr = scenegraph_->GetObjectFromID(child_ids[i]);
1501 }
1502 for (size_t i = 0, len = child_ids.size(); i < len; ++i) {
1503 prefab->children[i].direct_ptr->SetParent(prefab);
1504 }

Callers

nothing calls this directly

Calls 15

RibbonFlashFunction · 0.85
ActorsEditor_AddEntityFunction · 0.85
InitRelMatsMethod · 0.80
GetObjectFromIDMethod · 0.80
sizeMethod · 0.45
GetTypeMethod · 0.45
HasParentMethod · 0.45
resizeMethod · 0.45
SetParentMethod · 0.45
clearMethod · 0.45
UnlinkObjectMethod · 0.45
InitShapeMethod · 0.45

Tested by

no test coverage detected