content browser and textures on entity sprites
This commit is contained in:
@@ -1,8 +1,13 @@
|
||||
#ifndef EDITOR_HPP
|
||||
#define EDITOR_HPP
|
||||
|
||||
#include <filesystem>
|
||||
#include <open_engine.hpp>
|
||||
|
||||
#include "open_engine/application.hpp"
|
||||
#include "open_engine/scene/entity.hpp"
|
||||
#include "open_engine/scene/scene_serializer.hpp"
|
||||
#include "panels/content_browser.hpp"
|
||||
#include "panels/scene_hierarchy.hpp"
|
||||
|
||||
#include <glm/ext/matrix_transform.hpp>
|
||||
@@ -71,6 +76,13 @@ namespace OpenEngine {
|
||||
|
||||
scene = CreateRef<Scene>();
|
||||
|
||||
auto command_line_args = Application::Get().GetCommandLineArgs();
|
||||
if (command_line_args.count > 1) {
|
||||
auto scene_path = command_line_args[1];
|
||||
SceneSerializer serializer(scene);
|
||||
serializer.Deserialize(scene_path);
|
||||
}
|
||||
|
||||
editor_camera = EditorCamera(30.0f, 1920.0f/1080.0f, 0.1f, 1000.0f);
|
||||
|
||||
/*
|
||||
@@ -255,6 +267,15 @@ namespace OpenEngine {
|
||||
uint32_t texture_id = framebuffer->GetColorAttachmentRendererID();
|
||||
ImGui::Image((void*)(uint64_t)texture_id, ImVec2{ viewport_size.x, viewport_size.y }, ImVec2{ 0, 1 }, ImVec2{ 1, 0 });
|
||||
|
||||
if (ImGui::BeginDragDropTarget()) {
|
||||
if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("CONTENT_BROWSER_PAYLOAD")) {
|
||||
std::filesystem::path path = (const char*)payload->Data;
|
||||
if (path.extension() == ".oes")
|
||||
OpenScene(path);
|
||||
}
|
||||
ImGui::EndDragDropTarget();
|
||||
}
|
||||
|
||||
viewport_bounds[0] = { imgui_cursor_position.x, imgui_cursor_position.y };
|
||||
viewport_bounds[1] = { imgui_cursor_position.x + viewport_size.x,
|
||||
imgui_cursor_position.y + viewport_size.y };
|
||||
@@ -337,6 +358,18 @@ namespace OpenEngine {
|
||||
guizmo_operation = -1;
|
||||
};
|
||||
|
||||
void OpenScene(const std::string& file)
|
||||
{
|
||||
if (!file.empty()) {
|
||||
scene = CreateRef<Scene>();
|
||||
scene->OnViewportResize((uint32_t)viewport_size.x, (uint32_t)viewport_size.y);
|
||||
scene_hierarchy.Init(scene);
|
||||
|
||||
SceneSerializer serializer(scene);
|
||||
serializer.Deserialize(file);
|
||||
}
|
||||
}
|
||||
|
||||
void OnImGuiRender() override
|
||||
{
|
||||
OE_PROFILE_FUNCTION();
|
||||
@@ -355,15 +388,8 @@ namespace OpenEngine {
|
||||
}
|
||||
if (ImGui::MenuItem("Open Scene", "Ctrl+O")) {
|
||||
std::string file = FileDialogs::OpenFile("useless");
|
||||
OE_DEBUG("loading filename: {}", file);
|
||||
if (!file.empty()) {
|
||||
scene = CreateRef<Scene>();
|
||||
scene->OnViewportResize((uint32_t)viewport_size.x, (uint32_t)viewport_size.y);
|
||||
scene_hierarchy.Init(scene);
|
||||
|
||||
SceneSerializer serializer(scene);
|
||||
serializer.Deserialize(file);
|
||||
}
|
||||
OE_DEBUG("loading scene: {}", file);
|
||||
OpenScene(file);
|
||||
}
|
||||
if (ImGui::MenuItem("New Scene", "Ctrl+N")) {
|
||||
scene = CreateRef<Scene>();
|
||||
@@ -383,6 +409,7 @@ namespace OpenEngine {
|
||||
|
||||
DrawStats();
|
||||
scene_hierarchy.OnImGuiRender();
|
||||
brower.OnImGuiRender();
|
||||
DrawViewport();
|
||||
|
||||
ImGui::ShowDemoWindow();
|
||||
@@ -390,6 +417,7 @@ namespace OpenEngine {
|
||||
};
|
||||
|
||||
private:
|
||||
ContentBrowserPanel brower;
|
||||
std::vector<Time::ProfilingResult> profiling_results;
|
||||
|
||||
glm::vec2 world_pos_cursor = { 0.0f, 0.0f };
|
||||
@@ -406,13 +434,15 @@ namespace OpenEngine {
|
||||
|
||||
Ref<Scene> scene;
|
||||
Entity selected_entity;
|
||||
|
||||
std::vector<Entity> entities;
|
||||
};
|
||||
}
|
||||
|
||||
class EditorApp : public OpenEngine::Application
|
||||
{
|
||||
public:
|
||||
EditorApp();
|
||||
EditorApp(OpenEngine::ApplicationCommandLineArgs args);
|
||||
~EditorApp();
|
||||
};
|
||||
|
||||
|
||||
23
editor/include/panels/content_browser.hpp
Normal file
23
editor/include/panels/content_browser.hpp
Normal file
@@ -0,0 +1,23 @@
|
||||
#ifndef CONTENT_BROWSER_HPP
|
||||
#define CONTENT_BROWSER_HPP
|
||||
|
||||
#include "open_engine/renderer/texture.hpp"
|
||||
#include <filesystem>
|
||||
|
||||
namespace OpenEngine {
|
||||
|
||||
class ContentBrowserPanel
|
||||
{
|
||||
public:
|
||||
ContentBrowserPanel();
|
||||
|
||||
void OnImGuiRender();
|
||||
|
||||
private:
|
||||
std::filesystem::path current_directory;
|
||||
Ref<Texture2D> folder_icon;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // CONTENT_BROWSER_HPP
|
||||
@@ -1,3 +1,4 @@
|
||||
#include "open_engine/application.hpp"
|
||||
#include <open_engine/entry_point.hpp>
|
||||
|
||||
#include <open_engine.hpp>
|
||||
@@ -9,8 +10,8 @@
|
||||
#include <overlay.hpp>
|
||||
#include <modding.hpp>
|
||||
|
||||
EditorApp::EditorApp()
|
||||
: Application("OpenEngine Editor")
|
||||
EditorApp::EditorApp(OpenEngine::ApplicationCommandLineArgs args)
|
||||
: Application("OpenEngine Editor", args)
|
||||
{
|
||||
OpenEngine::Ref<OpenEngine::Layer> modding_layer = OpenEngine::CreateRef<Modding>();
|
||||
OpenEngine::Ref<OpenEngine::Layer> editor_layer = OpenEngine::CreateRef<OpenEngine::EditorLayer>();
|
||||
@@ -25,8 +26,8 @@ EditorApp::~EditorApp()
|
||||
{
|
||||
}
|
||||
|
||||
OpenEngine::Application* OpenEngine::CreateApplication()
|
||||
OpenEngine::Application* OpenEngine::CreateApplication(OpenEngine::ApplicationCommandLineArgs args)
|
||||
{
|
||||
OE_INFO("Editor Starting...");
|
||||
return new EditorApp();
|
||||
return new EditorApp(args);
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#include "imgui.h"
|
||||
#include <editor_component.hpp>
|
||||
#include <open_engine.hpp>
|
||||
|
||||
@@ -106,6 +107,16 @@ namespace OpenEngine {
|
||||
{
|
||||
auto& sprite = registry.get<SpriteRendererComponent>(entity);
|
||||
ImGui::ColorEdit4("color", glm::value_ptr(sprite.color));
|
||||
ImGui::Button("Texture", { 100, 0 });
|
||||
|
||||
if (ImGui::BeginDragDropTarget()) {
|
||||
if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("CONTENT_BROWSER_PAYLOAD"))
|
||||
sprite.texture = Texture2D::Create(((const char*)payload->Data));
|
||||
|
||||
ImGui::EndDragDropTarget();
|
||||
}
|
||||
|
||||
ImGui::DragFloat("Tiling factor", &sprite.tiling_factor);
|
||||
};
|
||||
|
||||
void CameraOnImGuiRender(entt::registry& registry, entt::entity entity)
|
||||
|
||||
88
editor/src/panels/content_browser.cpp
Normal file
88
editor/src/panels/content_browser.cpp
Normal file
@@ -0,0 +1,88 @@
|
||||
#include "imgui_internal.h"
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <panels/content_browser.hpp>
|
||||
|
||||
#include <open_engine/renderer/texture.hpp>
|
||||
#include <open_engine/logging.hpp>
|
||||
#include <filesystem>
|
||||
#include <imgui.h>
|
||||
|
||||
namespace OpenEngine {
|
||||
|
||||
const std::filesystem::path assets_directory = "assets";
|
||||
|
||||
ContentBrowserPanel::ContentBrowserPanel()
|
||||
: current_directory(assets_directory)
|
||||
{
|
||||
// TODO: Add file texture. Get free icons and add license
|
||||
folder_icon = Texture2D::Create("resources/textures/folder.png");
|
||||
}
|
||||
|
||||
void ContentBrowserPanel::OnImGuiRender()
|
||||
{
|
||||
ImGui::Begin("Assets");
|
||||
|
||||
ImGui::Text("%s", current_directory.c_str());
|
||||
|
||||
if (current_directory != assets_directory)
|
||||
if (ImGui::Button(".."))
|
||||
current_directory = current_directory.parent_path();
|
||||
|
||||
auto directory_it = std::filesystem::directory_iterator(current_directory);
|
||||
|
||||
ImVec2 button_size = { 100, 100 };
|
||||
auto panel_width = ImGui::GetContentRegionAvail().x;
|
||||
uint32_t table_columns = (int)(panel_width / button_size.x) - 1;
|
||||
|
||||
if (table_columns <= 0)
|
||||
table_columns = 1;
|
||||
|
||||
ImVec2 padding( 9, 9 );
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_CellPadding, padding);
|
||||
|
||||
if (ImGui::BeginTable("table1", table_columns, ImGuiTableFlags_SizingFixedSame))
|
||||
{
|
||||
for (auto& entry : directory_it) {
|
||||
auto file_name = entry.path().filename().string();
|
||||
|
||||
ImGui::PushID(file_name.c_str());
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, { 0.0f, 0.0f, 0.0f, 0.0f });
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, { 0.192f, 0.196f, 0.266f, 1.0f });
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonActive, { 0.270f, 0.278f, 0.352f, 1.0f });
|
||||
|
||||
ImGui::BeginGroup();
|
||||
ImGui::ImageButton("##X", (ImTextureID)folder_icon->GetID(), button_size, { 0, 1 }, { 1, 0 });
|
||||
if (entry.is_regular_file() && ImGui::BeginDragDropSource()) {
|
||||
const char* source = entry.path().c_str();
|
||||
ImGui::SetDragDropPayload("CONTENT_BROWSER_PAYLOAD", source, (strlen(source) + 1) * sizeof(char), ImGuiCond_Once);
|
||||
|
||||
ImGui::EndDragDropSource();
|
||||
}
|
||||
|
||||
float columnWidth = ImGui::GetColumnWidth();
|
||||
float textWidth = ImGui::CalcTextSize(file_name.c_str()).x;
|
||||
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + (columnWidth - textWidth) * 0.5f);
|
||||
ImGui::TextWrapped("%s", file_name.c_str());
|
||||
|
||||
ImGui::EndGroup();
|
||||
|
||||
if (entry.is_directory()) {
|
||||
if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left))
|
||||
current_directory = entry.path().c_str();
|
||||
}
|
||||
|
||||
ImGui::PopStyleColor(3);
|
||||
ImGui::PopID();
|
||||
}
|
||||
ImGui::EndTable();
|
||||
}
|
||||
ImGui::PopStyleVar();
|
||||
|
||||
ImGui::End();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user