summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/shopitem.cpp54
-rw-r--r--src/shopitem.h2
2 files changed, 21 insertions, 35 deletions
diff --git a/src/shopitem.cpp b/src/shopitem.cpp
index 10491ef2d..386583170 100644
--- a/src/shopitem.cpp
+++ b/src/shopitem.cpp
@@ -42,17 +42,8 @@ ShopItem::ShopItem(const int inventoryIndex, const int id,
mPrice(price),
mShowQuantity(true)
{
- if (serverFeatures->haveItemColors())
- {
- mDisplayName = std::string(getInfo().getName(color)).append(" (")
- .append(Units::formatCurrency(mPrice)).append(") ");
- }
- else
- {
- mDisplayName = std::string(getInfo().getName()).append(" (")
- .append(Units::formatCurrency(mPrice)).append(") ");
- }
- if (quantity > 0)
+ updateDisplayName(quantity);
+ if (quantity > 1)
mDisplayName.append("[").append(toString(quantity)).append("]");
setInvIndex(inventoryIndex);
@@ -66,16 +57,7 @@ ShopItem::ShopItem(const int id, const unsigned char color, const int price) :
mPrice(price),
mShowQuantity(false)
{
- if (serverFeatures->haveItemColors())
- {
- mDisplayName = std::string(getInfo().getName(color)).append(" (")
- .append(Units::formatCurrency(mPrice)).append(")");
- }
- else
- {
- mDisplayName = std::string(getInfo().getName()).append(" (")
- .append(Units::formatCurrency(mPrice)).append(")");
- }
+ updateDisplayName(0);
setInvIndex(-1);
addDuplicate(-1, 0);
}
@@ -90,23 +72,25 @@ ShopItem::~ShopItem()
}
}
-void ShopItem::update()
+void ShopItem::updateDisplayName(const int quantity)
{
- if (mShowQuantity)
+ if (serverFeatures->haveItemColors())
+ mDisplayName = std::string(getInfo().getName(mColor));
+ else
+ mDisplayName = std::string(getInfo().getName());
+ if (mPrice)
{
- if (serverFeatures->haveItemColors())
- {
- mDisplayName = std::string(getInfo().getName(mColor)).append(" (")
- .append(Units::formatCurrency(mPrice)).append(") ");
- }
- else
- {
- mDisplayName = std::string(getInfo().getName()).append(" (")
- .append(Units::formatCurrency(mPrice)).append(") ");
- }
- if (mQuantity > 0)
- mDisplayName.append("[").append(toString(mQuantity)).append("]");
+ mDisplayName.append(" (").append(
+ Units::formatCurrency(mPrice)).append(") ");
}
+ if (quantity > 1)
+ mDisplayName.append("[").append(toString(quantity)).append("]");
+}
+
+void ShopItem::update()
+{
+ if (mShowQuantity)
+ updateDisplayName(mQuantity);
}
void ShopItem::addDuplicate(const int inventoryIndex, const int quantity)
diff --git a/src/shopitem.h b/src/shopitem.h
index 449d9f91c..42616d389 100644
--- a/src/shopitem.h
+++ b/src/shopitem.h
@@ -132,6 +132,8 @@ class ShopItem final : public Item
{ return mDisplayName; }
protected:
+ void updateDisplayName(const int quantity);
+
std::string mDisplayName;
/**