diff options
author | Yohann Ferreira <bertram@cegetel.net> | 2005-08-22 21:57:34 +0000 |
---|---|---|
committer | Yohann Ferreira <bertram@cegetel.net> | 2005-08-22 21:57:34 +0000 |
commit | 097ef85eed1e7ea957f3204f4601a2ae63ba20f7 (patch) | |
tree | 09df7e7f087968aed4b2b7dc94d8a03ff3114e18 /src | |
parent | 59618657040cac0ccf2be7c39bbdfc0c15f6b40c (diff) | |
download | mana-097ef85eed1e7ea957f3204f4601a2ae63ba20f7.tar.gz mana-097ef85eed1e7ea957f3204f4601a2ae63ba20f7.tar.bz2 mana-097ef85eed1e7ea957f3204f4601a2ae63ba20f7.tar.xz mana-097ef85eed1e7ea957f3204f4601a2ae63ba20f7.zip |
Converted the buy & sell diaogs asserts into ifs to avoid game crashing, and made additional checks on buy sell events to have buttons enabled only when they're useful.
Diffstat (limited to 'src')
-rw-r--r-- | src/game.cpp | 2 | ||||
-rw-r--r-- | src/gui/buy.cpp | 104 | ||||
-rw-r--r-- | src/gui/sell.cpp | 5 |
3 files changed, 76 insertions, 35 deletions
diff --git a/src/game.cpp b/src/game.cpp index a0f2a518..05c5f13b 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -1574,7 +1574,9 @@ void do_parse() // Buy/Sell dialog case 0x00c4: buyDialog->setVisible(false); + buyDialog->reset(); sellDialog->setVisible(false); + sellDialog->reset(); buySellDialog->setVisible(true); current_npc = RFIFOL(2); break; diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp index 9d7cd7b2..fe8a525b 100644 --- a/src/gui/buy.cpp +++ b/src/gui/buy.cpp @@ -145,6 +145,11 @@ void BuyDialog::reset() { shopInventory.clear(); m_money = 0; + + // Reset Previous Selected Items to prevent failing asserts + itemList->setSelected(-1); + increaseButton->setEnabled(false); + decreaseButton->setEnabled(false); } void BuyDialog::addItem(short id, int price) @@ -181,7 +186,13 @@ void BuyDialog::action(const std::string& eventId) moneyLabel->setCaption(oss.str()); moneyLabel->adjustSize(); decreaseButton->setEnabled(false); + m_maxItems = m_money / shopInventory[selectedItem].price; + if (m_maxItems == 0) // The player cannot afford such an item + { + increaseButton->setEnabled(false); + buyButton->setEnabled(false); + } } else { @@ -229,8 +240,15 @@ void BuyDialog::action(const std::string& eventId) } else if (eventId == "+" && selectedItem > -1) { - assert(m_amountItems < m_maxItems); - m_amountItems++; + if (m_amountItems < m_maxItems) + { + m_amountItems++; + } + else + { + m_amountItems = m_maxItems; + } + slider->setValue(double(m_amountItems)/double(m_maxItems)); decreaseButton->setEnabled(true); @@ -239,6 +257,11 @@ void BuyDialog::action(const std::string& eventId) { increaseButton->setEnabled(false); } + if (m_maxItems == 0) // The player cannot afford such an item + { + decreaseButton->setEnabled(false); + buyButton->setEnabled(false); + } oss << m_amountItems; quantityLabel->setCaption(oss.str()); @@ -251,8 +274,14 @@ void BuyDialog::action(const std::string& eventId) } else if (eventId == "-" && selectedItem > -1) { - assert(m_amountItems > 0); - m_amountItems--; + if (m_amountItems > 0) + { + m_amountItems--; + } + else + { + m_amountItems = 0; + } slider->setValue(double(m_amountItems)/double(m_maxItems)); @@ -274,40 +303,45 @@ void BuyDialog::action(const std::string& eventId) } else if (eventId == "buy" && selectedItem > -1) { - // Attempt purchase - assert(m_amountItems > 0 && m_amountItems <= m_maxItems); - assert(selectedItem >= 0 && selectedItem < int(shopInventory.size())); - - WFIFOW(0) = net_w_value(0x00c8); - WFIFOW(2) = net_w_value(8); - WFIFOW(4) = net_w_value(m_amountItems); - WFIFOW(6) = net_w_value(shopInventory[selectedItem].id); - WFIFOSET(8); - - // update money ! - m_money -= m_amountItems * shopInventory[selectedItem].price; - - if (m_amountItems == m_maxItems) + // if purchase acceptable + if (m_amountItems > 0 && // Number of Items asked > 0 + m_amountItems <= m_maxItems && // Max of Items not overset + selectedItem >= 0 && // There is a selection > 0 + selectedItem < int(shopInventory.size()) ) // There a selection not too far in the list. { - m_maxItems = 0; - slider->setEnabled(false); - increaseButton->setEnabled(false); - } - else - { - m_maxItems = m_money / shopInventory[selectedItem].price; - } - - decreaseButton->setEnabled(false); - buyButton->setEnabled(false); - m_amountItems = 0; - slider->setValue(0); - quantityLabel->setCaption("O"); - quantityLabel->adjustSize(); + WFIFOW(0) = net_w_value(0x00c8); + WFIFOW(2) = net_w_value(8); + WFIFOW(4) = net_w_value(m_amountItems); + WFIFOW(6) = net_w_value(shopInventory[selectedItem].id); + WFIFOSET(8); + + // update money ! + m_money -= m_amountItems * shopInventory[selectedItem].price; + + if (m_amountItems == m_maxItems) + { + m_maxItems = 0; + slider->setEnabled(false); + increaseButton->setEnabled(false); + } + else + { + m_maxItems = m_money / shopInventory[selectedItem].price; + } + + decreaseButton->setEnabled(false); + buyButton->setEnabled(false); + + m_amountItems = 0; + slider->setValue(0); + quantityLabel->setCaption("O"); + quantityLabel->adjustSize(); + + moneyLabel->setCaption("price : 0 G"); + moneyLabel->adjustSize(); - moneyLabel->setCaption("price : 0 G"); - moneyLabel->adjustSize(); + } // End if purchase acceptable } else if (eventId == "quit") { diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp index 6bac0bb1..2a2a591e 100644 --- a/src/gui/sell.cpp +++ b/src/gui/sell.cpp @@ -125,6 +125,11 @@ void SellDialog::reset() m_amountItems = 0; quantityLabel->setCaption("0"); quantityLabel->adjustSize(); + + // Reset Previous Selected Items to prevent failing asserts + itemList->setSelected(-1); + increaseButton->setEnabled(false); + decreaseButton->setEnabled(false); } void SellDialog::addItem(short index, int price) |