From 6dc1f5e0b68cf390f7938329b50a9b28bd187862 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sun, 1 Feb 2015 23:48:15 +0300 Subject: Set correct vending status to local player. Allow buy from vending shop. --- src/gui/models/shopitems.cpp | 45 +++++++++++++++++++++++++------------------- src/gui/models/shopitems.h | 34 ++++++++++++++++----------------- 2 files changed, 43 insertions(+), 36 deletions(-) (limited to 'src/gui/models') diff --git a/src/gui/models/shopitems.cpp b/src/gui/models/shopitems.cpp index e154c0b2e..52a0d60b2 100644 --- a/src/gui/models/shopitems.cpp +++ b/src/gui/models/shopitems.cpp @@ -50,32 +50,38 @@ std::string ShopItems::getElementAt(int i) return mShopItems.at(i)->getDisplayName(); } -void ShopItems::addItem(const int id, - const int type, - const unsigned char color, - const int amount, - const int price) +ShopItem *ShopItems::addItem(const int id, + const int type, + const unsigned char color, + const int amount, + const int price) { - mShopItems.push_back(new ShopItem(-1, id, type, color, amount, price)); + ShopItem *const item = new ShopItem(-1, id, type, color, amount, price); + mShopItems.push_back(item); + return item; } -void ShopItems::addItemNoDup(const int id, - const int type, - const unsigned char color, - const int amount, - const int price) +ShopItem *ShopItems::addItemNoDup(const int id, + const int type, + const unsigned char color, + const int amount, + const int price) { - const ShopItem *const item = findItem(id, color); + ShopItem *item = findItem(id, color); if (!item) - mShopItems.push_back(new ShopItem(-1, id, type, color, amount, price)); + { + item = new ShopItem(-1, id, type, color, amount, price); + mShopItems.push_back(item); + } + return item; } -void ShopItems::addItem2(const int inventoryIndex, - const int id, - const int type, - const unsigned char color, - const int quantity, - const int price) +ShopItem *ShopItems::addItem2(const int inventoryIndex, + const int id, + const int type, + const unsigned char color, + const int quantity, + const int price) { ShopItem *item = nullptr; if (mMergeDuplicates) @@ -90,6 +96,7 @@ void ShopItems::addItem2(const int inventoryIndex, item = new ShopItem(inventoryIndex, id, type, color, quantity, price); mShopItems.push_back(item); } + return item; } ShopItem *ShopItems::at(unsigned int i) const diff --git a/src/gui/models/shopitems.h b/src/gui/models/shopitems.h index f0db94e3a..d3d4a44fc 100644 --- a/src/gui/models/shopitems.h +++ b/src/gui/models/shopitems.h @@ -59,11 +59,11 @@ class ShopItems final : public ListModel /** * Adds an item to the list. */ - void addItem(const int id, - const int type, - const unsigned char color, - const int amount, - const int price); + ShopItem *addItem(const int id, + const int type, + const unsigned char color, + const int amount, + const int price); /** * Adds an item to the list (used by sell dialog). Looks for @@ -74,18 +74,18 @@ class ShopItems final : public ListModel * @param quantity number of available copies of the item * @param price price of the item */ - void addItem2(const int inventoryIndex, - const int id, - const int type, - const unsigned char color, - const int amount, - const int price); - - void addItemNoDup(const int id, - const int type, - const unsigned char color, - const int amount, - const int price); + ShopItem *addItem2(const int inventoryIndex, + const int id, + const int type, + const unsigned char color, + const int amount, + const int price); + + ShopItem *addItemNoDup(const int id, + const int type, + const unsigned char color, + const int amount, + const int price); /** * Returns the number of items in the shop. -- cgit v1.2.3-70-g09d2