diff options
author | Andrei Karas <akaras@inbox.ru> | 2011-03-03 23:13:07 +0200 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2011-03-03 23:13:07 +0200 |
commit | 9437d4943a8b299b057020ee114b230399965abd (patch) | |
tree | 54e8d1bca3c2f5457db8402fcdfe1b9e04df54f7 | |
parent | bb73cadd0afdc9fa55ea66ecedd8be53a6f3198e (diff) | |
download | plus-9437d4943a8b299b057020ee114b230399965abd.tar.gz plus-9437d4943a8b299b057020ee114b230399965abd.tar.bz2 plus-9437d4943a8b299b057020ee114b230399965abd.tar.xz plus-9437d4943a8b299b057020ee114b230399965abd.zip |
Add colors to buy/sell dialogs.
-rw-r--r-- | src/gui/buy.cpp | 9 | ||||
-rw-r--r-- | src/gui/buy.h | 2 | ||||
-rw-r--r-- | src/gui/sell.cpp | 6 | ||||
-rw-r--r-- | src/gui/sell.h | 2 | ||||
-rw-r--r-- | src/gui/shopwindow.cpp | 19 | ||||
-rw-r--r-- | src/gui/widgets/shopitems.cpp | 21 | ||||
-rw-r--r-- | src/gui/widgets/shopitems.h | 9 | ||||
-rw-r--r-- | src/net/manaserv/buysellhandler.cpp | 3 | ||||
-rw-r--r-- | src/net/manaserv/npchandler.cpp | 3 | ||||
-rw-r--r-- | src/net/manaserv/npchandler.h | 2 | ||||
-rw-r--r-- | src/net/npchandler.h | 3 | ||||
-rw-r--r-- | src/net/tmwa/buysellhandler.cpp | 3 | ||||
-rw-r--r-- | src/net/tmwa/npchandler.cpp | 19 | ||||
-rw-r--r-- | src/net/tmwa/npchandler.h | 2 | ||||
-rw-r--r-- | src/shopitem.cpp | 8 | ||||
-rw-r--r-- | src/shopitem.h | 5 |
16 files changed, 68 insertions, 48 deletions
diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp index 45bc051fb..c413fdffc 100644 --- a/src/gui/buy.cpp +++ b/src/gui/buy.cpp @@ -159,9 +159,9 @@ void BuyDialog::reset() setMoney(0); } -void BuyDialog::addItem(int id, int amount, int price) +void BuyDialog::addItem(int id, unsigned char color, int amount, int price) { - mShopItems->addItem(id, amount, price); + mShopItems->addItem(id, color, amount, price); mShopItemList->adjustSize(); } @@ -213,8 +213,9 @@ void BuyDialog::action(const gcn::ActionEvent &event) { if (mNpcId != -1) { - Net::getNpcHandler()->buyItem(mNpcId, - mShopItems->at(selectedItem)->getId(), mAmountItems); + ShopItem *item = mShopItems->at(selectedItem); + Net::getNpcHandler()->buyItem(mNpcId, item->getId(), + item->getColor(), mAmountItems); // Update money and adjust the max number of items that can be bought mMaxItems -= mAmountItems; diff --git a/src/gui/buy.h b/src/gui/buy.h index edbe1bf98..c9d412645 100644 --- a/src/gui/buy.h +++ b/src/gui/buy.h @@ -81,7 +81,7 @@ class BuyDialog : public Window, public gcn::ActionListener, /** * Adds an item to the shop inventory. */ - void addItem(int id, int amount, int price); + void addItem(int id, unsigned char color, int amount, int price); /** * Called when receiving actions from the widgets. diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp index 5b05c6865..de1da395c 100644 --- a/src/gui/sell.cpp +++ b/src/gui/sell.cpp @@ -152,14 +152,14 @@ void SellDialog::addItem(const Item *item, int price) return; mShopItems->addItem2(item->getInvIndex(), item->getId(), - item->getQuantity(), price); + item->getColor(), item->getQuantity(), price); mShopItemList->adjustSize(); } -void SellDialog::addItem(int id, int amount, int price) +void SellDialog::addItem(int id, unsigned char color, int amount, int price) { - mShopItems->addItem(id, amount, price); + mShopItems->addItem(id, color, amount, price); mShopItemList->adjustSize(); } diff --git a/src/gui/sell.h b/src/gui/sell.h index 7ab454630..86343a953 100644 --- a/src/gui/sell.h +++ b/src/gui/sell.h @@ -99,7 +99,7 @@ class SellDialog : public Window, gcn::ActionListener, gcn::SelectionListener */ void setVisible(bool visible); - void addItem(int id, int amount, int price); + void addItem(int id, unsigned char color, int amount, int price); /** * Returns true if any instances exist. diff --git a/src/gui/shopwindow.cpp b/src/gui/shopwindow.cpp index 99a9a6a61..43e05aa70 100644 --- a/src/gui/shopwindow.cpp +++ b/src/gui/shopwindow.cpp @@ -278,7 +278,7 @@ void ShopWindow::addBuyItem(Item *item, int amount, int price) { if (!mBuyShopItems || !item) return; - mBuyShopItems->addItemNoDup(item->getId(), amount, price); + mBuyShopItems->addItemNoDup(item->getId(), item->getColor(), amount, price); updateButtonsAndLabels(); } @@ -286,7 +286,7 @@ void ShopWindow::addSellItem(Item *item, int amount, int price) { if (!mBuyShopItems || !item) return; - mSellShopItems->addItemNoDup(item->getId(), amount, price); + mSellShopItems->addItemNoDup(item->getId(), item->getColor(), amount, price); updateButtonsAndLabels(); } @@ -323,15 +323,16 @@ void ShopWindow::loadList() if (tokens.size() == 5 && tokens[0]) { + //+++ need impliment colors? if (tokens[1] && tokens[2] && mBuyShopItems) { mBuyShopItems->addItem( - tokens[0], tokens[1], tokens[2]); + tokens[0], 1, tokens[1], tokens[2]); } if (tokens[3] && tokens[4] && mSellShopItems) { mSellShopItems->addItem( - tokens[0], tokens[3], tokens[4]); + tokens[0], 1, tokens[3], tokens[4]); } } } @@ -599,8 +600,9 @@ void ShopWindow::showList(const std::string &nick, std::string data) int id = decodeStr(data.substr(f, 2)); int price = decodeStr(data.substr(f + 2, 4)); int amount = decodeStr(data.substr(f + 6, 3)); + //+++ need impliment colors? if (buyDialog && amount > 0) - buyDialog->addItem(id, amount, price); + buyDialog->addItem(id, 1, amount, price); if (sellDialog) { Item *item = inv->findItem(id); @@ -609,9 +611,9 @@ void ShopWindow::showList(const std::string &nick, std::string data) if (item->getQuantity() < amount) amount = item->getQuantity(); if (amount > 0) - sellDialog->addItem(id, amount, price); + sellDialog->addItem(id, 1, amount, price); else - sellDialog->addItem(id, -1, price); + sellDialog->addItem(id, 1, -1, price); } } } @@ -670,7 +672,8 @@ void ShopWindow::processRequest(std::string nick, std::string data, int mode) amount = atoi(part3.c_str()); delete mTradeItem; - mTradeItem = new ShopItem(-1, id, amount, price); + //+++ need impliment colors? + mTradeItem = new ShopItem(-1, id, 1, amount, price); if (mode == BUY) { diff --git a/src/gui/widgets/shopitems.cpp b/src/gui/widgets/shopitems.cpp index 3e46f51a4..c0b93508e 100644 --- a/src/gui/widgets/shopitems.cpp +++ b/src/gui/widgets/shopitems.cpp @@ -49,23 +49,24 @@ std::string ShopItems::getElementAt(int i) return mShopItems.at(i)->getDisplayName(); } -void ShopItems::addItem(int id, int amount, int price) +void ShopItems::addItem(int id, unsigned char color, int amount, int price) { - mShopItems.push_back(new ShopItem(-1, id, amount, price)); + mShopItems.push_back(new ShopItem(-1, id, color, amount, price)); } -void ShopItems::addItemNoDup(int id, int amount, int price) +void ShopItems::addItemNoDup(int id, unsigned char color, int amount, int price) { - ShopItem *item = findItem(id); + ShopItem *item = findItem(id, color); if (!item) - mShopItems.push_back(new ShopItem(-1, id, amount, price)); + mShopItems.push_back(new ShopItem(-1, id, color, amount, price)); } -void ShopItems::addItem2(int inventoryIndex, int id, int quantity, int price) +void ShopItems::addItem2(int inventoryIndex, int id, unsigned char color, + int quantity, int price) { ShopItem *item = 0; if (mMergeDuplicates) - item = findItem(id); + item = findItem(id, color); if (item) { @@ -73,7 +74,7 @@ void ShopItems::addItem2(int inventoryIndex, int id, int quantity, int price) } else { - item = new ShopItem(inventoryIndex, id, quantity, price); + item = new ShopItem(inventoryIndex, id, color, quantity, price); mShopItems.push_back(item); } } @@ -100,7 +101,7 @@ void ShopItems::clear() mShopItems.clear(); } -ShopItem *ShopItems::findItem(int id) +ShopItem *ShopItems::findItem(int id, unsigned char color) { ShopItem *item; @@ -109,7 +110,7 @@ ShopItem *ShopItems::findItem(int id) while (it != e) { item = *(it); - if (item->getId() == id) + if (item->getId() == id && item->getColor() == color) return item; ++it; diff --git a/src/gui/widgets/shopitems.h b/src/gui/widgets/shopitems.h index 949dcfc78..2b2dcc5eb 100644 --- a/src/gui/widgets/shopitems.h +++ b/src/gui/widgets/shopitems.h @@ -55,7 +55,7 @@ class ShopItems : public gcn::ListModel /** * Adds an item to the list. */ - void addItem(int id, int amount, int price); + void addItem(int id, unsigned char color, int amount, int price); /** * Adds an item to the list (used by sell dialog). Looks for @@ -66,9 +66,10 @@ class ShopItems : public gcn::ListModel * @param quantity number of available copies of the item * @param price price of the item */ - void addItem2(int inventoryIndex, int id, int amount, int price); + void addItem2(int inventoryIndex, int id, unsigned char color, + int amount, int price); - void addItemNoDup(int id, int amount, int price); + void addItemNoDup(int id, unsigned char color, int amount, int price); /** * Returns the number of items in the shop. @@ -109,7 +110,7 @@ class ShopItems : public gcn::ListModel * * @return the item found or 0 */ - ShopItem *findItem(int id); + ShopItem *findItem(int id, unsigned char color); /** The list of items in the shop. */ std::vector<ShopItem*> mShopItems; diff --git a/src/net/manaserv/buysellhandler.cpp b/src/net/manaserv/buysellhandler.cpp index 07737e20b..a519125de 100644 --- a/src/net/manaserv/buysellhandler.cpp +++ b/src/net/manaserv/buysellhandler.cpp @@ -79,7 +79,8 @@ void BuySellHandler::handleMessage(Net::MessageIn &msg) int itemId = msg.readInt16(); int amount = msg.readInt16(); int value = msg.readInt16(); - dialog->addItem(itemId, amount, value); + // colors not supported, using 1. + dialog->addItem(itemId, 1, amount, value); } break; } diff --git a/src/net/manaserv/npchandler.cpp b/src/net/manaserv/npchandler.cpp index 3117f9455..2c389bc7d 100644 --- a/src/net/manaserv/npchandler.cpp +++ b/src/net/manaserv/npchandler.cpp @@ -209,7 +209,8 @@ void NpcHandler::sell(int beingId _UNUSED_) // TODO } -void NpcHandler::buyItem(int beingId _UNUSED_, int itemId, int amount) +void NpcHandler::buyItem(int beingId _UNUSED_, int itemId, + unsigned char color _UNUSED_, int amount) { MessageOut msg(PGMSG_NPC_BUYSELL); msg.writeInt16(itemId); diff --git a/src/net/manaserv/npchandler.h b/src/net/manaserv/npchandler.h index faaff060c..6ecfb4e97 100644 --- a/src/net/manaserv/npchandler.h +++ b/src/net/manaserv/npchandler.h @@ -68,7 +68,7 @@ class NpcHandler : public MessageHandler, public Net::NpcHandler void sell(int beingId); - void buyItem(int beingId, int itemId, int amount); + void buyItem(int beingId, int itemId, unsigned char color, int amount); void sellItem(int beingId, int itemId, int amount); diff --git a/src/net/npchandler.h b/src/net/npchandler.h index 5850b9475..40b97deef 100644 --- a/src/net/npchandler.h +++ b/src/net/npchandler.h @@ -55,7 +55,8 @@ class NpcHandler virtual void sell(int beingId) = 0; - virtual void buyItem(int beingId, int itemId, int amount) = 0; + virtual void buyItem(int beingId, int itemId, unsigned char color, + int amount) = 0; virtual void sellItem(int beingId, int itemId, int amount) = 0; diff --git a/src/net/tmwa/buysellhandler.cpp b/src/net/tmwa/buysellhandler.cpp index bf5df61a1..07d5bcc96 100644 --- a/src/net/tmwa/buysellhandler.cpp +++ b/src/net/tmwa/buysellhandler.cpp @@ -102,8 +102,7 @@ void BuySellHandler::handleMessage(Net::MessageIn &msg) unsigned char color = 1; if (serverVersion > 0) color = msg.readInt8(); - mBuyDialog->addItem(itemId, 0, value); -// mBuyDialog->addItem(itemId, color, 0, value); + mBuyDialog->addItem(itemId, color, 0, value); } break; } diff --git a/src/net/tmwa/npchandler.cpp b/src/net/tmwa/npchandler.cpp index 553108fb8..8ddfeb090 100644 --- a/src/net/tmwa/npchandler.cpp +++ b/src/net/tmwa/npchandler.cpp @@ -221,12 +221,23 @@ void NpcHandler::sell(int beingId) outMsg.writeInt8(1); // Sell } -void NpcHandler::buyItem(int beingId _UNUSED_, int itemId, int amount) +void NpcHandler::buyItem(int beingId _UNUSED_, int itemId, + unsigned char color, int amount) { MessageOut outMsg(CMSG_NPC_BUY_REQUEST); - outMsg.writeInt16(8); // One item (length of packet) - outMsg.writeInt16(amount); - outMsg.writeInt16(itemId); + if (serverVersion > 0) + { + outMsg.writeInt16(9); // One item (length of packet) + outMsg.writeInt16(amount); + outMsg.writeInt16(itemId); + outMsg.writeInt8(color); + } + else + { + outMsg.writeInt16(8); // One item (length of packet) + outMsg.writeInt16(amount); + outMsg.writeInt16(itemId); + } } void NpcHandler::sellItem(int beingId _UNUSED_, int itemId, int amount) diff --git a/src/net/tmwa/npchandler.h b/src/net/tmwa/npchandler.h index c2db3394d..83d8e7981 100644 --- a/src/net/tmwa/npchandler.h +++ b/src/net/tmwa/npchandler.h @@ -69,7 +69,7 @@ class NpcHandler : public MessageHandler, public Net::NpcHandler void sell(int beingId); - void buyItem(int beingId, int itemId, int amount); + void buyItem(int beingId, int itemId, unsigned char color, int amount); void sellItem(int beingId, int itemId, int amount); diff --git a/src/shopitem.cpp b/src/shopitem.cpp index 5fce6685d..861d03bdc 100644 --- a/src/shopitem.cpp +++ b/src/shopitem.cpp @@ -28,9 +28,9 @@ #include "resources/iteminfo.h" -ShopItem::ShopItem(int inventoryIndex, int id, +ShopItem::ShopItem(int inventoryIndex, int id, unsigned char color, int quantity, int price) : - Item(id, 0), + Item(id, 0, 0, color), mPrice(price), mShowQuantity(true) { @@ -43,8 +43,8 @@ ShopItem::ShopItem(int inventoryIndex, int id, addDuplicate(inventoryIndex, quantity); } -ShopItem::ShopItem (int id, int price) : - Item (id, 0), +ShopItem::ShopItem (int id, unsigned char color, int price) : + Item (id, 0, 0, color), mPrice(price), mShowQuantity(false) { diff --git a/src/shopitem.h b/src/shopitem.h index 01356f3ae..5d78b918c 100644 --- a/src/shopitem.h +++ b/src/shopitem.h @@ -42,7 +42,8 @@ class ShopItem : public Item * @param quantity number of available copies of the item * @param price price of the item */ - ShopItem(int inventoryIndex, int id, int quantity, int price); + ShopItem(int inventoryIndex, int id, unsigned char color, + int quantity, int price); /** * Constructor. Creates a new ShopItem. Inventory index will be set to @@ -51,7 +52,7 @@ class ShopItem : public Item * @param id the id of the item * @param price price of the item */ - ShopItem(int id, int price); + ShopItem(int id, unsigned char color, int price); /** * Destructor. |