Skip to content

Commit

Permalink
Merge pull request #196 from JacobDomagala/194-add-group-layer-change
Browse files Browse the repository at this point in the history
[#194]: Add group modifications (layer and collision) in group select
  • Loading branch information
JacobDomagala authored Mar 2, 2024
2 parents 9d8007e + 4db4beb commit 7378ce2
Show file tree
Hide file tree
Showing 7 changed files with 213 additions and 36 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
17 changes: 11 additions & 6 deletions editor/editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,15 +173,16 @@ Editor::MouseButtonCallback(MouseButtonEvent& event)
gui_.ObjectUnselected(object);
}


auto& firstObject = currentLevel_->GetGameObjectRef(selectedObjects.front());

selectedObjects_ = selectedObjects;
auto& firstObject = currentLevel_->GetGameObjectRef(selectedObjects_.front());
auto gizmoPos = firstObject.GetCenteredPosition();
glm::vec2 min = gizmoPos;
glm::vec2 max = gizmoPos;

for (const auto object : selectedObjects)
for (const auto object : selectedObjects_)
{
gui_.ObjectSelected(object);
gui_.ObjectSelected(object, true);
const auto& objectPos =
currentLevel_->GetGameObjectRef(object).GetCenteredPosition();

Expand All @@ -196,7 +197,7 @@ Editor::MouseButtonCallback(MouseButtonEvent& event)
};
}

selectedObjects_ = selectedObjects;


gizmoActive_ = true;
gizmo_.Show();
Expand Down Expand Up @@ -495,6 +496,10 @@ Editor::HandleGameObjectClicked(Object::ID newSelectedGameObject, bool groupSele
}

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

movementOnGameObject_ = !fromGUI;
Expand Down Expand Up @@ -570,7 +575,7 @@ Editor::SelectGameObject(Object::ID newSelectedGameObject)
}

currentSelectedGameObject_ = newSelectedGameObject;
gui_.ObjectSelected(currentSelectedGameObject_);
gui_.ObjectSelected(currentSelectedGameObject_, false);

// Make sure to render animation points if needed
auto& gameObject = currentLevel_->GetGameObjectRef(newSelectedGameObject);
Expand Down
56 changes: 48 additions & 8 deletions editor/gui/editor_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
#include "game_object.hpp"
#include "helpers.hpp"
#include "icons.hpp"
#include "input/input_manager.hpp"
#include "renderer/renderer.hpp"
#include "renderer/shader.hpp"
#include "renderer/texture.hpp"
#include "renderer/types.hpp"
#include "renderer/vulkan_common.hpp"
#include "types.hpp"
#include "utils/file_manager.hpp"
#include "input/input_manager.hpp"

#include <GLFW/glfw3.h>
#include <fmt/format.h>
Expand All @@ -27,6 +27,32 @@ EditorGUI::EditorGUI(Editor& parent) : parent_(parent)
{
}

void
EditorGUI::RecalculateCommonRenderLayerAndColision()
{
if (selectedObjects_.empty())
{
return;
}

const auto& [idFirst, collisionFirst, layerFirst] = selectedObjects_.front();
commonRenderLayer_ = {true, layerFirst};
commonCollision_ = {true, collisionFirst};

for (uint32_t idx = 1; idx < selectedObjects_.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))
{
commonCollision_.first = false;
}
}
}

void
EditorGUI::KeyCallback(KeyEvent& event)
{
Expand Down Expand Up @@ -146,7 +172,7 @@ EditorGUI::UpdateUI()
}

ImGui::Render();

setScrollTo_ = {};
}

Expand Down Expand Up @@ -183,25 +209,39 @@ EditorGUI::LevelLoaded(const std::shared_ptr< Level >& loadedLevel)
}

void
EditorGUI::ObjectSelected(Object::ID ID)
EditorGUI::ObjectSelected(Object::ID ID, bool groupSelect)
{
objectsInfo_[ID].second = true;
setScrollTo_ = ID;

currentlySelectedGameObject_ = ID;
const auto& gameObject = parent_.GetLevel().GetGameObjectRef(ID);
selectedObjects_.emplace_back(
ID, gameObject.GetHasCollision(), gameObject.GetSprite().GetRenderInfo().layer);
RecalculateCommonRenderLayerAndColision();

if (not groupSelect)
{
currentlySelectedGameObject_ = ID;
}
}

void
EditorGUI::ObjectUnselected(Object::ID ID)
{
objectsInfo_[currentlySelectedGameObject_].second = false;
currentlySelectedGameObject_ = Object::INVALID_ID;

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
10 changes: 9 additions & 1 deletion editor/gui/editor_gui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class EditorGUI : public InputListener
LevelLoaded(const std::shared_ptr< Level >& loadedLevel);

void
ObjectSelected(Object::ID ID);
ObjectSelected(Object::ID ID, bool groupSelect);

void
ObjectUnselected(Object::ID ID);
Expand Down Expand Up @@ -90,12 +90,17 @@ class EditorGUI : public InputListener
void
RenderGameObjectContent();

void
RenderGroupSelectModifications();

void
RenderCreateNewLevelWindow();

void
RenderExitWindow();

void RecalculateCommonRenderLayerAndColision();

private:
static void
PrepareResources();
Expand All @@ -122,6 +127,9 @@ class EditorGUI : public InputListener
// Data needed for loaded objects menu
std::unordered_map< Object::ID, std::pair< std::string, bool > > objectsInfo_ = {};
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
Loading

0 comments on commit 7378ce2

Please sign in to comment.