27 const std::shared_ptr<Mesh>& defaultCubeMesh,
28 const std::shared_ptr<Material>& defaultCubeMaterial,
32 ImGui::Begin(
"Project");
34 if (m_CurrentDirectory.empty())
40 if (m_CurrentDirectory != projectRoot)
42 if (ImGui::Button(
"< Back"))
44 const auto parent = m_CurrentDirectory.parent_path();
45 m_CurrentDirectory = parent.string().size() < projectRoot.string().size()
46 ? projectRoot : parent;
51 ImGui::TextDisabled(
"%s",
52 m_CurrentDirectory.lexically_relative(projectRoot).generic_string().c_str());
54 ImGui::SetNextItemWidth(-1.0f);
55 ImGui::InputTextWithHint(
"##ProjectSearch",
"Search current folder...",
56 m_Search,
sizeof(m_Search));
59 const bool folderInsideAssets =
60 m_CurrentDirectory == assetsRoot ||
61 m_CurrentDirectory.string().rfind(assetsRoot.string(), 0) == 0;
63 if (folderInsideAssets)
65 ImGui::InvisibleButton(
"##ProjectPrefabDropTarget",
66 ImVec2(ImGui::GetContentRegionAvail().x, 28.0f));
67 if (ImGui::BeginDragDropTarget())
69 if (
const ImGuiPayload* payload = ImGui::AcceptDragDropPayload(
"NOJOB_ENTITY"))
71 const auto handle = *
static_cast<const std::uint32_t*
>(payload->Data);
72 if (scene && scene->
IsValid(handle))
74 Entity(handle, scene), m_CurrentDirectory, log);
76 ImGui::EndDragDropTarget();
78 ImGui::SetCursorPosY(ImGui::GetCursorPosY() - 28.0f);
79 ImGui::TextDisabled(
"Drop a Hierarchy object here to create a Prefab");
83 if (ImGui::BeginPopupContextWindow(
"ProjectCreateContext",
84 ImGuiPopupFlags_MouseButtonRight | ImGuiPopupFlags_NoOpenOverItems))
86 if (ImGui::BeginMenu(
"Create"))
88 const bool canCreatePrefab = folderInsideAssets &&
static_cast<bool>(selectedEntity);
89 if (ImGui::MenuItem(
"C++ Script",
nullptr,
false, folderInsideAssets))
90 m_RequestCreateCppScript =
true;
91 if (ImGui::MenuItem(
"Prefab From Selected",
nullptr,
false, canCreatePrefab))
98 if (m_RequestCreateCppScript)
100 ImGui::OpenPopup(
"Create C++ Script");
101 m_RequestCreateCppScript =
false;
104 static char newScriptName[128] =
"NewScript";
105 if (ImGui::BeginPopupModal(
"Create C++ Script",
nullptr, ImGuiWindowFlags_AlwaysAutoResize))
107 ImGui::TextUnformatted(
"Script name");
108 ImGui::SetNextItemWidth(280.0f);
109 const bool enter = ImGui::InputText(
"##CppScriptName", newScriptName,
110 sizeof(newScriptName), ImGuiInputTextFlags_EnterReturnsTrue);
112 const auto scriptsRoot = assetsRoot /
"Scripts";
114 const bool exists = std::filesystem::exists(scriptsRoot / (sanitized +
".h")) ||
115 std::filesystem::exists(scriptsRoot / (sanitized +
".cpp"));
116 if (exists) ImGui::TextDisabled(
"A script with this name already exists.");
117 else ImGui::TextDisabled(
"Creates Assets/Scripts/%s.h and %s.cpp",
118 sanitized.c_str(), sanitized.c_str());
120 const bool create = (ImGui::Button(
"Create") || enter) && !exists;
122 const bool cancel = ImGui::Button(
"Cancel");
125 m_CurrentDirectory = scriptsRoot;
126 newScriptName[0] =
'\0';
127 ImGui::CloseCurrentPopup();
129 if (cancel) ImGui::CloseCurrentPopup();
133 std::error_code error;
134 if (std::filesystem::exists(m_CurrentDirectory, error))
136 for (
const auto& entry : std::filesystem::directory_iterator(
137 m_CurrentDirectory, std::filesystem::directory_options::skip_permission_denied, error))
139 const auto path = entry.path();
140 const std::string name = path.filename().string();
142 if (m_Search[0] !=
'\0')
144 std::string filter = m_Search;
145 std::string lowerName = name;
146 std::transform(filter.begin(), filter.end(), filter.begin(),
147 [](
unsigned char c){ return static_cast<char>(std::tolower(c)); });
148 std::transform(lowerName.begin(), lowerName.end(), lowerName.begin(),
149 [](
unsigned char c){ return static_cast<char>(std::tolower(c)); });
150 if (lowerName.find(filter) == std::string::npos)
continue;
153 if (m_CurrentDirectory == projectRoot &&
154 path.lexically_normal() != assetsRoot.lexically_normal())
157 ImGui::PushID(path.string().c_str());
158 if (entry.is_directory())
160 if (ImGui::Selectable((
"[Folder] " + name).c_str(),
false,
161 ImGuiSelectableFlags_AllowDoubleClick) &&
162 ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left))
163 m_CurrentDirectory = path;
165 if (ImGui::BeginDragDropTarget())
167 if (
const ImGuiPayload* payload = ImGui::AcceptDragDropPayload(
"NOJOB_ENTITY"))
169 const auto handle = *
static_cast<const std::uint32_t*
>(payload->Data);
170 if (scene && scene->
IsValid(handle))
173 ImGui::EndDragDropTarget();
178 const std::string extension = path.extension().string();
179 const bool isTexture = extension ==
".png" || extension ==
".jpg" ||
180 extension ==
".jpeg" || extension ==
".bmp" || extension ==
".tga";
181 const bool isModel = extension ==
".obj" || extension ==
".fbx" ||
182 extension ==
".gltf" || extension ==
".glb" || extension ==
".dae" ||
183 extension ==
".stl" || extension ==
".ply" || extension ==
".3ds" ||
184 extension ==
".blend";
185 const bool isMaterial = extension ==
".nojobmat";
186 const bool isPrefab = extension ==
".nojobprefab";
187 const bool isScript = extension ==
".cpp" || extension ==
".h" || extension ==
".hpp";
188 const bool isAudio = extension ==
".wav" || extension ==
".mp3" || extension ==
".flac";
192 ImGui::Selectable((
"[Audio] " + name).c_str());
194 if (ImGui::BeginDragDropSource())
196 ImGui::SetDragDropPayload(
"NOJOB_AUDIO_ASSET", relative.c_str(), relative.size() + 1);
197 ImGui::Text(
"Audio: %s", name.c_str());
198 ImGui::EndDragDropSource();
203 const bool clicked = ImGui::Selectable((
"[C++] " + name).c_str(),
false,
204 ImGuiSelectableFlags_AllowDoubleClick);
206 if (clicked && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left))
208 if (ImGui::BeginPopupContextItem())
210 if (ImGui::MenuItem(
"Open in Visual Studio"))
213 ImGui::TextDisabled(
"%s", path.lexically_relative(projectRoot).generic_string().c_str());
220 if (ImGui::Selectable(name.c_str(),
false, ImGuiSelectableFlags_AllowDoubleClick) &&
221 ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left) && createModel)
226 auto instantiate = [&]()
230 if (entity) selectedEntity = entity;
232 if (ImGui::Selectable(name.c_str(),
false, ImGuiSelectableFlags_AllowDoubleClick) &&
233 ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left)) instantiate();
234 if (ImGui::BeginPopupContextItem())
236 if (ImGui::MenuItem(
"Instantiate Prefab")) instantiate();
242 const bool clicked = ImGui::Selectable(name.c_str(),
false,
243 ImGuiSelectableFlags_AllowDoubleClick);
245 if (clicked && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left) && selectedEntity &&
249 if (renderer.MaterialAsset)
254 if (loaded) renderer.MaterialAsset = loaded;
257 if (ImGui::BeginDragDropSource())
259 ImGui::SetDragDropPayload(
"NOJOB_MATERIAL_ASSET", relative.c_str(), relative.size() + 1);
260 ImGui::Text(
"Material: %s", name.c_str());
261 ImGui::EndDragDropSource();
266 ImGui::Selectable(name.c_str());
267 if (ImGui::BeginDragDropSource())
270 ImGui::SetDragDropPayload(
"NOJOB_TEXTURE_ASSET", relative.c_str(), relative.size() + 1);
271 ImGui::Text(
"Texture: %s", name.c_str());
272 ImGui::EndDragDropSource();
275 else ImGui::TextDisabled(
"%s", name.c_str());