重构UI架构:分离数据模型和显示逻辑
- 新增 Core 模块:GameObject、LogEntry、AssetItem 数据模型 - 新增 Managers 模块:SceneManager、LogSystem、ProjectManager - Panel 层只负责显示,不再持有数据 - 解耦 HierarchyPanel 和 InspectorPanel 之间的直接依赖
This commit is contained in:
@@ -1,22 +1,13 @@
|
||||
#include "ProjectPanel.h"
|
||||
#include "Managers/ProjectManager.h"
|
||||
#include "Core/AssetItem.h"
|
||||
#include <imgui.h>
|
||||
#include <imgui_internal.h>
|
||||
|
||||
namespace UI {
|
||||
|
||||
ProjectPanel::ProjectPanel() : Panel("Project") {
|
||||
m_folders = {"Assets", "Scenes", "Scripts", "Materials", "Prefabs"};
|
||||
|
||||
m_items = {
|
||||
{"Cube", "Prefab", false},
|
||||
{"Sphere", "Prefab", false},
|
||||
{"Player", "Prefab", false},
|
||||
{"MainScript", "Script", false},
|
||||
{"DefaultMat", "Material", false},
|
||||
{"Scene1", "Scene", false},
|
||||
{"Textures", "Folder", true},
|
||||
{"Models", "Folder", true},
|
||||
};
|
||||
ProjectManager::Get().CreateDemoAssets();
|
||||
}
|
||||
|
||||
void ProjectPanel::Render() {
|
||||
@@ -37,11 +28,12 @@ void ProjectPanel::Render() {
|
||||
int columns = (int)(panelWidth / (buttonWidth + padding));
|
||||
if (columns < 1) columns = 1;
|
||||
|
||||
for (int i = 0; i < m_items.size(); i++) {
|
||||
auto& items = ProjectManager::Get().GetItems();
|
||||
for (int i = 0; i < items.size(); i++) {
|
||||
if (i > 0 && i % columns != 0) {
|
||||
ImGui::SameLine();
|
||||
}
|
||||
RenderAssetItem(m_items[i], i);
|
||||
RenderAssetItem(items[i], i);
|
||||
}
|
||||
|
||||
ImGui::EndChild();
|
||||
@@ -51,14 +43,14 @@ void ProjectPanel::Render() {
|
||||
void ProjectPanel::RenderAssetItem(const AssetItem& item, int index) {
|
||||
ImGui::PushID(index);
|
||||
|
||||
bool isSelected = (m_selectedIndex == index);
|
||||
bool isSelected = (ProjectManager::Get().GetSelectedIndex() == index);
|
||||
if (isSelected) {
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.26f, 0.59f, 0.98f, 0.40f));
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.40f, 0.40f, 0.40f, 0.50f));
|
||||
}
|
||||
|
||||
ImVec2 buttonSize(80.0f, 90.0f);
|
||||
if (ImGui::Button("##Asset", buttonSize)) {
|
||||
m_selectedIndex = index;
|
||||
ProjectManager::Get().SetSelectedIndex(index);
|
||||
}
|
||||
|
||||
if (isSelected) {
|
||||
|
||||
Reference in New Issue
Block a user