Skip to content

Commit

Permalink
Fix editor menu items swapping positions
Browse files Browse the repository at this point in the history
  • Loading branch information
nerudaj committed Feb 9, 2024
1 parent b0c14b0 commit ebefd82
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
12 changes: 8 additions & 4 deletions src/lib-editor/src/Editor/Editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ Editor::Editor(
level.mesh.layerWidth, level.mesh.layerHeight, level.mesh.tileWidth);
configureMouseIndicator();
configureMeshTool(level);
populateMenuBar();
switchTool(EditorState::Mesh);
configureItemTool(level);
populateMenuBar();
configureCanvasCallbacks();
}

Expand Down Expand Up @@ -107,8 +107,13 @@ void Editor::populateMenuBar()

auto menu = gui->gui.get<tgui::MenuBar>("TopMenuBar");

if (!menu->getMenuEnabled(MENU_NAME))
{
menu->addMenu(MENU_NAME);
}

// Cleanup previously built data
menu->removeMenu(MENU_NAME);
menu->removeMenuItems(MENU_NAME);
shortcutEngine->unregisterShortcutGroup(MENU_NAME);

auto addEditorMenuItem =
Expand All @@ -117,7 +122,7 @@ void Editor::populateMenuBar()
sf::Keyboard::Key shortcut = sf::Keyboard::KeyCount,
bool ctrlRequired = false)
{
menu->addMenuItem(label);
menu->addMenuItem(MENU_NAME, label);
menu->connectMenuItem(MENU_NAME, label, callback);

if (shortcut != sf::Keyboard::KeyCount)
Expand All @@ -128,7 +133,6 @@ void Editor::populateMenuBar()
using namespace Strings::Editor::ContextMenu;

// Build menu
menu->addMenu(MENU_NAME);
addEditorMenuItem(
MESH_MODE, [this] { switchTool(EditorState::Mesh); }, sf::Keyboard::M);
addEditorMenuItem(
Expand Down
10 changes: 7 additions & 3 deletions src/lib-editor/src/Tools/ToolInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ void ToolInterface::buildCtxMenu(tgui::MenuBar::Ptr& menu)
{
destroyCtxMenu(menu);
shortcutEngine->unregisterShortcutGroup(CTX_MENU_NAME);
menu->addMenu(CTX_MENU_NAME);

if (!menu->getMenuEnabled(CTX_MENU_NAME))
{
menu->addMenu(CTX_MENU_NAME);
}
buildCtxMenuInternal(menu);
}

Expand All @@ -16,7 +20,7 @@ void ToolInterface::addCtxMenuItem(
std::function<void(void)> callback,
sf::Keyboard::Key key)
{
menu->addMenuItem(label);
menu->addMenuItem(CTX_MENU_NAME, label);
ctxMenuSignalHandlers.push_back(
menu->connectMenuItem(CTX_MENU_NAME, label, callback));
shortcutEngine->registerShortcut(
Expand All @@ -30,7 +34,7 @@ void ToolInterface::destroyCtxMenu(tgui::MenuBar::Ptr& menu)
menu->disconnect(id);*/

ctxMenuSignalHandlers.clear();
menu->removeMenu(CTX_MENU_NAME);
menu->removeMenuItems(CTX_MENU_NAME);
}

sf::Vector2i Helper::minVector(const sf::Vector2i& a, const sf::Vector2i& b)
Expand Down

0 comments on commit ebefd82

Please sign in to comment.