| 401 | } |
| 402 | |
| 403 | void MainInterface::handleInteractAction(InteractAction interactAction) { |
| 404 | auto assets = Root::singleton().assets(); |
| 405 | auto world = m_client->worldClient(); |
| 406 | |
| 407 | if (interactAction.type == InteractActionType::OpenContainer) { |
| 408 | // If we're currently displaying this container, close it. |
| 409 | if (m_containerPane && m_containerInteractor->openContainerId() == interactAction.entityId) { |
| 410 | m_paneManager.dismissPane(m_containerPane); |
| 411 | return; |
| 412 | } |
| 413 | |
| 414 | // If we're currently displaying another container, close it before we open. |
| 415 | if (m_containerPane) |
| 416 | m_paneManager.dismissPane(m_containerPane); |
| 417 | |
| 418 | auto containerEntity = world->get<ContainerEntity>(interactAction.entityId); |
| 419 | if (!containerEntity) |
| 420 | return; |
| 421 | |
| 422 | m_containerInteractor->openContainer(containerEntity); |
| 423 | |
| 424 | bool closeWithInventory = !m_paneManager.registeredPaneIsDisplayed(MainInterfacePanes::Inventory); |
| 425 | m_paneManager.displayRegisteredPane(MainInterfacePanes::Inventory); |
| 426 | |
| 427 | m_containerPane = make_shared<ContainerPane>(world, m_client->mainPlayer(), m_containerInteractor); |
| 428 | m_paneManager.displayPane(PaneLayer::Window, m_containerPane, [this, closeWithInventory](PanePtr const&) { |
| 429 | if (closeWithInventory) |
| 430 | m_paneManager.dismissRegisteredPane(MainInterfacePanes::Inventory); |
| 431 | else { |
| 432 | m_containerInteractor->closeContainer(); |
| 433 | m_containerPane = {}; |
| 434 | } |
| 435 | }); |
| 436 | |
| 437 | m_paneManager.bringPaneAdjacent(m_paneManager.registeredPane(MainInterfacePanes::Inventory), |
| 438 | m_containerPane, Root::singleton().assets()->json("/interface.config:bringAdjacentWindowGap").toFloat()); |
| 439 | } else if (interactAction.type == InteractActionType::SitDown) { |
| 440 | m_client->mainPlayer()->lounge(interactAction.entityId, interactAction.data.toUInt()); |
| 441 | } else if (interactAction.type == InteractActionType::OpenCraftingInterface) { |
| 442 | if (interactAction.entityId != NullEntityId && !world->entity(interactAction.entityId)) |
| 443 | return; |
| 444 | |
| 445 | openCraftingWindow(interactAction.data, interactAction.entityId); |
| 446 | } else if (interactAction.type == InteractActionType::OpenSongbookInterface) { |
| 447 | m_paneManager.displayRegisteredPane(MainInterfacePanes::Songbook); |
| 448 | } else if (interactAction.type == InteractActionType::OpenNpcCraftingInterface) { |
| 449 | if (interactAction.entityId != NullEntityId && !world->entity(interactAction.entityId)) |
| 450 | return; |
| 451 | // wait, this is literally the exact same as OpenCraftingInterface. what the fuck? lol |
| 452 | openCraftingWindow(interactAction.data, interactAction.entityId); |
| 453 | } else if (interactAction.type == InteractActionType::OpenMerchantInterface) { |
| 454 | if (interactAction.entityId != NullEntityId && !world->entity(interactAction.entityId)) |
| 455 | return; |
| 456 | |
| 457 | openMerchantWindow(interactAction.data, interactAction.entityId); |
| 458 | } else if (interactAction.type == InteractActionType::OpenAiInterface) { |
| 459 | as<AiInterface>(m_paneManager.registeredPane(MainInterfacePanes::Ai))->setSourceEntityId(interactAction.entityId); |
| 460 | m_paneManager.displayRegisteredPane(MainInterfacePanes::Ai); |
no test coverage detected