MCPcopy Create free account
hub / github.com/OpenLoco/OpenLoco / populateCompanySelect

Function populateCompanySelect

src/OpenLoco/src/Ui/Dropdown.cpp:915–977  ·  view source on GitHub ↗

0x004CF2B3

Source from the content-addressed store, hash-verified

913
914 // 0x004CF2B3
915 void populateCompanySelect(Window* window, Widget* widget)
916 {
917 std::array<bool, 16> companyOrdered = {};
918
919 CompanyId companyId = CompanyId::null;
920
921 size_t index = 0;
922 for (; index < Limits::kMaxCompanies; index++)
923 {
924 int16_t maxPerformanceIndex = -1;
925 for (const auto& company : CompanyManager::companies())
926 {
927 if (companyOrdered[enumValue(company.id())] & 1)
928 {
929 continue;
930 }
931
932 if (maxPerformanceIndex < company.performanceIndex)
933 {
934 maxPerformanceIndex = company.performanceIndex;
935 companyId = company.id();
936 }
937 }
938
939 if (maxPerformanceIndex == -1)
940 {
941 break;
942 }
943
944 companyOrdered[enumValue(companyId)] |= 1;
945 _dropdownItemFormats[index] = StringIds::dropdown_company_select;
946 _menuOptions[index] = enumValue(companyId);
947
948 auto company = CompanyManager::get(companyId);
949 auto competitorObj = ObjectManager::get<CompetitorObject>(company->competitorId);
950 auto ownerEmotion = company->ownerEmotion;
951 auto imageId = competitorObj->images[enumValue(ownerEmotion)];
952 imageId = Gfx::recolour(imageId, company->mainColours.primary);
953
954 add(index, StringIds::dropdown_company_select, { imageId, company->name });
955 }
956 auto x = widget->left + window->x;
957 auto y = widget->top + window->y;
958 auto colour = window->getColour(widget->windowColour).translucent();
959
960 showText(x, y, widget->width(), widget->height(), 25, colour, index, (1 << 6));
961
962 size_t highlightedIndex = 0;
963
964 while (enumValue(window->owner) != _menuOptions[highlightedIndex])
965 {
966 highlightedIndex++;
967
968 if (highlightedIndex > Limits::kMaxCompanies)
969 {
970 highlightedIndex = std::numeric_limits<size_t>::max();
971 break;
972 }

Callers 4

onMouseDownFunction · 0.85
onMouseDownFunction · 0.85
onMouseDownFunction · 0.85
onMouseDownFunction · 0.85

Calls 12

companiesFunction · 0.85
enumValueFunction · 0.85
recolourFunction · 0.85
showTextFunction · 0.85
setHighlightedItemFunction · 0.85
translucentMethod · 0.80
getColourMethod · 0.80
getFunction · 0.70
addFunction · 0.70
idMethod · 0.45
widthMethod · 0.45
heightMethod · 0.45

Tested by

no test coverage detected