| 381 | } |
| 382 | |
| 383 | void CraftingPane::setupWidget(WidgetPtr const& widget, ItemRecipe const& recipe, HashMap<ItemDescriptor, uint64_t> const& normalizedBag) { |
| 384 | auto& root = Root::singleton(); |
| 385 | |
| 386 | auto single = recipe.output.singular(); |
| 387 | ItemPtr item = m_itemCache[single]; |
| 388 | if (!item) { |
| 389 | item = root.itemDatabase()->itemShared(single); |
| 390 | m_itemCache[single] = item; |
| 391 | } |
| 392 | |
| 393 | bool unavailable = false; |
| 394 | size_t price = recipe.currencyInputs.value("money", 0); |
| 395 | |
| 396 | if (!m_player->isAdmin()) { |
| 397 | for (auto const& p : recipe.currencyInputs) { |
| 398 | if (m_player->currency(p.first) < p.second) |
| 399 | unavailable = true; |
| 400 | } |
| 401 | |
| 402 | auto itemDb = Root::singleton().itemDatabase(); |
| 403 | for (auto const& input : recipe.inputs) { |
| 404 | if (itemDb->getCountOfItem(normalizedBag, input, recipe.matchInputParameters) < input.count()) |
| 405 | unavailable = true; |
| 406 | } |
| 407 | } |
| 408 | |
| 409 | String name = item->friendlyName(); |
| 410 | if (recipe.output.count() > 1) |
| 411 | name = strf("{} (x{})", name, recipe.output.count()); |
| 412 | |
| 413 | auto itemName = widget->fetchChild<LabelWidget>("itemName"); |
| 414 | auto notcraftableoverlay = widget->fetchChild<ImageWidget>("notcraftableoverlay"); |
| 415 | |
| 416 | itemName->setText(name); |
| 417 | |
| 418 | if (unavailable) { |
| 419 | itemName->setColor(Color::Gray); |
| 420 | notcraftableoverlay->show(); |
| 421 | } else { |
| 422 | itemName->setColor(Color::White); |
| 423 | notcraftableoverlay->hide(); |
| 424 | } |
| 425 | |
| 426 | if (price > 0) { |
| 427 | widget->setLabel("priceLabel", toString(price)); |
| 428 | if (auto icon = widget->fetchChild<ImageWidget>("moneyIcon")) |
| 429 | icon->setVisibility(true); |
| 430 | } else { |
| 431 | widget->setLabel("priceLabel", ""); |
| 432 | if (auto icon = widget->fetchChild<ImageWidget>("moneyIcon")) |
| 433 | icon->setVisibility(false); |
| 434 | } |
| 435 | |
| 436 | if (auto newIndicator = widget->fetchChild<ImageWidget>("newIcon")) { |
| 437 | if (m_blueprints->isNew(recipe.output.singular())) { |
| 438 | newIndicator->show(); |
| 439 | widget->setLabel("priceLabel", ""); |
| 440 | if (auto icon = widget->fetchChild<ImageWidget>("moneyIcon")) |
nothing calls this directly
no test coverage detected