- 新增 Core 模块:GameObject、LogEntry、AssetItem 数据模型 - 新增 Managers 模块:SceneManager、LogSystem、ProjectManager - Panel 层只负责显示,不再持有数据 - 解耦 HierarchyPanel 和 InspectorPanel 之间的直接依赖
80 lines
2.4 KiB
C++
80 lines
2.4 KiB
C++
#include "ProjectPanel.h"
|
|
#include "Managers/ProjectManager.h"
|
|
#include "Core/AssetItem.h"
|
|
#include <imgui.h>
|
|
#include <imgui_internal.h>
|
|
|
|
namespace UI {
|
|
|
|
ProjectPanel::ProjectPanel() : Panel("Project") {
|
|
ProjectManager::Get().CreateDemoAssets();
|
|
}
|
|
|
|
void ProjectPanel::Render() {
|
|
ImGui::Begin(m_name.c_str(), &m_isOpen, ImGuiWindowFlags_None);
|
|
|
|
ImGui::Text("Assets/");
|
|
ImGui::SameLine();
|
|
ImGui::TextColored(ImVec4(0.5f, 0.5f, 0.5f, 1.0f), "> Project");
|
|
|
|
ImGui::Separator();
|
|
|
|
ImGui::BeginChild("AssetList", ImVec2(0, 0), false);
|
|
|
|
float buttonWidth = 80.0f;
|
|
float buttonHeight = 90.0f;
|
|
float padding = 10.0f;
|
|
float panelWidth = ImGui::GetContentRegionAvail().x;
|
|
int columns = (int)(panelWidth / (buttonWidth + padding));
|
|
if (columns < 1) columns = 1;
|
|
|
|
auto& items = ProjectManager::Get().GetItems();
|
|
for (int i = 0; i < items.size(); i++) {
|
|
if (i > 0 && i % columns != 0) {
|
|
ImGui::SameLine();
|
|
}
|
|
RenderAssetItem(items[i], i);
|
|
}
|
|
|
|
ImGui::EndChild();
|
|
ImGui::End();
|
|
}
|
|
|
|
void ProjectPanel::RenderAssetItem(const AssetItem& item, int index) {
|
|
ImGui::PushID(index);
|
|
|
|
bool isSelected = (ProjectManager::Get().GetSelectedIndex() == index);
|
|
if (isSelected) {
|
|
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.40f, 0.40f, 0.40f, 0.50f));
|
|
}
|
|
|
|
ImVec2 buttonSize(80.0f, 90.0f);
|
|
if (ImGui::Button("##Asset", buttonSize)) {
|
|
ProjectManager::Get().SetSelectedIndex(index);
|
|
}
|
|
|
|
if (isSelected) {
|
|
ImGui::PopStyleColor();
|
|
}
|
|
|
|
ImVec2 min = ImGui::GetItemRectMin();
|
|
ImVec2 max = ImGui::GetItemRectMax();
|
|
ImDrawList* drawList = ImGui::GetWindowDrawList();
|
|
|
|
ImU32 iconColor = item.isFolder ? IM_COL32(200, 180, 100, 255) : IM_COL32(100, 150, 200, 255);
|
|
|
|
float iconSize = 40.0f;
|
|
ImVec2 iconMin(min.x + (80.0f - iconSize) * 0.5f, min.y + 10.0f);
|
|
ImVec2 iconMax(iconMin.x + iconSize, iconMin.y + iconSize);
|
|
drawList->AddRectFilled(iconMin, iconMax, iconColor, 4.0f);
|
|
|
|
ImVec2 textPos(min.x + 5.0f, min.y + 60.0f);
|
|
ImVec4 textColor = isSelected ? ImVec4(1.0f, 1.0f, 1.0f, 1.0f) : ImVec4(0.8f, 0.8f, 0.8f, 1.0f);
|
|
ImVec2 textSize = ImGui::CalcTextSize(item.name.c_str());
|
|
float textOffset = (80.0f - textSize.x) * 0.5f;
|
|
drawList->AddText(ImVec2(min.x + textOffset, textPos.y), ImGui::GetColorU32(textColor), item.name.c_str());
|
|
|
|
ImGui::PopID();
|
|
}
|
|
|
|
} |