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

Function tooltip

src/OpenLoco/src/Ui/Windows/StationWindow.cpp:480–527  ·  view source on GitHub ↗

0x0048EB4F

Source from the content-addressed store, hash-verified

478
479 // 0x0048EB4F
480 static std::optional<FormatArguments> tooltip(Window& self, WidgetIndex_t widgetIndex, [[maybe_unused]] const WidgetId id)
481 {
482 FormatArguments args{};
483
484 if (widgetIndex == widx::scrollview)
485 {
486 args.push(StringIds::tooltip_scroll_cargo_list);
487 }
488 else if (widgetIndex == widx::status_bar)
489 {
490 // First, find out how wide the 'Accepted:' label is
491 const char* acceptedLabel = StringManager::getString(StringIds::accepted_cargo_separator);
492 const auto font = Gfx::Font::medium_bold;
493 const int16_t labelWidth = Gfx::TextRenderer::getStringWidthNewLined(font, acceptedLabel);
494
495 // Now find out where we're pointing relative to the label
496 const auto mousePos = Input::getMouseLocation();
497 const auto startPos = self.position() + self.widgets[widx::status_bar].position() + Point{ 2, -1 };
498 const auto relPos = mousePos - startPos;
499
500 // Find out which cargo icon we must be pointing at, if any
501 const auto cargoPointedAt = (relPos.x - labelWidth) / 12;
502 auto* station = StationManager::get(StationId(self.number));
503 auto cargoIndex = 0;
504 for (uint32_t cargoId = 0; cargoId < kMaxCargoStats; cargoId++)
505 {
506 auto& stats = station->cargoStats[cargoId];
507 if (!stats.isAccepted())
508 {
509 continue;
510 }
511
512 if (cargoIndex != cargoPointedAt)
513 {
514 cargoIndex++;
515 continue;
516 }
517
518 auto* cargoObj = ObjectManager::get<CargoObject>(cargoId);
519 args.push(cargoObj->name);
520 return args;
521 }
522
523 return std::nullopt;
524 }
525
526 return args;
527 }
528
529 // 0x0048E986
530 static void drawScroll(Window& self, Gfx::DrawingContext& drawingCtx, [[maybe_unused]] const uint32_t scrollIndex)

Callers

nothing calls this directly

Calls 8

getStringFunction · 0.85
getStringWidthNewLinedFunction · 0.85
getMouseLocationFunction · 0.85
StationIdEnum · 0.85
isAcceptedMethod · 0.80
getFunction · 0.50
pushMethod · 0.45
positionMethod · 0.45

Tested by

no test coverage detected