Beginning of properties window working

master
Joey Pollack 4 years ago
parent d55d28fe1b
commit 5c83a63b3c

@ -9,7 +9,8 @@ Build System:
Core:
✔ Wrap NFD in an API in the platform module @low @done(22-05-31 15:44)
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)
✔ 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)

@ -7,10 +7,13 @@ Editor:
✔ 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)
✔ 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
☐ 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
✔ Figure out how to make game asset types integrate with editor asset types @critical @done(22-06-27 13:32)
- Probably just wrap the game object in an EditorAsset object if needed
Panel System:
☐ Allow for saving custom panel layouts @low

@ -15,9 +15,13 @@ namespace lunarium { namespace editor
{
void CompGui::RenderTagComp(TagComponent& comp)
{
const int BUFFER_SIZE = 256;
static char buffer[BUFFER_SIZE] = "";
ImGui::Text("Tag:");
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)

@ -28,7 +28,7 @@
#include <world/components.h>
// TEST STUFF
// Game objects
#include <world/world.h>
#include <world/entity.h>
#include <world/components.h>
@ -69,7 +69,7 @@ namespace editor
}
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 PropertiesView(), mPanels.PropertiesView).LogIfFailed(LogCat);
@ -434,5 +434,14 @@ namespace editor
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
{
class World;
class Entity;
}
namespace lunarium { namespace editor
@ -56,6 +57,9 @@ namespace lunarium { namespace editor
std::filesystem::path GetAssetBrowserLocation();
Project* GetProject();
// Panel events
void OnEntitySelect(lunarium::Entity* pEnt);
private:
Editor(const Editor&) = delete;
const Editor& operator=(const Editor&) = delete;

@ -18,35 +18,84 @@ namespace lunarium { namespace editor
{
PropertiesView::PropertiesView()
: 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()
{
ShowToolBar();
if (mpSelectedEntity)
{
// TODO: iterate through components
if (mpSelectedEntity->HasComponent<TagComponent>())
{
CompGui::RenderTagComp(mpSelectedEntity->GetComponent<TagComponent>());
}
ShowEntity();
}
if (mpSelectedAsset)
{
ShowAsset();
}
}
/////////////////////////////////////////////////////////////////////
// INTERFACE METHODS
/////////////////////////////////////////////////////////////////////
void PropertiesView::SetSelection(Entity* pEntity)
{
if (mIsLocked)
{
return;
}
mpSelectedAsset = nullptr;
mpSelectedEntity = pEntity;
}
void PropertiesView::SetSelection(EditorAsset* pAsset)
{
if (mIsLocked)
{
return;
}
mpSelectedEntity = nullptr;
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();
private:
bool mIsLocked;
std::vector<CustromProperty*> mCustomProps;
// Only ONE of these should be set at a time
Entity* mpSelectedEntity;
EditorAsset* mpSelectedAsset;
private: // HELPERS
void ShowToolBar();
void ShowEntity();
void ShowAsset();
};
}
}

@ -1,12 +1,13 @@
/******************************************************************************
* File - worldTree.cpp
* Author - Joey Pollack
* 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
******************************************************************************/
* File - worldTree.cpp
* Author - Joey Pollack
* 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
******************************************************************************/
#include "world_tree.h"
#include <editor/editor.h>
#include <core/core.h>
#include <world/world.h>
#include <world/entity.h>
@ -17,109 +18,135 @@
namespace lunarium
{
namespace editor
{
WorldTree::WorldTree()
: Panel("World Tree", PanelDockZone::DDZ_LEFT, true, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoScrollbar),
mpWorld(new lunarium::World), mDoNewEntity(false)
namespace editor
{
WorldTree::WorldTree(Editor *editor)
: Panel("World Tree", PanelDockZone::DDZ_LEFT, true, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoScrollbar),
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)
{
mpWorld = pWorld;
}
return true;
});
}
lunarium::World* WorldTree::GetWorld()
{
return mpWorld;
}
void WorldTree::SetWorld(lunarium::World *pWorld)
{
mpWorld = pWorld;
}
void WorldTree::DoFrame()
{
if (ImGui::TreeNode("World Root") && mpWorld)
lunarium::World *WorldTree::GetWorld()
{
// 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;
}
return mpWorld;
}
if (ImGui::TreeNode(name.c_str()))
void WorldTree::DoFrame()
{
Entity *pSelection = nullptr;
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;
}
ImGui::TreePop();
if ((*iter)->HasChildren())
{
// TODO: Recurse through children
if (ImGui::TreeNode(name.c_str()))
{
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();
HandlePopupEvents();
}
DoContextMenu();
}
void WorldTree::DoContextMenu()
{
if (ImGui::BeginPopupContextWindow(0, ImGuiPopupFlags_MouseButtonRight))
void WorldTree::DoContextMenu()
{
if (ImGui::Button("Create New Entity"))
if (ImGui::BeginPopupContextWindow(0, ImGuiPopupFlags_MouseButtonRight))
{
if (!mpWorld)
{
Logger::Warn(Editor::LogCat, "Can not create new entity - World pointer is null");
}
else
if (ImGui::Button("Create New Entity"))
{
mDoNewEntity = true;
if (!mpWorld)
{
Logger::Warn(Editor::LogCat, "Can not create new entity - World pointer is null");
}
else
{
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
{
class World;
class Entity;
namespace editor
{
class Editor;
class WorldTree : public Panel
{
public:
WorldTree();
WorldTree(Editor* editor);
void SetWorld(lunarium::World* pWorld);
lunarium::World* GetWorld();
@ -29,6 +32,8 @@ namespace editor
private:
lunarium::World* mpWorld;
Editor* mpEditor;
Entity* mpSelectedEntity;
// Context menus
void DoContextMenu();
@ -38,6 +43,13 @@ namespace editor
void HandlePopupEvents();
void PopupNewEntity();
private: // POPUP ENUMS
enum PopUp
{
NEW_ENTITY,
};
};
}
}

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

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

Loading…
Cancel
Save