slightly smarter inventory close behavior with panes that open with the inventory

This commit is contained in:
Kae 2024-05-23 12:12:07 +10:00
parent f42031dc9e
commit 0abe47ab6c
3 changed files with 22 additions and 16 deletions

View File

@ -220,15 +220,12 @@ void MainInterface::openMerchantWindow(Json const& config, EntityId sourceEntity
} }
bool openWithInventory = config.getBool("openWithInventory", true); 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_merchantWindow = make_shared<MerchantPane>(m_client->worldClient(), m_client->mainPlayer(), config, sourceEntityId);
m_paneManager.displayPane(PaneLayer::Window, m_paneManager.displayPane(PaneLayer::Window, m_merchantWindow, [this, closeWithInventory](PanePtr const&) {
m_merchantWindow, if (closeWithInventory)
[this, openWithInventory](PanePtr const&) { m_paneManager.dismissRegisteredPane(MainInterfacePanes::Inventory);
if (auto player = m_client->mainPlayer()) });
player->clearSwap();
if (openWithInventory)
m_paneManager.dismissRegisteredPane(MainInterfacePanes::Inventory);
});
if (openWithInventory) if (openWithInventory)
m_paneManager.displayRegisteredPane(MainInterfacePanes::Inventory); m_paneManager.displayRegisteredPane(MainInterfacePanes::Inventory);
@ -404,13 +401,17 @@ void MainInterface::handleInteractAction(InteractAction interactAction) {
m_containerInteractor->openContainer(containerEntity); m_containerInteractor->openContainer(containerEntity);
bool closeWithInventory = !m_paneManager.registeredPaneIsDisplayed(MainInterfacePanes::Inventory);
m_paneManager.displayRegisteredPane(MainInterfacePanes::Inventory); m_paneManager.displayRegisteredPane(MainInterfacePanes::Inventory);
m_containerPane = make_shared<ContainerPane>(world, m_client->mainPlayer(), m_containerInteractor); m_containerPane = make_shared<ContainerPane>(world, m_client->mainPlayer(), m_containerInteractor);
m_paneManager.displayPane(PaneLayer::Window, m_containerPane, [this](PanePtr const&) { m_paneManager.displayPane(PaneLayer::Window, m_containerPane, [this, closeWithInventory](PanePtr const&) {
if (auto player = m_client->mainPlayer()) if (closeWithInventory)
player->clearSwap(); m_paneManager.dismissRegisteredPane(MainInterfacePanes::Inventory);
m_paneManager.dismissRegisteredPane(MainInterfacePanes::Inventory); else {
m_containerInteractor->closeContainer();
m_containerPane = {};
}
}); });
m_paneManager.bringPaneAdjacent(m_paneManager.registeredPane(MainInterfacePanes::Inventory), m_paneManager.bringPaneAdjacent(m_paneManager.registeredPane(MainInterfacePanes::Inventory),
@ -1580,10 +1581,10 @@ void MainInterface::displayScriptPane(ScriptPanePtr& scriptPane, EntityId source
layer = PaneLayerNames.getLeft(*layerName); layer = PaneLayerNames.getLeft(*layerName);
if (scriptPane->openWithInventory()) { if (scriptPane->openWithInventory()) {
m_paneManager.displayPane(layer, scriptPane, [this](PanePtr const&) { bool closeWithInventory = scriptPane->closeWithInventory();
if (auto player = m_client->mainPlayer()) m_paneManager.displayPane(layer, scriptPane, [this, closeWithInventory](PanePtr const&) {
player->clearSwap(); if (closeWithInventory)
m_paneManager.dismissRegisteredPane(MainInterfacePanes::Inventory); m_paneManager.dismissRegisteredPane(MainInterfacePanes::Inventory);
}); });
m_paneManager.displayRegisteredPane(MainInterfacePanes::Inventory); m_paneManager.displayRegisteredPane(MainInterfacePanes::Inventory);
m_paneManager.bringPaneAdjacent(m_paneManager.registeredPane(MainInterfacePanes::Inventory), m_paneManager.bringPaneAdjacent(m_paneManager.registeredPane(MainInterfacePanes::Inventory),

View File

@ -88,6 +88,10 @@ bool ScriptPane::openWithInventory() const {
return m_config.getBool("openWithInventory", false); return m_config.getBool("openWithInventory", false);
} }
bool ScriptPane::closeWithInventory() const {
return m_config.getBool("closeWithInventory", openWithInventory());
}
EntityId ScriptPane::sourceEntityId() const { EntityId ScriptPane::sourceEntityId() const {
return m_sourceEntityId; return m_sourceEntityId;
} }

View File

@ -20,6 +20,7 @@ public:
PanePtr createTooltip(Vec2I const& screenPosition) override; PanePtr createTooltip(Vec2I const& screenPosition) override;
bool openWithInventory() const; bool openWithInventory() const;
bool closeWithInventory() const;
EntityId sourceEntityId() const; EntityId sourceEntityId() const;