diff options
author | Cedric Borgese <cedric.borgese@gmail.com> | 2005-07-22 17:27:59 +0000 |
---|---|---|
committer | Cedric Borgese <cedric.borgese@gmail.com> | 2005-07-22 17:27:59 +0000 |
commit | 5731ddbf5ef5fa1556a7c5f84c0c71865a15499b (patch) | |
tree | 967cfacdf62a8930be9691152746b6f0e6b35a6e /src/gui/sell.cpp | |
parent | 4333effa0e80c996c91e4014cf449c30a32120b7 (diff) | |
download | mana-5731ddbf5ef5fa1556a7c5f84c0c71865a15499b.tar.gz mana-5731ddbf5ef5fa1556a7c5f84c0c71865a15499b.tar.bz2 mana-5731ddbf5ef5fa1556a7c5f84c0c71865a15499b.tar.xz mana-5731ddbf5ef5fa1556a7c5f84c0c71865a15499b.zip |
Merge between moi1392's branch and head
Diffstat (limited to 'src/gui/sell.cpp')
-rw-r--r-- | src/gui/sell.cpp | 191 |
1 files changed, 151 insertions, 40 deletions
diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp index 26487b9a..bc1fe2e8 100644 --- a/src/gui/sell.cpp +++ b/src/gui/sell.cpp @@ -39,42 +39,69 @@ SellDialog::SellDialog(): scrollArea = new ScrollArea(itemList); slider = new Slider(1.0); quantityLabel = new gcn::Label("0"); - okButton = new Button("OK"); - cancelButton = new Button("Cancel"); - okButton->setEnabled(false); + increaseButton = new Button("+"); + decreaseButton = new Button("-"); + sellButton = new Button("Sell"); + quitButton = new Button("Quit"); + sellButton->setEnabled(false); setContentSize(260, 175); scrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); scrollArea->setDimension(gcn::Rectangle(5, 5, 250, 110)); itemList->setDimension(gcn::Rectangle(5, 5, 238, 110)); + slider->setDimension(gcn::Rectangle(5, 120, 200, 10)); + slider->setEnabled(false); + quantityLabel->setPosition(215, 120); - okButton->setPosition(180, 145); - cancelButton->setPosition(208, 145); + + increaseButton->setPosition(40, 145); + increaseButton->setSize(20, 20); + increaseButton->setEnabled(false); + + decreaseButton->setPosition(10, 145); + decreaseButton->setSize(20, 20); + decreaseButton->setEnabled(false); + + sellButton->setPosition(175, 145); + sellButton->setEnabled(false); + + quitButton->setPosition(208, 145); itemList->setEventId("item"); slider->setEventId("slider"); - okButton->setEventId("ok"); - cancelButton->setEventId("cancel"); + increaseButton->setEventId("+"); + decreaseButton->setEventId("-"); + sellButton->setEventId("sell"); + quitButton->setEventId("quit"); itemList->addActionListener(this); slider->addActionListener(this); - okButton->addActionListener(this); - cancelButton->addActionListener(this); + increaseButton->addActionListener(this); + decreaseButton->addActionListener(this); + sellButton->addActionListener(this); + quitButton->addActionListener(this); add(scrollArea); add(slider); add(quantityLabel); - add(okButton); - add(cancelButton); + add(increaseButton); + add(decreaseButton); + add(sellButton); + add(quitButton); setLocationRelativeTo(getParent()); + + m_maxItems = 0; + m_amountItems = 0; } SellDialog::~SellDialog() { - delete cancelButton; - delete okButton; + delete increaseButton; + delete decreaseButton; + delete quitButton; + delete sellButton; delete slider; delete itemList; delete scrollArea; @@ -84,6 +111,7 @@ void SellDialog::reset() { shopInventory.clear(); slider->setValue(0.0); + m_amountItems = 0; quantityLabel->setCaption("0"); quantityLabel->adjustSize(); } @@ -111,41 +139,124 @@ void SellDialog::addItem(short index, int price) void SellDialog::action(const std::string& eventId) { int selectedItem = itemList->getSelected(); + std::stringstream oss; - if (eventId == "slider" || eventId == "item") { - if (selectedItem > -1) { - int maxItems = shopInventory[selectedItem].quantity; - int numItems = (int)(slider->getValue() * maxItems); - std::stringstream ss; + if (eventId == "item") + { + if (selectedItem > -1) + { + slider->setEnabled(true); + increaseButton->setEnabled(true); - ss << numItems; - quantityLabel->setCaption(ss.str()); - quantityLabel->adjustSize(); + m_maxItems = shopInventory[selectedItem].quantity; + m_amountItems = 0; + } + else + { + slider->setValue(0); + slider->setEnabled(false); + increaseButton->setEnabled(false); + decreaseButton->setEnabled(false); + sellButton->setEnabled(false); + m_amountItems = 0; + } + } + else if (eventId == "slider" && selectedItem > -1) + { + m_amountItems = (int)(slider->getValue() * m_maxItems); + + oss << m_amountItems; + quantityLabel->setCaption(oss.str()); + quantityLabel->adjustSize(); - okButton->setEnabled(numItems > 0); + if (m_amountItems > 0) + { + sellButton->setEnabled(true); + decreaseButton->setEnabled(true); } - else { - okButton->setEnabled(false); + else + { + sellButton->setEnabled(false); + decreaseButton->setEnabled(false); + } + + if (m_amountItems == m_maxItems) + { + increaseButton->setEnabled(false); + } + else + { + increaseButton->setEnabled(true); } } - else if (eventId == "ok") { - if (selectedItem > -1) { - // Attempt sell - int maxItems = shopInventory[selectedItem].quantity; - int amount = (int)(slider->getValue() * maxItems); - - if (amount > 0) { - WFIFOW(0) = net_w_value(0x00c9); - WFIFOW(2) = net_w_value(8); - WFIFOW(4) = net_w_value(shopInventory[selectedItem].index); - WFIFOW(6) = net_w_value(amount); - WFIFOSET(8); - } + else if (eventId == "+" && selectedItem > -1) + { + assert(m_amountItems < m_maxItems); + m_amountItems++; + slider->setValue(double(m_amountItems)/double(m_maxItems)); + + decreaseButton->setEnabled(true); + sellButton->setEnabled(true); + if (m_amountItems == m_maxItems) + { + increaseButton->setEnabled(false); } - setVisible(false); - current_npc = 0; + + oss << m_amountItems; + quantityLabel->setCaption(oss.str()); + quantityLabel->adjustSize(); + } + else if (eventId == "-" && selectedItem > -1) + { + assert(m_amountItems > 0); + m_amountItems--; + + slider->setValue(double(m_amountItems)/double(m_maxItems)); + + increaseButton->setEnabled(true); + if (m_amountItems == 0) + { + decreaseButton->setEnabled(false); + sellButton->setEnabled(false); + } + + oss << m_amountItems; + quantityLabel->setCaption(oss.str()); + quantityLabel->adjustSize(); + } + else if (eventId == "sell" && selectedItem > -1) + { + // Attempt sell + assert(m_amountItems > 0 && m_amountItems <= m_maxItems); + assert(selectedItem >= 0 && selectedItem < int(shopInventory.size())); + + WFIFOW(0) = net_w_value(0x00c9); + WFIFOW(2) = net_w_value(8); + WFIFOW(4) = net_w_value(shopInventory[selectedItem].index); + WFIFOW(6) = net_w_value(m_amountItems); + WFIFOSET(8); + + if (m_amountItems == m_maxItems) + { + slider->setEnabled(false); + increaseButton->setEnabled(false); + shopInventory.erase(shopInventory.begin() += selectedItem); + } + else + { + m_maxItems = shopInventory[selectedItem].quantity - m_amountItems; + } + + decreaseButton->setEnabled(false); + sellButton->setEnabled(false); + + m_amountItems = 0; + slider->setValue(0); + quantityLabel->setCaption("O"); + quantityLabel->adjustSize(); } - else if (eventId == "cancel") { + else if (eventId == "quit") + { setVisible(false); current_npc = 0; } |