Skip to content

Commit

Permalink
[#194]: Working group modification with warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobDomagala committed Mar 2, 2024
1 parent 992b959 commit e30dfe4
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
run: |
# Use newer ABI
conan profile detect
conan install $GITHUB_WORKSPACE --output-folder=build --build=missing --settings=build_type=$BUILD_TYPE
conan install $GITHUB_WORKSPACE --output-folder=build --build=missing --settings=build_type=$BUILD_TYPE -c tools.system.package_manager:mode=install
- name: Run CMake
shell: bash
Expand Down
4 changes: 4 additions & 0 deletions editor/editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,10 @@ Editor::HandleGameObjectClicked(Object::ID newSelectedGameObject, bool groupSele
}

selectedObjects_.push_back(newSelectedGameObject);
if (groupSelect)
{
gui_.ObjectSelected(newSelectedGameObject, groupSelect);
}
}

movementOnGameObject_ = !fromGUI;
Expand Down
50 changes: 25 additions & 25 deletions editor/gui/editor_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions editor/gui/editor_gui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,7 @@ class EditorGUI : public InputListener
void
RenderExitWindow();

void
RecalculateCommonRenderLayerAndColision();
void RecalculateCommonRenderLayerAndColision();

private:
static void
Expand Down Expand Up @@ -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<std::tuple< Object::ID, bool, int32_t > > selectedObjects_ = {};
};

} // namespace looper
44 changes: 38 additions & 6 deletions editor/gui/editor_gui_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
{
Expand All @@ -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};
});
}
}
Expand All @@ -151,6 +157,7 @@ EditorGUI::RenderGroupSelectModifications()
CreateActionRowLabel(
"Has Collision",
[this] {
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x);
if (ImGui::Checkbox("##GroupHasCollision", &commonCollision_.second))
{
parent_.AddToWorkQueue([this] {
Expand All @@ -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();
});
}
Expand Down Expand Up @@ -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();
});
}
}
Expand All @@ -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();
}
});
Expand Down

0 comments on commit e30dfe4

Please sign in to comment.