From 0abe47ab6c3e9c64d686549e9520566f3eb44b6a Mon Sep 17 00:00:00 2001 From: Kae <80987908+Novaenia@users.noreply.github.com> Date: Thu, 23 May 2024 12:12:07 +1000 Subject: [PATCH] slightly smarter inventory close behavior with panes that open with the inventory --- source/frontend/StarMainInterface.cpp | 33 ++++++++++++++------------- source/frontend/StarScriptPane.cpp | 4 ++++ source/frontend/StarScriptPane.hpp | 1 + 3 files changed, 22 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(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(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), diff --git a/source/frontend/StarScriptPane.cpp b/source/frontend/StarScriptPane.cpp index c98bd2c..bcd599c 100644 --- a/source/frontend/StarScriptPane.cpp +++ b/source/frontend/StarScriptPane.cpp @@ -88,6 +88,10 @@ bool ScriptPane::openWithInventory() const { return m_config.getBool("openWithInventory", false); } +bool ScriptPane::closeWithInventory() const { + return m_config.getBool("closeWithInventory", openWithInventory()); +} + EntityId ScriptPane::sourceEntityId() const { return m_sourceEntityId; } diff --git a/source/frontend/StarScriptPane.hpp b/source/frontend/StarScriptPane.hpp index 9f31dc6..e583d51 100644 --- a/source/frontend/StarScriptPane.hpp +++ b/source/frontend/StarScriptPane.hpp @@ -20,6 +20,7 @@ public: PanePtr createTooltip(Vec2I const& screenPosition) override; bool openWithInventory() const; + bool closeWithInventory() const; EntityId sourceEntityId() const;