From 593c59c2a45831082a47076e0f94d533ea5f09c8 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sun, 23 Jun 2013 18:13:36 +0300 Subject: remove some duplicates in popupmenu. --- src/gui/popupmenu.cpp | 182 ++++++++++++++------------------------------------ src/gui/popupmenu.h | 2 + 2 files changed, 52 insertions(+), 132 deletions(-) diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp index ef71160d7..0cd6e0511 100644 --- a/src/gui/popupmenu.cpp +++ b/src/gui/popupmenu.cpp @@ -1831,49 +1831,7 @@ void PopupMenu::showPopup(Window *const parent, const int x, const int y, mBrowserBox->addRow("##3---"); } - if (item->isEquipment()) - { - if (item->isEquipped()) - { - // TRANSLATORS: popup menu item - mBrowserBox->addRow("use", _("Unequip")); - } - else - { - // TRANSLATORS: popup menu item - mBrowserBox->addRow("use", _("Equip")); - } - } - else - { - if (!isProtected) - { - // TRANSLATORS: popup menu item - mBrowserBox->addRow("use", _("Use")); - } - } - - if (!isProtected) - { - if (cnt > 1) - { - // TRANSLATORS: popup menu item - mBrowserBox->addRow("drop", _("Drop...")); - // TRANSLATORS: popup menu item - mBrowserBox->addRow("drop all", _("Drop all")); - } - else - { - // TRANSLATORS: popup menu item - mBrowserBox->addRow("drop", _("Drop")); - } - } - - if (Net::getInventoryHandler()->canSplit(item)) - { - // TRANSLATORS: popup menu item - mBrowserBox->addRow("split", _("Split")); - } + addUseDrop(item, isProtected); } // Assume in storage for now else @@ -1967,50 +1925,7 @@ void PopupMenu::showItemPopup(const int x, const int y, Item *const item) if (item) { const bool isProtected = PlayerInfo::isItemProtected(mItemId); - if (item->isEquipment()) - { - if (item->isEquipped()) - { - // TRANSLATORS: popup menu item - mBrowserBox->addRow("use", _("Unequip")); - } - else - { - // TRANSLATORS: popup menu item - mBrowserBox->addRow("use", _("Equip")); - } - } - else - { - if (!isProtected) - { - // TRANSLATORS: popup menu item - mBrowserBox->addRow("use", _("Use")); - } - } - - if (!isProtected) - { - if (item->getQuantity() > 1) - { - // TRANSLATORS: popup menu item - mBrowserBox->addRow("drop", _("Drop...")); - // TRANSLATORS: popup menu item - mBrowserBox->addRow("drop all", _("Drop all")); - } - else - { - // TRANSLATORS: popup menu item - mBrowserBox->addRow("drop", _("Drop")); - } - } - - if (Net::getInventoryHandler()->canSplit(item)) - { - // TRANSLATORS: popup menu item - mBrowserBox->addRow("split", _("Split")); - } - + addUseDrop(item, isProtected); if (InventoryWindow::isStorageActive()) { // TRANSLATORS: popup menu item @@ -2048,51 +1963,7 @@ void PopupMenu::showDropPopup(const int x, const int y, Item *const item) mItemId = item->getId(); mItemColor = item->getColor(); const bool isProtected = PlayerInfo::isItemProtected(mItemId); - - if (item->isEquipment()) - { - if (item->isEquipped()) - { - // TRANSLATORS: popup menu item - mBrowserBox->addRow("use", _("Unequip")); - } - else - { - // TRANSLATORS: popup menu item - mBrowserBox->addRow("use", _("Equip")); - } - } - else - { - if (!isProtected) - { - // TRANSLATORS: popup menu item - mBrowserBox->addRow("use", _("Use")); - } - } - - if (!isProtected) - { - if (item->getQuantity() > 1) - { - // TRANSLATORS: popup menu item - mBrowserBox->addRow("drop", _("Drop...")); - // TRANSLATORS: popup menu item - mBrowserBox->addRow("drop all", _("Drop all")); - } - else - { - // TRANSLATORS: popup menu item - mBrowserBox->addRow("drop", _("Drop")); - } - } - - if (Net::getInventoryHandler()->canSplit(item)) - { - // TRANSLATORS: popup menu item - mBrowserBox->addRow("split", _("Split")); - } - + addUseDrop(item, isProtected); if (InventoryWindow::isStorageActive()) { // TRANSLATORS: popup menu item @@ -2694,6 +2565,53 @@ void PopupMenu::addProtection() } } +void PopupMenu::addUseDrop(const Item *const item, const bool isProtected) +{ + if (item->isEquipment()) + { + if (item->isEquipped()) + { + // TRANSLATORS: popup menu item + mBrowserBox->addRow("use", _("Unequip")); + } + else + { + // TRANSLATORS: popup menu item + mBrowserBox->addRow("use", _("Equip")); + } + } + else + { + if (!isProtected) + { + // TRANSLATORS: popup menu item + mBrowserBox->addRow("use", _("Use")); + } + } + + if (!isProtected) + { + if (item->getQuantity() > 1) + { + // TRANSLATORS: popup menu item + mBrowserBox->addRow("drop", _("Drop...")); + // TRANSLATORS: popup menu item + mBrowserBox->addRow("drop all", _("Drop all")); + } + else + { + // TRANSLATORS: popup menu item + mBrowserBox->addRow("drop", _("Drop")); + } + } + + if (Net::getInventoryHandler()->canSplit(item)) + { + // TRANSLATORS: popup menu item + mBrowserBox->addRow("split", _("Split")); + } +} + RenameListener::RenameListener() : gcn::ActionListener(), mMapItem(nullptr), diff --git a/src/gui/popupmenu.h b/src/gui/popupmenu.h index 3b615afec..04104fd18 100644 --- a/src/gui/popupmenu.h +++ b/src/gui/popupmenu.h @@ -205,6 +205,8 @@ class PopupMenu final : public Popup, public LinkHandler void addProtection(); + void addUseDrop(const Item *const item, const bool isProtected); + BrowserBox *mBrowserBox; ScrollArea *mScrollArea; -- cgit v1.2.3-70-g09d2