summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/inventorywindow.cpp13
-rw-r--r--src/gui/popupmenu.cpp155
-rw-r--r--src/gui/popupmenu.h2
-rw-r--r--src/gui/selldialog.cpp6
-rw-r--r--src/gui/tradewindow.cpp5
-rw-r--r--src/gui/widgets/shoplistbox.cpp5
6 files changed, 133 insertions, 53 deletions
diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp
index f659b8693..553313289 100644
--- a/src/gui/inventorywindow.cpp
+++ b/src/gui/inventorywindow.cpp
@@ -360,6 +360,8 @@ void InventoryWindow::action(const gcn::ActionEvent &event)
}
else
{
+ if (PlayerInfo::isItemProtected(item->getId()))
+ return;
Net::getInventoryHandler()->useItem(item);
}
}
@@ -374,11 +376,16 @@ void InventoryWindow::action(const gcn::ActionEvent &event)
}
else
{
+ if (PlayerInfo::isItemProtected(item->getId()))
+ return;
Net::getInventoryHandler()->useItem(item);
}
}
else if (eventId == "drop")
{
+ if (PlayerInfo::isItemProtected(item->getId()))
+ return;
+
if (isStorageActive())
{
Net::getInventoryHandler()->moveItem2(Inventory::INVENTORY,
@@ -503,6 +510,8 @@ void InventoryWindow::mouseClicked(gcn::MouseEvent &event)
}
else if (mod2 && mInventory->isMainInventory())
{
+ if (PlayerInfo::isItemProtected(item->getId()))
+ return;
if (event.getButton() == gcn::MouseEvent::RIGHT)
{
ItemAmountWindow::showWindow(ItemAmountWindow::TradeAdd,
@@ -525,6 +534,8 @@ void InventoryWindow::mouseClicked(gcn::MouseEvent &event)
}
else if (tradeWindow && tradeWindow->isWindowVisible())
{
+ if (PlayerInfo::isItemProtected(item->getId()))
+ return;
ItemAmountWindow::showWindow(ItemAmountWindow::TradeAdd,
tradeWindow, item);
}
@@ -539,6 +550,8 @@ void InventoryWindow::mouseClicked(gcn::MouseEvent &event)
}
else
{
+ if (PlayerInfo::isItemProtected(item->getId()))
+ return;
Net::getInventoryHandler()->useItem(item);
}
}
diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp
index b6272a4e4..ef71160d7 100644
--- a/src/gui/popupmenu.cpp
+++ b/src/gui/popupmenu.cpp
@@ -448,6 +448,7 @@ void PopupMenu::showPopup(const int x, const int y,
// TRANSLATORS: popup menu item
mBrowserBox->addRow("pickup", _("Pick up"));
}
+ addProtection();
// TRANSLATORS: popup menu item
mBrowserBox->addRow("chat", _("Add to chat"));
mBrowserBox->addRow("##3---");
@@ -962,7 +963,8 @@ void PopupMenu::handleLink(const std::string &link,
}
else
{
- Net::getInventoryHandler()->useItem(item);
+ if (!PlayerInfo::isItemProtected(item->getId()))
+ Net::getInventoryHandler()->useItem(item);
}
}
}
@@ -1066,12 +1068,16 @@ void PopupMenu::handleLink(const std::string &link,
}
else if (link == "drop" && mItem)
{
- ItemAmountWindow::showWindow(ItemAmountWindow::ItemDrop,
- inventoryWindow, mItem);
+ if (!PlayerInfo::isItemProtected(mItem->getId()))
+ {
+ ItemAmountWindow::showWindow(ItemAmountWindow::ItemDrop,
+ inventoryWindow, mItem);
+ }
}
else if (link == "drop all" && mItem)
{
- Net::getInventoryHandler()->dropItem(mItem, mItem->getQuantity());
+ if (!PlayerInfo::isItemProtected(mItem->getId()))
+ Net::getInventoryHandler()->dropItem(mItem, mItem->getQuantity());
}
else if (link == "store" && mItem)
{
@@ -1107,12 +1113,15 @@ void PopupMenu::handleLink(const std::string &link,
}
else if (link == "addtrade" && mItem)
{
- ItemAmountWindow::showWindow(ItemAmountWindow::TradeAdd,
- tradeWindow, mItem);
+ if (!PlayerInfo::isItemProtected(mItem->getId()))
+ {
+ ItemAmountWindow::showWindow(ItemAmountWindow::TradeAdd,
+ tradeWindow, mItem);
+ }
}
else if (link == "addtrade 10" && mItem)
{
- if (tradeWindow)
+ if (tradeWindow && !PlayerInfo::isItemProtected(mItem->getId()))
{
int cnt = 10;
if (cnt > mItem->getQuantity())
@@ -1122,17 +1131,17 @@ void PopupMenu::handleLink(const std::string &link,
}
else if (link == "addtrade half" && mItem)
{
- if (tradeWindow)
+ if (tradeWindow && !PlayerInfo::isItemProtected(mItem->getId()))
tradeWindow->tradeItem(mItem, mItem->getQuantity() / 2, true);
}
else if (link == "addtrade all-1" && mItem)
{
- if (tradeWindow)
+ if (tradeWindow && !PlayerInfo::isItemProtected(mItem->getId()))
tradeWindow->tradeItem(mItem, mItem->getQuantity() - 1, true);
}
else if (link == "addtrade all" && mItem)
{
- if (tradeWindow)
+ if (tradeWindow && !PlayerInfo::isItemProtected(mItem->getId()))
tradeWindow->tradeItem(mItem, mItem->getQuantity(), true);
}
else if (link == "retrieve" && mItem)
@@ -1167,6 +1176,14 @@ void PopupMenu::handleLink(const std::string &link,
mItem->getInvIndex(), mItem->getQuantity(),
Inventory::INVENTORY);
}
+ else if (link == "protect item" && mItemId)
+ {
+ PlayerInfo::protectItem(mItemId);
+ }
+ else if (link == "unprotect item" && mItemId)
+ {
+ PlayerInfo::unprotectItem(mItemId);
+ }
else if (link == "party" && being &&
being->getType() == ActorSprite::PLAYER)
{
@@ -1769,10 +1786,11 @@ void PopupMenu::showPopup(Window *const parent, const int x, const int y,
mBrowserBox->clearRows();
const int cnt = item->getQuantity();
+ const bool isProtected = PlayerInfo::isItemProtected(mItemId);
if (isInventory)
{
- if (tradeWindow && tradeWindow->isWindowVisible())
+ if (tradeWindow && tradeWindow->isWindowVisible() && !isProtected)
{
// TRANSLATORS: popup menu item
mBrowserBox->addRow("addtrade", _("Add to trade"));
@@ -1828,21 +1846,27 @@ void PopupMenu::showPopup(Window *const parent, const int x, const int y,
}
else
{
- // TRANSLATORS: popup menu item
- mBrowserBox->addRow("use", _("Use"));
+ if (!isProtected)
+ {
+ // TRANSLATORS: popup menu item
+ mBrowserBox->addRow("use", _("Use"));
+ }
}
- if (cnt > 1)
+ if (!isProtected)
{
- // 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 (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))
@@ -1871,6 +1895,7 @@ void PopupMenu::showPopup(Window *const parent, const int x, const int y,
mBrowserBox->addRow("retrieve all", _("Retrieve all"));
}
}
+ addProtection();
if (config.getBoolValue("enablePickupFilter"))
{
mNick = item->getName();
@@ -1907,8 +1932,12 @@ void PopupMenu::showItemPopup(const int x, const int y, const int itemId,
mY = y;
mBrowserBox->clearRows();
- // TRANSLATORS: popup menu item
- mBrowserBox->addRow("use", _("Use"));
+ if (!PlayerInfo::isItemProtected(mItemId))
+ {
+ // TRANSLATORS: popup menu item
+ mBrowserBox->addRow("use", _("Use"));
+ }
+ addProtection();
mBrowserBox->addRow("##3---");
// TRANSLATORS: popup menu item
mBrowserBox->addRow("cancel", _("Cancel"));
@@ -1937,6 +1966,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())
@@ -1952,21 +1982,27 @@ void PopupMenu::showItemPopup(const int x, const int y, Item *const item)
}
else
{
+ if (!isProtected)
+ {
// TRANSLATORS: popup menu item
- mBrowserBox->addRow("use", _("Use"));
+ mBrowserBox->addRow("use", _("Use"));
+ }
}
- if (item->getQuantity() > 1)
+ if (!isProtected)
{
- // 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 (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))
@@ -1991,6 +2027,7 @@ void PopupMenu::showItemPopup(const int x, const int y, Item *const item)
addPickupFilter(mNick);
}
}
+ addProtection();
mBrowserBox->addRow("##3---");
// TRANSLATORS: popup menu item
mBrowserBox->addRow("cancel", _("Cancel"));
@@ -2010,6 +2047,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())
{
@@ -2026,21 +2064,27 @@ void PopupMenu::showDropPopup(const int x, const int y, Item *const item)
}
else
{
- // TRANSLATORS: popup menu item
- mBrowserBox->addRow("use", _("Use"));
+ if (!isProtected)
+ {
+ // TRANSLATORS: popup menu item
+ mBrowserBox->addRow("use", _("Use"));
+ }
}
- if (item->getQuantity() > 1)
- {
- // TRANSLATORS: popup menu item
- mBrowserBox->addRow("drop", _("Drop..."));
- // TRANSLATORS: popup menu item
- mBrowserBox->addRow("drop all", _("Drop all"));
- }
- else
+ if (!isProtected)
{
- // TRANSLATORS: popup menu item
- mBrowserBox->addRow("drop", _("Drop"));
+ 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))
@@ -2054,6 +2098,7 @@ void PopupMenu::showDropPopup(const int x, const int y, Item *const item)
// TRANSLATORS: popup menu item
mBrowserBox->addRow("store", _("Store"));
}
+ addProtection();
// TRANSLATORS: popup menu item
mBrowserBox->addRow("chat", _("Add to chat"));
if (config.getBoolValue("enablePickupFilter"))
@@ -2635,6 +2680,20 @@ void PopupMenu::clear()
mTextField = nullptr;
}
+void PopupMenu::addProtection()
+{
+ if (PlayerInfo::isItemProtected(mItemId))
+ {
+ // TRANSLATORS: popup menu item
+ mBrowserBox->addRow("unprotect item", _("Unprotect item"));
+ }
+ else
+ {
+ // TRANSLATORS: popup menu item
+ mBrowserBox->addRow("protect item", _("Protect item"));
+ }
+}
+
RenameListener::RenameListener() :
gcn::ActionListener(),
mMapItem(nullptr),
diff --git a/src/gui/popupmenu.h b/src/gui/popupmenu.h
index 3eac9355a..3b615afec 100644
--- a/src/gui/popupmenu.h
+++ b/src/gui/popupmenu.h
@@ -203,6 +203,8 @@ class PopupMenu final : public Popup, public LinkHandler
void addPickupFilter(const std::string &name);
+ void addProtection();
+
BrowserBox *mBrowserBox;
ScrollArea *mScrollArea;
diff --git a/src/gui/selldialog.cpp b/src/gui/selldialog.cpp
index 8006355bc..c61dec541 100644
--- a/src/gui/selldialog.cpp
+++ b/src/gui/selldialog.cpp
@@ -22,6 +22,7 @@
#include "gui/selldialog.h"
+#include "playerinfo.h"
#include "shopitem.h"
#include "units.h"
@@ -228,9 +229,11 @@ void SellDialog::action(const gcn::ActionEvent &event)
{
if (mNpcId != -1)
{
+ ShopItem *const item = mShopItems->at(selectedItem);
+ if (PlayerInfo::isItemProtected(item->getId()))
+ return;
if (eventId == "presell")
{
- const ShopItem *const item = mShopItems->at(selectedItem);
const ItemInfo &info = ItemDB::get(item->getId());
if (info.isProtected())
{
@@ -245,7 +248,6 @@ void SellDialog::action(const gcn::ActionEvent &event)
}
}
// Attempt sell
- ShopItem *const item = mShopItems->at(selectedItem);
mPlayerMoney +=
mAmountItems * mShopItems->at(selectedItem)->getPrice();
mMaxItems -= mAmountItems;
diff --git a/src/gui/tradewindow.cpp b/src/gui/tradewindow.cpp
index 3c1ce60bb..a71b26f60 100644
--- a/src/gui/tradewindow.cpp
+++ b/src/gui/tradewindow.cpp
@@ -458,8 +458,11 @@ void TradeWindow::initTrade(const std::string &nick)
bool TradeWindow::checkItem(const Item *const item) const
{
+ const int itemId = item->getId();
+ if (PlayerInfo::isItemProtected(itemId))
+ return false;
const Item *const tItem = mMyInventory->findItem(
- item->getId(), item->getColor());
+ itemId, item->getColor());
if (tItem && (tItem->getQuantity() > 1
|| item->getQuantity() > 1))
diff --git a/src/gui/widgets/shoplistbox.cpp b/src/gui/widgets/shoplistbox.cpp
index 615b93010..827bb6755 100644
--- a/src/gui/widgets/shoplistbox.cpp
+++ b/src/gui/widgets/shoplistbox.cpp
@@ -24,6 +24,7 @@
#include "client.h"
#include "configuration.h"
+#include "playerinfo.h"
#include "shopitem.h"
#include "gui/itempopup.h"
@@ -107,8 +108,8 @@ void ShopListBox::draw(gcn::Graphics *gcnGraphics)
gcn::Color* backgroundColor = &mBackgroundColor;
ShopItem *const item = mShopItems->at(i);
- if (mShopItems && item &&
- mPlayerMoney < item->getPrice() && mPriceCheck)
+ if ((mShopItems && item && mPlayerMoney < item->getPrice()
+ && mPriceCheck) || PlayerInfo::isItemProtected(item->getId()))
{
if (i != mSelected)
{