content browser and textures on entity sprites
This commit is contained in:
@@ -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