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,13 +220,10 @@ 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.displayPane(PaneLayer::Window, m_merchantWindow, [this, closeWithInventory](PanePtr const&) {
if (closeWithInventory)
m_paneManager.dismissRegisteredPane(MainInterfacePanes::Inventory);
});
if (openWithInventory)
@ -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.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,9 +1581,9 @@ 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();
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);

View File

@ -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;
}

View File

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