MCPcopy Create free account
hub / github.com/OpenApoc/OpenApoc / updateProgressInfo

Method updateProgressInfo

game/ui/base/researchscreen.cpp:429–518  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

427}
428
429void ResearchScreen::updateProgressInfo()
430{
431 if (this->viewFacility && this->viewFacility->lab->current_project)
432 {
433 auto &topic = this->viewFacility->lab->current_project;
434 auto progressBar = form->findControlTyped<Graphic>("GRAPHIC_PROGRESS_BAR");
435 auto progressImage = mksp<RGBImage>(progressBar->Size);
436 float projectProgress = 0.0f;
437 switch (this->viewFacility->lab->current_project->type)
438 {
439 case ResearchTopic::Type::BioChem:
440 case ResearchTopic::Type::Physics:
441 projectProgress = clamp(static_cast<float>(topic->man_hours_progress) /
442 static_cast<float>(topic->man_hours),
443 0.0f, 1.0f);
444 break;
445 case ResearchTopic::Type::Engineering:
446 projectProgress =
447 clamp(static_cast<float>(
448 this->viewFacility->lab->manufacture_man_hours_invested +
449 topic->man_hours * this->viewFacility->lab->manufacture_done) /
450 static_cast<float>(topic->man_hours *
451 this->viewFacility->lab->manufacture_goal),
452 0.0f, 1.0f);
453 break;
454 default:
455 LogError("Unknown lab type");
456 break;
457 }
458 // This creates an image with the size of the PROGRESS_BAR control, then fills
459 // up a proportion of it with red pixels (starting from the left) corresponding
460 // to the progress of the project.
461 int redWidth = progressBar->Size.x * projectProgress;
462 {
463 RGBImageLock l(progressImage);
464 for (int y = 0; y < progressBar->Size.y; y++)
465 {
466 for (int x = 0; x < redWidth; x++)
467 {
468 l.set({x, y}, {255, 0, 0, 255});
469 }
470 }
471 }
472 progressBar->setImage(progressImage);
473 auto topicTitle = form->findControlTyped<Label>("TEXT_CURRENT_PROJECT");
474 topicTitle->setText(tr(topic->name));
475 auto completionPercent = form->findControlTyped<Label>("TEXT_PROJECT_COMPLETION");
476 auto completionText = format(tr("%d%%"), static_cast<int>(projectProgress * 100.0f));
477 completionPercent->setText(completionText);
478 }
479 else
480 {
481 auto progressBar = form->findControlTyped<Graphic>("GRAPHIC_PROGRESS_BAR");
482 progressBar->setImage(nullptr);
483 auto topicTitle = form->findControlTyped<Label>("TEXT_CURRENT_PROJECT");
484 topicTitle->setText(tr("No Project"));
485 auto completionPercent = form->findControlTyped<Label>("TEXT_PROJECT_COMPLETION");
486 completionPercent->setText("");

Callers 1

eventOccurredMethod · 0.95

Calls 9

clampFunction · 0.85
trFunction · 0.85
formatFunction · 0.85
getQuantityMethod · 0.80
setMethod · 0.45
setImageMethod · 0.45
setTextMethod · 0.45
setVisibleMethod · 0.45
setValueMethod · 0.45

Tested by

no test coverage detected