| 230 | } |
| 231 | |
| 232 | void CraftingPane::update(float dt) { |
| 233 | // shut down if we can't reach the table anymore. |
| 234 | if (m_sourceEntityId != NullEntityId) { |
| 235 | auto sourceEntity = as<TileEntity>(m_worldClient->entity(m_sourceEntityId)); |
| 236 | if (!sourceEntity || !m_worldClient->playerCanReachEntity(m_sourceEntityId) || !sourceEntity->isInteractive()) { |
| 237 | dismiss(); |
| 238 | return; |
| 239 | } |
| 240 | } |
| 241 | |
| 242 | // similarly if the player is dead |
| 243 | if (m_player->isDead()) { |
| 244 | dismiss(); |
| 245 | return; |
| 246 | } |
| 247 | |
| 248 | // has the selected recipe changed ? |
| 249 | bool changedHighlight = (m_displayedRecipe != m_guiList->selectedItem()); |
| 250 | |
| 251 | if (changedHighlight) { |
| 252 | stopCrafting(); // TODO: allow viewing other recipes without interrupting crafting |
| 253 | |
| 254 | m_displayedRecipe = m_guiList->selectedItem(); |
| 255 | countTextChanged(); |
| 256 | |
| 257 | auto recipe = recipeFromSelectedWidget(); |
| 258 | |
| 259 | if (recipe.isNull()) { |
| 260 | fetchChild<Widget>("description")->removeAllChildren(); |
| 261 | } else { |
| 262 | auto description = fetchChild<Widget>("description"); |
| 263 | description->removeAllChildren(); |
| 264 | |
| 265 | auto item = Root::singleton().itemDatabase()->itemShared(recipe.output); |
| 266 | ItemTooltipBuilder::buildItemDescription(description, item); |
| 267 | } |
| 268 | } |
| 269 | |
| 270 | // crafters gonna craft |
| 271 | while (m_crafting && m_craftTimer.wrapTick()) { |
| 272 | craft(min(m_count, (int)m_settings.getInt("craftCount", 1))); |
| 273 | } |
| 274 | |
| 275 | // update crafting icon, progress and buttons |
| 276 | if (auto currentRecipeIcon = fetchChild<ItemSlotWidget>("currentRecipeIcon")) { |
| 277 | auto recipe = recipeFromSelectedWidget(); |
| 278 | if (recipe.isNull()) { |
| 279 | currentRecipeIcon->setItem(nullptr); |
| 280 | } else { |
| 281 | auto single = recipe.output.singular(); |
| 282 | ItemPtr item = m_itemCache[single]; |
| 283 | currentRecipeIcon->setItem(item); |
| 284 | |
| 285 | if (m_crafting) |
| 286 | currentRecipeIcon->setProgress(1.0f - m_craftTimer.percent()); |
| 287 | else |
| 288 | currentRecipeIcon->setProgress(1.0f); |
| 289 | } |
nothing calls this directly
no test coverage detected