Advertisement
Guest User

Untitled

a guest
Jan 21st, 2020
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 8.57 KB | None | 0 0
  1. auto ShowData = [this, &selected, &counter, &allFsm, &firstSelected, &endSelection, &lastSelected, /*&EntityListContextualMenu,*/ gameContext, &selectPrevious, &selectNext](
  2.                 ECS::Entity &ent, const std::string &name) {
  3.             ImGui::PushID(counter);
  4.             const bool isItemSelected = selected.find(ent.Index()) != selected.end();
  5.  
  6.             bool errorState = ent.HasComponent<ECS::Comp::TamChangeCorruption>();
  7.  
  8.             if (isItemSelected) {
  9.                 firstSelected = std::min(firstSelected, counter);
  10.                 lastSelected = counter;
  11.             }
  12.  
  13.             // TODO: Esto será igual para las dos listas...
  14.             if(ImGui::IsWindowFocused()) {
  15.                 if(ImGui::IsKeyPressed(Keyboard::TOP_ARROW, true)) {
  16.                     selectPrevious = true;
  17.                 }
  18.                 if(ImGui::IsKeyPressed(Keyboard::BOTTOM_ARROW, true)) {
  19.                     selectNext = true;
  20.                 }
  21.             }
  22.  
  23.             if (ImGui::Selectable(name.c_str(), isItemSelected, ImGuiSelectableFlags_SpanAllColumns)) {
  24.                 if (ImGui::IsKeyDown(Key::LEFT_SHIFT)) {
  25.                     endSelection = counter;
  26.                 } else if (ImGui::IsKeyDown(Key::LEFT_CTRL)) {
  27.                     if (isItemSelected) {
  28.                         mSelectorSystem->RemoveSelected(ent);
  29.                     } else {
  30.                         mSelectorSystem->AddSelected(ent);
  31.                     }
  32.                 } else {
  33.                     mSelectorSystem->AddSelected(ent, true);
  34.                 }
  35.             }
  36.  
  37.             struct EntityBatchDragAndDrop {
  38.                 ECS::Entity entities[1024];
  39.                 uint32_t entitiesCount = 0;
  40.             };
  41.  
  42.             ImGui::SetItemAllowOverlap();
  43.             if (ImGui::BeginDragDropTarget()) {
  44.                 if (const ImGuiPayload *payload = ImGui::AcceptDragDropPayload(ENTITY_BATCH_PAYLOAD)) {
  45.                     EntityBatchDragAndDrop acceptedPayload = *(EntityBatchDragAndDrop *) (payload->Data);
  46.                     if (acceptedPayload.entitiesCount > 0) {
  47.  
  48.                         const auto destinationIndex = ent.Index();
  49.  
  50.                         bool isMovementValid = true;
  51.                         for (auto idx = 0u; idx < acceptedPayload.entitiesCount; idx++) {
  52.                             auto &e = acceptedPayload.entities[idx];
  53.                             if (destinationIndex == e.Index()) {
  54.                                 isMovementValid = false;
  55.                             }
  56.                         }
  57.                         if (isMovementValid) {
  58.                             if (ImGui::IsKeyDown(Key::LEFT_CTRL)) {
  59.                                 for (auto idx = 0u; idx < acceptedPayload.entitiesCount; idx++) {
  60.                                     auto &e = acceptedPayload.entities[idx];
  61.                                     mSGSystem->MoveOver(::ECS::Index(e.Index()), destinationIndex);
  62.                                 }
  63.                             } else {
  64.                                 for (auto idx = acceptedPayload.entitiesCount; idx > 0; idx--) {
  65.                                     auto &e = acceptedPayload.entities[idx - 1];
  66.                                     mSGSystem->MoveUnder(::ECS::Index(e.Index()), destinationIndex);
  67.                                 }
  68.                             }
  69.                             ent.GetComponentHandler<ECS::Comp::Transform>().ForceReplace();
  70.                         }
  71.                     }
  72.                 }
  73.                 ImGui::EndDragDropTarget();
  74.             }
  75.             ImGui::SetItemAllowOverlap();
  76.             if (ImGui::BeginDragDropSource(ImGuiDragDropFlags_SourceAllowNullID)) {
  77.  
  78.                 EntityBatchDragAndDrop ebdd;
  79.                 mSelectorSystem->ForEachSelected([&](size_t idx, ECS::Entity e) {
  80.                     if (ebdd.entitiesCount < 1002) {
  81.                         ebdd.entities[ebdd.entitiesCount++] = e;
  82.                     } else {
  83.                         std::cerr << "[ERR] more than 1000 items moving at same time!!" << std::endl;
  84.                     }
  85.                 });
  86.  
  87.                 ImGui::SetDragDropPayload(ENTITY_BATCH_PAYLOAD, &ebdd, sizeof(ebdd), ImGuiCond_Always);
  88.                 if (ebdd.entitiesCount == 1) {
  89.                     ImGui::Text("Moving node....%s", name.c_str());
  90.                 } else {
  91.                     std::stringstream ss;
  92.                     ImGui::Text("Moving %d entities.", ebdd.entitiesCount);
  93.                 }
  94.                 ImGui::EndDragDropSource();
  95.             }
  96.             ImGui::SetItemAllowOverlap();
  97.             if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(Mouse::CLICK)) {
  98.  
  99.             }
  100.  
  101.             if (ImGui::BeginPopupContextWindow()) {
  102. //                EntityListContextualMenu(counter);
  103.                 componentTag.ShowContextualMenu(selected, selectedForRemove);
  104.                 ImGui::EndPopup();
  105.             }
  106.  
  107.             ImGui::NextColumn();
  108.  
  109.  
  110.             //ImGui::Text("%d", c.z); ImGui::NextColumn();
  111.             //ImGui::Text("%d", c.cheatOrder); ImGui::NextColumn();
  112.             bool keep_line = false;
  113.  
  114.             const auto pre = ImGui::GetCursorPos();
  115.             const auto CHAR_SIZE = ImGui::CalcTextSize("A");
  116.  
  117.             auto item_signature = ent.GetSignature();
  118.  
  119. //            const auto add_component_tag = [&](const ECS::Signature &signature, ImColor color, std::string_view text) {
  120. //                if (ECS::Match(item_signature, signature)) {
  121. //                    if (keep_line) {
  122. //                        ImGui::SameLine();
  123. //                    }
  124. //                    ImGui::TextColored(color, "+%s", text.data());
  125. //                    keep_line = true;
  126. //                }
  127. //            };
  128.            
  129.             componentTag.RotTag(ent);
  130.             componentTag.RotRefTag(ent);
  131.             componentTag.RotBaseTag(ent);
  132.             componentTag.SpriteTag(ent);
  133.             componentTag.AnimationTag(ent);
  134.             componentTag.AnimationPlayingTag(ent);
  135.             componentTag.FontTag(ent);
  136.             componentTag.NativeReelTag(ent);
  137.             componentTag.SoundTag(ent);
  138.             componentTag.LayeredFontTag(ent);
  139.  
  140.             if (ent.HasComponent<ECS::Comp::Video>()) {
  141.                 if (keep_line) {
  142.                     ImGui::SameLine();
  143.                 }
  144.                 const std::string VIDEO_TAG = "Video"; // TODO: Ver como ponemos esto....
  145.                 ImGui::TextColored(EddieColors().COLOR_VIDEO, "+%s", VIDEO_TAG.c_str());
  146.                 keep_line = true;
  147.             }
  148.  
  149.             auto add_fsm = componentTag.FsmTag(ent);
  150.  
  151.  
  152.             if (add_fsm) {
  153.                 ImGui::SameLine();
  154.                 const auto post = ImGui::GetCursorPos();
  155.                 const auto spacing = ImVec2(post.x - pre.x, CHAR_SIZE.y);
  156.                 ImGui::SetCursorPos(pre);
  157.                 ImGui::Dummy(spacing);
  158.                 auto fsm_obj = ent.GetComponentHandler<ECS::Comp::Fsm>();
  159.                 if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(Mouse::CLICK)) {
  160.                     gContext->EmitEvent<ECS::DirectSelectFsm>(fsm_obj->fsmCode);
  161.                 }
  162.  
  163.                 if (isItemSelected) {
  164.                     allFsm.emplace(fsm_obj->fsmCode);
  165.                 }
  166.             }
  167.             ImGui::NextColumn();
  168.  
  169.             if (!errorState) {
  170.                 const auto cursor = ImGui::GetCursorPos();
  171.                 ImVec2 size;
  172.  
  173.                 if (ent.HasComponent<ECS::Comp::OnScene>()) {
  174.                     size = ImGui::CalcTextSize("- Visible");
  175.                     ImGui::TextColored(EddieColors().COLOR_VISIBLE, "- Visible");
  176.                 } else {
  177.                     size = ImGui::CalcTextSize("- Invisible");
  178.                     ImGui::TextColored(EddieColors().COLOR_INVISIBLE, "- Invisible");
  179.                 }
  180.                 ImGui::SetCursorPos(cursor);
  181.                 ImGui::Dummy(size);
  182.                 if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(0)) {
  183.                     if (ent.HasComponent<ECS::Comp::OnScene>()) {
  184.                         ent.Remove<ECS::Comp::OnScene>();
  185.                     } else {
  186.                         ent.AddComponent<ECS::Comp::OnScene>();
  187.                     }
  188.                 }
  189.                 ImGui::SameLine();
  190.                 componentTag.HideOnEditorTag(ent);
  191.             } else {
  192.                 ImGui::TextColored(EddieColors().COLOR_MISSING_DATA, "MISSING TAM DATA ");
  193.                 ImGui::SameLine();
  194.             }
  195.             ImGui::NextColumn();
  196.             ImGui::PopID();
  197.             counter++;
  198.         };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement