summaryrefslogtreecommitdiff
path: root/src/gui/buy.cpp
diff options
context:
space:
mode:
authorBjörn Steinbrink <B.Steinbrink@gmx.de>2006-03-09 05:16:27 +0000
committerBjörn Steinbrink <B.Steinbrink@gmx.de>2006-03-09 05:16:27 +0000
commite5f795ad9952b8bba6993ee3e324b22a0f104816 (patch)
tree1602ac0f74865135eae5acf935b0a285a8e918c2 /src/gui/buy.cpp
parent7593d6c71e2331c3e43c732db60ad03ee4d5385d (diff)
downloadmana-client-e5f795ad9952b8bba6993ee3e324b22a0f104816.tar.gz
mana-client-e5f795ad9952b8bba6993ee3e324b22a0f104816.tar.bz2
mana-client-e5f795ad9952b8bba6993ee3e324b22a0f104816.tar.xz
mana-client-e5f795ad9952b8bba6993ee3e324b22a0f104816.zip
Made all class members named like mClassMember.
Diffstat (limited to 'src/gui/buy.cpp')
-rw-r--r--src/gui/buy.cpp203
1 files changed, 101 insertions, 102 deletions
diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp
index 42c6ff2f..18542385 100644
--- a/src/gui/buy.cpp
+++ b/src/gui/buy.cpp
@@ -44,65 +44,65 @@
BuyDialog::BuyDialog(Network *network):
Window("Buy"), mNetwork(network),
- m_money(0), m_amountItems(0), m_maxItems(0)
+ mMoney(0), mAmountItems(0), mMaxItems(0)
{
mShopItems = new ShopItems;
- itemList = new ListBox(mShopItems);
- scrollArea = new ScrollArea(itemList);
- slider = new Slider(1.0);
- quantityLabel = new gcn::Label("0");
- moneyLabel = new gcn::Label("Price: 0 GP");
- increaseButton = new Button("+", "+", this);
- decreaseButton = new Button("-", "-", this);
- buyButton = new Button("Buy", "buy", this);
- quitButton = new Button("Quit", "quit", this);
- itemDescLabel = new gcn::Label("Description:");
- itemEffectLabel = new gcn::Label("Effect:");
+ mItemList = new ListBox(mShopItems);
+ mScrollArea = new ScrollArea(mItemList);
+ mSlider = new Slider(1.0);
+ mQuantityLabel = new gcn::Label("0");
+ mMoneyLabel = new gcn::Label("Price: 0 GP");
+ mIncreaseButton = new Button("+", "+", this);
+ mDecreaseButton = new Button("-", "-", this);
+ mBuyButton = new Button("Buy", "buy", this);
+ mQuitButton = new Button("Quit", "quit", this);
+ mItemDescLabel = new gcn::Label("Description:");
+ mItemEffectLabel = new gcn::Label("Effect:");
setContentSize(260, 210);
- scrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER);
- scrollArea->setDimension(gcn::Rectangle(5, 5, 250, 110));
- itemList->setDimension(gcn::Rectangle(5, 5, 238, 110));
+ mScrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER);
+ mScrollArea->setDimension(gcn::Rectangle(5, 5, 250, 110));
+ mItemList->setDimension(gcn::Rectangle(5, 5, 238, 110));
- slider->setDimension(gcn::Rectangle(5, 120, 200, 10));
- slider->setEnabled(false);
+ mSlider->setDimension(gcn::Rectangle(5, 120, 200, 10));
+ mSlider->setEnabled(false);
- quantityLabel->setPosition(215, 120);
- moneyLabel->setPosition(5, 130);
+ mQuantityLabel->setPosition(215, 120);
+ mMoneyLabel->setPosition(5, 130);
- increaseButton->setPosition(40, 186);
- increaseButton->setSize(20, 20);
- increaseButton->setEnabled(false);
+ mIncreaseButton->setPosition(40, 186);
+ mIncreaseButton->setSize(20, 20);
+ mIncreaseButton->setEnabled(false);
- decreaseButton->setPosition(10, 186);
- decreaseButton->setSize(20, 20);
- decreaseButton->setEnabled(false);
+ mDecreaseButton->setPosition(10, 186);
+ mDecreaseButton->setSize(20, 20);
+ mDecreaseButton->setEnabled(false);
- buyButton->setPosition(180, 186);
- buyButton->setEnabled(false);
+ mBuyButton->setPosition(180, 186);
+ mBuyButton->setEnabled(false);
- quitButton->setPosition(212, 186);
+ mQuitButton->setPosition(212, 186);
- itemEffectLabel->setDimension(gcn::Rectangle(5, 150, 240, 14));
- itemDescLabel->setDimension(gcn::Rectangle(5, 169, 240, 14));
+ mItemEffectLabel->setDimension(gcn::Rectangle(5, 150, 240, 14));
+ mItemDescLabel->setDimension(gcn::Rectangle(5, 169, 240, 14));
- itemList->setEventId("item");
- slider->setEventId("slider");
+ mItemList->setEventId("item");
+ mSlider->setEventId("slider");
- itemList->addActionListener(this);
- slider->addActionListener(this);
+ mItemList->addActionListener(this);
+ mSlider->addActionListener(this);
- add(scrollArea);
- add(slider);
- add(quantityLabel);
- add(buyButton);
- add(quitButton);
- add(increaseButton);
- add(decreaseButton);
- add(moneyLabel);
- add(itemDescLabel);
- add(itemEffectLabel);
+ add(mScrollArea);
+ add(mSlider);
+ add(mQuantityLabel);
+ add(mBuyButton);
+ add(mQuitButton);
+ add(mIncreaseButton);
+ add(mDecreaseButton);
+ add(mMoneyLabel);
+ add(mItemDescLabel);
+ add(mItemEffectLabel);
setLocationRelativeTo(getParent());
}
@@ -114,27 +114,26 @@ BuyDialog::~BuyDialog()
void BuyDialog::setMoney(int amount)
{
- m_money = amount;
+ mMoney = amount;
}
void BuyDialog::reset()
{
mShopItems->clear();
- m_money = 0;
- slider->setValue(0.0);
- m_amountItems = 0;
+ mMoney = 0;
+ mSlider->setValue(0.0);
+ mAmountItems = 0;
// Reset Previous Selected Items to prevent failing asserts
- itemList->setSelected(-1);
- increaseButton->setEnabled(false);
- decreaseButton->setEnabled(false);
- quantityLabel->setCaption("0");
- quantityLabel->adjustSize();
- moneyLabel->setCaption("Price: 0");
- moneyLabel->adjustSize();
- itemDescLabel->setCaption("");
- itemEffectLabel->setCaption("");
-
+ mItemList->setSelected(-1);
+ mIncreaseButton->setEnabled(false);
+ mDecreaseButton->setEnabled(false);
+ mQuantityLabel->setCaption("0");
+ mQuantityLabel->adjustSize();
+ mMoneyLabel->setCaption("Price: 0");
+ mMoneyLabel->adjustSize();
+ mItemDescLabel->setCaption("");
+ mItemEffectLabel->setCaption("");
}
void BuyDialog::addItem(short id, int price)
@@ -148,35 +147,35 @@ void BuyDialog::addItem(short id, int price)
item_shop.id = id;
mShopItems->push_back(item_shop);
- itemList->adjustSize();
+ mItemList->adjustSize();
}
void BuyDialog::action(const std::string& eventId)
{
- int selectedItem = itemList->getSelected();
+ int selectedItem = mItemList->getSelected();
if (eventId == "item") {
// Reset amount of items and update labels
- m_amountItems = 0;
- slider->setValue(0);
- quantityLabel->setCaption("0");
- quantityLabel->adjustSize();
- moneyLabel->setCaption("Price : 0 GP");
- moneyLabel->adjustSize();
+ mAmountItems = 0;
+ mSlider->setValue(0);
+ mQuantityLabel->setCaption("0");
+ mQuantityLabel->adjustSize();
+ mMoneyLabel->setCaption("Price : 0 GP");
+ mMoneyLabel->adjustSize();
// Disable buttons for buying and decreasing
- buyButton->setEnabled(false);
- decreaseButton->setEnabled(false);
+ mBuyButton->setEnabled(false);
+ mDecreaseButton->setEnabled(false);
// If no item was selected, none can be bought, otherwise
// calculate how many the player can afford
- m_maxItems = (itemList->getSelected() == -1) ? 0 :
- m_money / mShopItems->at(selectedItem).price;
+ mMaxItems = (mItemList->getSelected() == -1) ? 0 :
+ mMoney / mShopItems->at(selectedItem).price;
// When at least one item can be bought, enable the slider and the
// increase button
- increaseButton->setEnabled(m_maxItems > 0);
- slider->setEnabled(m_maxItems > 0);
+ mIncreaseButton->setEnabled(mMaxItems > 0);
+ mSlider->setEnabled(mMaxItems > 0);
}
else if (eventId == "quit") {
setVisible(false);
@@ -191,52 +190,52 @@ void BuyDialog::action(const std::string& eventId)
bool updateButtonsAndLabels = false;
if (eventId == "slider") {
- m_amountItems = (int)(slider->getValue() * m_maxItems);
+ mAmountItems = (int)(mSlider->getValue() * mMaxItems);
updateButtonsAndLabels = true;
}
else if (eventId == "+") {
- if (m_amountItems < m_maxItems) {
- m_amountItems++;
+ if (mAmountItems < mMaxItems) {
+ mAmountItems++;
} else {
- m_amountItems = m_maxItems;
+ mAmountItems = mMaxItems;
}
- slider->setValue(double(m_amountItems)/double(m_maxItems));
+ mSlider->setValue(double(mAmountItems)/double(mMaxItems));
updateButtonsAndLabels = true;
}
else if (eventId == "-") {
- if (m_amountItems > 0) {
- m_amountItems--;
+ if (mAmountItems > 0) {
+ mAmountItems--;
} else {
- m_amountItems = 0;
+ mAmountItems = 0;
}
- slider->setValue(double(m_amountItems)/double(m_maxItems));
+ mSlider->setValue(double(mAmountItems)/double(mMaxItems));
updateButtonsAndLabels = true;
}
// TODO Actually we'd have a bug elsewhere if this check for the number
// of items to be bought ever fails, Bertram removed the assertions, is
// there a better way to ensure this fails in an _obivous_ way in C++?
- else if (eventId == "buy" && (m_amountItems > 0 &&
- m_amountItems <= m_maxItems)) {
+ else if (eventId == "buy" && (mAmountItems > 0 &&
+ mAmountItems <= mMaxItems)) {
MessageOut outMsg(mNetwork);
outMsg.writeInt16(CMSG_NPC_BUY_REQUEST);
outMsg.writeInt16(8);
- outMsg.writeInt16(m_amountItems);
+ outMsg.writeInt16(mAmountItems);
outMsg.writeInt16(mShopItems->at(selectedItem).id);
// update money !
- m_money -= m_amountItems * mShopItems->at(selectedItem).price;
+ mMoney -= mAmountItems * mShopItems->at(selectedItem).price;
// Update number of items that can be bought at max
- m_maxItems -= m_amountItems;
+ mMaxItems -= mAmountItems;
- if (!m_maxItems) {
- slider->setEnabled(false);
+ if (!mMaxItems) {
+ mSlider->setEnabled(false);
}
// Reset selection
- m_amountItems = 0;
- slider->setValue(0);
+ mAmountItems = 0;
+ mSlider->setValue(0);
updateButtonsAndLabels = true;
}
@@ -246,19 +245,19 @@ void BuyDialog::action(const std::string& eventId)
std::stringstream oss;
// Update buttons
- increaseButton->setEnabled(m_amountItems < m_maxItems);
- decreaseButton->setEnabled(m_amountItems > 0);
- buyButton->setEnabled(m_amountItems > 0);
+ mIncreaseButton->setEnabled(mAmountItems < mMaxItems);
+ mDecreaseButton->setEnabled(mAmountItems > 0);
+ mBuyButton->setEnabled(mAmountItems > 0);
// Update labels
- oss << m_amountItems;
- quantityLabel->setCaption(oss.str());
- quantityLabel->adjustSize();
+ oss << mAmountItems;
+ mQuantityLabel->setCaption(oss.str());
+ mQuantityLabel->adjustSize();
oss.str("");
- oss << "Price : " << m_amountItems * mShopItems->at(selectedItem).price << " GP";
- moneyLabel->setCaption(oss.str());
- moneyLabel->adjustSize();
+ oss << "Price : " << mAmountItems * mShopItems->at(selectedItem).price << " GP";
+ mMoneyLabel->setCaption(oss.str());
+ mMoneyLabel->adjustSize();
}
}
@@ -266,12 +265,12 @@ void BuyDialog::mouseClick(int x, int y, int button, int count)
{
Window::mouseClick(x, y, button, count);
- int selectedItem = itemList->getSelected();
+ int selectedItem = mItemList->getSelected();
if (selectedItem > -1)
{
- itemDescLabel->setCaption("Description: " +
+ mItemDescLabel->setCaption("Description: " +
itemDb->getItemInfo(mShopItems->at(selectedItem).id)->getDescription());
- itemEffectLabel->setCaption("Effect: " +
+ mItemEffectLabel->setCaption("Effect: " +
itemDb->getItemInfo(mShopItems->at(selectedItem).id)->getEffect());
}
}