void InventoryWindow::mouseClicked(MouseEvent &event) { Window::mouseClicked(event); const int clicks = event.getClickCount(); if (clicks == 2 && gui) gui->resetClickCount(); const bool mod = (isStorageActive() && inputManager.isActionActive(InputAction::STOP_ATTACK)); const bool mod2 = (tradeWindow && tradeWindow->isWindowVisible() && inputManager.isActionActive(InputAction::STOP_ATTACK)); if (mInventory) { if (!mod && !mod2 && event.getButton() == MouseButton::RIGHT) { Item *const item = mItems->getSelectedItem(); if (!item) return; /* Convert relative to the window coordinates to absolute screen * coordinates. */ const int mx = event.getX() + getX(); const int my = event.getY() + getY(); if (popupMenu) { popupMenu->showPopup(this, mx, my, item, mInventory->getType()); } } } else { return; } if (event.getButton() == MouseButton::LEFT || event.getButton() == MouseButton::RIGHT) { Item *const item = mItems->getSelectedItem(); if (!item) return; if (mod) { if (mInventory->isMainInventory()) { if (event.getButton() == MouseButton::RIGHT) { ItemAmountWindow::showWindow(ItemAmountWindow::StoreAdd, inventoryWindow, item); } else { inventoryHandler->moveItem2(InventoryType::Inventory, item->getInvIndex(), item->getQuantity(), InventoryType::Storage); } } else { if (event.getButton() == MouseButton::RIGHT) { ItemAmountWindow::showWindow(ItemAmountWindow::StoreRemove, inventoryWindow, item); } else { inventoryHandler->moveItem2(InventoryType::Storage, item->getInvIndex(), item->getQuantity(), InventoryType::Inventory); } } } else if (mod2 && mInventory->isMainInventory()) { if (PlayerInfo::isItemProtected(item->getId())) return; if (event.getButton() == MouseButton::RIGHT) { ItemAmountWindow::showWindow(ItemAmountWindow::TradeAdd, tradeWindow, item); } else { if (tradeWindow) tradeWindow->tradeItem(item, item->getQuantity(), true); } } else if (clicks == 2) { if (mInventory->isMainInventory()) { if (isStorageActive()) { ItemAmountWindow::showWindow(ItemAmountWindow::StoreAdd, inventoryWindow, item); } else if (tradeWindow && tradeWindow->isWindowVisible()) { if (PlayerInfo::isItemProtected(item->getId())) return; ItemAmountWindow::showWindow(ItemAmountWindow::TradeAdd, tradeWindow, item); } else { PlayerInfo::useEquipItem(item, Sfx_true); } } else { if (isStorageActive()) { ItemAmountWindow::showWindow(ItemAmountWindow::StoreRemove, inventoryWindow, item); } } } } }
void InventoryWindow::mouseClicked(gcn::MouseEvent &event) { Window::mouseClicked(event); const int clicks = event.getClickCount(); if (clicks == 2 && gui) gui->resetClickCount(); const bool mod = (isStorageActive() && inputManager.isActionActive( static_cast<int>(Input::KEY_MOD))); const bool mod2 = (tradeWindow && tradeWindow->isWindowVisible() && inputManager.isActionActive(static_cast<int>(Input::KEY_MOD))); if (!mod && !mod2 && event.getButton() == gcn::MouseEvent::RIGHT) { Item *const item = mItems->getSelectedItem(); if (!item) return; /* Convert relative to the window coordinates to absolute screen * coordinates. */ const int mx = event.getX() + getX(); const int my = event.getY() + getY(); if (viewport) viewport->showPopup(this, mx, my, item, isMainInventory()); } if (!mInventory) return; if (event.getButton() == gcn::MouseEvent::LEFT || event.getButton() == gcn::MouseEvent::RIGHT) { Item *const item = mItems->getSelectedItem(); if (!item) return; if (mod) { if (mInventory->isMainInventory()) { if (event.getButton() == gcn::MouseEvent::RIGHT) { ItemAmountWindow::showWindow(ItemAmountWindow::StoreAdd, inventoryWindow, item); } else { Net::getInventoryHandler()->moveItem2(Inventory::INVENTORY, item->getInvIndex(), item->getQuantity(), Inventory::STORAGE); } } else { if (event.getButton() == gcn::MouseEvent::RIGHT) { ItemAmountWindow::showWindow(ItemAmountWindow::StoreRemove, inventoryWindow, item); } else { Net::getInventoryHandler()->moveItem2(Inventory::STORAGE, item->getInvIndex(), item->getQuantity(), Inventory::INVENTORY); } } } else if (mod2 && mInventory->isMainInventory()) { if (event.getButton() == gcn::MouseEvent::RIGHT) { ItemAmountWindow::showWindow(ItemAmountWindow::TradeAdd, tradeWindow, item); } else { if (tradeWindow) tradeWindow->tradeItem(item, item->getQuantity(), true); } } else if (clicks == 2) { if (mInventory->isMainInventory()) { if (isStorageActive()) { ItemAmountWindow::showWindow(ItemAmountWindow::StoreAdd, inventoryWindow, item); } else if (tradeWindow && tradeWindow->isWindowVisible()) { ItemAmountWindow::showWindow(ItemAmountWindow::TradeAdd, tradeWindow, item); } else { if (item->isEquipment()) { if (item->isEquipped()) Net::getInventoryHandler()->unequipItem(item); else Net::getInventoryHandler()->equipItem(item); } else { Net::getInventoryHandler()->useItem(item); } } } else { if (isStorageActive()) { ItemAmountWindow::showWindow(ItemAmountWindow::StoreRemove, inventoryWindow, item); } } } } }
void InventoryWindow::action(const ActionEvent &event) { const std::string &eventId = event.getId(); if (eventId == "outfit") { inputManager.executeAction(InputAction::WINDOW_OUTFIT); } else if (eventId == "shop") { inputManager.executeAction(InputAction::WINDOW_SHOP); } else if (eventId == "equipment") { inputManager.executeAction(InputAction::WINDOW_EQUIPMENT); } else if (eventId == "cart") { inputManager.executeAction(InputAction::WINDOW_CART); } else if (eventId == "close") { close(); } else if (eventId == "store") { if (!inventoryWindow || !inventoryWindow->isWindowVisible()) return; Item *const item = inventoryWindow->getSelectedItem(); if (!item) return; if (storageWindow) { ItemAmountWindow::showWindow(ItemAmountWindow::StoreAdd, this, item); } #ifdef EATHENA_SUPPORT else if (cartWindow && cartWindow->isWindowVisible()) { ItemAmountWindow::showWindow(ItemAmountWindow::CartAdd, this, item); } #endif } else if (eventId == "sort") { mItems->setSortType(mSortDropDown->getSelected()); storeSortOrder(); return; } else if (eventId == "namefilter") { mItems->setName(mNameFilter->getText()); mItems->updateMatrix(); } else if (!eventId.find("tag_")) { std::string tagName = event.getId().substr(4); mItems->setFilter(ItemDB::getTagId(tagName)); return; } Item *const item = mItems->getSelectedItem(); if (!item) return; if (eventId == "use") { PlayerInfo::useEquipItem(item, Sfx_true); } if (eventId == "equip") { PlayerInfo::useEquipItem2(item, Sfx_true); } else if (eventId == "drop") { if (isStorageActive()) { inventoryHandler->moveItem2(InventoryType::Inventory, item->getInvIndex(), item->getQuantity(), InventoryType::Storage); } #ifdef EATHENA_SUPPORT else if (cartWindow && cartWindow->isWindowVisible()) { inventoryHandler->moveItem2(InventoryType::Inventory, item->getInvIndex(), item->getQuantity(), InventoryType::Cart); } else #endif { if (PlayerInfo::isItemProtected(item->getId())) return; if (inputManager.isActionActive(InputAction::STOP_ATTACK)) { PlayerInfo::dropItem(item, item->getQuantity(), Sfx_true); } else { ItemAmountWindow::showWindow(ItemAmountWindow::ItemDrop, this, item); } } } else if (eventId == "split") { ItemAmountWindow::showWindow(ItemAmountWindow::ItemSplit, this, item, (item->getQuantity() - 1)); } else if (eventId == "retrieve") { if (storageWindow) { ItemAmountWindow::showWindow(ItemAmountWindow::StoreRemove, this, item); } #ifdef EATHENA_SUPPORT else if (cartWindow && cartWindow->isWindowVisible()) { ItemAmountWindow::showWindow(ItemAmountWindow::CartRemove, this, item); } #endif } }
void InventoryWindow::action(const gcn::ActionEvent &event) { const std::string &eventId = event.getId(); if (eventId == "outfit") { if (outfitWindow) { outfitWindow->setVisible(!outfitWindow->isWindowVisible()); if (outfitWindow->isWindowVisible()) outfitWindow->requestMoveToTop(); } } else if (eventId == "shop") { if (shopWindow) { shopWindow->setVisible(!shopWindow->isWindowVisible()); if (shopWindow->isWindowVisible()) shopWindow->requestMoveToTop(); } } else if (eventId == "equipment") { if (equipmentWindow) { equipmentWindow->setVisible(!equipmentWindow->isWindowVisible()); if (equipmentWindow->isWindowVisible()) equipmentWindow->requestMoveToTop(); } } else if (eventId == "close") { close(); } else if (eventId == "store") { if (!inventoryWindow || !inventoryWindow->isWindowVisible()) return; Item *const item = inventoryWindow->getSelectedItem(); if (!item) return; ItemAmountWindow::showWindow(ItemAmountWindow::StoreAdd, this, item); } else if (eventId == "sort") { mItems->setSortType(mSortDropDown->getSelected()); return; } else if (eventId == "namefilter") { mItems->setName(mNameFilter->getText()); mItems->updateMatrix(); } else if (!eventId.find("tag_")) { std::string tagName = event.getId().substr(4); mItems->setFilter(ItemDB::getTagId(tagName)); return; } Item *const item = mItems->getSelectedItem(); if (!item) return; if (eventId == "use") { if (item->isEquipment()) { if (item->isEquipped()) Net::getInventoryHandler()->unequipItem(item); else Net::getInventoryHandler()->equipItem(item); } else { Net::getInventoryHandler()->useItem(item); } } if (eventId == "equip") { if (!item->isEquipment()) { if (item->isEquipped()) Net::getInventoryHandler()->unequipItem(item); else Net::getInventoryHandler()->equipItem(item); } else { Net::getInventoryHandler()->useItem(item); } } else if (eventId == "drop") { if (isStorageActive()) { Net::getInventoryHandler()->moveItem2(Inventory::INVENTORY, item->getInvIndex(), item->getQuantity(), Inventory::STORAGE); } else { if (inputManager.isActionActive(static_cast<int>(Input::KEY_MOD))) { Net::getInventoryHandler()->dropItem( item, item->getQuantity()); } else { ItemAmountWindow::showWindow(ItemAmountWindow::ItemDrop, this, item); } } } else if (eventId == "split") { ItemAmountWindow::showWindow(ItemAmountWindow::ItemSplit, this, item, (item->getQuantity() - 1)); } else if (eventId == "retrieve") { ItemAmountWindow::showWindow(ItemAmountWindow::StoreRemove, this, item); } }