fix: crafting interfaces not working with new middle-click opening

This commit is contained in:
Kae 2024-03-28 04:46:07 +11:00
parent d76d217901
commit 0f9a200e6b
3 changed files with 12 additions and 16 deletions

View File

@ -110,7 +110,7 @@ InventoryPane::InventoryPane(MainInterface* parent, PlayerPtr player, ContainerI
auto actionData = sourceItem->instanceValue("interactData", Json());
if (actionData.isType(Json::Type::Object))
actionData = actionData.set("openWithInventory", false);
InteractAction action(actionType, m_player->entityId(), actionData);
InteractAction action(actionType, NullEntityId, actionData);
m_player->interact(action);
}
}

View File

@ -199,10 +199,7 @@ bool MainInterface::escapeDialogOpen() const {
void MainInterface::openCraftingWindow(Json const& config, EntityId sourceEntityId) {
if (m_craftingWindow && m_paneManager.isDisplayed(m_craftingWindow)) {
m_paneManager.dismissPane(m_craftingWindow);
bool fromPlayer = false;
if (auto player = m_client->mainPlayer())
fromPlayer = player->inWorld() && player->entityId() == sourceEntityId;
if (m_craftingWindow->sourceEntityId() == sourceEntityId) {
if (sourceEntityId != NullEntityId && m_craftingWindow->sourceEntityId() == sourceEntityId) {
m_craftingWindow.reset();
return;
}
@ -218,10 +215,7 @@ void MainInterface::openCraftingWindow(Json const& config, EntityId sourceEntity
void MainInterface::openMerchantWindow(Json const& config, EntityId sourceEntityId) {
if (m_merchantWindow && m_paneManager.isDisplayed(m_merchantWindow)) {
m_paneManager.dismissPane(m_merchantWindow);
bool fromPlayer = false;
if (auto player = m_client->mainPlayer())
fromPlayer = player->inWorld() && player->entityId() == sourceEntityId;
if (!fromPlayer && m_merchantWindow->sourceEntityId() == sourceEntityId) {
if (sourceEntityId != NullEntityId && m_merchantWindow->sourceEntityId() == sourceEntityId) {
m_merchantWindow.reset();
return;
}
@ -426,19 +420,19 @@ void MainInterface::handleInteractAction(InteractAction interactAction) {
} else if (interactAction.type == InteractActionType::SitDown) {
m_client->mainPlayer()->lounge(interactAction.entityId, interactAction.data.toUInt());
} else if (interactAction.type == InteractActionType::OpenCraftingInterface) {
if (!world->entity(interactAction.entityId))
if (interactAction.entityId != NullEntityId && !world->entity(interactAction.entityId))
return;
openCraftingWindow(interactAction.data, interactAction.entityId);
} else if (interactAction.type == InteractActionType::OpenSongbookInterface) {
m_paneManager.displayRegisteredPane(MainInterfacePanes::Songbook);
} else if (interactAction.type == InteractActionType::OpenNpcCraftingInterface) {
if (!world->entity(interactAction.entityId))
if (interactAction.entityId != NullEntityId && !world->entity(interactAction.entityId))
return;
// wait, this is literally the exact same as OpenCraftingInterface. what the fuck? lol
openCraftingWindow(interactAction.data, interactAction.entityId);
} else if (interactAction.type == InteractActionType::OpenMerchantInterface) {
if (!world->entity(interactAction.entityId))
if (interactAction.entityId != NullEntityId && !world->entity(interactAction.entityId))
return;
openMerchantWindow(interactAction.data, interactAction.entityId);

View File

@ -118,7 +118,8 @@ void MerchantPane::dismissed() {
for (auto unsold : m_itemBag->takeAll())
m_player->giveItem(unsold);
m_worldClient->sendEntityMessage(m_sourceEntityId, "onMerchantClosed");
if (m_sourceEntityId != NullEntityId)
m_worldClient->sendEntityMessage(m_sourceEntityId, "onMerchantClosed");
}
PanePtr MerchantPane::createTooltip(Vec2I const& screenPosition) {
@ -141,7 +142,7 @@ PanePtr MerchantPane::createTooltip(Vec2I const& screenPosition) {
void MerchantPane::update(float dt) {
Pane::update(dt);
if (!m_worldClient->playerCanReachEntity(m_sourceEntityId))
if (m_sourceEntityId != NullEntityId && !m_worldClient->playerCanReachEntity(m_sourceEntityId))
dismiss();
if (m_refreshTimer.wrapTick()) {
@ -315,7 +316,8 @@ void MerchantPane::buy() {
auto reportItem = m_selectedItem->clone();
reportItem->setCount(reportItem->count() * m_buyCount, true);
auto buySummary = JsonObject{{"item", reportItem->descriptor().toJson()}, {"total", m_buyTotal}};
m_worldClient->sendEntityMessage(m_sourceEntityId, "onBuy", {buySummary});
if (m_sourceEntityId != NullEntityId)
m_worldClient->sendEntityMessage(m_sourceEntityId, "onBuy", {buySummary});
auto& guiContext = GuiContext::singleton();
guiContext.playAudio(Root::singleton().assets()->json("/merchant.config:buySound").toString());