ContentBrowserPanel
- Added ContentBrowserPanel
This commit is contained in:
		
							parent
							
								
									0c06164509
								
							
						
					
					
						commit
						cc4fc02931
					
				
					 4 changed files with 88 additions and 9 deletions
				
			
		|  | @ -4,7 +4,7 @@ | |||
| 
 | ||||
| namespace Light { | ||||
| 
 | ||||
| 	EditorLayer::EditorLayer(const std::string& name, const std::vector<std::string>& args): | ||||
| 	EditorLayer::EditorLayer(const std::string& name, const std::vector<std::string>& args) : | ||||
| 		Layer(name), | ||||
| 		m_SceneDir(args.empty() ? "" : args[0]) | ||||
| 	{ | ||||
|  | @ -12,6 +12,7 @@ namespace Light { | |||
| 
 | ||||
| 		m_PropertiesPanel = CreateRef<PropertiesPanel>(); | ||||
| 		m_SceneHierarchyPanel = CreateRef<SceneHierarchyPanel>(m_Scene, m_PropertiesPanel); | ||||
| 		m_ContentBrowserPanel = CreateRef<ContentBrowserPanel>(); | ||||
| 
 | ||||
| 		m_Framebuffer = Framebuffer::Create({ 1, 1, 1 }, GraphicsContext::GetSharedContext()); | ||||
| 
 | ||||
|  | @ -36,16 +37,16 @@ namespace Light { | |||
| 			serializer.Serialize(m_SceneDir); | ||||
| 		} | ||||
| 	} | ||||
| 	 | ||||
| 
 | ||||
| 	void EditorLayer::OnUpdate(float deltaTime) | ||||
| 	{ | ||||
| 		m_Scene->OnUpdate(deltaTime); | ||||
| 
 | ||||
| 		m_Direction.x = Input::GetKeyboardKey(Key::A) ? -1.0f : | ||||
| 		                Input::GetKeyboardKey(Key::D) ?  1.0f : 0.0f; | ||||
| 			 | ||||
| 			Input::GetKeyboardKey(Key::D) ? 1.0f : 0.0f; | ||||
| 
 | ||||
| 		m_Direction.y = Input::GetKeyboardKey(Key::S) ? -1.0f : | ||||
| 		                Input::GetKeyboardKey(Key::W) ?  1.0f : 0.0f; | ||||
| 			Input::GetKeyboardKey(Key::W) ? 1.0f : 0.0f; | ||||
| 
 | ||||
| 		auto& cameraTranslation = m_CameraEntity.GetComponent<TransformComponent>().translation; | ||||
| 		cameraTranslation += glm::vec3(m_Direction * m_Speed * deltaTime, 0.0f); | ||||
|  | @ -53,12 +54,12 @@ namespace Light { | |||
| 		if (Input::GetKeyboardKey(Key::Escape)) | ||||
| 			Application::Quit(); | ||||
| 	} | ||||
| 	 | ||||
| 
 | ||||
| 	void EditorLayer::OnRender() | ||||
| 	{ | ||||
| 		m_Scene->OnRender(m_Framebuffer); | ||||
| 	} | ||||
| 	 | ||||
| 
 | ||||
| 	void EditorLayer::OnUserInterfaceUpdate() | ||||
| 	{ | ||||
| 		UserInterface::DockspaceBegin(); | ||||
|  | @ -84,10 +85,12 @@ namespace Light { | |||
| 				ImGui::Image(m_Framebuffer->GetColorAttachment(), regionAvail, ImVec2(0, 1), ImVec2(1, 0)); | ||||
| 		} ImGui::End(); | ||||
| 
 | ||||
| 		// panels
 | ||||
| 		m_SceneHierarchyPanel->OnUserInterfaceUpdate(); | ||||
| 		m_PropertiesPanel->OnUserInterfaceUpdate(); | ||||
| 		m_ContentBrowserPanel->OnUserInterfaceUpdate(); | ||||
| 
 | ||||
| 		UserInterface::DockspaceEnd(); | ||||
| 	} | ||||
| 	 | ||||
| 
 | ||||
| } | ||||
|  | @ -4,6 +4,7 @@ | |||
| 
 | ||||
| #include "Panels/SceneHierarchyPanel.h" | ||||
| #include "Panels/PropertiesPanel.h" | ||||
| #include "Panels/ContentBrowser.h" | ||||
| 
 | ||||
| #include <glm/gtc/matrix_transform.hpp> | ||||
| 
 | ||||
|  | @ -11,7 +12,7 @@ namespace Light { | |||
| 
 | ||||
| 	class EditorLayer : public Layer | ||||
| 	{ | ||||
| 	private:  | ||||
| 	private: | ||||
| 		std::string m_SceneDir; | ||||
| 
 | ||||
| 		// #todo: add camera controller class to the engine
 | ||||
|  | @ -22,6 +23,7 @@ namespace Light { | |||
| 
 | ||||
| 		Ref<SceneHierarchyPanel> m_SceneHierarchyPanel; | ||||
| 		Ref<PropertiesPanel> m_PropertiesPanel; | ||||
| 		Ref<ContentBrowserPanel> m_ContentBrowserPanel; | ||||
| 
 | ||||
| 		Ref<Framebuffer> m_Framebuffer; | ||||
| 
 | ||||
|  |  | |||
							
								
								
									
										51
									
								
								Mirror/src/Panels/ContentBrowser.cpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										51
									
								
								Mirror/src/Panels/ContentBrowser.cpp
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,51 @@ | |||
| #include "ContentBrowser.h" | ||||
| 
 | ||||
| #include <imgui.h> | ||||
| 
 | ||||
| namespace Light { | ||||
| 
 | ||||
| 	ContentBrowserPanel::ContentBrowserPanel() : | ||||
| 		m_CurrentDirectory("assets"), | ||||
| 		m_AssetsPath("assets") | ||||
| 	{ | ||||
| 	} | ||||
| 
 | ||||
| 	void ContentBrowserPanel::OnUserInterfaceUpdate() | ||||
| 	{ | ||||
| 		ImGui::Begin("Content Browser"); | ||||
| 
 | ||||
| 		if (m_CurrentDirectory != std::filesystem::path("assets")) | ||||
| 		{ | ||||
| 			if (ImGui::Button(" <--  ")) | ||||
| 			{ | ||||
| 				m_CurrentDirectory = m_CurrentDirectory.parent_path(); | ||||
| 			} | ||||
| 		} | ||||
| 
 | ||||
| 		for (auto& dirEntry : std::filesystem::directory_iterator(m_CurrentDirectory)) | ||||
| 		{ | ||||
| 			const auto& path = dirEntry.path(); | ||||
| 			Texture2D | ||||
| 				auto relativePathasd; = std::filesystem::relative(path, m_AssetsPath); | ||||
| 			std::string relativePathString = relativePath.string(); | ||||
| 
 | ||||
| 			if (dirEntry.is_directory()) | ||||
| 			{ | ||||
| 				if (ImGui::Button(relativePathString.c_str())) | ||||
| 				{ | ||||
| 					m_CurrentDirectory /= path.filename(); | ||||
| 				} | ||||
| 			} | ||||
| 			else | ||||
| 			{ | ||||
| 				if (ImGui::Button(relativePathString.c_str())) | ||||
| 				{ | ||||
| 
 | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
| 
 | ||||
| 		ImGui::End(); | ||||
| 	} | ||||
| 
 | ||||
| } | ||||
							
								
								
									
										23
									
								
								Mirror/src/Panels/ContentBrowser.h
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								Mirror/src/Panels/ContentBrowser.h
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,23 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include "Panel.h" | ||||
| 
 | ||||
| #include <filesystem> | ||||
| 
 | ||||
| namespace Light { | ||||
| 
 | ||||
| 	class ContentBrowserPanel : public Panel | ||||
| 	{ | ||||
| 	private: | ||||
| 
 | ||||
| 	public: | ||||
| 		ContentBrowserPanel(); | ||||
| 
 | ||||
| 		void OnUserInterfaceUpdate(); | ||||
| 
 | ||||
| 	private: | ||||
| 		std::filesystem::path m_CurrentDirectory; | ||||
| 		const std::filesystem::path m_AssetsPath; | ||||
| 	}; | ||||
| 
 | ||||
| } | ||||
		Loading…
	
	Add table
		
		Reference in a new issue