| 233 | } |
| 234 | |
| 235 | void MerchantPane::setupWidget(WidgetPtr const& widget, Json const& itemConfig) { |
| 236 | auto& root = Root::singleton(); |
| 237 | auto assets = root.assets(); |
| 238 | ItemPtr item = root.itemDatabase()->itemShared(ItemDescriptor(itemConfig.get("item"))); |
| 239 | |
| 240 | String name = item->friendlyName(); |
| 241 | if (item->count() > 1) |
| 242 | name = strf("{} (x{})", name, item->count()); |
| 243 | |
| 244 | auto itemName = widget->fetchChild<LabelWidget>("itemName"); |
| 245 | itemName->setText(name); |
| 246 | |
| 247 | unsigned price = ceil(itemConfig.getInt("price", item->price()) * m_buyFactor); |
| 248 | widget->setLabel("priceLabel", toString(price)); |
| 249 | widget->setData(price); |
| 250 | |
| 251 | bool unavailable = price > m_player->currency("money"); |
| 252 | auto unavailableoverlay = widget->fetchChild<ImageWidget>("unavailableoverlay"); |
| 253 | if (unavailable) { |
| 254 | itemName->setColor(Color::Gray); |
| 255 | unavailableoverlay->show(); |
| 256 | } else { |
| 257 | itemName->setColor(Color::White); |
| 258 | unavailableoverlay->hide(); |
| 259 | } |
| 260 | |
| 261 | widget->fetchChild<ItemSlotWidget>("itemIcon")->setItem(item); |
| 262 | widget->show(); |
| 263 | } |
| 264 | |
| 265 | void MerchantPane::updateSelection() { |
| 266 | if (m_selectedIndex != m_itemGuiList->selectedItem()) { |
nothing calls this directly
no test coverage detected