diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/widgets/selldialog.cpp | 13 | ||||
-rw-r--r-- | src/gui/widgets/selldialog.h | 11 | ||||
-rw-r--r-- | src/gui/widgets/shoplistbox.cpp | 7 | ||||
-rw-r--r-- | src/gui/windows/shopwindow.cpp | 18 | ||||
-rw-r--r-- | src/shopitem.cpp | 3 | ||||
-rw-r--r-- | src/shopitem.h | 7 |
6 files changed, 40 insertions, 19 deletions
diff --git a/src/gui/widgets/selldialog.cpp b/src/gui/widgets/selldialog.cpp index 3ad8e5e7e..76cea21f2 100644 --- a/src/gui/widgets/selldialog.cpp +++ b/src/gui/widgets/selldialog.cpp @@ -218,18 +218,19 @@ void SellDialog::addItem(const Item *const item, const int price) mShopItemList->adjustSize(); } -void SellDialog::addItem(const int id, - const int type, - const ItemColor color, - const int amount, - const int price) +ShopItem *SellDialog::addItem(const int id, + const int type, + const ItemColor color, + const int amount, + const int price) { - mShopItems->addItem(id, + ShopItem *const item = mShopItems->addItem(id, type, color, amount, price); mShopItemList->adjustSize(); + return item; } diff --git a/src/gui/widgets/selldialog.h b/src/gui/widgets/selldialog.h index 92008df38..e94619f1f 100644 --- a/src/gui/widgets/selldialog.h +++ b/src/gui/widgets/selldialog.h @@ -34,6 +34,7 @@ class Button; class Item; class Label; class ScrollArea; +class ShopItem; class ShopItems; class ShopListBox; class Slider; @@ -93,11 +94,11 @@ class SellDialog notfinal : public Window, */ void setVisible(Visible visible) override final; - void addItem(const int id, - const int type, - const ItemColor color, - const int amount, - const int price); + ShopItem *addItem(const int id, + const int type, + const ItemColor color, + const int amount, + const int price); /** * Returns true if any instances exist. diff --git a/src/gui/widgets/shoplistbox.cpp b/src/gui/widgets/shoplistbox.cpp index c8f1bd889..6cdf58d2e 100644 --- a/src/gui/widgets/shoplistbox.cpp +++ b/src/gui/widgets/shoplistbox.cpp @@ -106,9 +106,10 @@ void ShopListBox::draw(Graphics *graphics) Color* backgroundColor = &mBackgroundColor; ShopItem *const item = mShopItems->at(i); - if (item && ((mShopItems && mPlayerMoney < item->getPrice() - && mPriceCheck) - || (mProtectItems && PlayerInfo::isItemProtected(item->getId())))) + if (item && + (item->getDisabled() || + (mShopItems && mPlayerMoney < item->getPrice() && mPriceCheck) || + (mProtectItems && PlayerInfo::isItemProtected(item->getId())))) { if (i != mSelected) { diff --git a/src/gui/windows/shopwindow.cpp b/src/gui/windows/shopwindow.cpp index 645ae5314..67e361715 100644 --- a/src/gui/windows/shopwindow.cpp +++ b/src/gui/windows/shopwindow.cpp @@ -849,15 +849,25 @@ void ShopWindow::showList(const std::string &nick, std::string data) { // +++ need support for colors const Item *const item = inv->findItem(id, ItemColor_zero); + bool enabled(true); + if (item) { if (item->getQuantity() < amount) amount = item->getQuantity(); - if (amount > 0) - sellDialog->addItem(id, 0, ItemColor_one, amount, price); - else - sellDialog->addItem(id, 0, ItemColor_one, -1, price); } + else + { + amount = 0; + } + ShopItem *const shopItem = sellDialog->addItem(id, + 0, + ItemColor_one, + amount, + price); + + if (shopItem && amount <= 0) + shopItem->setDisabled(true); } } if (buyDialog) diff --git a/src/shopitem.cpp b/src/shopitem.cpp index eb7499522..db60e35f8 100644 --- a/src/shopitem.cpp +++ b/src/shopitem.cpp @@ -49,7 +49,8 @@ ShopItem::ShopItem(const int inventoryIndex, mPrice(price), mUsedQuantity(0), mShowQuantity(true), - mVisible(true) + mVisible(true), + mDisabled(false) { updateDisplayName(quantity); setInvIndex(inventoryIndex); diff --git a/src/shopitem.h b/src/shopitem.h index bfe7fe39a..36ccf3c65 100644 --- a/src/shopitem.h +++ b/src/shopitem.h @@ -148,6 +148,12 @@ class ShopItem final : public Item int getUsedQuantity() const A_WARN_UNUSED { return mUsedQuantity; } + void setDisabled(const bool b) + { mDisabled = b; } + + bool getDisabled() const A_WARN_UNUSED + { return mDisabled; } + protected: void updateDisplayName(const int quantity); @@ -166,6 +172,7 @@ class ShopItem final : public Item int mUsedQuantity; bool mShowQuantity; bool mVisible; + bool mDisabled; }; #endif // SHOPITEM_H |