From afae7d8282301951704aecb9171083a250e1683d Mon Sep 17 00:00:00 2001 From: Jakub Domagala Date: Sat, 2 Mar 2024 13:43:01 +0100 Subject: [PATCH] [#194]: Working group modification with warnings --- .github/workflows/ubuntu.yml | 3 +- editor/editor.cpp | 4 +++ editor/gui/editor_gui.cpp | 50 ++++++++++++++++---------------- editor/gui/editor_gui.hpp | 4 +-- editor/gui/editor_gui_object.cpp | 44 ++++++++++++++++++++++++---- 5 files changed, 71 insertions(+), 34 deletions(-) diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index e70b6e00..ec1221df 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -26,7 +26,8 @@ jobs: sudo apt-get install -y xorg-dev llvm-dev iwyu clang++-15 libx11-xcb-dev libxcb-render-util0-dev \ libxcb-xkb-dev libxcb-icccm4-dev libxcb-image0-dev libxcb-keysyms1-dev libxcb-randr0-dev \ libxcb-shape0-dev libxcb-sync-dev libxcb-xfixes0-dev libxcb-xinerama0-dev libxcb-dri3-dev \ - libxcb-util-dev libxcb-cursor-dev + libxcb-util-dev libxcb-cursor-dev libx11-dev libfontenc-dev libice-dev libsm-dev libxau-dev libxaw7-dev \ + libxcb-glx0-dev libxcb-dri2-0-dev libxcb-present-dev libxcb-composite0-dev libxcb-ewmh-dev libxcb-res0-dev pip install conan diff --git a/editor/editor.cpp b/editor/editor.cpp index cc729d95..757c3672 100644 --- a/editor/editor.cpp +++ b/editor/editor.cpp @@ -496,6 +496,10 @@ Editor::HandleGameObjectClicked(Object::ID newSelectedGameObject, bool groupSele } selectedObjects_.push_back(newSelectedGameObject); + if (groupSelect) + { + gui_.ObjectSelected(newSelectedGameObject, groupSelect); + } } movementOnGameObject_ = !fromGUI; diff --git a/editor/gui/editor_gui.cpp b/editor/gui/editor_gui.cpp index 7796a35f..48a27239 100644 --- a/editor/gui/editor_gui.cpp +++ b/editor/gui/editor_gui.cpp @@ -30,32 +30,25 @@ EditorGUI::EditorGUI(Editor& parent) : parent_(parent) void EditorGUI::RecalculateCommonRenderLayerAndColision() { - const auto& objects = parent_.GetSelectedObjects(); - - if (objects.empty()) + if (selectedObjects_.empty()) { return; } - const auto& gameObject = parent_.GetLevel().GetGameObjectRef(objects.front()); - commonCollision_ = {true, gameObject.GetHasCollision()}; - commonRenderLayer_ = {true, gameObject.GetSprite().GetRenderInfo().layer}; + const auto& [idFirst, collisionFirst, layerFirst] = selectedObjects_.front(); + commonRenderLayer_ = {true, layerFirst}; + commonCollision_ = {true, collisionFirst}; - if (objects.size() > 1) + for (int32_t idx = 1; idx < selectedObjects_.size(); idx++) { - for (int32_t idx = 1; idx < objects.size(); ++idx) + const auto& [id, collision, layer] = selectedObjects_.at(idx); + if (commonRenderLayer_.first and (layer != commonRenderLayer_.second)) + { + commonRenderLayer_.first = false; + } + if (commonCollision_.first and (collision != commonCollision_.second)) { - const auto& gameObject = parent_.GetLevel().GetGameObjectRef(objects.at(idx)); - if (commonCollision_.first and (gameObject.GetHasCollision() != commonCollision_.second)) - { - commonCollision_.first = false; - } - - if (commonRenderLayer_.first - and (gameObject.GetSprite().GetRenderInfo().layer != commonRenderLayer_.second)) - { - commonRenderLayer_.first = false; - } + commonCollision_.first = false; } } } @@ -221,6 +214,9 @@ EditorGUI::ObjectSelected(Object::ID ID, bool groupSelect) objectsInfo_[ID].second = true; setScrollTo_ = ID; + const auto& gameObject = parent_.GetLevel().GetGameObjectRef(ID); + selectedObjects_.push_back( + {ID, gameObject.GetHasCollision(), gameObject.GetSprite().GetRenderInfo().layer}); RecalculateCommonRenderLayerAndColision(); if (not groupSelect) @@ -232,16 +228,20 @@ EditorGUI::ObjectSelected(Object::ID ID, bool groupSelect) void EditorGUI::ObjectUnselected(Object::ID ID) { - objectsInfo_[currentlySelectedGameObject_].second = false; - currentlySelectedGameObject_ = Object::INVALID_ID; - - RecalculateCommonRenderLayerAndColision(); - - objectsInfo_[ID].second = false; if (currentlySelectedGameObject_ == ID) { currentlySelectedGameObject_ = Object::INVALID_ID; } + else + { + objectsInfo_[ID].second = false; + + selectedObjects_.erase(stl::find_if(selectedObjects_, [ID](const auto& obj) { + const auto [id, collision, layer] = obj; + return id == ID; + })); + RecalculateCommonRenderLayerAndColision(); + } } void diff --git a/editor/gui/editor_gui.hpp b/editor/gui/editor_gui.hpp index 404d626a..672ff312 100644 --- a/editor/gui/editor_gui.hpp +++ b/editor/gui/editor_gui.hpp @@ -99,8 +99,7 @@ class EditorGUI : public InputListener void RenderExitWindow(); - void - RecalculateCommonRenderLayerAndColision(); + void RecalculateCommonRenderLayerAndColision(); private: static void @@ -130,6 +129,7 @@ class EditorGUI : public InputListener Object::ID setScrollTo_ = Object::INVALID_ID; std::pair< bool, int32_t > commonRenderLayer_ = {false, 0}; std::pair< bool, bool > commonCollision_ = {false, false}; + std::vector > selectedObjects_ = {}; }; } // namespace looper diff --git a/editor/gui/editor_gui_object.cpp b/editor/gui/editor_gui_object.cpp index 374f2a2e..4fcff957 100644 --- a/editor/gui/editor_gui_object.cpp +++ b/editor/gui/editor_gui_object.cpp @@ -111,6 +111,7 @@ EditorGUI::RenderGroupSelectModifications() [this] { const auto items = std::to_array< std::string >({"1", "2", "3", "4", "5", "6", "7", "8", "9", "10"}); + ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); if (ImGui::BeginCombo("##GroupSetLayer", fmt::format("{}", commonRenderLayer_.second).c_str())) { @@ -119,17 +120,22 @@ EditorGUI::RenderGroupSelectModifications() if (ImGui::Selectable(item.c_str())) { parent_.AddToWorkQueue([item, this] { - const auto layer = std::stoi(item); + const auto newLayer = std::stoi(item); const auto& gameObjects = parent_.GetSelectedObjects(); for (auto object : gameObjects) { parent_.GetLevel() .GetGameObjectRef(object) .GetSprite() - .ChangeRenderLayer(layer); + .ChangeRenderLayer(newLayer); } - commonRenderLayer_.second = layer; + for (auto& [id, collision, layer] : selectedObjects_) + { + layer = newLayer; + } + + commonRenderLayer_ = {true, newLayer}; }); } } @@ -151,6 +157,7 @@ EditorGUI::RenderGroupSelectModifications() CreateActionRowLabel( "Has Collision", [this] { + ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); if (ImGui::Checkbox("##GroupHasCollision", &commonCollision_.second)) { parent_.AddToWorkQueue([this] { @@ -160,6 +167,13 @@ EditorGUI::RenderGroupSelectModifications() parent_.GetLevel().GetGameObjectRef(object).SetHasCollision( commonCollision_.second); } + + for (auto& [id, collision, layer] : selectedObjects_) + { + collision = commonCollision_.second; + } + commonCollision_.first = true; + parent_.GetLevel().UpdateCollisionTexture(); }); } @@ -217,9 +231,19 @@ EditorGUI::RenderGameObjectContent() { if (ImGui::Selectable(item.c_str())) { - parent_.AddToWorkQueue([&gameObject, item] { - const auto layer = std::stoi(item); - gameObject.GetSprite().ChangeRenderLayer(layer); + parent_.AddToWorkQueue([&gameObject, item, this] { + const auto newLayer = std::stoi(item); + gameObject.GetSprite().ChangeRenderLayer(newLayer); + + auto obj = + stl::find_if(selectedObjects_, + [curID = currentlySelectedGameObject_](const auto& obj) { + auto [id, collision, layer] = obj; + return id == curID; + }); + auto& [objID, objCollision, objLayer] = *obj; + objLayer = newLayer; + RecalculateCommonRenderLayerAndColision(); }); } } @@ -233,6 +257,14 @@ EditorGUI::RenderGameObjectContent() if (ImGui::Checkbox("##Has Collision", &collision)) { gameObject.SetHasCollision(collision); + auto obj = stl::find_if(selectedObjects_, + [curID = currentlySelectedGameObject_](const auto& obj) { + auto [id, collision, layer] = obj; + return id == curID; + }); + auto& [objID, objCollision, objLayer] = *obj; + objCollision = collision; + RecalculateCommonRenderLayerAndColision(); parent_.GetLevel().UpdateCollisionTexture(); } });