Editor widget selection and creation
This commit is contained in:
@@ -36,13 +36,55 @@ void EditorGUI::drawTools()
|
||||
}
|
||||
|
||||
// Translate widget button
|
||||
ImGui::ImageButton((void*)tryLoadTexture("Textures/Icons/Translate.png"), ImVec2(24, 24), ImVec2(0, 1), ImVec2(1, 0));
|
||||
if (ImGui::ImageButton(
|
||||
(void*)tryLoadTexture("Textures/Icons/Translate.png"),
|
||||
ImVec2(24, 24),
|
||||
ImVec2(0, 1),
|
||||
ImVec2(1, 0),
|
||||
-1,
|
||||
ImVec4(0, 0, 0, 0),
|
||||
(m_CurrentWidgetMode == WidgetMode::Translate) ? ImVec4(0, 1, 0, 1) : ImVec4(1, 1, 1, 1)
|
||||
)
|
||||
) {
|
||||
m_CurrentWidgetMode = WidgetMode::Translate;
|
||||
if (m_OnWidgetMode != nullptr) {
|
||||
m_OnWidgetMode(m_CurrentWidgetMode);
|
||||
}
|
||||
}
|
||||
// Rotate widget button
|
||||
ImGui::SameLine();
|
||||
ImGui::ImageButton((void*)tryLoadTexture("Textures/Icons/Rotate.png"), ImVec2(24, 24), ImVec2(0, 1), ImVec2(1, 0));
|
||||
if (ImGui::ImageButton(
|
||||
(void*)tryLoadTexture("Textures/Icons/Rotate.png"),
|
||||
ImVec2(24, 24),
|
||||
ImVec2(0, 1),
|
||||
ImVec2(1, 0),
|
||||
-1,
|
||||
ImVec4(0, 0, 0, 0),
|
||||
(m_CurrentWidgetMode == WidgetMode::Rotate) ? ImVec4(0, 1, 0, 1) : ImVec4(1, 1, 1, 1)
|
||||
)
|
||||
) {
|
||||
m_CurrentWidgetMode = WidgetMode::Rotate;
|
||||
if (m_OnWidgetMode != nullptr) {
|
||||
m_OnWidgetMode(m_CurrentWidgetMode);
|
||||
}
|
||||
}
|
||||
// Scale widget button
|
||||
ImGui::SameLine();
|
||||
ImGui::ImageButton((void*)tryLoadTexture("Textures/Icons/Scale.png"), ImVec2(24, 24), ImVec2(0, 1), ImVec2(1, 0));
|
||||
if (ImGui::ImageButton(
|
||||
(void*)tryLoadTexture("Textures/Icons/Scale.png"),
|
||||
ImVec2(24, 24),
|
||||
ImVec2(0, 1),
|
||||
ImVec2(1, 0),
|
||||
-1,
|
||||
ImVec4(0, 0, 0, 0),
|
||||
(m_CurrentWidgetMode == WidgetMode::Scale) ? ImVec4(0, 1, 0, 1) : ImVec4(1, 1, 1, 1)
|
||||
)
|
||||
) {
|
||||
m_CurrentWidgetMode = WidgetMode::Scale;
|
||||
if (m_OnWidgetMode != nullptr) {
|
||||
m_OnWidgetMode(m_CurrentWidgetMode);
|
||||
}
|
||||
}
|
||||
|
||||
ImGui::SameLine();
|
||||
ImGui::ItemSize(ImVec2(5, 0));
|
||||
@@ -83,7 +125,7 @@ void EditorGUI::drawEntities(World* world)
|
||||
entityImport(world);
|
||||
}
|
||||
ImGui::SameLine(0.f, 5.f);
|
||||
ImGui::Button("Reference", ImVec2(buttonWidth, 0));
|
||||
ImGui::ButtonEx("Reference", ImVec2(buttonWidth, 0), ImGuiButtonFlags_Disabled);
|
||||
|
||||
// Naming
|
||||
char buffer[256];
|
||||
|
||||
@@ -12,9 +12,7 @@ EditorSystem::EditorSystem(World* world, EventBroker* eventBroker, IRenderer* re
|
||||
m_EditorWorldSystemPipeline->AddSystem<UniformScaleSystem>(0);
|
||||
m_EditorWorldSystemPipeline->AddSystem<EditorRenderSystem>(1, m_Renderer, m_RenderFrame);
|
||||
|
||||
m_Widget = importEntity(EntityWrapper(m_EditorWorld, EntityID_Invalid), "Schema/Entities/EditorWidget.xml");
|
||||
|
||||
m_Camera = EntityWrapper(m_EditorWorld, m_EditorWorld->CreateEntity());
|
||||
m_Camera = importEntity(EntityWrapper(m_EditorWorld, EntityID_Invalid), "Schema/Entities/Empty.xml");
|
||||
m_EditorWorld->AttachComponent(m_Camera.ID, "Transform");
|
||||
m_EditorWorld->AttachComponent(m_Camera.ID, "Camera");
|
||||
m_DebugCameraInputController = new DebugCameraInputController<EditorSystem>(m_EventBroker, -1);
|
||||
@@ -29,6 +27,7 @@ EditorSystem::EditorSystem(World* world, EventBroker* eventBroker, IRenderer* re
|
||||
m_EditorGUI->SetEntityChangeNameCallback(std::bind(&EditorSystem::OnEntityChangeName, this, std::placeholders::_1, std::placeholders::_2));
|
||||
m_EditorGUI->SetComponentAttachCallback(std::bind(&EditorSystem::OnComponentAttach, this, std::placeholders::_1, std::placeholders::_2));
|
||||
m_EditorGUI->SetComponentDeleteCallback(std::bind(&EditorSystem::OnComponentDelete, this, std::placeholders::_1, std::placeholders::_2));
|
||||
m_EditorGUI->SetWidgetModeCallback(std::bind(&EditorSystem::setWidgetMode, this, std::placeholders::_1));
|
||||
|
||||
m_EditorStats = new EditorStats();
|
||||
|
||||
@@ -60,7 +59,8 @@ void EditorSystem::Update(double dt)
|
||||
|
||||
void EditorSystem::OnEntitySelected(EntityWrapper entity)
|
||||
{
|
||||
m_Widget["Transform"]["Position"] = Transform::AbsolutePosition(entity.World, entity.ID);
|
||||
m_CurrentSelection = entity;
|
||||
setWidgetMode(m_WidgetMode);
|
||||
}
|
||||
|
||||
void EditorSystem::OnEntitySave(EntityWrapper entity, boost::filesystem::path filePath)
|
||||
@@ -118,4 +118,36 @@ EntityWrapper EditorSystem::importEntity(EntityWrapper parent, boost::filesystem
|
||||
} catch (const std::exception&) {
|
||||
return EntityWrapper::Invalid;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void EditorSystem::setWidgetMode(EditorGUI::WidgetMode mode)
|
||||
{
|
||||
if (mode == m_WidgetMode && m_Widget.Valid() && m_CurrentSelection.Valid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_Widget.Valid()) {
|
||||
m_Widget.World->DeleteEntity(m_Widget.ID);
|
||||
m_Widget = EntityWrapper::Invalid;
|
||||
}
|
||||
|
||||
if (!m_CurrentSelection.Valid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (mode) {
|
||||
case EditorGUI::WidgetMode::Translate:
|
||||
m_Widget = importEntity(EntityWrapper(m_World, EntityID_Invalid), "Schema/Entities/EditorWidgetTranslate.xml");
|
||||
break;
|
||||
case EditorGUI::WidgetMode::Rotate:
|
||||
m_Widget = importEntity(EntityWrapper(m_World, EntityID_Invalid), "Schema/Entities/EditorWidgetRotate.xml");
|
||||
break;
|
||||
case EditorGUI::WidgetMode::Scale:
|
||||
m_Widget = importEntity(EntityWrapper(m_World, EntityID_Invalid), "Schema/Entities/EditorWidgetScale.xml");
|
||||
break;
|
||||
}
|
||||
|
||||
m_Widget["Transform"]["Position"] = Transform::AbsolutePosition(m_CurrentSelection.World, m_CurrentSelection.ID);
|
||||
|
||||
m_WidgetMode = mode;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user