From 6e12efb67ea04742b84b26f8b6a3518cf0d56404 Mon Sep 17 00:00:00 2001 From: ssdfasd <2156608475@qq.com> Date: Thu, 12 Mar 2026 18:58:06 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=A4=9A=E4=B8=AAUI?= =?UTF-8?q?=E6=A1=86=E6=9E=B6=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修复 InspectorPanel InputText 使用 data()/capacity() 的错误 - 修复未使用变量警告 - 修复 ProjectManager 路径重复拼接 bug (Assets/Assets) - 返回按钮在 Assets 目录时禁用但保持显示 - 删除 ProjectPanel 创建按钮,调整 Refresh 位置 - 修复 ProjectPanel 搜索过滤时的 ID 冲突 - 修复 InspectorPanel CollapsingHeader ID 冲突 --- ui/src/Application.cpp | 6 ++---- ui/src/Managers/ProjectManager.cpp | 12 +++++++----- ui/src/panels/InspectorPanel.cpp | 17 ++++++++++++++--- ui/src/panels/ProjectPanel.cpp | 19 ++++++++----------- 4 files changed, 31 insertions(+), 23 deletions(-) diff --git a/ui/src/Application.cpp b/ui/src/Application.cpp index 9a6c2fe6..cf231c04 100644 --- a/ui/src/Application.cpp +++ b/ui/src/Application.cpp @@ -30,10 +30,8 @@ bool Application::Initialize(HWND hwnd) { ImGuiIO& io = ImGui::GetIO(); io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; - ImFont* font = io.Fonts->AddFontFromFileTTF("C:/Windows/Fonts/msyh.ttc", 16.0f); - ImFont* defaultFont = io.Fonts->AddFontDefault(); - (void)font; - (void)defaultFont; + io.Fonts->AddFontFromFileTTF("C:/Windows/Fonts/msyh.ttc", 16.0f); + io.Fonts->AddFontDefault(); unsigned char* pixels; int width, height; diff --git a/ui/src/Managers/ProjectManager.cpp b/ui/src/Managers/ProjectManager.cpp index 7451bab7..c4f0908c 100644 --- a/ui/src/Managers/ProjectManager.cpp +++ b/ui/src/Managers/ProjectManager.cpp @@ -34,10 +34,10 @@ void ProjectManager::NavigateBack() { } std::string ProjectManager::GetCurrentPath() const { - if (m_path.empty()) return ""; - std::string result; - for (size_t i = 0; i < m_path.size(); i++) { - if (i > 0) result += "/"; + if (m_path.empty()) return "Assets"; + std::string result = "Assets"; + for (size_t i = 1; i < m_path.size(); i++) { + result += "/"; result += m_path[i]->name; } return result; @@ -99,8 +99,10 @@ void ProjectManager::Initialize(const std::string& projectPath) { } std::wstring ProjectManager::GetCurrentFullPathW() const { + if (m_path.empty()) return Utf8ToWstring(m_projectPath); + std::wstring fullPath = Utf8ToWstring(m_projectPath); - for (size_t i = 0; i < m_path.size(); i++) { + for (size_t i = 1; i < m_path.size(); i++) { fullPath += L"/" + Utf8ToWstring(m_path[i]->name); } return fullPath; diff --git a/ui/src/panels/InspectorPanel.cpp b/ui/src/panels/InspectorPanel.cpp index 14f4b560..73cf074f 100644 --- a/ui/src/panels/InspectorPanel.cpp +++ b/ui/src/panels/InspectorPanel.cpp @@ -2,6 +2,7 @@ #include "Managers/SceneManager.h" #include "Managers/SelectionManager.h" #include +#include namespace UI { @@ -45,7 +46,9 @@ void InspectorPanel::RenderComponent(Component* component) { const char* name = component->GetName().c_str(); - if (ImGui::CollapsingHeader(name, ImGuiTreeNodeFlags_DefaultOpen)) { + std::string headerId = name + std::string("##") + std::to_string(reinterpret_cast(component)); + + if (ImGui::CollapsingHeader(headerId.c_str(), ImGuiTreeNodeFlags_DefaultOpen)) { ImGui::Indent(10.0f); if (auto* transform = dynamic_cast(component)) { @@ -65,15 +68,23 @@ void InspectorPanel::RenderComponent(Component* component) { ImGui::DragFloat3("##Scale", transform->scale, 0.1f); } else if (auto* meshRenderer = dynamic_cast(component)) { + char materialBuffer[256] = {}; + strncpy_s(materialBuffer, meshRenderer->materialName.c_str(), sizeof(materialBuffer) - 1); ImGui::Text("Material"); ImGui::SameLine(80); ImGui::SetNextItemWidth(180); - ImGui::InputText("##Material", meshRenderer->materialName.data(), meshRenderer->materialName.capacity()); + if (ImGui::InputText("##Material", materialBuffer, sizeof(materialBuffer))) { + meshRenderer->materialName = materialBuffer; + } + char meshBuffer[256] = {}; + strncpy_s(meshBuffer, meshRenderer->meshName.c_str(), sizeof(meshBuffer) - 1); ImGui::Text("Mesh"); ImGui::SameLine(80); ImGui::SetNextItemWidth(180); - ImGui::InputText("##Mesh", meshRenderer->meshName.data(), meshRenderer->meshName.capacity()); + if (ImGui::InputText("##Mesh", meshBuffer, sizeof(meshBuffer))) { + meshRenderer->meshName = meshBuffer; + } } ImGui::Unindent(10.0f); diff --git a/ui/src/panels/ProjectPanel.cpp b/ui/src/panels/ProjectPanel.cpp index d22fb112..0adb0b60 100644 --- a/ui/src/panels/ProjectPanel.cpp +++ b/ui/src/panels/ProjectPanel.cpp @@ -18,27 +18,24 @@ void ProjectPanel::Render() { auto& manager = ProjectManager::Get(); - if (manager.CanNavigateBack()) { - if (ImGui::Button("<")) { + bool canGoBack = manager.CanNavigateBack(); + ImGui::BeginDisabled(!canGoBack); + if (ImGui::Button("<")) { + if (canGoBack) { manager.NavigateBack(); } - ImGui::SameLine(); } + ImGui::EndDisabled(); + ImGui::SameLine(); ImGui::Text("%s", manager.GetCurrentPath().c_str()); ImGui::SameLine(); - ImGui::SetCursorPosX(ImGui::GetWindowWidth() - 140.0f); + ImGui::SetCursorPosX(ImGui::GetWindowWidth() - 80.0f); if (ImGui::Button("Refresh")) { manager.RefreshCurrentFolder(); } - ImGui::SameLine(); - if (ImGui::Button("+")) { - m_showCreateFolderPopup = true; - strcpy_s(m_newFolderName, "NewFolder"); - } - ImGui::Separator(); ImGui::PushItemWidth(-1); @@ -69,7 +66,7 @@ void ProjectPanel::Render() { if (itemIndex > 0 && itemIndex % columns != 0) { ImGui::SameLine(); } - RenderAssetItem(items[i], i); + RenderAssetItem(items[i], itemIndex); itemIndex++; }