From a655f0bae5f428361f41ca5c8e4da689c537baba Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Thu, 17 Dec 2015 13:28:31 +0100 Subject: [PATCH] Drag-and-drop asset picking and base work for showing component field tooltips in the editor --- assets | 2 +- include/Engine/Editor/EditorSystem.h | 5 ++++ src/Engine/Editor/EditorSystem.cpp | 42 +++++++++++++++++++++++----- 3 files changed, 41 insertions(+), 8 deletions(-) diff --git a/assets b/assets index c5f67434..673d4a4e 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit c5f674349a915ab1a2b4da632d87a9832d1f6fab +Subproject commit 673d4a4e4c5a3f5bc9fedf82234e8f8751f63a44 diff --git a/include/Engine/Editor/EditorSystem.h b/include/Engine/Editor/EditorSystem.h index 021a14ca..6709775d 100644 --- a/include/Engine/Editor/EditorSystem.h +++ b/include/Engine/Editor/EditorSystem.h @@ -1,5 +1,6 @@ #include #include +#include #include "../Core/System.h" #include "../Core/EMousePress.h" #include "../Core/EMouseRelease.h" @@ -8,6 +9,7 @@ #include "../Input/EInputCommand.h" #include "../Rendering/IRenderer.h" #include "../Rendering/EPicking.h" +#include "../Core/EFileDropped.h" #include "../Rendering/RenderQueueFactory.h" class EditorSystem : public ImpureSystem @@ -50,6 +52,7 @@ private: EntityID m_Selection = 0; EntityID m_LastSelection = 0; glm::vec3 m_Position; + std::string m_LastDroppedFile; EventRelay m_EInputCommand; bool OnInputCommand(const Events::InputCommand& e); @@ -61,6 +64,8 @@ private: bool OnMouseMove(const Events::MouseMove& e); EventRelay m_EPicking; bool OnPicking(const Events::Picking& e); + EventRelay m_EFileDropped; + bool OnFileDropped(const Events::FileDropped& e); void updateWidget(); void setWidgetMode(WidgetMode newMode); diff --git a/src/Engine/Editor/EditorSystem.cpp b/src/Engine/Editor/EditorSystem.cpp index 2463aec6..32f5b162 100644 --- a/src/Engine/Editor/EditorSystem.cpp +++ b/src/Engine/Editor/EditorSystem.cpp @@ -19,6 +19,7 @@ EditorSystem::EditorSystem(EventBroker* eventBroker, IRenderer* renderer) EVENT_SUBSCRIBE_MEMBER(m_EMouseRelease, &EditorSystem::OnMouseRelease); EVENT_SUBSCRIBE_MEMBER(m_EMouseMove, &EditorSystem::OnMouseMove); EVENT_SUBSCRIBE_MEMBER(m_EPicking, &EditorSystem::OnPicking); + EVENT_SUBSCRIBE_MEMBER(m_EFileDropped, &EditorSystem::OnFileDropped); } void EditorSystem::Update(World* world, double dt) @@ -36,6 +37,11 @@ void EditorSystem::Update(World* world, double dt) updateWidget(); drawUI(world, dt); + + // Clear drop queue if it wasn't handled by any UI element + if (!m_LastDroppedFile.empty()) { + m_LastDroppedFile = ""; + } } bool EditorSystem::OnInputCommand(const Events::InputCommand& e) @@ -212,6 +218,12 @@ bool EditorSystem::OnPicking(const Events::Picking& e) return true; }; +bool EditorSystem::OnFileDropped(const Events::FileDropped& e) +{ + m_LastDroppedFile = boost::filesystem::path(e.Path).lexically_relative(boost::filesystem::current_path()).string(); + std::replace(m_LastDroppedFile.begin(), m_LastDroppedFile.end(), '\\', '/'); + return true; +} void EditorSystem::updateWidget() { @@ -389,37 +401,53 @@ void EditorSystem::drawUI(World* world, double dt) const std::string& field = pair.first; const std::string& type = pair.second; + ImGui::PushID(field.c_str()); if (type == "Vector") { auto& val = component.Property(field); if (field == "Scale") { - ImGui::DragFloat3(field.c_str(), glm::value_ptr(val), 0.1f, 0.f, std::numeric_limits::max()); + ImGui::DragFloat3("", glm::value_ptr(val), 0.1f, 0.f, std::numeric_limits::max()); } else if (field == "Orientation") { glm::vec3 tempVal = glm::fmod(val, glm::vec3(glm::two_pi())); - if (ImGui::SliderFloat3(field.c_str(), glm::value_ptr(tempVal), 0.f, glm::two_pi())) { + if (ImGui::SliderFloat3("", glm::value_ptr(tempVal), 0.f, glm::two_pi())) { val = tempVal; } } else { - ImGui::DragFloat3(field.c_str(), glm::value_ptr(val), 0.1f, std::numeric_limits::lowest(), std::numeric_limits::max()); + ImGui::DragFloat3("", glm::value_ptr(val), 0.1f, std::numeric_limits::lowest(), std::numeric_limits::max()); } } else if (type == "Color") { auto& val = component.Property(field); - ImGui::ColorEdit4(field.c_str(), glm::value_ptr(val), true); + ImGui::ColorEdit4("", glm::value_ptr(val), true); } else if (type == "string") { std::string& val = component.Property(field); char tempString[1024]; memcpy(tempString, val.c_str(), std::min(val.length() + 1, sizeof(tempString))); - if (ImGui::InputText(field.c_str(), tempString, sizeof(tempString))) { + if (ImGui::InputText("", tempString, sizeof(tempString))) { val = std::string(tempString); LOG_DEBUG("%s::%s changed!", componentType.c_str(), field.c_str()); } + // DROP STUFF + if (ImGui::IsItemHovered() && !m_LastDroppedFile.empty()) { + val = m_LastDroppedFile; + m_LastDroppedFile = ""; + } + } else if (type == "double") { float tempVal = static_cast(component.Property(field)); - if (ImGui::InputFloat(field.c_str(), &tempVal, 0.01f, 1.f)) { + if (ImGui::InputFloat("", &tempVal, 0.01f, 1.f)) { component.SetProperty(field, static_cast(tempVal)); } } else if (type == "bool") { auto& val = component.Property(field); - ImGui::Checkbox(field.c_str(), &val); + ImGui::Checkbox("", &val); + } else { + ImGui::TextDisabled(type.c_str()); + } + ImGui::PopID(); + + ImGui::SameLine(); + ImGui::Text(field.c_str()); + if (ImGui::IsItemHovered()) { + ImGui::SetTooltip("field annotation goes here"); } } }