Skip to content

Commit

Permalink
Added actor rename option
Browse files Browse the repository at this point in the history
* added an option to rename an actor
* renamed HierarchyContextualMenu to ActorContextualMenu
* moved rename action to be shown before delete action in hierarchy for better consistency between contextual menus
  • Loading branch information
adriengivry committed Nov 23, 2023
1 parent 86b701b commit 168fe24
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,10 @@ class BrowserItemContextualMenu : public OvUI::Plugins::ContextualMenu
{
if (!m_protected)
{
auto& renameMenu = CreateWidget<OvUI::Widgets::Menu::MenuList>("Rename to...");
auto& deleteAction = CreateWidget<OvUI::Widgets::Menu::MenuItem>("Delete");
deleteAction.ClickedEvent += [this] { DeleteItem(); };

auto& renameMenu = CreateWidget<OvUI::Widgets::Menu::MenuList>("Rename to...");

auto& nameEditor = renameMenu.CreateWidget<OvUI::Widgets::InputFields::InputText>("");
nameEditor.selectAllOnClick = true;
Expand All @@ -130,8 +132,6 @@ class BrowserItemContextualMenu : public OvUI::Plugins::ContextualMenu
nameEditor.content = nameEditor.content.substr(0, pos);
};

deleteAction.ClickedEvent += [this] { DeleteItem(); };

nameEditor.EnterPressedEvent += [this](std::string p_newName)
{
if (!std::filesystem::is_directory(filePath))
Expand Down
23 changes: 19 additions & 4 deletions Sources/Overload/OvEditor/src/OvEditor/Panels/Hierarchy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@

#include "OvEditor/Utils/ActorCreationMenu.h"

class HierarchyContextualMenu : public OvUI::Plugins::ContextualMenu
class ActorContextualMenu : public OvUI::Plugins::ContextualMenu
{
public:
HierarchyContextualMenu(OvCore::ECS::Actor* p_target, OvUI::Widgets::Layout::TreeNode& p_treeNode, bool p_panelMenu = false) :
ActorContextualMenu(OvCore::ECS::Actor* p_target, OvUI::Widgets::Layout::TreeNode& p_treeNode, bool p_panelMenu = false) :
m_target(p_target),
m_treeNode(p_treeNode)
{
Expand Down Expand Up @@ -64,6 +64,21 @@ class HierarchyContextualMenu : public OvUI::Plugins::ContextualMenu
{
EDITOR_EXEC(DestroyActor(std::ref(*m_target)));
};

auto& renameMenu = CreateWidget<OvUI::Widgets::Menu::MenuList>("Rename to...");

auto& nameEditor = renameMenu.CreateWidget<OvUI::Widgets::InputFields::InputText>("");
nameEditor.selectAllOnClick = true;

renameMenu.ClickedEvent += [this, &nameEditor]
{
nameEditor.content = m_target->GetName();
};

nameEditor.EnterPressedEvent += [this](std::string p_newName)
{
m_target->SetName(p_newName);
};
}

auto& createActor = CreateWidget<OvUI::Widgets::Menu::MenuList>("Create...");
Expand Down Expand Up @@ -176,7 +191,7 @@ OvEditor::Panels::Hierarchy::Hierarchy

p_element.first->DetachFromParent();
};
m_sceneRoot->AddPlugin<HierarchyContextualMenu>(nullptr, *m_sceneRoot);
m_sceneRoot->AddPlugin<ActorContextualMenu>(nullptr, *m_sceneRoot);

EDITOR_EVENT(ActorUnselectedEvent) += std::bind(&Hierarchy::UnselectActorsWidgets, this);
EDITOR_CONTEXT(sceneManager).SceneUnloadEvent += std::bind(&Hierarchy::Clear, this);
Expand Down Expand Up @@ -278,7 +293,7 @@ void OvEditor::Panels::Hierarchy::AddActorByInstance(OvCore::ECS::Actor & p_acto
{
auto& textSelectable = m_sceneRoot->CreateWidget<OvUI::Widgets::Layout::TreeNode>(p_actor.GetName(), true);
textSelectable.leaf = true;
textSelectable.AddPlugin<HierarchyContextualMenu>(&p_actor, textSelectable);
textSelectable.AddPlugin<ActorContextualMenu>(&p_actor, textSelectable);
textSelectable.AddPlugin<OvUI::Plugins::DDSource<std::pair<OvCore::ECS::Actor*, OvUI::Widgets::Layout::TreeNode*>>>("Actor", "Attach to...", std::make_pair(&p_actor, &textSelectable));
textSelectable.AddPlugin<OvUI::Plugins::DDTarget<std::pair<OvCore::ECS::Actor*, OvUI::Widgets::Layout::TreeNode*>>>("Actor").DataReceivedEvent += [&p_actor, &textSelectable](std::pair<OvCore::ECS::Actor*, OvUI::Widgets::Layout::TreeNode*> p_element)
{
Expand Down

0 comments on commit 168fe24

Please sign in to comment.