Added new folder icon

New entities can be added to the world root
gui_api_redesign
Joey Pollack 4 years ago
parent 72894c35fa
commit 0fb6e94a2f

@ -68,7 +68,7 @@ Core:
✔ Functionality for adding/working with components (through EnTT) @done(22-06-01 14:01)
Components:
☐ Tag
✔ Tag @done(22-06-23 15:49)
☐ Transform
☐ SpriteRenderer
☐ Animation Controller

@ -34,11 +34,9 @@ Editor:
✔ Save/Update contents file @done (3/3/2022, 3:16:23 PM)
GUI Panels:
Project Overview (Tree view):
World View:
Scene View:
Scene Hierarchy (Tree View):
World Hierarchy (Tree View):
Asset Viewer:
✔ Get references to the EditorAsset objects instead of the raw file locations @done(22-06-01 18:48)
@ -46,11 +44,18 @@ Editor:
✔ Double click folders in content view to open @done(22-06-21 15:17)
✔ Drag and Drop asset files to move them to different folders @done(22-06-21 15:18)
✔ Add directory back button to content view @done(22-06-21 15:45)
☐ Add folder drag/drop
☐ Design the content area tool bar
Properties:
☐ Implement showing components on selected Entity
Tools:
Tile Map Editor:
✔ Switch to NFD dialogs (or move tile set import to the main editor) @high @done(22-05-23 16:01)
☐ Allow Tile Maps to be named
☐ Stamp system
Tile Map Canvas:
☐ Implement a proper camera system and do not use panel scrolling @high
@ -73,6 +78,3 @@ Editor:
☐ Stamp creation
Properties:

@ -0,0 +1,28 @@
/******************************************************************************
* new_folder.h
* This file was automatically genereated from the source file: new_folder.png
* Generated by data2c version 0.1.1
******************************************************************************/
namespace lunarium_data_newdir
{
const unsigned int new_folderDataSize = 1088;
const unsigned int new_folderDataWidth = 17;
const unsigned int new_folderDataHeight = 16;
const unsigned int new_folderDataNumChannels = 4;
const unsigned char new_folderData[] = { 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 84, 145, 255, 170, 85, 3, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255,
153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 183, 255, 159, 80, 16, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 153, 85, 198, 255, 153, 85, 198, 255, 153, 85, 198, 255, 153, 85, 198, 255, 153, 84, 210, 255, 153, 84, 210, 255,
153, 84, 210, 255, 152, 85, 184, 255, 153, 85, 90, 255, 153, 84, 85, 255, 153, 84, 85, 255, 153, 84, 85, 255, 153, 84, 85, 255, 153, 84, 85, 255, 153, 84, 85, 255, 153, 84, 85, 255, 153, 84, 85, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255,
153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255,
153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 202, 123, 71, 255, 87, 57, 42, 255, 225, 136, 77, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255,
153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 185, 113, 67, 255, 36, 28, 28, 255, 215, 130, 75, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255,
153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 185, 113, 67, 255, 36, 28, 28, 255, 215, 130, 75, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255,
153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 185, 113, 67, 255, 36, 28, 28, 255, 215, 130, 75, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 166, 102, 61, 255, 117, 74, 49, 255, 117, 74, 49, 255, 117, 74, 49, 255, 91,
60, 43, 255, 36, 28, 28, 255, 102, 66, 46, 255, 117, 74, 49, 255, 117, 74, 49, 255, 117, 74, 49, 255, 206, 125, 72, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 145, 90, 56, 255, 85, 56, 41, 255, 85, 56, 41, 255, 85, 56, 41, 255, 69, 47, 37, 255, 36, 28, 28, 255, 76, 51, 39, 255, 85,
56, 41, 255, 85, 56, 41, 255, 85, 56, 41, 255, 194, 118, 69, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 185, 113, 67, 255, 36, 28, 28, 255, 215, 130, 75, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255,
153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 185, 113, 67, 255, 36, 28, 28, 255, 215, 130, 75, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255,
153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 185, 113, 67, 255, 36, 28, 28, 255, 215, 130, 75, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255,
153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 185, 113, 67, 255, 36, 28, 28, 255, 215, 130, 75, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255,
153, 85, 255, 255, 153, 85, 255, 252, 151, 84, 255, 244, 146, 82, 255, 253, 152, 84, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255, 255, 153, 85, 255
};
}

@ -18,7 +18,7 @@
#include "data_headers/open_font.h"
#include "data_headers/roboto_font.h"
#include "data_headers/folder16.h"
#include "data_headers/new_dir_icon.h"
#include "data_headers/new_folder.h"
#include "data_headers/up_arrow_icon.h"
#include <fstream>
@ -49,13 +49,13 @@ namespace lunarium
/////////////////////////////////////////
// new_dir_icon
format = ImageFormat::RGB;
if (lunarium_data_newdir::new_dir_iconDataNumChannels == 4)
if (lunarium_data_newdir::new_folderDataNumChannels == 4)
{
format = ImageFormat::RGBA;
}
pData = new unsigned char[lunarium_data_newdir::new_dir_iconDataSize];
memcpy(pData, lunarium_data_newdir::new_dir_iconData, lunarium_data_newdir::new_dir_iconDataSize);
mNewFolderIcon = new Image(pData, lunarium_data_newdir::new_dir_iconDataWidth, lunarium_data_newdir::new_dir_iconDataHeight, format);
pData = new unsigned char[lunarium_data_newdir::new_folderDataSize];
memcpy(pData, lunarium_data_newdir::new_folderData, lunarium_data_newdir::new_folderDataSize);
mNewFolderIcon = new Image(pData, lunarium_data_newdir::new_folderDataWidth, lunarium_data_newdir::new_folderDataHeight, format);
Core::Graphics().RegisterImage(*mNewFolderIcon);
mNewFolderIcon->FreeRawData();
//////////////////////////////////////////

@ -145,6 +145,8 @@ namespace lunarium { namespace editor
OpRes ContentManager::Save()
{
Logger::Info(Editor::LogCat, "Updating content_meta.json...");
if (!mpProject)
{
return OpRes::Fail("ConentManager::Save failed: no project set");
@ -305,7 +307,7 @@ namespace lunarium { namespace editor
delete iter->second;
mAssets.erase(iter);
Save();
Save().LogIfFailed(Editor::LogCat, "Asset was removed");
}
@ -316,7 +318,7 @@ namespace lunarium { namespace editor
std::filesystem::path r = mpProject->MakeRelativeToAssets(to);
asset->mLocation = r;
Save();
Save().LogIfFailed(Editor::LogCat, "Asset was moved");
}
bool ContentManager::IsValidAsset(nlohmann::json& node)

@ -7,6 +7,8 @@
******************************************************************************/
#include "asset_browser.h"
#include <core/core.h>
#include <input/input_manager.h>
#include <gui/gui.h>
#include <dearimgui/imgui.h>
#include <editor/editor.h>
@ -48,6 +50,8 @@ namespace editor
return false;
}
//DoNewFolder();
// Directory tree
// TODO: Figure out a better way to size stuff other
// than using this guess-work magic numbers
@ -69,6 +73,8 @@ namespace editor
// Contents
DoContentArea(wind_size);
HandlePopupActions();
ImGui::End();
return true;
}
@ -143,6 +149,14 @@ namespace editor
mSyncTree = true;
}
ImGui::SameLine();
if (ImGui::ImageButton((ImTextureID)DataManager::mNewFolderIcon->GetGLTextureID64(),
ImVec2(DataManager::mNewFolderIcon->GetWidth(), DataManager::mNewFolderIcon->GetHeight()),
ImVec2(0, 0), ImVec2(1, 1), 4))
{
mNewFolder = true;
}
ImGui::EndChild();
ImGui::Separator();
@ -216,7 +230,11 @@ namespace editor
// TODO: Buttons for creating/importing new assets
ImGui::EndPopup();
}
}
void AssetBrowser::DoNewFolder()
{
if (ImGui::BeginPopupContextItem("New Folder Name"))
{
char name_buf[64] = "New Folder";
@ -228,12 +246,25 @@ namespace editor
mNewFolder = false;
ImGui::CloseCurrentPopup();
}
if (Core::Input().IsKeyDown(KeyCode::ESCAPE, true))
{
mNewFolder = false;
ImGui::CloseCurrentPopup();
}
ImGui::EndPopup();
}
}
void AssetBrowser::HandlePopupActions()
{
if (mNewFolder)
{
DoNewFolder();
ImGui::OpenPopup("New Folder Name");
}
}
void AssetBrowser::HandleAssetDrop(std::filesystem::path dir)
{
@ -243,12 +274,10 @@ namespace editor
{
EditorAsset* pAsset = *((EditorAsset**) payload->Data);
// EditorAsset* pAsset = ((EditorAsset*) payload->Data);
Logger::Info(Editor::LogCat, "Dropping asset: %s - To: %s",
pAsset->GetFileLocation().stem().string().c_str(), dir.string().c_str());
// Logger::Info(Editor::LogCat, "Dropping asset: %s - To: %s",
// pAsset->GetFileLocation().stem().string().c_str(), dir.string().c_str());
// TODO: Handle moving the asset
ContentManager::GetInstance().MoveAsset(pAsset, dir / pAsset->GetFileLocation().filename());
Logger::Debug(Editor::LogCat, "Asset Location: %s", pAsset->GetFileLocation().string().c_str());
}
ImGui::EndDragDropTarget();
}

@ -46,12 +46,13 @@ namespace editor
bool mSyncTree;
private:
void HandlePopupActions();
void HandleAssetDrop(std::filesystem::path dir);
void DoDirTree(std::filesystem::path dir);
void DoContentArea(ImVec2 wind_size);
void DoContextMenu();
void DoNewFolder();
};
}
}

@ -7,16 +7,20 @@
******************************************************************************/
#include "world_tree.h"
#include <core/core.h>
#include <world/world.h>
#include <world/entity.h>
#include <world/components.h>
#include <dearimgui/imgui.h>
#include <editor/editor.h>
#include <utils/logger.h>
namespace lunarium
{
namespace editor
{
WorldTree::WorldTree()
: Panel("World Tree", gui::PanelDockZone::DDZ_LEFT, true), mpWorld(nullptr)
: Panel("World Tree", gui::PanelDockZone::DDZ_LEFT, true), mpWorld(new lunarium::World), mDoNewEntity(false)
{
}
@ -42,21 +46,90 @@ namespace editor
return false;
}
if (ImGui::TreeNode("World Root"))
if (ImGui::TreeNode("World Root") && mpWorld)
{
// List all world entities
// This will fail if we end up implementing child entities
// In that case this needs to become recursive
int idx = 0;
for (auto iter = mpWorld->EntitiesBegin(); !mpWorld->EntitiesIsEnd(iter); iter++, idx++)
{
std::string name = "Entity";
name += std::to_string(idx);
if ((*iter)->HasComponent<TagComponent>())
{
name = (*iter)->GetComponent<TagComponent>().Info;
}
if (ImGui::TreeNode(name.c_str()))
{
// TODO: Build tree of world contents
ImGui::TreePop();
}
}
ImGui::TreePop();
}
DoContextMenu();
HandlePopupEvents();
ImGui::End();
return true;
}
void WorldTree::DoContextMenu()
{
if (ImGui::BeginPopupContextWindow(0, ImGuiPopupFlags_MouseButtonRight))
{
if (ImGui::Button("Create New Entity"))
{
if (!mpWorld)
{
Logger::Warn(Editor::LogCat, "Can not create new entity - World pointer is null");
}
else
{
mDoNewEntity = true;
}
}
ImGui::EndPopup();
}
}
ImGui::End();
return true;
void WorldTree::HandlePopupEvents()
{
if (mDoNewEntity)
{
PopupNewEntity();
ImGui::OpenPopup("New Entity");
}
}
void WorldTree::PopupNewEntity()
{
if (ImGui::BeginPopupContextItem("New Entity"))
{
char name_buf[64] = "NewEntity";
ImGui::TextUnformatted("Entity Name: ");
ImGui::SameLine();
if (ImGui::InputText("##Entity Name", name_buf, 64, ImGuiInputTextFlags_AutoSelectAll | ImGuiInputTextFlags_EnterReturnsTrue))
{
LUUID id = mpWorld->CreateEntity();
mpWorld->GetEntity(id)->AddComponent<TagComponent>();
TagComponent& tc = mpWorld->GetEntity(id)->GetComponent<TagComponent>();
tc.Info = name_buf;
mDoNewEntity = false;
ImGui::CloseCurrentPopup();
}
if (Core::Input().IsKeyDown(KeyCode::ESCAPE, true))
{
mDoNewEntity = false;
ImGui::CloseCurrentPopup();
}
ImGui::EndPopup();
}
}
}
}

@ -29,6 +29,15 @@ namespace editor
private:
lunarium::World* mpWorld;
// Context menus
void DoContextMenu();
// Popup events
bool mDoNewEntity;
void HandlePopupEvents();
void PopupNewEntity();
};
}
}

@ -34,7 +34,13 @@ namespace lunarium
{
glm::vec3 Position = { 0.0f, 0.0f, 0.0f };
glm::vec3 Rotation = { 0.0f, 0.0f, 0.0f };
glm::vec3 Scale = { 1.0f, 1.0f, 1.0f };;
glm::vec3 Scale = { 1.0f, 1.0f, 1.0f };
TransformComponent()
: Position(glm::vec3(0.0f, 0.0f, 0.0f)), Rotation(glm::vec3(0.0f, 0.0f, 0.0f)), Scale(glm::vec3(1.0f, 1.0f, 1.0f))
{
}
glm::mat4 GetTransform()
{

@ -19,7 +19,6 @@ namespace lunarium
class Entity
{
public:
// TODO: Maybe change this to take the World instead of the registry
Entity(World& w);
Entity(World& w, LUUID uuid, entt::entity handle = entt::null);

@ -76,23 +76,39 @@ namespace lunarium
//Logger::Error(LogCategory::GAME_SYSTEM, "World::CreateEntity not implemented!");
Entity* new_ent = new Entity(*this);
if (mEntities.find(new_ent->GetUUID()) != mEntities.end())
if (mEntitiesByUUID.find(new_ent->GetUUID()) != mEntitiesByUUID.end())
{
Logger::Warn(LogCategory::GAME_SYSTEM, "UUID collision when creating new entity! UUID: %d", new_ent->GetUUID());
}
mEntities[new_ent->GetUUID()] = new_ent;
mEntitiesByUUID[new_ent->GetUUID()] = new_ent;
mEntities.push_back(new_ent);
return new_ent->GetUUID();
}
Entity* World::GetEntity(LUUID id)
{
if (mEntities.find(id) == mEntities.end())
if (mEntitiesByUUID.find(id) == mEntitiesByUUID.end())
{
Logger::Warn(LogCategory::GAME_SYSTEM, "Entity with id: %d not found.", id);
}
return mEntities[id];
return mEntitiesByUUID[id];
}
unsigned int World::GetNumEntities() const
{
return mEntities.size();
}
std::vector<Entity*>::iterator World::EntitiesBegin()
{
return mEntities.begin();
}
bool World::EntitiesIsEnd(std::vector<Entity*>::iterator& iter)
{
return iter == mEntities.end();
}
}

@ -32,6 +32,12 @@ namespace lunarium
namespace lunarium
{
struct EntityIterator
{
Entity* mEntity;
int Index;
};
class World
{
public:
@ -65,20 +71,25 @@ namespace lunarium
entt::registry* GetEntityRegistry();
LUUID CreateEntity();
Entity* GetEntity(LUUID id);
unsigned int GetNumEntities() const;
std::vector<Entity*>::iterator EntitiesBegin();
bool EntitiesIsEnd(std::vector<Entity*>::iterator& iter);
private:
entt::registry mECSRegistry;
//Camera* mpCamera;
//std::vector<GameObject*> mWorldObjects;
std::vector<Entity*> mEntities;
lunarium::Script* mpWorldScript;
// TODO: Move these into a TileMap class?
// This would allow worlds to support non-tile based levels/worlds
Sizei mRegionSize; // in tiles
Sizei mWorldSize; // num regions ex. 10x10
Vec2i mActiveRegion;
// TEST STUFF
std::map<LUUID, Entity*> mEntities;
std::map<LUUID, Entity*> mEntitiesByUUID;
};

Loading…
Cancel
Save