diff --git a/include/Engine/Editor/EditorGUI.h b/include/Engine/Editor/EditorGUI.h index 104c6787..49e0f8ab 100644 --- a/include/Engine/Editor/EditorGUI.h +++ b/include/Engine/Editor/EditorGUI.h @@ -131,6 +131,7 @@ private: // Custom UI elements bool createDeleteButton(const std::string& componentType); + void createWidgetToolButton(WidgetMode mode); }; #endif \ No newline at end of file diff --git a/resources/Schema/Entities/EditorWidgetRotate.xml b/resources/Schema/Entities/EditorWidgetRotate.xml index 55dd9af4..8c454f0c 100644 --- a/resources/Schema/Entities/EditorWidgetRotate.xml +++ b/resources/Schema/Entities/EditorWidgetRotate.xml @@ -3,6 +3,9 @@ + + + @@ -12,7 +15,6 @@ - Models/RotationWidgetX.obj @@ -27,7 +29,6 @@ - Models/RotationWidgetY.obj @@ -42,7 +43,6 @@ - Models/RotationWidgetZ.obj @@ -53,7 +53,10 @@ - + + -1 + 0 + diff --git a/resources/Schema/Entities/EditorWidgetScale.xml b/resources/Schema/Entities/EditorWidgetScale.xml index b317b1cc..15bcb38b 100644 --- a/resources/Schema/Entities/EditorWidgetScale.xml +++ b/resources/Schema/Entities/EditorWidgetScale.xml @@ -6,6 +6,9 @@ Models/ScaleWidgetOrigin.obj + + + @@ -15,7 +18,6 @@ - Models/ScaleWidgetX.obj @@ -30,7 +32,6 @@ - Models/ScaleWidgetY.obj @@ -45,7 +46,6 @@ - Models/ScaleWidgetZ.obj diff --git a/resources/Schema/Entities/EditorWidgetTranslate.xml b/resources/Schema/Entities/EditorWidgetTranslate.xml index 56943adc..e2cfd69a 100644 --- a/resources/Schema/Entities/EditorWidgetTranslate.xml +++ b/resources/Schema/Entities/EditorWidgetTranslate.xml @@ -6,17 +6,15 @@ Models/TranslationWidgetOrigin.obj + + + - - - - - - + Models/TranslationWidgetX.obj @@ -26,12 +24,7 @@ - - - - - - + Models/TranslationWidgetY.obj @@ -41,12 +34,7 @@ - - - - - - + Models/TranslationWidgetZ.obj @@ -56,12 +44,7 @@ - - - - - - + Models/WidgetPlaneX.obj @@ -71,12 +54,7 @@ - - - - - - + Models/WidgetPlaneY.obj @@ -86,12 +64,7 @@ - - - - - - + Models/WidgetPlaneZ.obj diff --git a/src/Engine/Editor/EditorGUI.cpp b/src/Engine/Editor/EditorGUI.cpp index 318e3199..f65386aa 100644 --- a/src/Engine/Editor/EditorGUI.cpp +++ b/src/Engine/Editor/EditorGUI.cpp @@ -35,57 +35,20 @@ void EditorGUI::drawTools() return; } - // Translate widget button - 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); - } + createWidgetToolButton(WidgetMode::Translate); + if (ImGui::IsItemHovered()) { + ImGui::SetTooltip("Translate"); } - // Rotate widget button ImGui::SameLine(); - 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); - } + createWidgetToolButton(WidgetMode::Rotate); + if (ImGui::IsItemHovered()) { + ImGui::SetTooltip("Rotate"); } - // Scale widget button ImGui::SameLine(); - 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); - } + createWidgetToolButton(WidgetMode::Scale); + if (ImGui::IsItemHovered()) { + ImGui::SetTooltip("Scale"); } - ImGui::SameLine(); ImGui::ItemSize(ImVec2(5, 0)); @@ -497,6 +460,36 @@ bool EditorGUI::createDeleteButton(const std::string& componentType) return pressed; } +void EditorGUI::createWidgetToolButton(WidgetMode mode) +{ + GLuint texture = 0; + switch (mode) { + case WidgetMode::Translate: + texture = tryLoadTexture("Textures/Icons/Translate.png"); + break; + case WidgetMode::Rotate: + texture = tryLoadTexture("Textures/Icons/Rotate.png"); + break; + case WidgetMode::Scale: + texture = tryLoadTexture("Textures/Icons/Scale.png"); + break; + } + if (ImGui::ImageButton( + (void*)texture, + ImVec2(24, 24), + ImVec2(0, 1), + ImVec2(1, 0), + -1, + ImVec4(0, 0, 0, 0), + (m_CurrentWidgetMode == mode) ? ImVec4(0, 1, 0, 1) : ImVec4(1, 1, 1, 1) + ) + ) { + if (m_OnWidgetMode != nullptr) { + m_OnWidgetMode(mode); + } + m_CurrentWidgetMode = mode; + } +} boost::filesystem::path EditorGUI::fileOpenDialog() { diff --git a/src/Engine/Editor/EditorSystem.cpp b/src/Engine/Editor/EditorSystem.cpp index 03b90a37..596f8154 100644 --- a/src/Engine/Editor/EditorSystem.cpp +++ b/src/Engine/Editor/EditorSystem.cpp @@ -126,6 +126,8 @@ void EditorSystem::setWidgetMode(EditorGUI::WidgetMode mode) return; } + m_WidgetMode = mode; + if (m_Widget.Valid()) { m_Widget.World->DeleteEntity(m_Widget.ID); m_Widget = EntityWrapper::Invalid; @@ -137,17 +139,15 @@ void EditorSystem::setWidgetMode(EditorGUI::WidgetMode mode) switch (mode) { case EditorGUI::WidgetMode::Translate: - m_Widget = importEntity(EntityWrapper(m_World, EntityID_Invalid), "Schema/Entities/EditorWidgetTranslate.xml"); + m_Widget = importEntity(EntityWrapper(m_EditorWorld, EntityID_Invalid), "Schema/Entities/EditorWidgetTranslate.xml"); break; case EditorGUI::WidgetMode::Rotate: - m_Widget = importEntity(EntityWrapper(m_World, EntityID_Invalid), "Schema/Entities/EditorWidgetRotate.xml"); + m_Widget = importEntity(EntityWrapper(m_EditorWorld, EntityID_Invalid), "Schema/Entities/EditorWidgetRotate.xml"); break; case EditorGUI::WidgetMode::Scale: - m_Widget = importEntity(EntityWrapper(m_World, EntityID_Invalid), "Schema/Entities/EditorWidgetScale.xml"); + m_Widget = importEntity(EntityWrapper(m_EditorWorld, EntityID_Invalid), "Schema/Entities/EditorWidgetScale.xml"); break; } m_Widget["Transform"]["Position"] = Transform::AbsolutePosition(m_CurrentSelection.World, m_CurrentSelection.ID); - - m_WidgetMode = mode; }