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 afae7d8
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 34 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
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 afae7d8

Please sign in to comment.