diff options
author | Jared Adams <jaxad0127@gmail.com> | 2009-05-06 16:34:06 -0600 |
---|---|---|
committer | Jared Adams <jaxad0127@gmail.com> | 2009-05-06 16:36:11 -0600 |
commit | 574ef501d32c7735d2aed022f2a3761d053bbe7c (patch) | |
tree | ca5dd0709d6a0d1989af3fab6b1f85c6726a2fb0 /src/gui/itemamount.cpp | |
parent | 3603521356ad1646d456a1681ff9f8a7c88ab458 (diff) | |
download | mana-574ef501d32c7735d2aed022f2a3761d053bbe7c.tar.gz mana-574ef501d32c7735d2aed022f2a3761d053bbe7c.tar.bz2 mana-574ef501d32c7735d2aed022f2a3761d053bbe7c.tar.xz mana-574ef501d32c7735d2aed022f2a3761d053bbe7c.zip |
Clean up the bypass code for the ItemAmountWindow
Diffstat (limited to 'src/gui/itemamount.cpp')
-rw-r--r-- | src/gui/itemamount.cpp | 70 |
1 files changed, 41 insertions, 29 deletions
diff --git a/src/gui/itemamount.cpp b/src/gui/itemamount.cpp index 1bbd6fdd..190290e3 100644 --- a/src/gui/itemamount.cpp +++ b/src/gui/itemamount.cpp @@ -35,6 +35,30 @@ #include "utils/gettext.h" #include "utils/stringutils.h" +void ItemAmountWindow::finish(Item *item, int amount, Usage usage) +{ + switch (usage) + { + case TradeAdd: + tradeWindow->tradeItem(item, amount); + break; + case ItemDrop: + player_node->dropItem(item, amount); + break; + case ItemSplit: + player_node->splitItem(item, amount); + break; + case StoreAdd: + storageWindow->addStore(item, amount); + break; + case StoreRemove: + storageWindow->removeStore(item, amount); + break; + default: + break; + } +} + ItemAmountWindow::ItemAmountWindow(Usage usage, Window *parent, Item *item, int maxRange): Window("", true, parent), @@ -68,14 +92,6 @@ ItemAmountWindow::ItemAmountWindow(Usage usage, Window *parent, Item *item, minusButton->adjustSize(); minusButton->setWidth(plusButton->getWidth()); - // If only one item is available, then the window isn't needed, so move on - // To prevent problems, we still build the gui elements - if (mMax <= 1) - { - action(gcn::ActionEvent(this, "All")); - return; - } - // Set positions ContainerPlacer place; place = getPlacer(0, 0); @@ -145,27 +161,7 @@ void ItemAmountWindow::action(const gcn::ActionEvent &event) if (event.getId() == "All") amount = mMax; - switch (mUsage) - { - case TradeAdd: - tradeWindow->tradeItem(mItem, amount); - break; - case ItemDrop: - player_node->dropItem(mItem, amount); - break; - case ItemSplit: - player_node->splitItem(mItem, amount); - break; - case StoreAdd: - storageWindow->addStore(mItem, amount); - break; - case StoreRemove: - storageWindow->removeStore(mItem, amount); - break; - default: - return; - break; - } + finish(mItem, amount, mUsage); scheduleDelete(); return; @@ -179,3 +175,19 @@ void ItemAmountWindow::close() { scheduleDelete(); } + +void ItemAmountWindow::showWindow(Usage usage, Window *parent, Item *item, + int maxRange) +{ + if (!maxRange) + maxRange = item->getQuantity(); + + if (maxRange <= 1) + { + finish(item, maxRange, usage); + } + else + { + new ItemAmountWindow(usage, parent, item, maxRange); + } +} |