Beginning of properties window working

master
Joey Pollack 4 years ago
parent d55d28fe1b
commit 5c83a63b3c

@ -9,7 +9,8 @@ Build System:
Core: Core:
✔ Wrap NFD in an API in the platform module @low @done(22-05-31 15:44) ✔ Wrap NFD in an API in the platform module @low @done(22-05-31 15:44)
Wrapper added to utils - not platform Wrapper added to utils - not platform
☐ Add custom (64 bit?) UUID generator (based on Chreno's UUIDs) ✔ Add custom (64 bit?) UUID generator (based on Chreno's UUIDs) @done(22-06-27 13:34)
☐ Allow Entities to have children @medium
✔ Add Terminal subsystem to allow for printing colored text in a cross-platform way @done(22-05-16 18:05) ✔ Add Terminal subsystem to allow for printing colored text in a cross-platform way @done(22-05-16 18:05)
✔ Create a LogListener that uses the colored text (replace the current stdout listener) @done(22-05-16 18:23) ✔ Create a LogListener that uses the colored text (replace the current stdout listener) @done(22-05-16 18:23)
✔ Replace XML with JSON (https://github.com/nlohmann/json) @high @done(22-05-19 15:35) ✔ Replace XML with JSON (https://github.com/nlohmann/json) @high @done(22-05-19 15:35)

@ -7,10 +7,13 @@ Editor:
✔ Implement Run Mode interface class @high @done (2/8/2022, 4:05:17 PM) ✔ Implement Run Mode interface class @high @done (2/8/2022, 4:05:17 PM)
✔ Reference raw asset files in a "content" folder@high @done (3/3/2022, 3:15:32 PM) ✔ Reference raw asset files in a "content" folder@high @done (3/3/2022, 3:15:32 PM)
✔ Platform independant file browsing @done (2/8/2022, 4:05:29 PM) ✔ Platform independant file browsing @done (2/8/2022, 4:05:29 PM)
☐ Turn World into an editor asset that can be created
☐ Store entities in the World object
☐ Implement Saving/loading the World asset
☐ Test the Asset Trashing system @high ☐ Test the Asset Trashing system @high
☐ Add ability to browse and restore trashed assets ☐ Add ability to browse and restore trashed assets
☐ Scan script files to make sure they don't overwrite globals ✔ Figure out how to make game asset types integrate with editor asset types @critical @done(22-06-27 13:32)
☐ Figure out how to make game asset types integrate with editor asset types @critical - Probably just wrap the game object in an EditorAsset object if needed
Panel System: Panel System:
☐ Allow for saving custom panel layouts @low ☐ Allow for saving custom panel layouts @low

@ -15,9 +15,13 @@ namespace lunarium { namespace editor
{ {
void CompGui::RenderTagComp(TagComponent& comp) void CompGui::RenderTagComp(TagComponent& comp)
{ {
const int BUFFER_SIZE = 256;
static char buffer[BUFFER_SIZE] = "";
ImGui::Text("Tag:"); ImGui::Text("Tag:");
ImGui::SameLine(); ImGui::SameLine();
ImGui::InputText("##Tag", comp.Info.data(), comp.Info.capacity()); strcpy(buffer, comp.Info.c_str());
ImGui::InputText("##Tag", buffer, BUFFER_SIZE);
comp.Info = buffer;
} }
void CompGui::RenderTransformComp(TransformComponent& comp) void CompGui::RenderTransformComp(TransformComponent& comp)

@ -28,7 +28,7 @@
#include <world/components.h> #include <world/components.h>
// TEST STUFF // Game objects
#include <world/world.h> #include <world/world.h>
#include <world/entity.h> #include <world/entity.h>
#include <world/components.h> #include <world/components.h>
@ -69,7 +69,7 @@ namespace editor
} }
mPanelManager.AddPanel(new AssetBrowser("", this), mPanels.AssetBrowser).LogIfFailed(LogCat); mPanelManager.AddPanel(new AssetBrowser("", this), mPanels.AssetBrowser).LogIfFailed(LogCat);
mPanelManager.AddPanel(new WorldTree(), mPanels.WorldTree).LogIfFailed(LogCat); mPanelManager.AddPanel(new WorldTree(this), mPanels.WorldTree).LogIfFailed(LogCat);
mPanelManager.AddPanel(new WorldView(), mPanels.WorldView).LogIfFailed(LogCat); mPanelManager.AddPanel(new WorldView(), mPanels.WorldView).LogIfFailed(LogCat);
mPanelManager.AddPanel(new PropertiesView(), mPanels.PropertiesView).LogIfFailed(LogCat); mPanelManager.AddPanel(new PropertiesView(), mPanels.PropertiesView).LogIfFailed(LogCat);
@ -434,5 +434,14 @@ namespace editor
ImGui::End(); ImGui::End();
} }
/////////////////////////////////////////////////////////////////////
// PANEL EVENTS
/////////////////////////////////////////////////////////////////////
void Editor::OnEntitySelect(lunarium::Entity* pEnt)
{
//Logger::Info(Editor::LogCat, "ENTITY SELECT: %ll", (long long) pEnt);
((PropertiesView*)mPanelManager.GetPanel(mPanels.PropertiesView))->SetSelection(pEnt);
}
} }
} }

@ -23,6 +23,7 @@
namespace lunarium namespace lunarium
{ {
class World; class World;
class Entity;
} }
namespace lunarium { namespace editor namespace lunarium { namespace editor
@ -56,6 +57,9 @@ namespace lunarium { namespace editor
std::filesystem::path GetAssetBrowserLocation(); std::filesystem::path GetAssetBrowserLocation();
Project* GetProject(); Project* GetProject();
// Panel events
void OnEntitySelect(lunarium::Entity* pEnt);
private: private:
Editor(const Editor&) = delete; Editor(const Editor&) = delete;
const Editor& operator=(const Editor&) = delete; const Editor& operator=(const Editor&) = delete;

@ -18,35 +18,84 @@ namespace lunarium { namespace editor
{ {
PropertiesView::PropertiesView() PropertiesView::PropertiesView()
: Panel("Properties", PanelDockZone::DDZ_RIGHT, true, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoScrollbar), : Panel("Properties", PanelDockZone::DDZ_RIGHT, true, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoScrollbar),
mpSelectedAsset(nullptr), mpSelectedEntity(nullptr) mpSelectedAsset(nullptr), mpSelectedEntity(nullptr), mIsLocked(false)
{ {
} }
/////////////////////////////////////////////////////////////////////
// RENDER METHOD
/////////////////////////////////////////////////////////////////////
void PropertiesView::DoFrame() void PropertiesView::DoFrame()
{ {
ShowToolBar();
if (mpSelectedEntity) if (mpSelectedEntity)
{ {
// TODO: iterate through components ShowEntity();
if (mpSelectedEntity->HasComponent<TagComponent>())
{
CompGui::RenderTagComp(mpSelectedEntity->GetComponent<TagComponent>());
} }
if (mpSelectedAsset)
{
ShowAsset();
} }
} }
/////////////////////////////////////////////////////////////////////
// INTERFACE METHODS
/////////////////////////////////////////////////////////////////////
void PropertiesView::SetSelection(Entity* pEntity) void PropertiesView::SetSelection(Entity* pEntity)
{ {
if (mIsLocked)
{
return;
}
mpSelectedAsset = nullptr; mpSelectedAsset = nullptr;
mpSelectedEntity = pEntity; mpSelectedEntity = pEntity;
} }
void PropertiesView::SetSelection(EditorAsset* pAsset) void PropertiesView::SetSelection(EditorAsset* pAsset)
{ {
if (mIsLocked)
{
return;
}
mpSelectedEntity = nullptr; mpSelectedEntity = nullptr;
mpSelectedAsset = pAsset; mpSelectedAsset = pAsset;
} }
/////////////////////////////////////////////////////////////////////
// HELPER METHODS HELPER METHODS
/////////////////////////////////////////////////////////////////////
void PropertiesView::ShowToolBar()
{
ImGui::BeginChild("##PropsToolBar", ImVec2(0, ImGui::GetFrameHeightWithSpacing()));
ImGui::Checkbox("Locked", &mIsLocked);
ImGui::EndChild();
ImGui::Separator();
}
void PropertiesView::ShowEntity()
{
ImGui::Text("Components");
// TODO: iterate through components
if (mpSelectedEntity->HasComponent<TagComponent>())
{
CompGui::RenderTagComp(mpSelectedEntity->GetComponent<TagComponent>());
}
}
void PropertiesView::ShowAsset()
{
}
}} }}

@ -32,11 +32,18 @@ namespace editor
void DoFrame(); void DoFrame();
private: private:
bool mIsLocked;
std::vector<CustromProperty*> mCustomProps; std::vector<CustromProperty*> mCustomProps;
// Only ONE of these should be set at a time // Only ONE of these should be set at a time
Entity* mpSelectedEntity; Entity* mpSelectedEntity;
EditorAsset* mpSelectedAsset; EditorAsset* mpSelectedAsset;
private: // HELPERS
void ShowToolBar();
void ShowEntity();
void ShowAsset();
}; };
} }
} }

@ -1,12 +1,13 @@
/****************************************************************************** /******************************************************************************
* File - worldTree.cpp * File - worldTree.cpp
* Author - Joey Pollack * Author - Joey Pollack
* Date - 2021/11/04 (y/m/d) * Date - 2021/11/04 (y/m/d)
* Mod Date - 2021/11/04 (y/m/d) * Mod Date - 2021/11/04 (y/m/d)
* Description - The tree view listing all objects in the world * Description - The tree view listing all objects in the world
******************************************************************************/ ******************************************************************************/
#include "world_tree.h" #include "world_tree.h"
#include <editor/editor.h>
#include <core/core.h> #include <core/core.h>
#include <world/world.h> #include <world/world.h>
#include <world/entity.h> #include <world/entity.h>
@ -17,27 +18,52 @@
namespace lunarium namespace lunarium
{ {
namespace editor namespace editor
{ {
WorldTree::WorldTree() WorldTree::WorldTree(Editor *editor)
: Panel("World Tree", PanelDockZone::DDZ_LEFT, true, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoScrollbar), : Panel("World Tree", PanelDockZone::DDZ_LEFT, true, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoScrollbar),
mpWorld(new lunarium::World), mDoNewEntity(false) mpEditor(editor),
// TODO: Temp world created here
mpWorld(new lunarium::World),
mDoNewEntity(false), mpSelectedEntity(nullptr)
{
AddPopup(PopUp::NEW_ENTITY, "New Entity", [](Panel *p)
{
WorldTree* pWT = (WorldTree*)p;
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 = pWT->mpWorld->CreateEntity();
pWT->mpWorld->GetEntity(id)->AddComponent<TagComponent>();
TagComponent& tc = pWT->mpWorld->GetEntity(id)->GetComponent<TagComponent>();
tc.Info = name_buf;
return false;
}
if (Core::Input().IsKeyDown(KeyCode::ESCAPE, true))
{
return false;
} }
void WorldTree::SetWorld(lunarium::World* pWorld) return true;
});
}
void WorldTree::SetWorld(lunarium::World *pWorld)
{ {
mpWorld = pWorld; mpWorld = pWorld;
} }
lunarium::World* WorldTree::GetWorld() lunarium::World *WorldTree::GetWorld()
{ {
return mpWorld; return mpWorld;
} }
void WorldTree::DoFrame() void WorldTree::DoFrame()
{ {
Entity *pSelection = nullptr;
if (ImGui::TreeNode("World Root") && mpWorld) if (ImGui::TreeNode("World Root") && mpWorld)
{ {
// List all world entities // List all world entities
@ -53,19 +79,54 @@ namespace editor
name = (*iter)->GetComponent<TagComponent>().Info; name = (*iter)->GetComponent<TagComponent>().Info;
} }
if ((*iter)->HasChildren())
{
// TODO: Recurse through children
if (ImGui::TreeNode(name.c_str())) if (ImGui::TreeNode(name.c_str()))
{ {
ImGui::TreePop(); ImGui::TreePop();
} }
} }
else
{
bool is_selected = false;
if ((*iter) == mpSelectedEntity)
{
is_selected = true;
}
if (ImGui::Selectable(name.c_str(), &is_selected))
{
mpSelectedEntity = (*iter);
if (is_selected)
{
mpEditor->OnEntitySelect(mpSelectedEntity);
}
else
{
mpEditor->OnEntitySelect(nullptr);
mpSelectedEntity = nullptr;
}
}
}
}
ImGui::TreePop(); ImGui::TreePop();
} }
if (ImGui::IsMouseClicked(ImGuiMouseButton_Left) && ImGui::IsWindowHovered())
{
mpSelectedEntity = nullptr;
mpEditor->OnEntitySelect(nullptr);
}
// TODO: Find a way to change this so that OnEntitySelect is not called every frame
// if (pSelection != mpSelectedEntity)
// {
// mpSelectedEntity = pSelection;
// mpEditor->OnEntitySelect(mpSelectedEntity);
// }
DoContextMenu(); DoContextMenu();
HandlePopupEvents();
} }
void WorldTree::DoContextMenu() void WorldTree::DoContextMenu()
@ -80,46 +141,12 @@ namespace editor
} }
else else
{ {
mDoNewEntity = true; OpenPopup(PopUp::NEW_ENTITY);
} }
} }
ImGui::EndPopup(); ImGui::EndPopup();
} }
} }
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();
}
}
}
} }

@ -14,13 +14,16 @@
namespace lunarium namespace lunarium
{ {
class World; class World;
class Entity;
namespace editor namespace editor
{ {
class Editor;
class WorldTree : public Panel class WorldTree : public Panel
{ {
public: public:
WorldTree(); WorldTree(Editor* editor);
void SetWorld(lunarium::World* pWorld); void SetWorld(lunarium::World* pWorld);
lunarium::World* GetWorld(); lunarium::World* GetWorld();
@ -29,6 +32,8 @@ namespace editor
private: private:
lunarium::World* mpWorld; lunarium::World* mpWorld;
Editor* mpEditor;
Entity* mpSelectedEntity;
// Context menus // Context menus
void DoContextMenu(); void DoContextMenu();
@ -38,6 +43,13 @@ namespace editor
void HandlePopupEvents(); void HandlePopupEvents();
void PopupNewEntity(); void PopupNewEntity();
private: // POPUP ENUMS
enum PopUp
{
NEW_ENTITY,
};
}; };
} }
} }

@ -33,4 +33,10 @@ namespace lunarium
{ {
return mUUID; return mUUID;
} }
bool Entity::HasChildren() const
{
return mChildren.size() > 0;
}
} }

@ -64,11 +64,13 @@ namespace lunarium
LUUID GetUUID() const; LUUID GetUUID() const;
bool HasChildren() const;
private: private:
LUUID mUUID; LUUID mUUID;
entt::entity mHandle; entt::entity mHandle;
World& mWorld; // The world the entity is contained within World& mWorld; // The world the entity is contained within
//entt::registry* mpRegistry; std::vector<Entity*> mChildren;
private: private:
void Init(); void Init();

Loading…
Cancel
Save