88 lines
2.6 KiB
C++
88 lines
2.6 KiB
C++
|
|
#include "ProjectPanel.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},
|
||
|
|
};
|
||
|
|
}
|
||
|
|
|
||
|
|
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;
|
||
|
|
|
||
|
|
for (int i = 0; i < m_items.size(); i++) {
|
||
|
|
if (i > 0 && i % columns != 0) {
|
||
|
|
ImGui::SameLine();
|
||
|
|
}
|
||
|
|
RenderAssetItem(m_items[i], i);
|
||
|
|
}
|
||
|
|
|
||
|
|
ImGui::EndChild();
|
||
|
|
ImGui::End();
|
||
|
|
}
|
||
|
|
|
||
|
|
void ProjectPanel::RenderAssetItem(const AssetItem& item, int index) {
|
||
|
|
ImGui::PushID(index);
|
||
|
|
|
||
|
|
bool isSelected = (m_selectedIndex == index);
|
||
|
|
if (isSelected) {
|
||
|
|
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.26f, 0.59f, 0.98f, 0.40f));
|
||
|
|
}
|
||
|
|
|
||
|
|
ImVec2 buttonSize(80.0f, 90.0f);
|
||
|
|
if (ImGui::Button("##Asset", buttonSize)) {
|
||
|
|
m_selectedIndex = 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();
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|