diff options
author | Kae <80987908+Novaenia@users.noreply.github.com> | 2024-05-23 12:12:07 +1000 |
---|---|---|
committer | Kae <80987908+Novaenia@users.noreply.github.com> | 2024-05-23 12:12:07 +1000 |
commit | 0abe47ab6c3e9c64d686549e9520566f3eb44b6a (patch) | |
tree | 6455d7e250b104ec6d6f80dea5a07b894fed25db /source/frontend/StarMainInterface.cpp | |
parent | f42031dc9ee89d58232442320ae44447cd0acda5 (diff) |
slightly smarter inventory close behavior with panes that open with the inventory
Diffstat (limited to 'source/frontend/StarMainInterface.cpp')
-rw-r--r-- | source/frontend/StarMainInterface.cpp | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/source/frontend/StarMainInterface.cpp b/source/frontend/StarMainInterface.cpp index 5163eeb..9f0bc0d 100644 --- a/source/frontend/StarMainInterface.cpp +++ b/source/frontend/StarMainInterface.cpp @@ -220,15 +220,12 @@ void MainInterface::openMerchantWindow(Json const& config, EntityId sourceEntity } bool openWithInventory = config.getBool("openWithInventory", true); + bool closeWithInventory = config.getBool("closeWithInventory", !m_paneManager.registeredPaneIsDisplayed(MainInterfacePanes::Inventory)); m_merchantWindow = make_shared<MerchantPane>(m_client->worldClient(), m_client->mainPlayer(), config, sourceEntityId); - m_paneManager.displayPane(PaneLayer::Window, - m_merchantWindow, - [this, openWithInventory](PanePtr const&) { - if (auto player = m_client->mainPlayer()) - player->clearSwap(); - if (openWithInventory) - m_paneManager.dismissRegisteredPane(MainInterfacePanes::Inventory); - }); + m_paneManager.displayPane(PaneLayer::Window, m_merchantWindow, [this, closeWithInventory](PanePtr const&) { + if (closeWithInventory) + m_paneManager.dismissRegisteredPane(MainInterfacePanes::Inventory); + }); if (openWithInventory) m_paneManager.displayRegisteredPane(MainInterfacePanes::Inventory); @@ -404,13 +401,17 @@ void MainInterface::handleInteractAction(InteractAction interactAction) { m_containerInteractor->openContainer(containerEntity); + bool closeWithInventory = !m_paneManager.registeredPaneIsDisplayed(MainInterfacePanes::Inventory); m_paneManager.displayRegisteredPane(MainInterfacePanes::Inventory); m_containerPane = make_shared<ContainerPane>(world, m_client->mainPlayer(), m_containerInteractor); - m_paneManager.displayPane(PaneLayer::Window, m_containerPane, [this](PanePtr const&) { - if (auto player = m_client->mainPlayer()) - player->clearSwap(); - m_paneManager.dismissRegisteredPane(MainInterfacePanes::Inventory); + m_paneManager.displayPane(PaneLayer::Window, m_containerPane, [this, closeWithInventory](PanePtr const&) { + if (closeWithInventory) + m_paneManager.dismissRegisteredPane(MainInterfacePanes::Inventory); + else { + m_containerInteractor->closeContainer(); + m_containerPane = {}; + } }); m_paneManager.bringPaneAdjacent(m_paneManager.registeredPane(MainInterfacePanes::Inventory), @@ -1580,10 +1581,10 @@ void MainInterface::displayScriptPane(ScriptPanePtr& scriptPane, EntityId source layer = PaneLayerNames.getLeft(*layerName); if (scriptPane->openWithInventory()) { - m_paneManager.displayPane(layer, scriptPane, [this](PanePtr const&) { - if (auto player = m_client->mainPlayer()) - player->clearSwap(); - m_paneManager.dismissRegisteredPane(MainInterfacePanes::Inventory); + bool closeWithInventory = scriptPane->closeWithInventory(); + m_paneManager.displayPane(layer, scriptPane, [this, closeWithInventory](PanePtr const&) { + if (closeWithInventory) + m_paneManager.dismissRegisteredPane(MainInterfacePanes::Inventory); }); m_paneManager.displayRegisteredPane(MainInterfacePanes::Inventory); m_paneManager.bringPaneAdjacent(m_paneManager.registeredPane(MainInterfacePanes::Inventory), |